nrf21540_defs.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /**
  2. * Copyright (c) 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRF21540_DEFS_H_
  41. #define NRF21540_DEFS_H_
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /**
  46. * @brief Macros creating instance channels number dependent parameters.
  47. */
  48. #define NRF21540_TIMER CONCAT_2(NRF_TIMER, NRF21540_TIMER_NO)
  49. #define NRF21540_TIMER_IRQ_HANDLER CONCAT_3(TIMER, NRF21540_TIMER_NO, _IRQHandler)
  50. #define NRF21540_TIMER_IRQn CONCAT_3(TIMER, NRF21540_TIMER_NO, _IRQn)
  51. #define NRF21540_TIM_INTERRUPT_MASK CONCAT_3(TIMER_INTENSET_COMPARE, \
  52. NRF21540_TIMER_CC_PD_PG_CHANNEL_NO, _Msk)
  53. #if NRF21540_TIMER_CC_START_TO_PDN_UP_CHANNEL_NO == NRF21540_TIMER_CC_PD_PG_CHANNEL_NO
  54. #error These CC channels must be different
  55. #endif
  56. #if (NRF21540_PDN_PPI_CHANNEL_NO == NRF21540_USER_PPI_CHANNEL_NO) || \
  57. (NRF21540_PDN_PPI_CHANNEL_NO == NRF21540_TRX_PPI_CHANNEL_NO) || \
  58. (NRF21540_TRX_PPI_CHANNEL_NO == NRF21540_USER_PPI_CHANNEL_NO)
  59. #error These PPI channels must be different
  60. #endif
  61. #define NRF21540_USER_PPI_CHANNEL CONCAT_2(NRF_PPI_CHANNEL, NRF21540_USER_PPI_CHANNEL_NO)
  62. #define NRF21540_PDN_PPI_CHANNEL CONCAT_2(NRF_PPI_CHANNEL, NRF21540_PDN_PPI_CHANNEL_NO)
  63. #define NRF21540_TRX_PPI_CHANNEL CONCAT_2(NRF_PPI_CHANNEL, NRF21540_TRX_PPI_CHANNEL_NO)
  64. #define NRF21540_USER_PPI_CHANNEL CONCAT_2(NRF_PPI_CHANNEL, NRF21540_USER_PPI_CHANNEL_NO)
  65. #define NRF21540_PDN_PPI_CHANNEL CONCAT_2(NRF_PPI_CHANNEL, NRF21540_PDN_PPI_CHANNEL_NO)
  66. #define NRF21540_TRX_PPI_CHANNEL CONCAT_2(NRF_PPI_CHANNEL, NRF21540_TRX_PPI_CHANNEL_NO)
  67. #define NRF21540_TIMER_CC_FINISHED_CHANNEL_STOP_MASK CONCAT_3(NRF_TIMER_SHORT_COMPARE, NRF21540_TIMER_CC_PD_PG_CHANNEL_NO, _STOP_MASK)
  68. #define NRF21540_TIMER_CC_FINISHED_CHANNEL_CLEAR_MASK CONCAT_3(NRF_TIMER_SHORT_COMPARE, NRF21540_TIMER_CC_PD_PG_CHANNEL_NO, _CLEAR_MASK)
  69. #define NRF21540_TIMER_CC_START_TO_PDN_UP_CHANNEL CONCAT_2(NRF_TIMER_CC_CHANNEL, NRF21540_TIMER_CC_START_TO_PDN_UP_CHANNEL_NO)
  70. #define NRF21540_TIMER_CC_PD_PG_CHANNEL CONCAT_2(NRF_TIMER_CC_CHANNEL, NRF21540_TIMER_CC_PD_PG_CHANNEL_NO)
  71. #define NRF21540_TIMER_CC_TRX_PG_CHANNEL NRF21540_TIMER_CC_PD_PG_CHANNEL
  72. #define NRF21540_TIMER_CC_START_TO_PDN_UP_EVENT CONCAT_2(NRF_TIMER_EVENT_COMPARE, NRF21540_TIMER_CC_START_TO_PDN_UP_CHANNEL_NO)
  73. #define NRF21540_TIMER_CC_PD_PG_EVENT CONCAT_2(NRF_TIMER_EVENT_COMPARE, NRF21540_TIMER_CC_PD_PG_CHANNEL_NO)
  74. #define NRF21540_TIMER_CC_TRX_PG_EVENT NRF21540_TIMER_CC_PD_PG_EVENT
  75. #if (NRF21540_PDN_GPIOTE_CHANNEL_NO == NRF21540_PA_GPIOTE_CHANNEL_NO) || \
  76. (NRF21540_PDN_GPIOTE_CHANNEL_NO == NRF21540_LNA_GPIOTE_CHANNEL_NO) || \
  77. (NRF21540_LNA_GPIOTE_CHANNEL_NO == NRF21540_PA_GPIOTE_CHANNEL_NO)
  78. #error These GPIOTE channels must be different
  79. #endif
  80. #define NRF21540_PDN_GPIOTE_TASK_CLR CONCAT_2(NRF_GPIOTE_TASKS_CLR_, NRF21540_PDN_GPIOTE_CHANNEL_NO)
  81. #define NRF21540_LNA_GPIOTE_TASK_CLR CONCAT_2(NRF_GPIOTE_TASKS_CLR_, NRF21540_LNA_GPIOTE_CHANNEL_NO)
  82. #define NRF21540_PA_GPIOTE_TASK_CLR CONCAT_2(NRF_GPIOTE_TASKS_CLR_, NRF21540_PA_GPIOTE_CHANNEL_NO)
  83. #define NRF21540_PDN_GPIOTE_TASK_SET CONCAT_2(NRF_GPIOTE_TASKS_SET_, NRF21540_PDN_GPIOTE_CHANNEL_NO)
  84. #define NRF21540_LNA_GPIOTE_TASK_SET CONCAT_2(NRF_GPIOTE_TASKS_SET_, NRF21540_LNA_GPIOTE_CHANNEL_NO)
  85. #define NRF21540_PA_GPIOTE_TASK_SET CONCAT_2(NRF_GPIOTE_TASKS_SET_, NRF21540_PA_GPIOTE_CHANNEL_NO)
  86. #define NRF21540_GPIO_TASK_SET(channel) CONCAT_2(NRF_GPIOTE_TASKS_SET_, channel)
  87. #define NRF21540_GPIO_TASK_CLR(channel) CONCAT_2(NRF_GPIOTE_TASKS_CLR_, channel)
  88. #if !NRF21540_DO_NOT_USE_NATIVE_RADIO_IRQ_HANDLER
  89. #define NRF21540_RADIO_IRQ_HANDLER RADIO_IRQHandler
  90. #define NRF21540_RADIO_IRQn RADIO_IRQn
  91. #define NRF21540_RADIO_READY_Msk RADIO_INTENSET_READY_Msk
  92. #define NRF21540_RADIO_EVENT_READY NRF_RADIO_EVENT_READY
  93. #define NRF21540_RADIO_DISABLED_Msk RADIO_INTENSET_DISABLED_Msk
  94. #define NRF21540_RADIO_EVENT_DISABLED NRF_RADIO_EVENT_DISABLED
  95. #else
  96. #if (NRF21540_USER_PPI_CHANNEL_NO == NRF21540_RADIO_READY_TO_EGU_PPI_CHANNEL_NO) || \
  97. (NRF21540_PDN_PPI_CHANNEL_NO == NRF21540_RADIO_READY_TO_EGU_PPI_CHANNEL_NO) || \
  98. (NRF21540_TRX_PPI_CHANNEL_NO == NRF21540_RADIO_READY_TO_EGU_PPI_CHANNEL_NO) || \
  99. (NRF21540_USER_PPI_CHANNEL_NO == NRF21540_RADIO_DISABLED_TO_EGU_PPI_CHANNEL_NO) || \
  100. (NRF21540_PDN_PPI_CHANNEL_NO == NRF21540_RADIO_DISABLED_TO_EGU_PPI_CHANNEL_NO) || \
  101. (NRF21540_TRX_PPI_CHANNEL_NO == NRF21540_RADIO_DISABLED_TO_EGU_PPI_CHANNEL_NO) || \
  102. (NRF21540_RADIO_READY_TO_EGU_PPI_CHANNEL_NO == NRF21540_RADIO_DISABLED_TO_EGU_PPI_CHANNEL_NO)
  103. #error These PPI channels must be different
  104. #endif
  105. #if (NRF21540_RADIO_READY_EGU_CHANNEL_NO == NRF21540_RADIO_DISABLED_EGU_CHANNEL_NO)
  106. #error These EGU channels must be different
  107. #endif
  108. #define NRF21540_EGU CONCAT_2(NRF_EGU, NRF21540_EGU_NO)
  109. #define SWIx_EGU CONCAT_3(SWI, NRF21540_EGU_NO, _EGU)
  110. #define NRF21540_RADIO_IRQ_HANDLER CONCAT_3(SWIx_EGU, NRF21540_EGU_NO, _IRQHandler)
  111. #define NRF21540_RADIO_IRQn CONCAT_3(SWIx_EGU, NRF21540_EGU_NO, _IRQn)
  112. #define NRF21540_RADIO_READY_Msk (1 << NRF21540_RADIO_READY_EGU_CHANNEL_NO)
  113. #define NRF21540_RADIO_DISABLED_Msk (1 << NRF21540_RADIO_DISABLED_EGU_CHANNEL_NO)
  114. #define NRF21540_RADIO_EVENT_READY CONCAT_2(NRF_EGU_EVENT_TRIGGERED, NRF21540_RADIO_READY_EGU_CHANNEL_NO)
  115. #define NRF21540_RADIO_EVENT_DISABLED CONCAT_2(NRF_EGU_EVENT_TRIGGERED, NRF21540_RADIO_DISABLED_EGU_CHANNEL_NO)
  116. #define NRF21540_RADIO_READY_EGU_TASK CONCAT_2(NRF_EGU_TASK_TRIGGER, NRF21540_RADIO_READY_EGU_CHANNEL_NO)
  117. #define NRF21540_RADIO_DISABLED_EGU_TASK CONCAT_2(NRF_EGU_TASK_TRIGGER, NRF21540_RADIO_DISABLED_EGU_CHANNEL_NO)
  118. #define NRF21540_RADIO_READY_TO_EGU_PPI_CHANNEL CONCAT_2(NRF_PPI_CHANNEL, NRF21540_RADIO_READY_TO_EGU_PPI_CHANNEL_NO)
  119. #define NRF21540_RADIO_DISABLED_TO_EGU_PPI_CHANNEL CONCAT_2(NRF_PPI_CHANNEL, NRF21540_RADIO_DISABLED_TO_EGU_PPI_CHANNEL_NO)
  120. #endif //!NRF21540_DO_NOT_USE_NATIVE_RADIO_IRQ_HANDLER
  121. #define NRF21540_RADIO_INTERRUPT_MASK (NRF21540_RADIO_READY_Msk | NRF21540_RADIO_DISABLED_Msk)
  122. /**@brief Time in microseconds when PA GPIO is activated before the radio is ready for
  123. * transmission.
  124. */
  125. #define NRF21540_PA_PG_TRX_TIME_US 13
  126. /**@brief Time in microseconds when LNA GPIO is activated before the radio is ready for
  127. * reception.
  128. */
  129. #define NRF21540_LNA_PG_TRX_TIME_US 13
  130. /**@brief The time between activating the PDN and asserting the RX_EN/TX_EN.
  131. */
  132. #define NRF21540_PD_PG_TIME_US 18
  133. /**@brief The time between deasserting the RX_EN/TX_EN and deactivating PDN.
  134. */
  135. #define NRF21540_TRX_PG_TIME_US 5
  136. /**@brief Timing definitions for radio peripheral on nRF uc.
  137. */
  138. #define TX_FAST_RAMP_UP_TIME 40 ///< Radio fast ramp up time in us for tx
  139. #define RX_FAST_RAMP_UP_TIME 40 ///< Radio fast ramp up time in us for rx
  140. #define TX_RAMP_UP_TIME 130 ///< Radio normal ramp up time in us for tx
  141. #define RX_RAMP_UP_TIME 130 ///< Radio normal ramp up time in us for rx
  142. #if (TX_RAMP_UP_TIME == RX_RAMP_UP_TIME && TX_FAST_RAMP_UP_TIME == RX_FAST_RAMP_UP_TIME)
  143. #define FAST_RAMP_UP_TIME TX_FAST_RAMP_UP_TIME
  144. #define RAMP_UP_TIME TX_RAMP_UP_TIME
  145. #else
  146. #error ramp up times for rx and tx direction are different. Driver needs rework
  147. #endif
  148. #if (FAST_RAMP_UP_TIME < (NRF21540_PA_PG_TRX_TIME_US + NRF21540_PD_PG_TIME_US))
  149. #error fast ramp up time must be greater or equal than (TPD->PG + TPG->TRX)
  150. #endif
  151. #if (FAST_RAMP_UP_TIME > RAMP_UP_TIME)
  152. #error fast ramp up time connot be greater than ramp up time
  153. #endif
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif // NRF21540_DEFS_H_