port.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*! ----------------------------------------------------------------------------
  2. * @file port.c
  3. * @brief HW specific definitions and functions for portability
  4. *
  5. * @attention
  6. *
  7. * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
  8. *
  9. * All rights reserved.
  10. *
  11. * @author DecaWave
  12. */
  13. #include "bsp.h"
  14. #include "compiler.h"
  15. #include "port.h"
  16. /**
  17. * @brief Checks whether the specified EXTI line is enabled or not.
  18. * @param EXTI_Line: specifies the EXTI line to check.
  19. * This parameter can be:
  20. * @arg EXTI_Linex: External interrupt line x where x(0..19)
  21. * @retval The "enable" state of EXTI_Line (SET or RESET).
  22. */
  23. ITStatus EXTI_GetITEnStatus(uint32_t EXTI_Line)
  24. {
  25. ITStatus bitstatus = RESET;
  26. uint32_t enablestatus = 0;
  27. /* Check the parameters */
  28. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  29. enablestatus = EXTI->IMR & EXTI_Line;
  30. if (enablestatus != (uint32_t)RESET)
  31. {
  32. bitstatus = SET;
  33. }
  34. else
  35. {
  36. bitstatus = RESET;
  37. }
  38. return bitstatus;
  39. }
  40. void reset_DW1000(void)
  41. {
  42. port_SPIx_RST_clear();
  43. Sleep(2);
  44. port_SPIx_RST_set();
  45. Sleep(3);
  46. }
  47. /*
  48. * RST irq
  49. * When reset, this PIN is pulled down by DW1000, then rising up
  50. */
  51. void setup_DW1000RSTnIRQ(int enable)
  52. {
  53. GPIO_InitTypeDef GPIO_InitStruct;
  54. DWM_RST_CLK_ENABLE();
  55. if(enable) //Enable RST irq
  56. {
  57. GPIO_InitStruct.Pin = DWM_RST_PIN;
  58. //MP IRQ polarity is high by default
  59. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  60. //IRQ pin should be Pull Down to prevent unnecessary EXT IRQ while DW1000 goes to sleep mode
  61. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  62. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  63. GPIO_InitStruct.Alternate = 0;
  64. HAL_GPIO_Init(DWM_RST_PORT, &GPIO_InitStruct);
  65. HAL_NVIC_SetPriority(DWM_RST_IRQ, DWM_RST_PRIORITY, 0);
  66. HAL_NVIC_EnableIRQ(DWM_RST_IRQ);
  67. }
  68. else
  69. {
  70. GPIO_InitStruct.Pin = DWM_RST_PIN;
  71. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  72. GPIO_InitStruct.Pull = GPIO_PULLDOWN;//Keep pulldown
  73. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  74. GPIO_InitStruct.Alternate = 0;
  75. HAL_GPIO_Init(DWM_RST_PORT, &GPIO_InitStruct);
  76. HAL_NVIC_DisableIRQ(DWM_RST_IRQ);
  77. }
  78. }
  79. void setup_DW1000RSTnPin(uint8_t input)
  80. {
  81. GPIO_InitTypeDef GPIO_InitStruct;
  82. DWM_RST_CLK_ENABLE();
  83. GPIO_InitStruct.Pin = DWM_RST_PIN;
  84. if(input)
  85. {
  86. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  87. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  88. //GPIO_InitStruct.Pull = GPIO_PULLUP;
  89. }
  90. else
  91. {
  92. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  93. //GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  94. //GPIO_InitStruct.Pull = GPIO_PULLUP;
  95. GPIO_InitStruct.Pull = GPIO_NOPULL;
  96. }
  97. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  98. GPIO_InitStruct.Alternate = 0;
  99. HAL_GPIO_Init(DWM_RST_PORT, &GPIO_InitStruct);
  100. }
  101. uint32_t read_DW1000RstnPin(void)
  102. {
  103. return HAL_GPIO_ReadPin(DWM_RST_PORT, DWM_RST_PIN);
  104. }
  105. void write_DW1000RstnPin(uint8_t pin)
  106. {
  107. if(pin)
  108. {
  109. HAL_GPIO_WritePin(DWM_RST_PORT, DWM_RST_PIN, GPIO_PIN_SET);
  110. }
  111. else
  112. {
  113. HAL_GPIO_WritePin(DWM_RST_PORT, DWM_RST_PIN, GPIO_PIN_RESET);
  114. }
  115. }
  116. int is_IRQ_enabled(void)
  117. {
  118. return (( NVIC->ISER[((uint32_t)(DWM_IRQ_EXTI) >> 5)]
  119. & (uint32_t)(0x01 << (DWM_IRQ_EXTI & (uint8_t)0x1F)) ) ? 1 : 0) ;
  120. }