nrf_sdh_ble.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. /**@file
  41. *
  42. * @defgroup nrf_sdh_ble BLE support in SoftDevice Handler
  43. * @{
  44. * @ingroup nrf_sdh
  45. * @brief This file contains the declarations of types and functions required for BLE stack
  46. * support.
  47. */
  48. #ifndef NRF_SDH_BLE_H__
  49. #define NRF_SDH_BLE_H__
  50. #include "app_util.h"
  51. #include "ble.h"
  52. #include "nrf_section_iter.h"
  53. #include "sdk_config.h"
  54. #include "sdk_errors.h"
  55. #include <stdint.h>
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. /** @brief Size of the buffer for a BLE event. */
  60. #define NRF_SDH_BLE_EVT_BUF_SIZE BLE_EVT_LEN_MAX(NRF_SDH_BLE_GATT_MAX_MTU_SIZE)
  61. #if !(defined(__LINT__))
  62. /**@brief Macro for registering @ref nrf_sdh_soc_evt_observer_t. Modules that want to be
  63. * notified about SoC events must register the handler using this macro.
  64. *
  65. * @details This macro places the observer in a section named "sdh_soc_observers".
  66. *
  67. * @param[in] _name Observer name.
  68. * @param[in] _prio Priority of the observer event handler.
  69. * The smaller the number, the higher the priority.
  70. * @param[in] _handler BLE event handler.
  71. * @param[in] _context Parameter to the event handler.
  72. * @hideinitializer
  73. */
  74. #define NRF_SDH_BLE_OBSERVER(_name, _prio, _handler, _context) \
  75. STATIC_ASSERT(NRF_SDH_BLE_ENABLED, "NRF_SDH_BLE_ENABLED not set!"); \
  76. STATIC_ASSERT(_prio < NRF_SDH_BLE_OBSERVER_PRIO_LEVELS, "Priority level unavailable."); \
  77. NRF_SECTION_SET_ITEM_REGISTER(sdh_ble_observers, _prio, static nrf_sdh_ble_evt_observer_t _name) = \
  78. { \
  79. .handler = _handler, \
  80. .p_context = _context \
  81. }
  82. /**@brief Macro for registering an array of @ref nrf_sdh_ble_evt_observer_t.
  83. * Modules that want to be notified about SoC events must register the handler using
  84. * this macro.
  85. *
  86. * Each observer's handler will be dispatched an event with its relative context from @p _context.
  87. * This macro places the observer in a section named "sdh_ble_observers".
  88. *
  89. * @param[in] _name Observer name.
  90. * @param[in] _prio Priority of the observer event handler.
  91. * The smaller the number, the higher the priority.
  92. * @param[in] _handler BLE event handler.
  93. * @param[in] _context An array of parameters to the event handler.
  94. * @param[in] _cnt Number of observers to register.
  95. * @hideinitializer
  96. */
  97. #define NRF_SDH_BLE_OBSERVERS(_name, _prio, _handler, _context, _cnt) \
  98. STATIC_ASSERT(NRF_SDH_BLE_ENABLED, "NRF_SDH_BLE_ENABLED not set!"); \
  99. STATIC_ASSERT(_prio < NRF_SDH_BLE_OBSERVER_PRIO_LEVELS, "Priority level unavailable."); \
  100. NRF_SECTION_SET_ITEM_REGISTER(sdh_ble_observers, _prio, static nrf_sdh_ble_evt_observer_t _name[_cnt]) = \
  101. { \
  102. MACRO_REPEAT_FOR(_cnt, HANDLER_SET, _handler, _context) \
  103. }
  104. #if !(defined(DOXYGEN))
  105. #define HANDLER_SET(_idx, _handler, _context) \
  106. { \
  107. .handler = _handler, \
  108. .p_context = _context[_idx], \
  109. },
  110. #endif
  111. #else // __LINT__
  112. /* Swallow semicolons */
  113. /*lint -save -esym(528, *) -esym(529, *) : Symbol not referenced. */
  114. #define NRF_SDH_BLE_OBSERVER(A, B, C, D) static int semicolon_swallow_##A
  115. #define NRF_SDH_BLE_OBSERVERS(A, B, C, D, E) static int semicolon_swallow_##A
  116. /*lint -restore */
  117. #endif
  118. /**@brief BLE stack event handler. */
  119. typedef void (*nrf_sdh_ble_evt_handler_t)(ble_evt_t const * p_ble_evt, void * p_context);
  120. /**@brief BLE event observer. */
  121. typedef struct
  122. {
  123. nrf_sdh_ble_evt_handler_t handler; //!< BLE event handler.
  124. void * p_context; //!< A parameter to the event handler.
  125. } const nrf_sdh_ble_evt_observer_t;
  126. /**@brief Function for retrieving the address of the start of application's RAM.
  127. *
  128. * @param[out] p_app_ram_start Address of the start of application's RAM.
  129. *
  130. * @retval NRF_SUCCESS If the address was successfully retrieved.
  131. * @retval NRF_ERROR_NULL If @p p_app_ram_start was @c NULL.
  132. */
  133. ret_code_t nrf_sdh_ble_app_ram_start_get(uint32_t * p_app_ram_start);
  134. /**@brief Set the default BLE stack configuration.
  135. *
  136. * This function configures the BLE stack with the settings specified in the
  137. * SoftDevice handler BLE configuration. The following configurations will be set:
  138. * - Number of peripheral links
  139. * - Number of central links
  140. * - ATT MTU size (for the given connection)
  141. * - Vendor specific UUID count
  142. * - GATTS Attribute table size
  143. * - Service changed
  144. *
  145. * @param[in] conn_cfg_tag The connection to configure.
  146. * @param[out] p_ram_start Application RAM start address.
  147. */
  148. ret_code_t nrf_sdh_ble_default_cfg_set(uint8_t conn_cfg_tag, uint32_t * p_ram_start);
  149. /**@brief Function for configuring and enabling the BLE stack.
  150. *
  151. * @param[in] p_app_ram_start Address of the start of application's RAM.
  152. */
  153. ret_code_t nrf_sdh_ble_enable(uint32_t * p_app_ram_start);
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif // NRF_SDH_BLE_H__
  158. /** @} */