Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
640:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 640:c90ae1400bf2 1 /*
Vincent Coubard 640:c90ae1400bf2 2 * Copyright (c) Nordic Semiconductor ASA
Vincent Coubard 640:c90ae1400bf2 3 * All rights reserved.
Vincent Coubard 640:c90ae1400bf2 4 *
Vincent Coubard 640:c90ae1400bf2 5 * Redistribution and use in source and binary forms, with or without modification,
Vincent Coubard 640:c90ae1400bf2 6 * are permitted provided that the following conditions are met:
Vincent Coubard 640:c90ae1400bf2 7 *
Vincent Coubard 640:c90ae1400bf2 8 * 1. Redistributions of source code must retain the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 9 * list of conditions and the following disclaimer.
Vincent Coubard 640:c90ae1400bf2 10 *
Vincent Coubard 640:c90ae1400bf2 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 12 * list of conditions and the following disclaimer in the documentation and/or
Vincent Coubard 640:c90ae1400bf2 13 * other materials provided with the distribution.
Vincent Coubard 640:c90ae1400bf2 14 *
Vincent Coubard 640:c90ae1400bf2 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
Vincent Coubard 640:c90ae1400bf2 16 * contributors to this software may be used to endorse or promote products
Vincent Coubard 640:c90ae1400bf2 17 * derived from this software without specific prior written permission.
Vincent Coubard 640:c90ae1400bf2 18 *
Vincent Coubard 640:c90ae1400bf2 19 *
Vincent Coubard 640:c90ae1400bf2 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Vincent Coubard 640:c90ae1400bf2 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Vincent Coubard 640:c90ae1400bf2 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Vincent Coubard 640:c90ae1400bf2 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Vincent Coubard 640:c90ae1400bf2 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Vincent Coubard 640:c90ae1400bf2 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Vincent Coubard 640:c90ae1400bf2 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Vincent Coubard 640:c90ae1400bf2 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Vincent Coubard 640:c90ae1400bf2 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Vincent Coubard 640:c90ae1400bf2 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Vincent Coubard 640:c90ae1400bf2 30 *
Vincent Coubard 640:c90ae1400bf2 31 */
Vincent Coubard 640:c90ae1400bf2 32
Vincent Coubard 640:c90ae1400bf2 33 /**
Vincent Coubard 640:c90ae1400bf2 34 @addtogroup BLE_COMMON BLE SoftDevice Common
Vincent Coubard 640:c90ae1400bf2 35 @{
Vincent Coubard 640:c90ae1400bf2 36 @defgroup ble_api Events, type definitions and API calls
Vincent Coubard 640:c90ae1400bf2 37 @{
Vincent Coubard 640:c90ae1400bf2 38
Vincent Coubard 640:c90ae1400bf2 39 @brief Module independent events, type definitions and API calls for the BLE SoftDevice.
Vincent Coubard 640:c90ae1400bf2 40
Vincent Coubard 640:c90ae1400bf2 41 */
Vincent Coubard 640:c90ae1400bf2 42
Vincent Coubard 640:c90ae1400bf2 43 #ifndef BLE_H__
Vincent Coubard 640:c90ae1400bf2 44 #define BLE_H__
Vincent Coubard 640:c90ae1400bf2 45
Vincent Coubard 640:c90ae1400bf2 46 #include "ble_ranges.h"
Vincent Coubard 640:c90ae1400bf2 47 #include "ble_types.h"
Vincent Coubard 640:c90ae1400bf2 48 #include "ble_gap.h"
Vincent Coubard 640:c90ae1400bf2 49 #include "ble_l2cap.h"
Vincent Coubard 640:c90ae1400bf2 50 #include "ble_gatt.h"
Vincent Coubard 640:c90ae1400bf2 51 #include "ble_gattc.h"
Vincent Coubard 640:c90ae1400bf2 52 #include "ble_gatts.h"
Vincent Coubard 640:c90ae1400bf2 53
Vincent Coubard 640:c90ae1400bf2 54 /** @addtogroup BLE_COMMON_ENUMERATIONS Enumerations
Vincent Coubard 640:c90ae1400bf2 55 * @{ */
Vincent Coubard 640:c90ae1400bf2 56
Vincent Coubard 640:c90ae1400bf2 57 /**
Vincent Coubard 640:c90ae1400bf2 58 * @brief Common API SVC numbers.
Vincent Coubard 640:c90ae1400bf2 59 */
Vincent Coubard 640:c90ae1400bf2 60 enum BLE_COMMON_SVCS
Vincent Coubard 640:c90ae1400bf2 61 {
Vincent Coubard 640:c90ae1400bf2 62 SD_BLE_ENABLE = BLE_SVC_BASE, /**< Enable and initialize the BLE stack */
Vincent Coubard 640:c90ae1400bf2 63 SD_BLE_EVT_GET, /**< Get an event from the pending events queue. */
Vincent Coubard 640:c90ae1400bf2 64 SD_BLE_TX_BUFFER_COUNT_GET, /**< Get the total number of available application transmission buffers from the BLE stack. */
Vincent Coubard 640:c90ae1400bf2 65 SD_BLE_UUID_VS_ADD, /**< Add a Vendor Specific UUID. */
Vincent Coubard 640:c90ae1400bf2 66 SD_BLE_UUID_DECODE, /**< Decode UUID bytes. */
Vincent Coubard 640:c90ae1400bf2 67 SD_BLE_UUID_ENCODE, /**< Encode UUID bytes. */
Vincent Coubard 640:c90ae1400bf2 68 SD_BLE_VERSION_GET, /**< Get the local version information (company id, Link Layer Version, Link Layer Subversion). */
Vincent Coubard 640:c90ae1400bf2 69 SD_BLE_USER_MEM_REPLY, /**< User Memory Reply. */
Vincent Coubard 640:c90ae1400bf2 70 SD_BLE_OPT_SET, /**< Set a BLE option. */
Vincent Coubard 640:c90ae1400bf2 71 SD_BLE_OPT_GET, /**< Get a BLE option. */
Vincent Coubard 640:c90ae1400bf2 72 };
Vincent Coubard 640:c90ae1400bf2 73
Vincent Coubard 640:c90ae1400bf2 74 /**
Vincent Coubard 640:c90ae1400bf2 75 * @brief BLE Module Independent Event IDs.
Vincent Coubard 640:c90ae1400bf2 76 */
Vincent Coubard 640:c90ae1400bf2 77 enum BLE_COMMON_EVTS
Vincent Coubard 640:c90ae1400bf2 78 {
Vincent Coubard 640:c90ae1400bf2 79 BLE_EVT_TX_COMPLETE = BLE_EVT_BASE, /**< Transmission Complete. @ref ble_evt_tx_complete_t */
Vincent Coubard 640:c90ae1400bf2 80 BLE_EVT_USER_MEM_REQUEST, /**< User Memory request. @ref ble_evt_user_mem_request_t */
Vincent Coubard 640:c90ae1400bf2 81 BLE_EVT_USER_MEM_RELEASE /**< User Memory release. @ref ble_evt_user_mem_release_t */
Vincent Coubard 640:c90ae1400bf2 82 };
Vincent Coubard 640:c90ae1400bf2 83
Vincent Coubard 640:c90ae1400bf2 84 /**@brief Common Option IDs.
Vincent Coubard 640:c90ae1400bf2 85 * IDs that uniquely identify a common option.
Vincent Coubard 640:c90ae1400bf2 86 */
Vincent Coubard 640:c90ae1400bf2 87 enum BLE_COMMON_OPTS
Vincent Coubard 640:c90ae1400bf2 88 {
Vincent Coubard 640:c90ae1400bf2 89 BLE_COMMON_OPT_RADIO_CPU_MUTEX = BLE_OPT_BASE /**< Radio CPU mutex option. @ref ble_common_opt_radio_cpu_mutex_t */
Vincent Coubard 640:c90ae1400bf2 90 };
Vincent Coubard 640:c90ae1400bf2 91 /** @} */
Vincent Coubard 640:c90ae1400bf2 92
Vincent Coubard 640:c90ae1400bf2 93 /** @addtogroup BLE_COMMON_DEFINES Defines
Vincent Coubard 640:c90ae1400bf2 94 * @{ */
Vincent Coubard 640:c90ae1400bf2 95
Vincent Coubard 640:c90ae1400bf2 96 /** @brief Required pointer alignment for BLE Events.
Vincent Coubard 640:c90ae1400bf2 97 */
Vincent Coubard 640:c90ae1400bf2 98 #define BLE_EVTS_PTR_ALIGNMENT 4
Vincent Coubard 640:c90ae1400bf2 99
Vincent Coubard 640:c90ae1400bf2 100 /** @defgroup BLE_USER_MEM_TYPES User Memory Types
Vincent Coubard 640:c90ae1400bf2 101 * @{ */
Vincent Coubard 640:c90ae1400bf2 102 #define BLE_USER_MEM_TYPE_INVALID 0x00 /**< Invalid User Memory Types. */
Vincent Coubard 640:c90ae1400bf2 103 #define BLE_USER_MEM_TYPE_GATTS_QUEUED_WRITES 0x01 /**< User Memory for GATTS queued writes. */
Vincent Coubard 640:c90ae1400bf2 104 /** @} */
Vincent Coubard 640:c90ae1400bf2 105
Vincent Coubard 640:c90ae1400bf2 106 /** @brief Maximum number of Vendor Specific UUIDs.
Vincent Coubard 640:c90ae1400bf2 107 */
Vincent Coubard 640:c90ae1400bf2 108 #define BLE_UUID_VS_MAX_COUNT 10
Vincent Coubard 640:c90ae1400bf2 109
Vincent Coubard 640:c90ae1400bf2 110 /** @} */
Vincent Coubard 640:c90ae1400bf2 111
Vincent Coubard 640:c90ae1400bf2 112 /** @addtogroup BLE_COMMON_STRUCTURES Structures
Vincent Coubard 640:c90ae1400bf2 113 * @{ */
Vincent Coubard 640:c90ae1400bf2 114
Vincent Coubard 640:c90ae1400bf2 115 /**@brief User Memory Block. */
Vincent Coubard 640:c90ae1400bf2 116 typedef struct
Vincent Coubard 640:c90ae1400bf2 117 {
Vincent Coubard 640:c90ae1400bf2 118 uint8_t *p_mem; /**< Pointer to the start of the user memory block. */
Vincent Coubard 640:c90ae1400bf2 119 uint16_t len; /**< Length in bytes of the user memory block. */
Vincent Coubard 640:c90ae1400bf2 120 } ble_user_mem_block_t;
Vincent Coubard 640:c90ae1400bf2 121
Vincent Coubard 640:c90ae1400bf2 122 /**
Vincent Coubard 640:c90ae1400bf2 123 * @brief Event structure for @ref BLE_EVT_TX_COMPLETE.
Vincent Coubard 640:c90ae1400bf2 124 */
Vincent Coubard 640:c90ae1400bf2 125 typedef struct
Vincent Coubard 640:c90ae1400bf2 126 {
Vincent Coubard 640:c90ae1400bf2 127 uint8_t count; /**< Number of packets transmitted. */
Vincent Coubard 640:c90ae1400bf2 128 } ble_evt_tx_complete_t;
Vincent Coubard 640:c90ae1400bf2 129
Vincent Coubard 640:c90ae1400bf2 130 /**@brief Event structure for @ref BLE_EVT_USER_MEM_REQUEST. */
Vincent Coubard 640:c90ae1400bf2 131 typedef struct
Vincent Coubard 640:c90ae1400bf2 132 {
Vincent Coubard 640:c90ae1400bf2 133 uint8_t type; /**< User memory type, see @ref BLE_USER_MEM_TYPES. */
Vincent Coubard 640:c90ae1400bf2 134 } ble_evt_user_mem_request_t;
Vincent Coubard 640:c90ae1400bf2 135
Vincent Coubard 640:c90ae1400bf2 136 /**@brief Event structure for @ref BLE_EVT_USER_MEM_RELEASE. */
Vincent Coubard 640:c90ae1400bf2 137 typedef struct
Vincent Coubard 640:c90ae1400bf2 138 {
Vincent Coubard 640:c90ae1400bf2 139 uint8_t type; /**< User memory type, see @ref BLE_USER_MEM_TYPES. */
Vincent Coubard 640:c90ae1400bf2 140 ble_user_mem_block_t mem_block; /**< User memory block */
Vincent Coubard 640:c90ae1400bf2 141 } ble_evt_user_mem_release_t;
Vincent Coubard 640:c90ae1400bf2 142
Vincent Coubard 640:c90ae1400bf2 143
Vincent Coubard 640:c90ae1400bf2 144 /**@brief Event structure for events not associated with a specific function module. */
Vincent Coubard 640:c90ae1400bf2 145 typedef struct
Vincent Coubard 640:c90ae1400bf2 146 {
Vincent Coubard 640:c90ae1400bf2 147 uint16_t conn_handle; /**< Connection Handle on which this event occurred. */
Vincent Coubard 640:c90ae1400bf2 148 union
Vincent Coubard 640:c90ae1400bf2 149 {
Vincent Coubard 640:c90ae1400bf2 150 ble_evt_tx_complete_t tx_complete; /**< Transmission Complete. */
Vincent Coubard 640:c90ae1400bf2 151 ble_evt_user_mem_request_t user_mem_request; /**< User Memory Request Event Parameters. */
Vincent Coubard 640:c90ae1400bf2 152 ble_evt_user_mem_release_t user_mem_release; /**< User Memory Release Event Parameters. */
Vincent Coubard 640:c90ae1400bf2 153 } params;
Vincent Coubard 640:c90ae1400bf2 154 } ble_common_evt_t;
Vincent Coubard 640:c90ae1400bf2 155
Vincent Coubard 640:c90ae1400bf2 156 /**@brief BLE Event header. */
Vincent Coubard 640:c90ae1400bf2 157 typedef struct
Vincent Coubard 640:c90ae1400bf2 158 {
Vincent Coubard 640:c90ae1400bf2 159 uint16_t evt_id; /**< Value from a BLE_<module>_EVT series. */
Vincent Coubard 640:c90ae1400bf2 160 uint16_t evt_len; /**< Length in octets excluding this header. */
Vincent Coubard 640:c90ae1400bf2 161 } ble_evt_hdr_t;
Vincent Coubard 640:c90ae1400bf2 162
Vincent Coubard 640:c90ae1400bf2 163 /**@brief Common BLE Event type, wrapping the module specific event reports. */
Vincent Coubard 640:c90ae1400bf2 164 typedef struct
Vincent Coubard 640:c90ae1400bf2 165 {
Vincent Coubard 640:c90ae1400bf2 166 ble_evt_hdr_t header; /**< Event header. */
Vincent Coubard 640:c90ae1400bf2 167 union
Vincent Coubard 640:c90ae1400bf2 168 {
Vincent Coubard 640:c90ae1400bf2 169 ble_common_evt_t common_evt; /**< Common Event, evt_id in BLE_EVT_* series. */
Vincent Coubard 640:c90ae1400bf2 170 ble_gap_evt_t gap_evt; /**< GAP originated event, evt_id in BLE_GAP_EVT_* series. */
Vincent Coubard 640:c90ae1400bf2 171 ble_l2cap_evt_t l2cap_evt; /**< L2CAP originated event, evt_id in BLE_L2CAP_EVT* series. */
Vincent Coubard 640:c90ae1400bf2 172 ble_gattc_evt_t gattc_evt; /**< GATT client originated event, evt_id in BLE_GATTC_EVT* series. */
Vincent Coubard 640:c90ae1400bf2 173 ble_gatts_evt_t gatts_evt; /**< GATT server originated event, evt_id in BLE_GATTS_EVT* series. */
Vincent Coubard 640:c90ae1400bf2 174 } evt;
Vincent Coubard 640:c90ae1400bf2 175 } ble_evt_t;
Vincent Coubard 640:c90ae1400bf2 176
Vincent Coubard 640:c90ae1400bf2 177
Vincent Coubard 640:c90ae1400bf2 178 /**
Vincent Coubard 640:c90ae1400bf2 179 * @brief Version Information.
Vincent Coubard 640:c90ae1400bf2 180 */
Vincent Coubard 640:c90ae1400bf2 181 typedef struct
Vincent Coubard 640:c90ae1400bf2 182 {
Vincent Coubard 640:c90ae1400bf2 183 uint8_t version_number; /**< Link Layer Version number for BT 4.1 spec is 7 (https://www.bluetooth.org/en-us/specification/assigned-numbers/link-layer). */
Vincent Coubard 640:c90ae1400bf2 184 uint16_t company_id; /**< Company ID, Nordic Semiconductor's company ID is 89 (0x0059) (https://www.bluetooth.org/apps/content/Default.aspx?doc_id=49708). */
Vincent Coubard 640:c90ae1400bf2 185 uint16_t subversion_number; /**< Link Layer Sub Version number, corresponds to the SoftDevice Config ID or Firmware ID (FWID). */
Vincent Coubard 640:c90ae1400bf2 186 } ble_version_t;
Vincent Coubard 640:c90ae1400bf2 187
Vincent Coubard 640:c90ae1400bf2 188 /**@brief Mutual exclusion of radio activity and CPU execution.
Vincent Coubard 640:c90ae1400bf2 189 *
Vincent Coubard 640:c90ae1400bf2 190 * This option configures the application's access to the CPU when the radio is active. The
Vincent Coubard 640:c90ae1400bf2 191 * application can configure itself to be blocked from using the CPU while the radio is
Vincent Coubard 640:c90ae1400bf2 192 * active. By default, the application will be able to share CPU time with the SoftDevice
Vincent Coubard 640:c90ae1400bf2 193 * during radio activity. This parameter structure is used together with @ref sd_ble_opt_set
Vincent Coubard 640:c90ae1400bf2 194 * to configure the @ref BLE_COMMON_OPT_RADIO_CPU_MUTEX option.
Vincent Coubard 640:c90ae1400bf2 195 *
Vincent Coubard 640:c90ae1400bf2 196 * @note Note that the application should use this option to configure the SoftDevice to block the
Vincent Coubard 640:c90ae1400bf2 197 * CPU during radio activity (i.e enable mutual exclusion) when running the SoftDevice on
Vincent Coubard 640:c90ae1400bf2 198 * hardware affected by PAN #44 "CCM may exceed real time requirements"and PAN #45 "AAR may
Vincent Coubard 640:c90ae1400bf2 199 * exceed real time requirements".
Vincent Coubard 640:c90ae1400bf2 200 *
Vincent Coubard 640:c90ae1400bf2 201 * @note Note that when acting as a scanner, the mutex is only enabled for radio TX activity.
Vincent Coubard 640:c90ae1400bf2 202 *
Vincent Coubard 640:c90ae1400bf2 203 * @note @ref sd_ble_opt_get is not supported for this option.
Vincent Coubard 640:c90ae1400bf2 204 *
Vincent Coubard 640:c90ae1400bf2 205 */
Vincent Coubard 640:c90ae1400bf2 206 typedef struct
Vincent Coubard 640:c90ae1400bf2 207 {
Vincent Coubard 640:c90ae1400bf2 208 uint8_t enable : 1; /**< Enable mutual exclusion of radio activity and the CPU execution. */
Vincent Coubard 640:c90ae1400bf2 209 } ble_common_opt_radio_cpu_mutex_t;
Vincent Coubard 640:c90ae1400bf2 210
Vincent Coubard 640:c90ae1400bf2 211 /**@brief Option structure for common options. */
Vincent Coubard 640:c90ae1400bf2 212 typedef union
Vincent Coubard 640:c90ae1400bf2 213 {
Vincent Coubard 640:c90ae1400bf2 214 ble_common_opt_radio_cpu_mutex_t radio_cpu_mutex; /**< Parameters for the option for the mutual exclusion of radio activity and CPU execution. */
Vincent Coubard 640:c90ae1400bf2 215 } ble_common_opt_t;
Vincent Coubard 640:c90ae1400bf2 216
Vincent Coubard 640:c90ae1400bf2 217 /**@brief Common BLE Option type, wrapping the module specific options. */
Vincent Coubard 640:c90ae1400bf2 218 typedef union
Vincent Coubard 640:c90ae1400bf2 219 {
Vincent Coubard 640:c90ae1400bf2 220 ble_common_opt_t common_opt; /**< Common option, opt_id in BLE_COMMON_OPT_* series. */
Vincent Coubard 640:c90ae1400bf2 221 ble_gap_opt_t gap_opt; /**< GAP option, opt_id in BLE_GAP_OPT_* series. */
Vincent Coubard 640:c90ae1400bf2 222 } ble_opt_t;
Vincent Coubard 640:c90ae1400bf2 223
Vincent Coubard 640:c90ae1400bf2 224 /**
Vincent Coubard 640:c90ae1400bf2 225 * @brief BLE GATTS init options
Vincent Coubard 640:c90ae1400bf2 226 */
Vincent Coubard 640:c90ae1400bf2 227 typedef struct
Vincent Coubard 640:c90ae1400bf2 228 {
Vincent Coubard 640:c90ae1400bf2 229 ble_gatts_enable_params_t gatts_enable_params; /**< GATTS init options @ref ble_gatts_enable_params_t. */
Vincent Coubard 640:c90ae1400bf2 230 } ble_enable_params_t;
Vincent Coubard 640:c90ae1400bf2 231
Vincent Coubard 640:c90ae1400bf2 232 /** @} */
Vincent Coubard 640:c90ae1400bf2 233
Vincent Coubard 640:c90ae1400bf2 234 /** @addtogroup BLE_COMMON_FUNCTIONS Functions
Vincent Coubard 640:c90ae1400bf2 235 * @{ */
Vincent Coubard 640:c90ae1400bf2 236
Vincent Coubard 640:c90ae1400bf2 237 /**@brief Enable the BLE stack
Vincent Coubard 640:c90ae1400bf2 238 *
Vincent Coubard 640:c90ae1400bf2 239 * @param[in] p_ble_enable_params Pointer to ble_enable_params_t
Vincent Coubard 640:c90ae1400bf2 240 *
Vincent Coubard 640:c90ae1400bf2 241 * @details This call initializes the BLE stack, no other BLE related function can be called before this one.
Vincent Coubard 640:c90ae1400bf2 242 *
Vincent Coubard 640:c90ae1400bf2 243 * @return @ref NRF_SUCCESS BLE the BLE stack has been initialized successfully
Vincent Coubard 640:c90ae1400bf2 244 * @retval @ref NRF_ERROR_INVALID_STATE the BLE stack had already been initialized and cannot be reinitialized.
Vincent Coubard 640:c90ae1400bf2 245 * @return @ref NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied.
Vincent Coubard 640:c90ae1400bf2 246 * @return @ref NRF_ERROR_INVALID_LENGTH The specified Attribute Table size is either too small or not a multiple of 4.
Vincent Coubard 640:c90ae1400bf2 247 * The minimum acceptable size is defined by @ref BLE_GATTS_ATTR_TAB_SIZE_MIN.
Vincent Coubard 640:c90ae1400bf2 248 * @return @ref NRF_ERROR_NO_MEM The Attribute Table size is too large. Decrease size in @ref ble_gatts_enable_params_t.
Vincent Coubard 640:c90ae1400bf2 249 */
Vincent Coubard 640:c90ae1400bf2 250 SVCALL(SD_BLE_ENABLE, uint32_t, sd_ble_enable(ble_enable_params_t * p_ble_enable_params));
Vincent Coubard 640:c90ae1400bf2 251
Vincent Coubard 640:c90ae1400bf2 252 /**@brief Get an event from the pending events queue.
Vincent Coubard 640:c90ae1400bf2 253 *
Vincent Coubard 640:c90ae1400bf2 254 * @param[out] p_dest Pointer to buffer to be filled in with an event, or NULL to retrieve the event length. This buffer <b>must be 4-byte aligned in memory</b>.
Vincent Coubard 640:c90ae1400bf2 255 * @param[in, out] p_len Pointer the length of the buffer, on return it is filled with the event length.
Vincent Coubard 640:c90ae1400bf2 256 *
Vincent Coubard 640:c90ae1400bf2 257 * @details This call allows the application to pull a BLE event from the BLE stack. The application is signalled that an event is
Vincent Coubard 640:c90ae1400bf2 258 * available from the BLE stack by the triggering of the SD_EVT_IRQn interrupt.
Vincent Coubard 640:c90ae1400bf2 259 * The application is free to choose whether to call this function from thread mode (main context) or directly from the Interrupt Service Routine
Vincent Coubard 640:c90ae1400bf2 260 * that maps to SD_EVT_IRQn. In any case however, and because the BLE stack runs at a higher priority than the application, this function should be called
Vincent Coubard 640:c90ae1400bf2 261 * in a loop (until @ref NRF_ERROR_NOT_FOUND is returned) every time SD_EVT_IRQn is raised to ensure that all available events are pulled from the BLE stack.
Vincent Coubard 640:c90ae1400bf2 262 * Failure to do so could potentially leave events in the internal queue without the application being aware of this fact.
Vincent Coubard 640:c90ae1400bf2 263 * Sizing the p_dest buffer is equally important, since the application needs to provide all the memory necessary for the event to be copied into
Vincent Coubard 640:c90ae1400bf2 264 * application memory. If the buffer provided is not large enough to fit the entire contents of the event, @ref NRF_ERROR_DATA_SIZE will be returned
Vincent Coubard 640:c90ae1400bf2 265 * and the application can then call again with a larger buffer size.
Vincent Coubard 640:c90ae1400bf2 266 * Please note that because of the variable length nature of some events, sizeof(ble_evt_t) will not always be large enough to fit certain events,
Vincent Coubard 640:c90ae1400bf2 267 * and so it is the application's responsibility to provide an amount of memory large enough so that the relevant event is copied in full.
Vincent Coubard 640:c90ae1400bf2 268 * The application may "peek" the event length by providing p_dest as a NULL pointer and inspecting the value of *p_len upon return.
Vincent Coubard 640:c90ae1400bf2 269 *
Vincent Coubard 640:c90ae1400bf2 270 * @note The pointer supplied must be aligned to the extend defined by @ref BLE_EVTS_PTR_ALIGNMENT
Vincent Coubard 640:c90ae1400bf2 271 *
Vincent Coubard 640:c90ae1400bf2 272 * @retval ::NRF_SUCCESS Event pulled and stored into the supplied buffer.
Vincent Coubard 640:c90ae1400bf2 273 * @retval ::NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied.
Vincent Coubard 640:c90ae1400bf2 274 * @retval ::NRF_ERROR_NOT_FOUND No events ready to be pulled.
Vincent Coubard 640:c90ae1400bf2 275 * @retval ::NRF_ERROR_DATA_SIZE Event ready but could not fit into the supplied buffer.
Vincent Coubard 640:c90ae1400bf2 276 */
Vincent Coubard 640:c90ae1400bf2 277 SVCALL(SD_BLE_EVT_GET, uint32_t, sd_ble_evt_get(uint8_t *p_dest, uint16_t *p_len));
Vincent Coubard 640:c90ae1400bf2 278
Vincent Coubard 640:c90ae1400bf2 279
Vincent Coubard 640:c90ae1400bf2 280 /**@brief Get the total number of available application transmission buffers per link in the BLE stack.
Vincent Coubard 640:c90ae1400bf2 281 *
Vincent Coubard 640:c90ae1400bf2 282 * @details This call allows the application to obtain the total number of
Vincent Coubard 640:c90ae1400bf2 283 * transmission buffers available per link for application data. Please note that
Vincent Coubard 640:c90ae1400bf2 284 * this does not give the number of free buffers, but rather the total amount of them.
Vincent Coubard 640:c90ae1400bf2 285 * The application has two options to handle its own application transmission buffers:
Vincent Coubard 640:c90ae1400bf2 286 * - Use a simple arithmetic calculation: at boot time the application should use this function
Vincent Coubard 640:c90ae1400bf2 287 * to find out the total amount of buffers available to it and store it in a variable.
Vincent Coubard 640:c90ae1400bf2 288 * Every time a packet that consumes an application buffer is sent using any of the
Vincent Coubard 640:c90ae1400bf2 289 * exposed functions in this BLE API, the application should decrement that variable.
Vincent Coubard 640:c90ae1400bf2 290 * Conversely, whenever a @ref BLE_EVT_TX_COMPLETE event is received by the application
Vincent Coubard 640:c90ae1400bf2 291 * it should retrieve the count field in such event and add that number to the same
Vincent Coubard 640:c90ae1400bf2 292 * variable storing the number of available packets.
Vincent Coubard 640:c90ae1400bf2 293 * This mechanism allows the application to be aware at any time of the number of
Vincent Coubard 640:c90ae1400bf2 294 * application packets available in the BLE stack's internal buffers, and therefore
Vincent Coubard 640:c90ae1400bf2 295 * it can know with certainty whether it is possible to send more data or it has to
Vincent Coubard 640:c90ae1400bf2 296 * wait for a @ref BLE_EVT_TX_COMPLETE event before it proceeds.
Vincent Coubard 640:c90ae1400bf2 297 * - Choose to simply not keep track of available buffers at all, and instead handle the
Vincent Coubard 640:c90ae1400bf2 298 * @ref BLE_ERROR_NO_TX_BUFFERS error by queueing the packet to be transmitted and
Vincent Coubard 640:c90ae1400bf2 299 * try again as soon as a @ref BLE_EVT_TX_COMPLETE event arrives.
Vincent Coubard 640:c90ae1400bf2 300 *
Vincent Coubard 640:c90ae1400bf2 301 * The API functions that <b>may</b> consume an application buffer depending on
Vincent Coubard 640:c90ae1400bf2 302 * the parameters supplied to them can be found below:
Vincent Coubard 640:c90ae1400bf2 303 *
Vincent Coubard 640:c90ae1400bf2 304 * - @ref sd_ble_gattc_write (write without response only)
Vincent Coubard 640:c90ae1400bf2 305 * - @ref sd_ble_gatts_hvx (notifications only)
Vincent Coubard 640:c90ae1400bf2 306 * - @ref sd_ble_l2cap_tx (all packets)
Vincent Coubard 640:c90ae1400bf2 307 *
Vincent Coubard 640:c90ae1400bf2 308 * @param[out] p_count Pointer to a uint8_t which will contain the number of application transmission buffers upon
Vincent Coubard 640:c90ae1400bf2 309 * successful return.
Vincent Coubard 640:c90ae1400bf2 310 *
Vincent Coubard 640:c90ae1400bf2 311 * @retval ::NRF_SUCCESS Number of application transmission buffers retrieved successfully.
Vincent Coubard 640:c90ae1400bf2 312 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
Vincent Coubard 640:c90ae1400bf2 313 */
Vincent Coubard 640:c90ae1400bf2 314 SVCALL(SD_BLE_TX_BUFFER_COUNT_GET, uint32_t, sd_ble_tx_buffer_count_get(uint8_t *p_count));
Vincent Coubard 640:c90ae1400bf2 315
Vincent Coubard 640:c90ae1400bf2 316
Vincent Coubard 640:c90ae1400bf2 317 /**@brief Add a Vendor Specific UUID.
Vincent Coubard 640:c90ae1400bf2 318 *
Vincent Coubard 640:c90ae1400bf2 319 * @details This call enables the application to add a vendor specific UUID to the BLE stack's table,
Vincent Coubard 640:c90ae1400bf2 320 * for later use all other modules and APIs. This then allows the application to use the shorter,
Vincent Coubard 640:c90ae1400bf2 321 * 24-bit @ref ble_uuid_t format when dealing with both 16-bit and 128-bit UUIDs without having to
Vincent Coubard 640:c90ae1400bf2 322 * check for lengths and having split code paths. The way that this is accomplished is by extending the
Vincent Coubard 640:c90ae1400bf2 323 * grouping mechanism that the Bluetooth SIG standard base UUID uses for all other 128-bit UUIDs. The
Vincent Coubard 640:c90ae1400bf2 324 * type field in the @ref ble_uuid_t structure is an index (relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN)
Vincent Coubard 640:c90ae1400bf2 325 * to the table populated by multiple calls to this function, and the uuid field in the same structure
Vincent Coubard 640:c90ae1400bf2 326 * contains the 2 bytes at indices 12 and 13. The number of possible 128-bit UUIDs available to the
Vincent Coubard 640:c90ae1400bf2 327 * application is therefore the number of Vendor Specific UUIDs added with the help of this function times 65536,
Vincent Coubard 640:c90ae1400bf2 328 * although restricted to modifying bytes 12 and 13 for each of the entries in the supplied array.
Vincent Coubard 640:c90ae1400bf2 329 *
Vincent Coubard 640:c90ae1400bf2 330 * @note Bytes 12 and 13 of the provided UUID will not be used internally, since those are always replaced by
Vincent Coubard 640:c90ae1400bf2 331 * the 16-bit uuid field in @ref ble_uuid_t.
Vincent Coubard 640:c90ae1400bf2 332 *
Vincent Coubard 640:c90ae1400bf2 333 *
Vincent Coubard 640:c90ae1400bf2 334 * @param[in] p_vs_uuid Pointer to a 16-octet (128-bit) little endian Vendor Specific UUID disregarding
Vincent Coubard 640:c90ae1400bf2 335 * bytes 12 and 13.
Vincent Coubard 640:c90ae1400bf2 336 * @param[out] p_uuid_type Pointer to a uint8_t where the type field in @ref ble_uuid_t corresponding to this UUID will be stored.
Vincent Coubard 640:c90ae1400bf2 337 *
Vincent Coubard 640:c90ae1400bf2 338 * @retval ::NRF_SUCCESS Successfully added the Vendor Specific UUID.
Vincent Coubard 640:c90ae1400bf2 339 * @retval ::NRF_ERROR_INVALID_ADDR If p_vs_uuid or p_uuid_type is NULL or invalid.
Vincent Coubard 640:c90ae1400bf2 340 * @retval ::NRF_ERROR_NO_MEM If there are no more free slots for VS UUIDs.
Vincent Coubard 640:c90ae1400bf2 341 * @retval ::NRF_ERROR_FORBIDDEN If p_vs_uuid has already been added to the VS UUID table.
Vincent Coubard 640:c90ae1400bf2 342 */
Vincent Coubard 640:c90ae1400bf2 343 SVCALL(SD_BLE_UUID_VS_ADD, uint32_t, sd_ble_uuid_vs_add(ble_uuid128_t const *p_vs_uuid, uint8_t *p_uuid_type));
Vincent Coubard 640:c90ae1400bf2 344
Vincent Coubard 640:c90ae1400bf2 345
Vincent Coubard 640:c90ae1400bf2 346 /** @brief Decode little endian raw UUID bytes (16-bit or 128-bit) into a 24 bit @ref ble_uuid_t structure.
Vincent Coubard 640:c90ae1400bf2 347 *
Vincent Coubard 640:c90ae1400bf2 348 * @details The raw UUID bytes excluding bytes 12 and 13 (i.e. bytes 0-11 and 14-15) of p_uuid_le are compared
Vincent Coubard 640:c90ae1400bf2 349 * to the corresponding ones in each entry of the table of vendor specific UUIDs populated with @ref sd_ble_uuid_vs_add
Vincent Coubard 640:c90ae1400bf2 350 * to look for a match. If there is such a match, bytes 12 and 13 are returned as p_uuid->uuid and the index
Vincent Coubard 640:c90ae1400bf2 351 * relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN as p_uuid->type.
Vincent Coubard 640:c90ae1400bf2 352 *
Vincent Coubard 640:c90ae1400bf2 353 * @note If the UUID length supplied is 2, then the type set by this call will always be @ref BLE_UUID_TYPE_BLE.
Vincent Coubard 640:c90ae1400bf2 354 *
Vincent Coubard 640:c90ae1400bf2 355 * @param[in] uuid_le_len Length in bytes of the buffer pointed to by p_uuid_le (must be 2 or 16 bytes).
Vincent Coubard 640:c90ae1400bf2 356 * @param[in] p_uuid_le Pointer pointing to little endian raw UUID bytes.
Vincent Coubard 640:c90ae1400bf2 357 * @param[out] p_uuid Pointer to a @ref ble_uuid_t structure to be filled in.
Vincent Coubard 640:c90ae1400bf2 358 *
Vincent Coubard 640:c90ae1400bf2 359 * @retval ::NRF_SUCCESS Successfully decoded into the @ref ble_uuid_t structure.
Vincent Coubard 640:c90ae1400bf2 360 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
Vincent Coubard 640:c90ae1400bf2 361 * @retval ::NRF_ERROR_INVALID_LENGTH Invalid UUID length.
Vincent Coubard 640:c90ae1400bf2 362 * @retval ::NRF_ERROR_NOT_FOUND For a 128-bit UUID, no match in the populated table of UUIDs.
Vincent Coubard 640:c90ae1400bf2 363 */
Vincent Coubard 640:c90ae1400bf2 364 SVCALL(SD_BLE_UUID_DECODE, uint32_t, sd_ble_uuid_decode(uint8_t uuid_le_len, uint8_t const *p_uuid_le, ble_uuid_t *p_uuid));
Vincent Coubard 640:c90ae1400bf2 365
Vincent Coubard 640:c90ae1400bf2 366
Vincent Coubard 640:c90ae1400bf2 367 /** @brief Encode a @ref ble_uuid_t structure into little endian raw UUID bytes (16-bit or 128-bit).
Vincent Coubard 640:c90ae1400bf2 368 *
Vincent Coubard 640:c90ae1400bf2 369 * @note The pointer to the destination buffer p_uuid_le may be NULL, in which case only the validity and size of p_uuid is computed.
Vincent Coubard 640:c90ae1400bf2 370 *
Vincent Coubard 640:c90ae1400bf2 371 * @param[in] p_uuid Pointer to a @ref ble_uuid_t structure that will be encoded into bytes.
Vincent Coubard 640:c90ae1400bf2 372 * @param[out] p_uuid_le_len Pointer to a uint8_t that will be filled with the encoded length (2 or 16 bytes).
Vincent Coubard 640:c90ae1400bf2 373 * @param[out] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes (2 or 16) will be stored.
Vincent Coubard 640:c90ae1400bf2 374 *
Vincent Coubard 640:c90ae1400bf2 375 * @retval ::NRF_SUCCESS Successfully encoded into the buffer.
Vincent Coubard 640:c90ae1400bf2 376 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
Vincent Coubard 640:c90ae1400bf2 377 * @retval ::NRF_ERROR_INVALID_PARAM Invalid UUID type.
Vincent Coubard 640:c90ae1400bf2 378 */
Vincent Coubard 640:c90ae1400bf2 379 SVCALL(SD_BLE_UUID_ENCODE, uint32_t, sd_ble_uuid_encode(ble_uuid_t const *p_uuid, uint8_t *p_uuid_le_len, uint8_t *p_uuid_le));
Vincent Coubard 640:c90ae1400bf2 380
Vincent Coubard 640:c90ae1400bf2 381
Vincent Coubard 640:c90ae1400bf2 382 /**@brief Get Version Information.
Vincent Coubard 640:c90ae1400bf2 383 *
Vincent Coubard 640:c90ae1400bf2 384 * @details This call allows the application to get the BLE stack version information.
Vincent Coubard 640:c90ae1400bf2 385 *
Vincent Coubard 640:c90ae1400bf2 386 * @param[out] p_version Pointer to a ble_version_t structure to be filled in.
Vincent Coubard 640:c90ae1400bf2 387 *
Vincent Coubard 640:c90ae1400bf2 388 * @retval ::NRF_SUCCESS Version information stored successfully.
Vincent Coubard 640:c90ae1400bf2 389 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
Vincent Coubard 640:c90ae1400bf2 390 * @retval ::NRF_ERROR_BUSY The BLE stack is busy (typically doing a locally-initiated disconnection procedure).
Vincent Coubard 640:c90ae1400bf2 391 */
Vincent Coubard 640:c90ae1400bf2 392 SVCALL(SD_BLE_VERSION_GET, uint32_t, sd_ble_version_get(ble_version_t *p_version));
Vincent Coubard 640:c90ae1400bf2 393
Vincent Coubard 640:c90ae1400bf2 394
Vincent Coubard 640:c90ae1400bf2 395 /**@brief Provide a user memory block.
Vincent Coubard 640:c90ae1400bf2 396 *
Vincent Coubard 640:c90ae1400bf2 397 * @note This call can only be used as a response to a @ref BLE_EVT_USER_MEM_REQUEST event issued to the application.
Vincent Coubard 640:c90ae1400bf2 398 *
Vincent Coubard 640:c90ae1400bf2 399 * @param[in] conn_handle Connection handle.
Vincent Coubard 640:c90ae1400bf2 400 * @param[in,out] p_block Pointer to a user memory block structure.
Vincent Coubard 640:c90ae1400bf2 401 *
Vincent Coubard 640:c90ae1400bf2 402 * @retval ::NRF_SUCCESS Successfully queued a response to the peer.
Vincent Coubard 640:c90ae1400bf2 403 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
Vincent Coubard 640:c90ae1400bf2 404 * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection state or no execute write request pending.
Vincent Coubard 640:c90ae1400bf2 405 * @retval ::NRF_ERROR_BUSY The BLE stack is busy. Retry at later time.
Vincent Coubard 640:c90ae1400bf2 406 */
Vincent Coubard 640:c90ae1400bf2 407 SVCALL(SD_BLE_USER_MEM_REPLY, uint32_t, sd_ble_user_mem_reply(uint16_t conn_handle, ble_user_mem_block_t const *p_block));
Vincent Coubard 640:c90ae1400bf2 408
Vincent Coubard 640:c90ae1400bf2 409 /**@brief Set a BLE option.
Vincent Coubard 640:c90ae1400bf2 410 *
Vincent Coubard 640:c90ae1400bf2 411 * @details This call allows the application to set the value of an option.
Vincent Coubard 640:c90ae1400bf2 412 *
Vincent Coubard 640:c90ae1400bf2 413 * @param[in] opt_id Option ID.
Vincent Coubard 640:c90ae1400bf2 414 * @param[in] p_opt Pointer to a ble_opt_t structure containing the option value.
Vincent Coubard 640:c90ae1400bf2 415 *
Vincent Coubard 640:c90ae1400bf2 416 * @retval ::NRF_SUCCESS Option set successfully.
Vincent Coubard 640:c90ae1400bf2 417 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
Vincent Coubard 640:c90ae1400bf2 418 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
Vincent Coubard 640:c90ae1400bf2 419 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
Vincent Coubard 640:c90ae1400bf2 420 * @retval ::NRF_ERROR_INVALID_STATE Unable to set the parameter at this time.
Vincent Coubard 640:c90ae1400bf2 421 * @retval ::NRF_ERROR_BUSY The BLE stack is busy or the previous procedure has not completed.
Vincent Coubard 640:c90ae1400bf2 422 */
Vincent Coubard 640:c90ae1400bf2 423 SVCALL(SD_BLE_OPT_SET, uint32_t, sd_ble_opt_set(uint32_t opt_id, ble_opt_t const *p_opt));
Vincent Coubard 640:c90ae1400bf2 424
Vincent Coubard 640:c90ae1400bf2 425
Vincent Coubard 640:c90ae1400bf2 426 /**@brief Get a BLE option.
Vincent Coubard 640:c90ae1400bf2 427 *
Vincent Coubard 640:c90ae1400bf2 428 * @details This call allows the application to retrieve the value of an option.
Vincent Coubard 640:c90ae1400bf2 429 *
Vincent Coubard 640:c90ae1400bf2 430 * @param[in] opt_id Option ID.
Vincent Coubard 640:c90ae1400bf2 431 * @param[out] p_opt Pointer to a ble_opt_t structure to be filled in.
Vincent Coubard 640:c90ae1400bf2 432 *
Vincent Coubard 640:c90ae1400bf2 433 * @retval ::NRF_SUCCESS Option retrieved successfully.
Vincent Coubard 640:c90ae1400bf2 434 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
Vincent Coubard 640:c90ae1400bf2 435 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
Vincent Coubard 640:c90ae1400bf2 436 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
Vincent Coubard 640:c90ae1400bf2 437 * @retval ::NRF_ERROR_INVALID_STATE Unable to retrieve the parameter at this time.
Vincent Coubard 640:c90ae1400bf2 438 * @retval ::NRF_ERROR_BUSY The BLE stack is busy or the previous procedure has not completed.
Vincent Coubard 640:c90ae1400bf2 439 * @retval ::NRF_ERROR_NOT_SUPPORTED This option is not supported.
Vincent Coubard 640:c90ae1400bf2 440 *
Vincent Coubard 640:c90ae1400bf2 441 */
Vincent Coubard 640:c90ae1400bf2 442 SVCALL(SD_BLE_OPT_GET, uint32_t, sd_ble_opt_get(uint32_t opt_id, ble_opt_t *p_opt));
Vincent Coubard 640:c90ae1400bf2 443
Vincent Coubard 640:c90ae1400bf2 444 /** @} */
Vincent Coubard 640:c90ae1400bf2 445
Vincent Coubard 640:c90ae1400bf2 446 #endif /* BLE_H__ */
Vincent Coubard 640:c90ae1400bf2 447
Vincent Coubard 640:c90ae1400bf2 448 /**
Vincent Coubard 640:c90ae1400bf2 449 @}
Vincent Coubard 640:c90ae1400bf2 450 @}
Vincent Coubard 640:c90ae1400bf2 451 */