nrf_sdh_soc.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * Copyright (c) 2017 - 2019, 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_soc SoC support in SoftDevice Handler
  43. * @{
  44. * @ingroup nrf_sdh
  45. * @brief This file contains the declarations of types and functions required for SoftDevice Handler
  46. * SoC support.
  47. */
  48. #ifndef NRF_SDH_SOC_H__
  49. #define NRF_SDH_SOC_H__
  50. #include "sdk_common.h"
  51. #include "nrf_section_iter.h"
  52. #include "nrf_soc.h"
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. #if !(defined(__LINT__))
  57. /**@brief Macro for registering @ref nrf_sdh_soc_evt_observer_t. Modules that want to be
  58. * notified about SoC events must register the handler using this macro.
  59. *
  60. * @details This macro places the observer in a section named "sdh_soc_observers".
  61. *
  62. * @param[in] _name Observer name.
  63. * @param[in] _prio Priority of the observer event handler.
  64. * The smaller the number, the higher the priority.
  65. * @param[in] _handler SoC event handler.
  66. * @param[in] _context Parameter to the event handler.
  67. * @hideinitializer
  68. */
  69. #define NRF_SDH_SOC_OBSERVER(_name, _prio, _handler, _context) \
  70. STATIC_ASSERT(NRF_SDH_SOC_ENABLED, "NRF_SDH_SOC_ENABLED not set!"); \
  71. STATIC_ASSERT(_prio < NRF_SDH_SOC_OBSERVER_PRIO_LEVELS, "Priority level unavailable."); \
  72. NRF_SECTION_SET_ITEM_REGISTER(sdh_soc_observers, _prio, static nrf_sdh_soc_evt_observer_t _name) = \
  73. { \
  74. .handler = _handler, \
  75. .p_context = _context \
  76. }
  77. /**@brief Macro for registering an array of @ref nrf_sdh_soc_evt_observer_t.
  78. * Modules that want to be notified about SoC events must register the handler using
  79. * this macro.
  80. *
  81. * Each observer's handler will be dispatched an event with its relative context from @p _context.
  82. * This macro places the observer in a section named "sdh_soc_observers".
  83. *
  84. * @param[in] _name Observer name.
  85. * @param[in] _prio Priority of the observer event handler.
  86. * The smaller the number, the higher the priority.
  87. * @param[in] _handler SoC event handler.
  88. * @param[in] _context An array of parameters to the event handler.
  89. * @param[in] _cnt Number of observers to register.
  90. * @hideinitializer
  91. */
  92. #define NRF_SDH_SOC_EVENT_OBSERVERS(_name, _prio, _handler, _context, _cnt) \
  93. STATIC_ASSERT(NRF_SDH_SOC_ENABLED, "NRF_SDH_SOC_ENABLED not set!"); \
  94. STATIC_ASSERT(_prio < NRF_SDH_SOC_OBSERVER_PRIO_LEVELS, "Priority level unavailable."); \
  95. NRF_SECTION_SET_ITEM_REGISTER(sdh_soc_observers, _prio, static nrf_sdh_soc_evt_observer_t _name[_cnt]) = \
  96. { \
  97. MACRO_REPEAT_FOR(_cnt, HANDLER_SET, _handler, _context) \
  98. }
  99. #if !(defined(DOXYGEN))
  100. #define HANDLER_SET(_idx, _handler, _context) \
  101. { \
  102. .handler = _handler, \
  103. .p_context = _context[_idx], \
  104. },
  105. #endif
  106. #else // __LINT__
  107. /* Swallow semicolons */
  108. /*lint -save -esym(528, *) -esym(529, *) : Symbol not referenced. */
  109. #define NRF_SDH_SOC_OBSERVER(A, B, C, D) static int semicolon_swallow_##A
  110. #define NRF_SDH_SOC_OBSERVERS(A, B, C, D, E) static int semicolon_swallow_##A
  111. /*lint -restore */
  112. #endif
  113. /**@brief SoC event handler. */
  114. typedef void (*nrf_sdh_soc_evt_handler_t) (uint32_t evt_id, void * p_context);
  115. /**@brief SoC event observer. */
  116. typedef struct
  117. {
  118. nrf_sdh_soc_evt_handler_t handler; //!< SoC event handler.
  119. void * p_context; //!< A parameter to the event handler.
  120. } const nrf_sdh_soc_evt_observer_t;
  121. #ifdef __cplusplus
  122. }
  123. #endif
  124. #endif // NRF_SDH_SOC_H__
  125. /** @} */