nrfx_glue.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * 3. Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef NRFX_GLUE_H__
  32. #define NRFX_GLUE_H__
  33. // THIS IS A TEMPLATE FILE.
  34. // It should be copied to a suitable location within the host environment into
  35. // which nrfx is integrated, and the following macros should be provided with
  36. // appropriate implementations.
  37. // And this comment should be removed from the customized file.
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #include <stdbool.h>
  42. #include "nrf.h"
  43. /**
  44. * @defgroup nrfx_glue nrfx_glue.h
  45. * @{
  46. * @ingroup nrfx
  47. *
  48. * @brief This file contains macros that should be implemented according to
  49. * the needs of the host environment into which @em nrfx is integrated.
  50. */
  51. // Uncomment this line to use the standard MDK way of binding IRQ handlers
  52. // at linking time.
  53. #include <soc/nrfx_irqs.h>
  54. //------------------------------------------------------------------------------
  55. /**
  56. * @brief Macro for placing a runtime assertion.
  57. *
  58. * @param expression Expression to be evaluated.
  59. */
  60. #define NRFX_ASSERT(expression)
  61. /**
  62. * @brief Macro for placing a compile time assertion.
  63. *
  64. * @param expression Expression to be evaluated.
  65. */
  66. #define NRFX_STATIC_ASSERT(expression)
  67. //------------------------------------------------------------------------------
  68. /**
  69. * @brief Macro for setting the priority of a specific IRQ.
  70. *
  71. * @param irq_number IRQ number.
  72. * @param priority Priority to be set.
  73. */
  74. #define NRFX_IRQ_PRIORITY_SET(irq_number, priority) NVIC_SetPriority(irq_number, priority)
  75. /**
  76. * @brief Macro for enabling a specific IRQ.
  77. *
  78. * @param irq_number IRQ number.
  79. */
  80. #define NRFX_IRQ_ENABLE(irq_number) NVIC_EnableIRQ(irq_number)
  81. /**
  82. * @brief Macro for checking if a specific IRQ is enabled.
  83. *
  84. * @param irq_number IRQ number.
  85. *
  86. * @retval true If the IRQ is enabled.
  87. * @retval false Otherwise.
  88. */
  89. #define NRFX_IRQ_IS_ENABLED(irq_number) _NRFX_IRQ_IS_ENABLED(irq_number)
  90. static inline bool _NRFX_IRQ_IS_ENABLED(IRQn_Type irq_number)
  91. {
  92. return 0 != (NVIC->ISER[irq_number / 32] & (1UL << (irq_number % 32)));
  93. }
  94. /**
  95. * @brief Macro for disabling a specific IRQ.
  96. *
  97. * @param irq_number IRQ number.
  98. */
  99. #define NRFX_IRQ_DISABLE(irq_number) _NRFX_IRQ_DISABLE(irq_number)
  100. static inline void _NRFX_IRQ_DISABLE(IRQn_Type irq_number)
  101. {
  102. NVIC_DisableIRQ(irq_number);
  103. }
  104. /**
  105. * @brief Macro for setting a specific IRQ as pending.
  106. *
  107. * @param irq_number IRQ number.
  108. */
  109. #define NRFX_IRQ_PENDING_SET(irq_number)
  110. /**
  111. * @brief Macro for clearing the pending status of a specific IRQ.
  112. *
  113. * @param irq_number IRQ number.
  114. */
  115. #define NRFX_IRQ_PENDING_CLEAR(irq_number)
  116. /**
  117. * @brief Macro for checking the pending status of a specific IRQ.
  118. *
  119. * @retval true If the IRQ is pending.
  120. * @retval false Otherwise.
  121. */
  122. #define NRFX_IRQ_IS_PENDING(irq_number)
  123. /** @brief Macro for entering into a critical section. */
  124. #define NRFX_CRITICAL_SECTION_ENTER()
  125. /** @brief Macro for exiting from a critical section. */
  126. #define NRFX_CRITICAL_SECTION_EXIT()
  127. //------------------------------------------------------------------------------
  128. /**
  129. * @brief When set to a non-zero value, this macro specifies that
  130. * @ref nrfx_coredep_delay_us uses a precise DWT-based solution.
  131. * A compilation error is generated if the DWT unit is not present
  132. * in the SoC used.
  133. */
  134. #define NRFX_DELAY_DWT_BASED 0
  135. /**
  136. * @brief Macro for delaying the code execution for at least the specified time.
  137. *
  138. * @param us_time Number of microseconds to wait.
  139. */
  140. #define NRFX_DELAY_US(us_time)
  141. //------------------------------------------------------------------------------
  142. /** @brief Atomic 32-bit unsigned type. */
  143. #define nrfx_atomic_t
  144. /**
  145. * @brief Macro for storing a value to an atomic object and returning its previous value.
  146. *
  147. * @param[in] p_data Atomic memory pointer.
  148. * @param[in] value Value to store.
  149. *
  150. * @return Previous value of the atomic object.
  151. */
  152. #define NRFX_ATOMIC_FETCH_STORE(p_data, value)
  153. /**
  154. * @brief Macro for running a bitwise OR operation on an atomic object and returning its previous value.
  155. *
  156. * @param[in] p_data Atomic memory pointer.
  157. * @param[in] value Value of the second operand in the OR operation.
  158. *
  159. * @return Previous value of the atomic object.
  160. */
  161. #define NRFX_ATOMIC_FETCH_OR(p_data, value)
  162. /**
  163. * @brief Macro for running a bitwise AND operation on an atomic object
  164. * and returning its previous value.
  165. *
  166. * @param[in] p_data Atomic memory pointer.
  167. * @param[in] value Value of the second operand in the AND operation.
  168. *
  169. * @return Previous value of the atomic object.
  170. */
  171. #define NRFX_ATOMIC_FETCH_AND(p_data, value)
  172. /**
  173. * @brief Macro for running a bitwise XOR operation on an atomic object
  174. * and returning its previous value.
  175. *
  176. * @param[in] p_data Atomic memory pointer.
  177. * @param[in] value Value of the second operand in the XOR operation.
  178. *
  179. * @return Previous value of the atomic object.
  180. */
  181. #define NRFX_ATOMIC_FETCH_XOR(p_data, value)
  182. /**
  183. * @brief Macro for running an addition operation on an atomic object
  184. * and returning its previous value.
  185. *
  186. * @param[in] p_data Atomic memory pointer.
  187. * @param[in] value Value of the second operand in the ADD operation.
  188. *
  189. * @return Previous value of the atomic object.
  190. */
  191. #define NRFX_ATOMIC_FETCH_ADD(p_data, value)
  192. /**
  193. * @brief Macro for running a subtraction operation on an atomic object
  194. * and returning its previous value.
  195. *
  196. * @param[in] p_data Atomic memory pointer.
  197. * @param[in] value Value of the second operand in the SUB operation.
  198. *
  199. * @return Previous value of the atomic object.
  200. */
  201. #define NRFX_ATOMIC_FETCH_SUB(p_data, value)
  202. //------------------------------------------------------------------------------
  203. /**
  204. * @brief When set to a non-zero value, this macro specifies that the
  205. * @ref nrfx_error_codes and the @ref nrfx_err_t type itself are defined
  206. * in a customized way and the default definitions from @c <nrfx_error.h>
  207. * should not be used.
  208. */
  209. #define NRFX_CUSTOM_ERROR_CODES 0
  210. //------------------------------------------------------------------------------
  211. /** @brief Bitmask that defines DPPI channels that are reserved for use outside of the nrfx library. */
  212. #define NRFX_DPPI_CHANNELS_USED 0
  213. /** @brief Bitmask that defines DPPI groups that are reserved for use outside of the nrfx library. */
  214. #define NRFX_DPPI_GROUPS_USED 0
  215. /** @brief Bitmask that defines PPI channels that are reserved for use outside of the nrfx library. */
  216. #define NRFX_PPI_CHANNELS_USED 0
  217. /** @brief Bitmask that defines PPI groups that are reserved for use outside of the nrfx library. */
  218. #define NRFX_PPI_GROUPS_USED 0
  219. /** @brief Bitmask that defines EGU instances that are reserved for use outside of the nrfx library. */
  220. #define NRFX_EGUS_USED 0
  221. /** @brief Bitmask that defines TIMER instances that are reserved for use outside of the nrfx library. */
  222. #define NRFX_TIMERS_USED 0
  223. /** @} */
  224. #ifdef __cplusplus
  225. }
  226. #endif
  227. #endif // NRFX_GLUE_H__