Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Thu Apr 07 17:37:40 2016 +0100
Revision:
19:47192cb9def7
Parent:
10:233fefd8162b
Child:
20:a90c48eb1d30
Synchronized with git rev 9251259f
Author: Liyou Zhou
Copy over coresponding files from nordic-sdk 9.0.0

Who changed what in which revision?

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