nrfx_glue.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /**
  2. * Copyright (c) 2017 - 2018, 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 NRFX_GLUE_H__
  41. #define NRFX_GLUE_H__
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /**
  46. * @defgroup nrfx_glue nrfx_glue.h
  47. * @{
  48. * @ingroup nrfx
  49. *
  50. * @brief This file contains macros that should be implemented according to
  51. * the needs of the host environment into which @em nrfx is integrated.
  52. */
  53. #include <legacy/apply_old_config.h>
  54. #include <soc/nrfx_irqs.h>
  55. //------------------------------------------------------------------------------
  56. #include <nrf_assert.h>
  57. /**
  58. * @brief Macro for placing a runtime assertion.
  59. *
  60. * @param expression Expression to evaluate.
  61. */
  62. #define NRFX_ASSERT(expression) ASSERT(expression)
  63. #include <app_util.h>
  64. /**
  65. * @brief Macro for placing a compile time assertion.
  66. *
  67. * @param expression Expression to evaluate.
  68. */
  69. #define NRFX_STATIC_ASSERT(expression) STATIC_ASSERT(expression)
  70. //------------------------------------------------------------------------------
  71. #ifdef NRF51
  72. #ifdef SOFTDEVICE_PRESENT
  73. #define INTERRUPT_PRIORITY_IS_VALID(pri) (((pri) == 1) || ((pri) == 3))
  74. #else
  75. #define INTERRUPT_PRIORITY_IS_VALID(pri) ((pri) < 4)
  76. #endif //SOFTDEVICE_PRESENT
  77. #else
  78. #ifdef SOFTDEVICE_PRESENT
  79. #define INTERRUPT_PRIORITY_IS_VALID(pri) ((((pri) > 1) && ((pri) < 4)) || \
  80. (((pri) > 4) && ((pri) < 8)))
  81. #else
  82. #define INTERRUPT_PRIORITY_IS_VALID(pri) ((pri) < 8)
  83. #endif //SOFTDEVICE_PRESENT
  84. #endif //NRF52
  85. /**
  86. * @brief Macro for setting the priority of a specific IRQ.
  87. *
  88. * @param irq_number IRQ number.
  89. * @param priority Priority to set.
  90. */
  91. #define NRFX_IRQ_PRIORITY_SET(irq_number, priority) \
  92. _NRFX_IRQ_PRIORITY_SET(irq_number, priority)
  93. static inline void _NRFX_IRQ_PRIORITY_SET(IRQn_Type irq_number,
  94. uint8_t priority)
  95. {
  96. ASSERT(INTERRUPT_PRIORITY_IS_VALID(priority));
  97. NVIC_SetPriority(irq_number, priority);
  98. }
  99. /**
  100. * @brief Macro for enabling a specific IRQ.
  101. *
  102. * @param irq_number IRQ number.
  103. */
  104. #define NRFX_IRQ_ENABLE(irq_number) _NRFX_IRQ_ENABLE(irq_number)
  105. static inline void _NRFX_IRQ_ENABLE(IRQn_Type irq_number)
  106. {
  107. NVIC_ClearPendingIRQ(irq_number);
  108. NVIC_EnableIRQ(irq_number);
  109. }
  110. /**
  111. * @brief Macro for checking if a specific IRQ is enabled.
  112. *
  113. * @param irq_number IRQ number.
  114. *
  115. * @retval true If the IRQ is enabled.
  116. * @retval false Otherwise.
  117. */
  118. #define NRFX_IRQ_IS_ENABLED(irq_number) _NRFX_IRQ_IS_ENABLED(irq_number)
  119. static inline bool _NRFX_IRQ_IS_ENABLED(IRQn_Type irq_number)
  120. {
  121. return 0 != (NVIC->ISER[irq_number / 32] & (1UL << (irq_number % 32)));
  122. }
  123. /**
  124. * @brief Macro for disabling a specific IRQ.
  125. *
  126. * @param irq_number IRQ number.
  127. */
  128. #define NRFX_IRQ_DISABLE(irq_number) _NRFX_IRQ_DISABLE(irq_number)
  129. static inline void _NRFX_IRQ_DISABLE(IRQn_Type irq_number)
  130. {
  131. NVIC_DisableIRQ(irq_number);
  132. }
  133. /**
  134. * @brief Macro for setting a specific IRQ as pending.
  135. *
  136. * @param irq_number IRQ number.
  137. */
  138. #define NRFX_IRQ_PENDING_SET(irq_number) _NRFX_IRQ_PENDING_SET(irq_number)
  139. static inline void _NRFX_IRQ_PENDING_SET(IRQn_Type irq_number)
  140. {
  141. NVIC_SetPendingIRQ(irq_number);
  142. }
  143. /**
  144. * @brief Macro for clearing the pending status of a specific IRQ.
  145. *
  146. * @param irq_number IRQ number.
  147. */
  148. #define NRFX_IRQ_PENDING_CLEAR(irq_number) _NRFX_IRQ_PENDING_CLEAR(irq_number)
  149. static inline void _NRFX_IRQ_PENDING_CLEAR(IRQn_Type irq_number)
  150. {
  151. NVIC_ClearPendingIRQ(irq_number);
  152. }
  153. /**
  154. * @brief Macro for checking the pending status of a specific IRQ.
  155. *
  156. * @retval true If the IRQ is pending.
  157. * @retval false Otherwise.
  158. */
  159. #define NRFX_IRQ_IS_PENDING(irq_number) _NRFX_IRQ_IS_PENDING(irq_number)
  160. static inline bool _NRFX_IRQ_IS_PENDING(IRQn_Type irq_number)
  161. {
  162. return (NVIC_GetPendingIRQ(irq_number) == 1);
  163. }
  164. #include <nordic_common.h>
  165. #include <app_util_platform.h>
  166. /**
  167. * @brief Macro for entering into a critical section.
  168. */
  169. #define NRFX_CRITICAL_SECTION_ENTER() CRITICAL_REGION_ENTER()
  170. /**
  171. * @brief Macro for exiting from a critical section.
  172. */
  173. #define NRFX_CRITICAL_SECTION_EXIT() CRITICAL_REGION_EXIT()
  174. //------------------------------------------------------------------------------
  175. /**
  176. * @brief When set to a non-zero value, this macro specifies that
  177. * @ref nrfx_coredep_delay_us uses a precise DWT-based solution.
  178. * A compilation error is generated if the DWT unit is not present
  179. * in the SoC used.
  180. */
  181. #define NRFX_DELAY_DWT_BASED 0
  182. #include <soc/nrfx_coredep.h>
  183. #define NRFX_DELAY_US(us_time) nrfx_coredep_delay_us(us_time)
  184. //------------------------------------------------------------------------------
  185. #include <sdk_errors.h>
  186. /**
  187. * @brief When set to a non-zero value, this macro specifies that the
  188. * @ref nrfx_error_codes and the @ref ret_code_t type itself are defined
  189. * in a customized way and the default definitions from @c <nrfx_error.h>
  190. * should not be used.
  191. */
  192. #define NRFX_CUSTOM_ERROR_CODES 1
  193. typedef ret_code_t nrfx_err_t;
  194. #define NRFX_SUCCESS NRF_SUCCESS
  195. #define NRFX_ERROR_INTERNAL NRF_ERROR_INTERNAL
  196. #define NRFX_ERROR_NO_MEM NRF_ERROR_NO_MEM
  197. #define NRFX_ERROR_NOT_SUPPORTED NRF_ERROR_NOT_SUPPORTED
  198. #define NRFX_ERROR_INVALID_PARAM NRF_ERROR_INVALID_PARAM
  199. #define NRFX_ERROR_INVALID_STATE NRF_ERROR_INVALID_STATE
  200. #define NRFX_ERROR_INVALID_LENGTH NRF_ERROR_INVALID_LENGTH
  201. #define NRFX_ERROR_TIMEOUT NRF_ERROR_TIMEOUT
  202. #define NRFX_ERROR_FORBIDDEN NRF_ERROR_FORBIDDEN
  203. #define NRFX_ERROR_NULL NRF_ERROR_NULL
  204. #define NRFX_ERROR_INVALID_ADDR NRF_ERROR_INVALID_ADDR
  205. #define NRFX_ERROR_BUSY NRF_ERROR_BUSY
  206. #define NRFX_ERROR_ALREADY_INITIALIZED NRF_ERROR_MODULE_ALREADY_INITIALIZED
  207. #define NRFX_ERROR_DRV_TWI_ERR_OVERRUN NRF_ERROR_DRV_TWI_ERR_OVERRUN
  208. #define NRFX_ERROR_DRV_TWI_ERR_ANACK NRF_ERROR_DRV_TWI_ERR_ANACK
  209. #define NRFX_ERROR_DRV_TWI_ERR_DNACK NRF_ERROR_DRV_TWI_ERR_DNACK
  210. //------------------------------------------------------------------------------
  211. #include <sdk_resources.h>
  212. /**
  213. * @brief Bitmask defining PPI channels reserved to be used outside of nrfx.
  214. */
  215. #define NRFX_PPI_CHANNELS_USED NRF_PPI_CHANNELS_USED
  216. /**
  217. * @brief Bitmask defining PPI groups reserved to be used outside of nrfx.
  218. */
  219. #define NRFX_PPI_GROUPS_USED NRF_PPI_GROUPS_USED
  220. /**
  221. * @brief Bitmask defining SWI instances reserved to be used outside of nrfx.
  222. */
  223. #define NRFX_SWI_USED NRF_SWI_USED
  224. /**
  225. * @brief Bitmask defining TIMER instances reserved to be used outside of nrfx.
  226. */
  227. #define NRFX_TIMERS_USED NRF_TIMERS_USED
  228. /** @} */
  229. #ifdef __cplusplus
  230. }
  231. #endif
  232. #endif // NRFX_GLUE_H__