nrf_sdh_ant.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * Copyright (c) 2017 - 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. /**@file
  41. *
  42. * @defgroup nrf_sdh_ant ANT support in SoftDevice Handler
  43. * @{
  44. * @ingroup nrf_sdh
  45. * @brief This file contains the declarations of types and functions required for ANT stack support.
  46. */
  47. #ifndef NRF_SDH_ANT_H__
  48. #define NRF_SDH_ANT_H__
  49. #include "ant_parameters.h"
  50. #include "app_util.h"
  51. #include "nrf_section_iter.h"
  52. #include "sdk_errors.h"
  53. #include <stdint.h>
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. #define NRF_SDH_ANT_EVT_CHANNEL_FIELD_SIZE 1 //!< Size of the channel field in ANT stack event
  58. #define NRF_SDH_ANT_EVT_EVENT_FIELD_SIZE 1 //!< Size of the event field in ANT stack event
  59. /**@brief Size of the buffer provided to the ANT SoftDevice.
  60. * @hideinitializer
  61. */
  62. #define NRF_SDH_ANT_BUF_SIZE ANT_ENABLE_GET_REQUIRED_SPACE( \
  63. NRF_SDH_ANT_TOTAL_CHANNELS_ALLOCATED, \
  64. NRF_SDH_ANT_ENCRYPTED_CHANNELS, \
  65. NRF_SDH_ANT_BURST_QUEUE_SIZE, \
  66. NRF_SDH_ANT_EVENT_QUEUE_SIZE)
  67. /**@brief Size of the buffer provided to the ANT SoftDevice to receive ANT events. */
  68. #define NRF_SDH_ANT_MESSAGE_SIZE ((CEIL_DIV(MESG_BUFFER_SIZE, sizeof(uint32_t))) * sizeof(uint32_t))
  69. /**@brief Size of the buffer provided to the Events Scheduler to hold ANT events. */
  70. #define NRF_SDH_ANT_EVT_BUF_SIZE ((CEIL_DIV(NRF_SDH_ANT_MESSAGE_SIZE + \
  71. NRF_SDH_ANT_EVT_CHANNEL_FIELD_SIZE + \
  72. NRF_SDH_ANT_EVT_EVENT_FIELD_SIZE, \
  73. sizeof(uint32_t))) * sizeof(uint32_t))
  74. #if !(defined(__LINT__))
  75. /**@brief Macro for registering an ANT observer. Modules that want to be
  76. * notified about ANT events must register the handler using this macro.
  77. *
  78. * @details This macro places the observer in a section named "sdh_ant_observers".
  79. *
  80. * @param[in] _name Observer name.
  81. * @param[in] _prio Priority of the observer event handler.
  82. * The smaller the number, the higher the priority.
  83. * @param[in] _handler ANT event handler.
  84. * @param[in] _context Parameter to the event handler.
  85. * @hideinitializer
  86. */
  87. #define NRF_SDH_ANT_OBSERVER(_name, _prio, _handler, _context) \
  88. STATIC_ASSERT(NRF_SDH_ANT_ENABLED, "NRF_SDH_ANT_ENABLED not set!"); \
  89. STATIC_ASSERT(_prio < NRF_SDH_ANT_OBSERVER_PRIO_LEVELS, "Priority level unavailable."); \
  90. NRF_SECTION_SET_ITEM_REGISTER(sdh_ant_observers, _prio, static nrf_sdh_ant_evt_observer_t _name) = \
  91. { \
  92. .handler = _handler, \
  93. .p_context = _context \
  94. }
  95. /**@brief Macro for registering an array of @ref nrf_sdh_ant_evt_observer_t.
  96. * Modules that want to be notified about ANT events must register the handler using
  97. * this macro.
  98. *
  99. * Each observer's handler will be dispatched an event with its relative context from @p _context.
  100. * This macro places the observer in a section named "sdh_ant_observers".
  101. *
  102. * @param[in] _name Observer name.
  103. * @param[in] _prio Priority of the observer event handler.
  104. * The smaller the number, the higher the priority.
  105. * @param[in] _handler ANT event handler.
  106. * @param[in] _context An array of parameters to the event handler.
  107. * @param[in] _cnt Number of observers to register.
  108. * @hideinitializer
  109. */
  110. #define NRF_SDH_ANT_OBSERVERS(_name, _prio, _handler, _context, _cnt) \
  111. STATIC_ASSERT(NRF_SDH_ANT_ENABLED, "NRF_SDH_ANT_ENABLED not set!"); \
  112. STATIC_ASSERT(_prio < NRF_SDH_ANT_OBSERVER_PRIO_LEVELS, "Priority level unavailable."); \
  113. NRF_SECTION_SET_ITEM_REGISTER(sdh_ant_observers, _prio, static nrf_sdh_ant_evt_observer_t _name[_cnt]) = \
  114. { \
  115. MACRO_REPEAT_FOR(_cnt, HANDLER_SET, _handler, _context) \
  116. }
  117. #if !(defined(DOXYGEN))
  118. #define HANDLER_SET(_idx, _handler, _context) \
  119. { \
  120. .handler = _handler, \
  121. .p_context = _context[_idx], \
  122. },
  123. #endif
  124. #else // __LINT__
  125. /* Swallow semicolons */
  126. /*lint -save -esym(528, *) -esym(529, *) : Symbol not referenced. */
  127. #define NRF_SDH_ANT_OBSERVER(A, B, C, D) static int semicolon_swallow_##A
  128. #define NRF_SDH_ANT_OBSERVERS(A, B, C, D, E) static int semicolon_swallow_##A
  129. /*lint -restore */
  130. #endif
  131. /**@brief ANT stack event. */
  132. typedef struct
  133. {
  134. ANT_MESSAGE message; //!< ANT Message.
  135. uint8_t channel; //!< Channel number.
  136. uint8_t event; //!< Event code.
  137. } ant_evt_t;
  138. /**@brief ANT stack event handler. */
  139. typedef void (*nrf_sdh_ant_evt_handler_t)(ant_evt_t * p_ant_evt, void * p_context);
  140. /**@brief ANT event observer. */
  141. typedef struct
  142. {
  143. nrf_sdh_ant_evt_handler_t handler; //!< ANT event handler.
  144. void * p_context; //!< A parameter to the event handler.
  145. } const nrf_sdh_ant_evt_observer_t;
  146. /**@brief Function for configuring and enabling the ANT stack.
  147. *
  148. * @details The function sets the channel configuration for the stack using the parameters
  149. * provided in the @c sdk_config file. It also assigns a correspondingly large
  150. * buffer as a static resource.
  151. */
  152. ret_code_t nrf_sdh_ant_enable(void);
  153. #ifdef __cplusplus
  154. }
  155. #endif
  156. #endif // NRF_SDH_ANT_H__
  157. /** @} */