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