Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Puck/nRF51822/nordic-sdk/components/softdevice/s110/headers/ble.h@0:b8221deeaa87, 2015-04-30 (annotated)
- Committer:
- Grimmkey
- Date:
- Thu Apr 30 20:46:27 2015 +0000
- Revision:
- 0:b8221deeaa87
Georgia Institute of Technology ECE 4180 Spring 2015 Jazz Hands project, Nordic nRF51822 half
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Grimmkey | 0:b8221deeaa87 | 1 | /* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved. |
Grimmkey | 0:b8221deeaa87 | 2 | * |
Grimmkey | 0:b8221deeaa87 | 3 | * The information contained herein is confidential property of Nordic Semiconductor. The use, |
Grimmkey | 0:b8221deeaa87 | 4 | * copying, transfer or disclosure of such information is prohibited except by express written |
Grimmkey | 0:b8221deeaa87 | 5 | * agreement with Nordic Semiconductor. |
Grimmkey | 0:b8221deeaa87 | 6 | * |
Grimmkey | 0:b8221deeaa87 | 7 | */ |
Grimmkey | 0:b8221deeaa87 | 8 | /** |
Grimmkey | 0:b8221deeaa87 | 9 | @addtogroup BLE_COMMON BLE SoftDevice Common |
Grimmkey | 0:b8221deeaa87 | 10 | @{ |
Grimmkey | 0:b8221deeaa87 | 11 | @defgroup ble_api Events, type definitions and API calls |
Grimmkey | 0:b8221deeaa87 | 12 | @{ |
Grimmkey | 0:b8221deeaa87 | 13 | |
Grimmkey | 0:b8221deeaa87 | 14 | @brief Module independent events, type definitions and API calls for the S110 SoftDevice. |
Grimmkey | 0:b8221deeaa87 | 15 | |
Grimmkey | 0:b8221deeaa87 | 16 | */ |
Grimmkey | 0:b8221deeaa87 | 17 | |
Grimmkey | 0:b8221deeaa87 | 18 | #ifndef BLE_H__ |
Grimmkey | 0:b8221deeaa87 | 19 | #define BLE_H__ |
Grimmkey | 0:b8221deeaa87 | 20 | |
Grimmkey | 0:b8221deeaa87 | 21 | #include "ble_ranges.h" |
Grimmkey | 0:b8221deeaa87 | 22 | #include "ble_types.h" |
Grimmkey | 0:b8221deeaa87 | 23 | #include "ble_gap.h" |
Grimmkey | 0:b8221deeaa87 | 24 | #include "ble_l2cap.h" |
Grimmkey | 0:b8221deeaa87 | 25 | #include "ble_gatt.h" |
Grimmkey | 0:b8221deeaa87 | 26 | #include "ble_gattc.h" |
Grimmkey | 0:b8221deeaa87 | 27 | #include "ble_gatts.h" |
Grimmkey | 0:b8221deeaa87 | 28 | |
Grimmkey | 0:b8221deeaa87 | 29 | /** @addtogroup BLE_COMMON_ENUMERATIONS Enumerations |
Grimmkey | 0:b8221deeaa87 | 30 | * @{ */ |
Grimmkey | 0:b8221deeaa87 | 31 | |
Grimmkey | 0:b8221deeaa87 | 32 | /** |
Grimmkey | 0:b8221deeaa87 | 33 | * @brief Common API SVC numbers. |
Grimmkey | 0:b8221deeaa87 | 34 | */ |
Grimmkey | 0:b8221deeaa87 | 35 | enum BLE_COMMON_SVCS |
Grimmkey | 0:b8221deeaa87 | 36 | { |
Grimmkey | 0:b8221deeaa87 | 37 | SD_BLE_ENABLE = BLE_SVC_BASE, /**< Enable and initialize the BLE stack */ |
Grimmkey | 0:b8221deeaa87 | 38 | SD_BLE_EVT_GET, /**< Get an event from the pending events queue. */ |
Grimmkey | 0:b8221deeaa87 | 39 | SD_BLE_TX_BUFFER_COUNT_GET, /**< Get the total number of available application transmission buffers from the stack. */ |
Grimmkey | 0:b8221deeaa87 | 40 | SD_BLE_UUID_VS_ADD, /**< Add a Vendor Specific UUID. */ |
Grimmkey | 0:b8221deeaa87 | 41 | SD_BLE_UUID_DECODE, /**< Decode UUID bytes. */ |
Grimmkey | 0:b8221deeaa87 | 42 | SD_BLE_UUID_ENCODE, /**< Encode UUID bytes. */ |
Grimmkey | 0:b8221deeaa87 | 43 | SD_BLE_VERSION_GET, /**< Get the local version information (company id, Link Layer Version, Link Layer Subversion). */ |
Grimmkey | 0:b8221deeaa87 | 44 | SD_BLE_USER_MEM_REPLY, /**< User Memory Reply. */ |
Grimmkey | 0:b8221deeaa87 | 45 | SD_BLE_OPT_SET, /**< Set a BLE option. */ |
Grimmkey | 0:b8221deeaa87 | 46 | SD_BLE_OPT_GET, /**< Get a BLE option. */ |
Grimmkey | 0:b8221deeaa87 | 47 | }; |
Grimmkey | 0:b8221deeaa87 | 48 | |
Grimmkey | 0:b8221deeaa87 | 49 | /**@brief Common Option IDs. |
Grimmkey | 0:b8221deeaa87 | 50 | * IDs that uniquely identify a common option. |
Grimmkey | 0:b8221deeaa87 | 51 | */ |
Grimmkey | 0:b8221deeaa87 | 52 | enum BLE_COMMON_OPTS |
Grimmkey | 0:b8221deeaa87 | 53 | { |
Grimmkey | 0:b8221deeaa87 | 54 | BLE_COMMON_OPT_RADIO_CPU_MUTEX = BLE_OPT_BASE /**< Radio CPU mutex option. @ref ble_common_opt_radio_cpu_mutex_t */ |
Grimmkey | 0:b8221deeaa87 | 55 | }; |
Grimmkey | 0:b8221deeaa87 | 56 | /** @} */ |
Grimmkey | 0:b8221deeaa87 | 57 | |
Grimmkey | 0:b8221deeaa87 | 58 | /** @addtogroup BLE_COMMON_DEFINES Defines |
Grimmkey | 0:b8221deeaa87 | 59 | * @{ */ |
Grimmkey | 0:b8221deeaa87 | 60 | |
Grimmkey | 0:b8221deeaa87 | 61 | /** @brief Required pointer alignment for BLE Events. |
Grimmkey | 0:b8221deeaa87 | 62 | */ |
Grimmkey | 0:b8221deeaa87 | 63 | #define BLE_EVTS_PTR_ALIGNMENT 4 |
Grimmkey | 0:b8221deeaa87 | 64 | |
Grimmkey | 0:b8221deeaa87 | 65 | /** @defgroup BLE_USER_MEM_TYPES User Memory Types |
Grimmkey | 0:b8221deeaa87 | 66 | * @{ */ |
Grimmkey | 0:b8221deeaa87 | 67 | #define BLE_USER_MEM_TYPE_INVALID 0x00 /**< Invalid User Memory Types. */ |
Grimmkey | 0:b8221deeaa87 | 68 | #define BLE_USER_MEM_TYPE_GATTS_QUEUED_WRITES 0x01 /**< User Memory for GATTS queued writes. */ |
Grimmkey | 0:b8221deeaa87 | 69 | /** @} */ |
Grimmkey | 0:b8221deeaa87 | 70 | |
Grimmkey | 0:b8221deeaa87 | 71 | /** @brief Maximum number of Vendor Specific UUIDs. |
Grimmkey | 0:b8221deeaa87 | 72 | */ |
Grimmkey | 0:b8221deeaa87 | 73 | #define BLE_UUID_VS_MAX_COUNT 10 |
Grimmkey | 0:b8221deeaa87 | 74 | |
Grimmkey | 0:b8221deeaa87 | 75 | /** @} */ |
Grimmkey | 0:b8221deeaa87 | 76 | |
Grimmkey | 0:b8221deeaa87 | 77 | /** @addtogroup BLE_COMMON_STRUCTURES Structures |
Grimmkey | 0:b8221deeaa87 | 78 | * @{ */ |
Grimmkey | 0:b8221deeaa87 | 79 | |
Grimmkey | 0:b8221deeaa87 | 80 | /** |
Grimmkey | 0:b8221deeaa87 | 81 | * @brief BLE Module Independent Event IDs. |
Grimmkey | 0:b8221deeaa87 | 82 | */ |
Grimmkey | 0:b8221deeaa87 | 83 | enum BLE_COMMON_EVTS |
Grimmkey | 0:b8221deeaa87 | 84 | { |
Grimmkey | 0:b8221deeaa87 | 85 | BLE_EVT_TX_COMPLETE = BLE_EVT_BASE, /**< Transmission Complete. */ |
Grimmkey | 0:b8221deeaa87 | 86 | BLE_EVT_USER_MEM_REQUEST, /**< User Memory request. */ |
Grimmkey | 0:b8221deeaa87 | 87 | BLE_EVT_USER_MEM_RELEASE /**< User Memory release. */ |
Grimmkey | 0:b8221deeaa87 | 88 | }; |
Grimmkey | 0:b8221deeaa87 | 89 | |
Grimmkey | 0:b8221deeaa87 | 90 | /**@brief User Memory Block. */ |
Grimmkey | 0:b8221deeaa87 | 91 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 92 | { |
Grimmkey | 0:b8221deeaa87 | 93 | uint8_t* p_mem; /**< Pointer to the start of the user memory block. */ |
Grimmkey | 0:b8221deeaa87 | 94 | uint16_t len; /**< Length in bytes of the user memory block. */ |
Grimmkey | 0:b8221deeaa87 | 95 | } ble_user_mem_block_t; |
Grimmkey | 0:b8221deeaa87 | 96 | |
Grimmkey | 0:b8221deeaa87 | 97 | /** |
Grimmkey | 0:b8221deeaa87 | 98 | * @brief TX complete event. |
Grimmkey | 0:b8221deeaa87 | 99 | */ |
Grimmkey | 0:b8221deeaa87 | 100 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 101 | { |
Grimmkey | 0:b8221deeaa87 | 102 | uint8_t count; /**< Number of packets transmitted. */ |
Grimmkey | 0:b8221deeaa87 | 103 | } ble_evt_tx_complete_t; |
Grimmkey | 0:b8221deeaa87 | 104 | |
Grimmkey | 0:b8221deeaa87 | 105 | /**@brief Event structure for BLE_EVT_USER_MEM_REQUEST. */ |
Grimmkey | 0:b8221deeaa87 | 106 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 107 | { |
Grimmkey | 0:b8221deeaa87 | 108 | uint8_t type; /**< User memory type, see @ref BLE_USER_MEM_TYPES. */ |
Grimmkey | 0:b8221deeaa87 | 109 | } ble_evt_user_mem_request_t; |
Grimmkey | 0:b8221deeaa87 | 110 | |
Grimmkey | 0:b8221deeaa87 | 111 | /**@brief Event structure for BLE_EVT_USER_MEM_RELEASE. */ |
Grimmkey | 0:b8221deeaa87 | 112 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 113 | { |
Grimmkey | 0:b8221deeaa87 | 114 | uint8_t type; /**< User memory type, see @ref BLE_USER_MEM_TYPES. */ |
Grimmkey | 0:b8221deeaa87 | 115 | ble_user_mem_block_t mem_block; /**< User memory block */ |
Grimmkey | 0:b8221deeaa87 | 116 | } ble_evt_user_mem_release_t; |
Grimmkey | 0:b8221deeaa87 | 117 | |
Grimmkey | 0:b8221deeaa87 | 118 | |
Grimmkey | 0:b8221deeaa87 | 119 | /**@brief Event structure for events not associated with a specific function module. */ |
Grimmkey | 0:b8221deeaa87 | 120 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 121 | { |
Grimmkey | 0:b8221deeaa87 | 122 | uint16_t conn_handle; /**< Connection Handle on which this event occured. */ |
Grimmkey | 0:b8221deeaa87 | 123 | union |
Grimmkey | 0:b8221deeaa87 | 124 | { |
Grimmkey | 0:b8221deeaa87 | 125 | ble_evt_tx_complete_t tx_complete; /**< Transmission Complete. */ |
Grimmkey | 0:b8221deeaa87 | 126 | ble_evt_user_mem_request_t user_mem_request; /**< User Memory Request Event Parameters. */ |
Grimmkey | 0:b8221deeaa87 | 127 | ble_evt_user_mem_release_t user_mem_release; /**< User Memory Release Event Parameters. */ |
Grimmkey | 0:b8221deeaa87 | 128 | } params; |
Grimmkey | 0:b8221deeaa87 | 129 | } ble_common_evt_t; |
Grimmkey | 0:b8221deeaa87 | 130 | |
Grimmkey | 0:b8221deeaa87 | 131 | /**@brief BLE Event header. */ |
Grimmkey | 0:b8221deeaa87 | 132 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 133 | { |
Grimmkey | 0:b8221deeaa87 | 134 | uint16_t evt_id; /**< Value from a BLE_<module>_EVT series. */ |
Grimmkey | 0:b8221deeaa87 | 135 | uint16_t evt_len; /**< Length in octets excluding this header. */ |
Grimmkey | 0:b8221deeaa87 | 136 | } ble_evt_hdr_t; |
Grimmkey | 0:b8221deeaa87 | 137 | |
Grimmkey | 0:b8221deeaa87 | 138 | /**@brief Common BLE Event type, wrapping the module specific event reports. */ |
Grimmkey | 0:b8221deeaa87 | 139 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 140 | { |
Grimmkey | 0:b8221deeaa87 | 141 | ble_evt_hdr_t header; /**< Event header. */ |
Grimmkey | 0:b8221deeaa87 | 142 | union |
Grimmkey | 0:b8221deeaa87 | 143 | { |
Grimmkey | 0:b8221deeaa87 | 144 | ble_common_evt_t common_evt; /**< Common Event, evt_id in BLE_EVT_* series. */ |
Grimmkey | 0:b8221deeaa87 | 145 | ble_gap_evt_t gap_evt; /**< GAP originated event, evt_id in BLE_GAP_EVT_* series. */ |
Grimmkey | 0:b8221deeaa87 | 146 | ble_l2cap_evt_t l2cap_evt; /**< L2CAP originated event, evt_id in BLE_L2CAP_EVT* series. */ |
Grimmkey | 0:b8221deeaa87 | 147 | ble_gattc_evt_t gattc_evt; /**< GATT client originated event, evt_id in BLE_GATTC_EVT* series. */ |
Grimmkey | 0:b8221deeaa87 | 148 | ble_gatts_evt_t gatts_evt; /**< GATT server originated event, evt_id in BLE_GATTS_EVT* series. */ |
Grimmkey | 0:b8221deeaa87 | 149 | } evt; |
Grimmkey | 0:b8221deeaa87 | 150 | } ble_evt_t; |
Grimmkey | 0:b8221deeaa87 | 151 | |
Grimmkey | 0:b8221deeaa87 | 152 | |
Grimmkey | 0:b8221deeaa87 | 153 | /** |
Grimmkey | 0:b8221deeaa87 | 154 | * @brief Version Information. |
Grimmkey | 0:b8221deeaa87 | 155 | */ |
Grimmkey | 0:b8221deeaa87 | 156 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 157 | { |
Grimmkey | 0:b8221deeaa87 | 158 | 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). */ |
Grimmkey | 0:b8221deeaa87 | 159 | 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). */ |
Grimmkey | 0:b8221deeaa87 | 160 | uint16_t subversion_number; /**< Link Layer Sub Version number, corresponds to the SoftDevice Config ID or Firmware ID (FWID). */ |
Grimmkey | 0:b8221deeaa87 | 161 | } ble_version_t; |
Grimmkey | 0:b8221deeaa87 | 162 | |
Grimmkey | 0:b8221deeaa87 | 163 | /**@brief Mutual exclusion of radio activity and CPU execution. |
Grimmkey | 0:b8221deeaa87 | 164 | * |
Grimmkey | 0:b8221deeaa87 | 165 | * This option configures the application's access to the CPU when the radio is active. The |
Grimmkey | 0:b8221deeaa87 | 166 | * application can configure itself to have access to the CPU while the radio is active. |
Grimmkey | 0:b8221deeaa87 | 167 | * By default, the application will be not able to share CPU time with the SoftDevice |
Grimmkey | 0:b8221deeaa87 | 168 | * during radio activity. This parameter structure is used together with @ref sd_ble_opt_set |
Grimmkey | 0:b8221deeaa87 | 169 | * to configure the @ref BLE_COMMON_OPT_RADIO_CPU_MUTEX option. |
Grimmkey | 0:b8221deeaa87 | 170 | * |
Grimmkey | 0:b8221deeaa87 | 171 | * @note Note that the mutual exclusion of radio activity and CPU execution should remain enabled |
Grimmkey | 0:b8221deeaa87 | 172 | * when running the SoftDevice on hardware affected by PAN #44 "CCM may exceed real time |
Grimmkey | 0:b8221deeaa87 | 173 | * requirements"and PAN #45 "AAR may exceed real time requirements". |
Grimmkey | 0:b8221deeaa87 | 174 | * |
Grimmkey | 0:b8221deeaa87 | 175 | * @note @ref sd_ble_opt_get is not supported for this option. |
Grimmkey | 0:b8221deeaa87 | 176 | * |
Grimmkey | 0:b8221deeaa87 | 177 | */ |
Grimmkey | 0:b8221deeaa87 | 178 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 179 | { |
Grimmkey | 0:b8221deeaa87 | 180 | uint8_t enable : 1; /**< Enable mutual exclusion of radio activity and the CPU execution. */ |
Grimmkey | 0:b8221deeaa87 | 181 | } ble_common_opt_radio_cpu_mutex_t; |
Grimmkey | 0:b8221deeaa87 | 182 | |
Grimmkey | 0:b8221deeaa87 | 183 | /**@brief Option structure for common options. */ |
Grimmkey | 0:b8221deeaa87 | 184 | typedef union |
Grimmkey | 0:b8221deeaa87 | 185 | { |
Grimmkey | 0:b8221deeaa87 | 186 | ble_common_opt_radio_cpu_mutex_t radio_cpu_mutex; /**< Parameters for the option for the mutual exclusion of radio activity and CPU execution. */ |
Grimmkey | 0:b8221deeaa87 | 187 | } ble_common_opt_t; |
Grimmkey | 0:b8221deeaa87 | 188 | |
Grimmkey | 0:b8221deeaa87 | 189 | /**@brief Common BLE Option type, wrapping the module specific options. */ |
Grimmkey | 0:b8221deeaa87 | 190 | typedef union |
Grimmkey | 0:b8221deeaa87 | 191 | { |
Grimmkey | 0:b8221deeaa87 | 192 | ble_common_opt_t common_opt; /**< Common option, opt_id in BLE_COMMON_OPT_* series. */ |
Grimmkey | 0:b8221deeaa87 | 193 | ble_gap_opt_t gap_opt; /**< GAP option, opt_id in BLE_GAP_OPT_* series. */ |
Grimmkey | 0:b8221deeaa87 | 194 | } ble_opt_t; |
Grimmkey | 0:b8221deeaa87 | 195 | |
Grimmkey | 0:b8221deeaa87 | 196 | /** |
Grimmkey | 0:b8221deeaa87 | 197 | * @brief BLE GATTS init options |
Grimmkey | 0:b8221deeaa87 | 198 | */ |
Grimmkey | 0:b8221deeaa87 | 199 | typedef struct |
Grimmkey | 0:b8221deeaa87 | 200 | { |
Grimmkey | 0:b8221deeaa87 | 201 | ble_gatts_enable_params_t gatts_enable_params; /**< GATTS init options @ref ble_gatts_enable_params_t. */ |
Grimmkey | 0:b8221deeaa87 | 202 | } ble_enable_params_t; |
Grimmkey | 0:b8221deeaa87 | 203 | |
Grimmkey | 0:b8221deeaa87 | 204 | /** @} */ |
Grimmkey | 0:b8221deeaa87 | 205 | |
Grimmkey | 0:b8221deeaa87 | 206 | /** @addtogroup BLE_COMMON_FUNCTIONS Functions |
Grimmkey | 0:b8221deeaa87 | 207 | * @{ */ |
Grimmkey | 0:b8221deeaa87 | 208 | |
Grimmkey | 0:b8221deeaa87 | 209 | /**@brief Enable the bluetooth stack |
Grimmkey | 0:b8221deeaa87 | 210 | * |
Grimmkey | 0:b8221deeaa87 | 211 | * @param[in] p_ble_enable_params Pointer to ble_enable_params_t |
Grimmkey | 0:b8221deeaa87 | 212 | * |
Grimmkey | 0:b8221deeaa87 | 213 | * @details This call initializes the bluetooth stack, no other BLE related call can be called before this one has been executed. |
Grimmkey | 0:b8221deeaa87 | 214 | * |
Grimmkey | 0:b8221deeaa87 | 215 | * @return @ref NRF_SUCCESS BLE stack has been initialized successfully |
Grimmkey | 0:b8221deeaa87 | 216 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied. |
Grimmkey | 0:b8221deeaa87 | 217 | */ |
Grimmkey | 0:b8221deeaa87 | 218 | SVCALL(SD_BLE_ENABLE, uint32_t, sd_ble_enable(ble_enable_params_t * p_ble_enable_params)); |
Grimmkey | 0:b8221deeaa87 | 219 | |
Grimmkey | 0:b8221deeaa87 | 220 | /**@brief Get an event from the pending events queue. |
Grimmkey | 0:b8221deeaa87 | 221 | * |
Grimmkey | 0:b8221deeaa87 | 222 | * @param[in] 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>. |
Grimmkey | 0:b8221deeaa87 | 223 | * @param[in, out] p_len Pointer the length of the buffer, on return it is filled with the event length. |
Grimmkey | 0:b8221deeaa87 | 224 | * |
Grimmkey | 0:b8221deeaa87 | 225 | * @details This call allows the application to pull a BLE event from the BLE stack. The application is signalled that an event is |
Grimmkey | 0:b8221deeaa87 | 226 | * available from the BLE Stack by the triggering of the SD_EVT_IRQn interrupt (mapped to IRQ 22). |
Grimmkey | 0:b8221deeaa87 | 227 | * The application is free to choose whether to call this function from thread mode (main context) or directly from the Interrupt Service Routine |
Grimmkey | 0:b8221deeaa87 | 228 | * 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 |
Grimmkey | 0:b8221deeaa87 | 229 | * 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 stack. |
Grimmkey | 0:b8221deeaa87 | 230 | * Failure to do so could potentially leave events in the internal queue without the application being aware of this fact. |
Grimmkey | 0:b8221deeaa87 | 231 | * 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 |
Grimmkey | 0:b8221deeaa87 | 232 | * 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 |
Grimmkey | 0:b8221deeaa87 | 233 | * and the application can then call again with a larger buffer size. |
Grimmkey | 0:b8221deeaa87 | 234 | * 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, |
Grimmkey | 0:b8221deeaa87 | 235 | * and so it is the application's responsability to provide an amount of memory large enough so that the relevant event is copied in full. |
Grimmkey | 0:b8221deeaa87 | 236 | * The application may "peek" the event length by providing p_dest as a NULL pointer and inspecting the value of *p_len upon return. |
Grimmkey | 0:b8221deeaa87 | 237 | * |
Grimmkey | 0:b8221deeaa87 | 238 | * @note The pointer supplied must be aligned to the extend defined by @ref BLE_EVTS_PTR_ALIGNMENT |
Grimmkey | 0:b8221deeaa87 | 239 | * |
Grimmkey | 0:b8221deeaa87 | 240 | * @return @ref NRF_SUCCESS Event pulled and stored into the supplied buffer. |
Grimmkey | 0:b8221deeaa87 | 241 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied. |
Grimmkey | 0:b8221deeaa87 | 242 | * @return @ref NRF_ERROR_NOT_FOUND No events ready to be pulled. |
Grimmkey | 0:b8221deeaa87 | 243 | * @return @ref NRF_ERROR_DATA_SIZE Event ready but could not fit into the supplied buffer. |
Grimmkey | 0:b8221deeaa87 | 244 | */ |
Grimmkey | 0:b8221deeaa87 | 245 | SVCALL(SD_BLE_EVT_GET, uint32_t, sd_ble_evt_get(uint8_t* p_dest, uint16_t *p_len)); |
Grimmkey | 0:b8221deeaa87 | 246 | |
Grimmkey | 0:b8221deeaa87 | 247 | |
Grimmkey | 0:b8221deeaa87 | 248 | /**@brief Get the total number of available application transmission buffers in the BLE stack. |
Grimmkey | 0:b8221deeaa87 | 249 | * |
Grimmkey | 0:b8221deeaa87 | 250 | * @details This call allows the application to obtain the total number of |
Grimmkey | 0:b8221deeaa87 | 251 | * transmission buffers available for application data. Please note that |
Grimmkey | 0:b8221deeaa87 | 252 | * this does not give the number of free buffers, but rather the total amount of them. |
Grimmkey | 0:b8221deeaa87 | 253 | * The application has two options to handle its own application transmission buffers: |
Grimmkey | 0:b8221deeaa87 | 254 | * - Use a simple arithmetic calculation: at boot time the application should use this function |
Grimmkey | 0:b8221deeaa87 | 255 | * to find out the total amount of buffers available to it and store it in a variable. |
Grimmkey | 0:b8221deeaa87 | 256 | * Every time a packet that consumes an application buffer is sent using any of the |
Grimmkey | 0:b8221deeaa87 | 257 | * exposed functions in this BLE API, the application should decrement that variable. |
Grimmkey | 0:b8221deeaa87 | 258 | * Conversely, whenever a @ref BLE_EVT_TX_COMPLETE event is received by the application |
Grimmkey | 0:b8221deeaa87 | 259 | * it should retrieve the count field in such event and add that number to the same |
Grimmkey | 0:b8221deeaa87 | 260 | * variable storing the number of available packets. |
Grimmkey | 0:b8221deeaa87 | 261 | * This mechanism allows the application to be aware at any time of the number of |
Grimmkey | 0:b8221deeaa87 | 262 | * application packets available in the BLE stack's internal buffers, and therefore |
Grimmkey | 0:b8221deeaa87 | 263 | * it can know with certainty whether it is possible to send more data or it has to |
Grimmkey | 0:b8221deeaa87 | 264 | * wait for a @ref BLE_EVT_TX_COMPLETE event before it proceeds. |
Grimmkey | 0:b8221deeaa87 | 265 | * - Choose to simply not keep track of available buffers at all, and instead handle the |
Grimmkey | 0:b8221deeaa87 | 266 | * @ref BLE_ERROR_NO_TX_BUFFERS error by queueing the packet to be transmitted and |
Grimmkey | 0:b8221deeaa87 | 267 | * try again as soon as a @ref BLE_EVT_TX_COMPLETE event arrives. |
Grimmkey | 0:b8221deeaa87 | 268 | * |
Grimmkey | 0:b8221deeaa87 | 269 | * The API functions that <b>may</b> consume an application buffer depending on |
Grimmkey | 0:b8221deeaa87 | 270 | * the parameters supplied to them can be found below: |
Grimmkey | 0:b8221deeaa87 | 271 | * |
Grimmkey | 0:b8221deeaa87 | 272 | * - @ref sd_ble_gattc_write (write witout response only) |
Grimmkey | 0:b8221deeaa87 | 273 | * - @ref sd_ble_gatts_hvx (notifications only) |
Grimmkey | 0:b8221deeaa87 | 274 | * - @ref sd_ble_l2cap_tx (all packets) |
Grimmkey | 0:b8221deeaa87 | 275 | * |
Grimmkey | 0:b8221deeaa87 | 276 | * @param[out] p_count Pointer to a uint8_t which will contain the number of application transmission buffers upon |
Grimmkey | 0:b8221deeaa87 | 277 | * successful return. |
Grimmkey | 0:b8221deeaa87 | 278 | * |
Grimmkey | 0:b8221deeaa87 | 279 | * @return @ref NRF_SUCCESS Number of application transmission buffers retrieved successfully. |
Grimmkey | 0:b8221deeaa87 | 280 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
Grimmkey | 0:b8221deeaa87 | 281 | */ |
Grimmkey | 0:b8221deeaa87 | 282 | SVCALL(SD_BLE_TX_BUFFER_COUNT_GET, uint32_t, sd_ble_tx_buffer_count_get(uint8_t* p_count)); |
Grimmkey | 0:b8221deeaa87 | 283 | |
Grimmkey | 0:b8221deeaa87 | 284 | |
Grimmkey | 0:b8221deeaa87 | 285 | /**@brief Add a Vendor Specific UUID. |
Grimmkey | 0:b8221deeaa87 | 286 | * |
Grimmkey | 0:b8221deeaa87 | 287 | * @details This call enables the application to add a vendor specific UUID to the BLE stack's table, |
Grimmkey | 0:b8221deeaa87 | 288 | * for later use all other modules and APIs. This then allows the application to use the shorter, |
Grimmkey | 0:b8221deeaa87 | 289 | * 24-bit @ref ble_uuid_t format when dealing with both 16-bit and 128-bit UUIDs without having to |
Grimmkey | 0:b8221deeaa87 | 290 | * check for lengths and having split code paths. The way that this is accomplished is by extending the |
Grimmkey | 0:b8221deeaa87 | 291 | * grouping mechanism that the Bluetooth SIG standard base UUID uses for all other 128-bit UUIDs. The |
Grimmkey | 0:b8221deeaa87 | 292 | * type field in the @ref ble_uuid_t structure is an index (relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN) |
Grimmkey | 0:b8221deeaa87 | 293 | * to the table populated by multiple calls to this function, and the uuid field in the same structure |
Grimmkey | 0:b8221deeaa87 | 294 | * contains the 2 bytes at indices 12 and 13. The number of possible 128-bit UUIDs available to the |
Grimmkey | 0:b8221deeaa87 | 295 | * application is therefore the number of Vendor Specific UUIDs added with the help of this function times 65536, |
Grimmkey | 0:b8221deeaa87 | 296 | * although restricted to modifying bytes 12 and 13 for each of the entries in the supplied array. |
Grimmkey | 0:b8221deeaa87 | 297 | * |
Grimmkey | 0:b8221deeaa87 | 298 | * @note Bytes 12 and 13 of the provided UUID will not be used internally, since those are always replaced by |
Grimmkey | 0:b8221deeaa87 | 299 | * the 16-bit uuid field in @ref ble_uuid_t. |
Grimmkey | 0:b8221deeaa87 | 300 | * |
Grimmkey | 0:b8221deeaa87 | 301 | * |
Grimmkey | 0:b8221deeaa87 | 302 | * @param[in] p_vs_uuid Pointer to a 16-octet (128-bit) little endian Vendor Specific UUID disregarding |
Grimmkey | 0:b8221deeaa87 | 303 | * bytes 12 and 13. |
Grimmkey | 0:b8221deeaa87 | 304 | * @param[out] p_uuid_type Pointer where the type field in @ref ble_uuid_t corresponding to this UUID will be stored. |
Grimmkey | 0:b8221deeaa87 | 305 | * |
Grimmkey | 0:b8221deeaa87 | 306 | * @return @ref NRF_SUCCESS Successfully added the Vendor Specific UUID. |
Grimmkey | 0:b8221deeaa87 | 307 | * @return @ref NRF_ERROR_INVALID_ADDR If p_vs_uuid or p_uuid_type is NULL or invalid. |
Grimmkey | 0:b8221deeaa87 | 308 | * @return @ref NRF_ERROR_NO_MEM If there are no more free slots for VS UUIDs. |
Grimmkey | 0:b8221deeaa87 | 309 | * @return @ref NRF_ERROR_FORBIDDEN If p_vs_uuid has already been added to the VS UUID table. |
Grimmkey | 0:b8221deeaa87 | 310 | */ |
Grimmkey | 0:b8221deeaa87 | 311 | SVCALL(SD_BLE_UUID_VS_ADD, uint32_t, sd_ble_uuid_vs_add(ble_uuid128_t const * const p_vs_uuid, uint8_t * const p_uuid_type)); |
Grimmkey | 0:b8221deeaa87 | 312 | |
Grimmkey | 0:b8221deeaa87 | 313 | |
Grimmkey | 0:b8221deeaa87 | 314 | /** @brief Decode little endian raw UUID bytes (16-bit or 128-bit) into a 24 bit @ref ble_uuid_t structure. |
Grimmkey | 0:b8221deeaa87 | 315 | * |
Grimmkey | 0:b8221deeaa87 | 316 | * @details The raw UUID bytes excluding bytes 12 and 13 (i.e. bytes 0-11 and 14-15) of p_uuid_le are compared |
Grimmkey | 0:b8221deeaa87 | 317 | * to the corresponding ones in each entry of the table of vendor specific UUIDs pouplated with @ref sd_ble_uuid_vs_add |
Grimmkey | 0:b8221deeaa87 | 318 | * to look for a match. If there is such a match, bytes 12 and 13 are returned as p_uuid->uuid and the index |
Grimmkey | 0:b8221deeaa87 | 319 | * relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN as p_uuid->type. |
Grimmkey | 0:b8221deeaa87 | 320 | * |
Grimmkey | 0:b8221deeaa87 | 321 | * @note If the UUID length supplied is 2, then the type set by this call will always be @ref BLE_UUID_TYPE_BLE. |
Grimmkey | 0:b8221deeaa87 | 322 | * |
Grimmkey | 0:b8221deeaa87 | 323 | * @param[in] uuid_le_len Length in bytes of the buffer pointed to by p_uuid_le (must be 2 or 16 bytes). |
Grimmkey | 0:b8221deeaa87 | 324 | * @param[in] p_uuid_le Pointer pointing to little endian raw UUID bytes. |
Grimmkey | 0:b8221deeaa87 | 325 | * @param[in,out] p_uuid Pointer to a @ref ble_uuid_t structure to be filled in. |
Grimmkey | 0:b8221deeaa87 | 326 | * |
Grimmkey | 0:b8221deeaa87 | 327 | * @return @ref NRF_SUCCESS Successfully decoded into the @ref ble_uuid_t structure. |
Grimmkey | 0:b8221deeaa87 | 328 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
Grimmkey | 0:b8221deeaa87 | 329 | * @return @ref NRF_ERROR_INVALID_LENGTH Invalid UUID length. |
Grimmkey | 0:b8221deeaa87 | 330 | * @return @ref NRF_ERROR_NOT_FOUND For a 128-bit UUID, no match in the populated table of UUIDs. |
Grimmkey | 0:b8221deeaa87 | 331 | */ |
Grimmkey | 0:b8221deeaa87 | 332 | SVCALL(SD_BLE_UUID_DECODE, uint32_t, sd_ble_uuid_decode(uint8_t uuid_le_len, uint8_t const * const p_uuid_le, ble_uuid_t * const p_uuid)); |
Grimmkey | 0:b8221deeaa87 | 333 | |
Grimmkey | 0:b8221deeaa87 | 334 | |
Grimmkey | 0:b8221deeaa87 | 335 | /** @brief Encode a @ref ble_uuid_t structure into little endian raw UUID bytes (16-bit or 128-bit). |
Grimmkey | 0:b8221deeaa87 | 336 | * |
Grimmkey | 0:b8221deeaa87 | 337 | * @note The pointer to the destination buffer p_uuid_le may be NULL, in which case only the validitiy and size of p_uuid is computed. |
Grimmkey | 0:b8221deeaa87 | 338 | * |
Grimmkey | 0:b8221deeaa87 | 339 | * @param[in] p_uuid Pointer to a @ref ble_uuid_t structure that will be encoded into bytes. |
Grimmkey | 0:b8221deeaa87 | 340 | * @param[out] p_uuid_le_len Pointer to a uint8_t that will be filled with the encoded length (2 or 16 bytes). |
Grimmkey | 0:b8221deeaa87 | 341 | * @param[out] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes (2 or 16) will be stored. |
Grimmkey | 0:b8221deeaa87 | 342 | * |
Grimmkey | 0:b8221deeaa87 | 343 | * @return @ref NRF_SUCCESS Successfully encoded into the buffer. |
Grimmkey | 0:b8221deeaa87 | 344 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
Grimmkey | 0:b8221deeaa87 | 345 | * @return @ref NRF_ERROR_INVALID_PARAM Invalid UUID type. |
Grimmkey | 0:b8221deeaa87 | 346 | */ |
Grimmkey | 0:b8221deeaa87 | 347 | SVCALL(SD_BLE_UUID_ENCODE, uint32_t, sd_ble_uuid_encode(ble_uuid_t const * const p_uuid, uint8_t * const p_uuid_le_len, uint8_t * const p_uuid_le)); |
Grimmkey | 0:b8221deeaa87 | 348 | |
Grimmkey | 0:b8221deeaa87 | 349 | |
Grimmkey | 0:b8221deeaa87 | 350 | /**@brief Get Version Information. |
Grimmkey | 0:b8221deeaa87 | 351 | * |
Grimmkey | 0:b8221deeaa87 | 352 | * @details This call allows the application to get the BLE stack version information. |
Grimmkey | 0:b8221deeaa87 | 353 | * |
Grimmkey | 0:b8221deeaa87 | 354 | * @param[in] p_version Pointer to ble_version_t structure to be filled in. |
Grimmkey | 0:b8221deeaa87 | 355 | * |
Grimmkey | 0:b8221deeaa87 | 356 | * @return @ref NRF_SUCCESS Version information stored successfully. |
Grimmkey | 0:b8221deeaa87 | 357 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
Grimmkey | 0:b8221deeaa87 | 358 | * @return @ref NRF_ERROR_BUSY The stack is busy (typically doing a locally-initiated disconnection procedure). |
Grimmkey | 0:b8221deeaa87 | 359 | */ |
Grimmkey | 0:b8221deeaa87 | 360 | SVCALL(SD_BLE_VERSION_GET, uint32_t, sd_ble_version_get(ble_version_t * p_version)); |
Grimmkey | 0:b8221deeaa87 | 361 | |
Grimmkey | 0:b8221deeaa87 | 362 | |
Grimmkey | 0:b8221deeaa87 | 363 | /**@brief Provide a user memory block. |
Grimmkey | 0:b8221deeaa87 | 364 | * |
Grimmkey | 0:b8221deeaa87 | 365 | * @note This call can only be used as a response to a @ref BLE_EVT_USER_MEM_REQUEST event issued to the application. |
Grimmkey | 0:b8221deeaa87 | 366 | * |
Grimmkey | 0:b8221deeaa87 | 367 | * @param[in] conn_handle Connection handle. |
Grimmkey | 0:b8221deeaa87 | 368 | * @param[in] p_block Pointer to a user memory block structure. |
Grimmkey | 0:b8221deeaa87 | 369 | * |
Grimmkey | 0:b8221deeaa87 | 370 | * @return @ref NRF_SUCCESS Successfully queued a response to the peer. |
Grimmkey | 0:b8221deeaa87 | 371 | * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. |
Grimmkey | 0:b8221deeaa87 | 372 | * @return @ref NRF_ERROR_INVALID_STATE No execute write request pending. |
Grimmkey | 0:b8221deeaa87 | 373 | */ |
Grimmkey | 0:b8221deeaa87 | 374 | SVCALL(SD_BLE_USER_MEM_REPLY, uint32_t, sd_ble_user_mem_reply(uint16_t conn_handle, ble_user_mem_block_t *p_block)); |
Grimmkey | 0:b8221deeaa87 | 375 | |
Grimmkey | 0:b8221deeaa87 | 376 | |
Grimmkey | 0:b8221deeaa87 | 377 | /**@brief Set a BLE option. |
Grimmkey | 0:b8221deeaa87 | 378 | * |
Grimmkey | 0:b8221deeaa87 | 379 | * @details This call allows the application to set the value of an option. |
Grimmkey | 0:b8221deeaa87 | 380 | * |
Grimmkey | 0:b8221deeaa87 | 381 | * @param[in] opt_id Option ID. |
Grimmkey | 0:b8221deeaa87 | 382 | * @param[in] p_opt Pointer to a ble_opt_t structure containing the option value. |
Grimmkey | 0:b8221deeaa87 | 383 | * |
Grimmkey | 0:b8221deeaa87 | 384 | * @retval ::NRF_SUCCESS Option set successfully. |
Grimmkey | 0:b8221deeaa87 | 385 | * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
Grimmkey | 0:b8221deeaa87 | 386 | * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. |
Grimmkey | 0:b8221deeaa87 | 387 | * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints. |
Grimmkey | 0:b8221deeaa87 | 388 | * @retval ::NRF_ERROR_INVALID_STATE Unable to set the parameter at this time. |
Grimmkey | 0:b8221deeaa87 | 389 | * @retval ::NRF_ERROR_BUSY The stack is busy or the previous procedure has not completed. |
Grimmkey | 0:b8221deeaa87 | 390 | */ |
Grimmkey | 0:b8221deeaa87 | 391 | SVCALL(SD_BLE_OPT_SET, uint32_t, sd_ble_opt_set(uint32_t opt_id, ble_opt_t const *p_opt)); |
Grimmkey | 0:b8221deeaa87 | 392 | |
Grimmkey | 0:b8221deeaa87 | 393 | |
Grimmkey | 0:b8221deeaa87 | 394 | /**@brief Get a BLE option. |
Grimmkey | 0:b8221deeaa87 | 395 | * |
Grimmkey | 0:b8221deeaa87 | 396 | * @details This call allows the application to retrieve the value of an option. |
Grimmkey | 0:b8221deeaa87 | 397 | * |
Grimmkey | 0:b8221deeaa87 | 398 | * @param[in] opt_id Option ID. |
Grimmkey | 0:b8221deeaa87 | 399 | * @param[out] p_opt Pointer to a ble_opt_t structure to be filled in. |
Grimmkey | 0:b8221deeaa87 | 400 | * |
Grimmkey | 0:b8221deeaa87 | 401 | * @retval ::NRF_SUCCESS Option retrieved successfully. |
Grimmkey | 0:b8221deeaa87 | 402 | * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
Grimmkey | 0:b8221deeaa87 | 403 | * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. |
Grimmkey | 0:b8221deeaa87 | 404 | * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints. |
Grimmkey | 0:b8221deeaa87 | 405 | * @retval ::NRF_ERROR_INVALID_STATE Unable to retrieve the parameter at this time. |
Grimmkey | 0:b8221deeaa87 | 406 | * @retval ::NRF_ERROR_BUSY The stack is busy or the previous procedure has not completed. |
Grimmkey | 0:b8221deeaa87 | 407 | * @retval ::NRF_ERROR_NOT_SUPPORTED This option is not supported. |
Grimmkey | 0:b8221deeaa87 | 408 | * |
Grimmkey | 0:b8221deeaa87 | 409 | */ |
Grimmkey | 0:b8221deeaa87 | 410 | SVCALL(SD_BLE_OPT_GET, uint32_t, sd_ble_opt_get(uint32_t opt_id, ble_opt_t *p_opt)); |
Grimmkey | 0:b8221deeaa87 | 411 | |
Grimmkey | 0:b8221deeaa87 | 412 | /** @} */ |
Grimmkey | 0:b8221deeaa87 | 413 | |
Grimmkey | 0:b8221deeaa87 | 414 | #endif /* BLE_H__ */ |
Grimmkey | 0:b8221deeaa87 | 415 | |
Grimmkey | 0:b8221deeaa87 | 416 | /** |
Grimmkey | 0:b8221deeaa87 | 417 | @} |
Grimmkey | 0:b8221deeaa87 | 418 | @} |
Grimmkey | 0:b8221deeaa87 | 419 | */ |