Skip to content

Commit 19c0cff

Browse files
committed
- add RFduino compatibility
1 parent 3e96851 commit 19c0cff

File tree

9 files changed

+349
-201
lines changed

9 files changed

+349
-201
lines changed

utility/RFduino/ble.h

+37-29
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
/*
1+
/*
22
* Copyright (c) Nordic Semiconductor ASA
33
* All rights reserved.
4-
*
4+
*
55
* Redistribution and use in source and binary forms, with or without modification,
66
* are permitted provided that the following conditions are met:
7-
*
7+
*
88
* 1. Redistributions of source code must retain the above copyright notice, this
99
* list of conditions and the following disclaimer.
10-
*
10+
*
1111
* 2. Redistributions in binary form must reproduce the above copyright notice, this
1212
* list of conditions and the following disclaimer in the documentation and/or
1313
* other materials provided with the distribution.
14-
*
14+
*
1515
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
1616
* contributors to this software may be used to endorse or promote products
1717
* derived from this software without specific prior written permission.
18-
*
18+
*
1919
* 4. This software must only be used in a processor manufactured by Nordic
2020
* Semiconductor ASA, or in a processor manufactured by a third party that
2121
* is used in combination with a processor manufactured by Nordic Semiconductor.
22-
*
23-
*
22+
*
23+
*
2424
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2525
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2626
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -31,7 +31,7 @@
3131
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3232
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3333
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34-
*
34+
*
3535
*/
3636

3737
/**
@@ -63,8 +63,12 @@
6363
*/
6464
enum BLE_COMMON_SVCS
6565
{
66+
#ifndef __RFduino__
6667
SD_BLE_ENABLE = BLE_SVC_BASE, /**< Enable and initialize the BLE stack */
6768
SD_BLE_EVT_GET, /**< Get an event from the pending events queue. */
69+
#else
70+
SD_BLE_EVT_GET = BLE_SVC_BASE, /**< Get an event from the pending events queue. */
71+
#endif
6872
SD_BLE_TX_BUFFER_COUNT_GET, /**< Get the total number of available application transmission buffers from the BLE stack. */
6973
SD_BLE_UUID_VS_ADD, /**< Add a Vendor Specific UUID. */
7074
SD_BLE_UUID_DECODE, /**< Decode UUID bytes. */
@@ -152,8 +156,10 @@ typedef struct
152156
union
153157
{
154158
ble_evt_tx_complete_t tx_complete; /**< Transmission Complete. */
159+
#ifndef __RFduino__
155160
ble_evt_user_mem_request_t user_mem_request; /**< User Memory Request Event Parameters. */
156161
ble_evt_user_mem_release_t user_mem_release; /**< User Memory Release Event Parameters. */
162+
#endif
157163
} params;
158164
} ble_common_evt_t;
159165

@@ -238,6 +244,7 @@ typedef struct
238244
/** @addtogroup BLE_COMMON_FUNCTIONS Functions
239245
* @{ */
240246

247+
#ifndef __RFduino__
241248
/**@brief Enable the BLE stack
242249
*
243250
* @param[in] p_ble_enable_params Pointer to ble_enable_params_t
@@ -252,22 +259,23 @@ typedef struct
252259
* @return @ref NRF_ERROR_NO_MEM The Attribute Table size is too large. Decrease size in @ref ble_gatts_enable_params_t.
253260
*/
254261
SVCALL(SD_BLE_ENABLE, uint32_t, sd_ble_enable(ble_enable_params_t * p_ble_enable_params));
262+
#endif
255263

256264
/**@brief Get an event from the pending events queue.
257265
*
258266
* @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>.
259267
* @param[in, out] p_len Pointer the length of the buffer, on return it is filled with the event length.
260268
*
261-
* @details This call allows the application to pull a BLE event from the BLE stack. The application is signalled that an event is
269+
* @details This call allows the application to pull a BLE event from the BLE stack. The application is signalled that an event is
262270
* available from the BLE stack by the triggering of the SD_EVT_IRQn interrupt.
263271
* The application is free to choose whether to call this function from thread mode (main context) or directly from the Interrupt Service Routine
264272
* 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
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.
273+
* 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.
266274
* Failure to do so could potentially leave events in the internal queue without the application being aware of this fact.
267275
* 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
268276
* 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
269277
* and the application can then call again with a larger buffer size.
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,
278+
* 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,
271279
* 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.
272280
* The application may "peek" the event length by providing p_dest as a NULL pointer and inspecting the value of *p_len upon return.
273281
*
@@ -289,7 +297,7 @@ SVCALL(SD_BLE_EVT_GET, uint32_t, sd_ble_evt_get(uint8_t *p_dest, uint16_t *p_len
289297
* The application has two options to handle its own application transmission buffers:
290298
* - Use a simple arithmetic calculation: at boot time the application should use this function
291299
* to find out the total amount of buffers available to it and store it in a variable.
292-
* Every time a packet that consumes an application buffer is sent using any of the
300+
* Every time a packet that consumes an application buffer is sent using any of the
293301
* exposed functions in this BLE API, the application should decrement that variable.
294302
* Conversely, whenever a @ref BLE_EVT_TX_COMPLETE event is received by the application
295303
* it should retrieve the count field in such event and add that number to the same
@@ -298,11 +306,11 @@ SVCALL(SD_BLE_EVT_GET, uint32_t, sd_ble_evt_get(uint8_t *p_dest, uint16_t *p_len
298306
* application packets available in the BLE stack's internal buffers, and therefore
299307
* it can know with certainty whether it is possible to send more data or it has to
300308
* wait for a @ref BLE_EVT_TX_COMPLETE event before it proceeds.
301-
* - Choose to simply not keep track of available buffers at all, and instead handle the
302-
* @ref BLE_ERROR_NO_TX_BUFFERS error by queueing the packet to be transmitted and
309+
* - Choose to simply not keep track of available buffers at all, and instead handle the
310+
* @ref BLE_ERROR_NO_TX_BUFFERS error by queueing the packet to be transmitted and
303311
* try again as soon as a @ref BLE_EVT_TX_COMPLETE event arrives.
304312
*
305-
* The API functions that <b>may</b> consume an application buffer depending on
313+
* The API functions that <b>may</b> consume an application buffer depending on
306314
* the parameters supplied to them can be found below:
307315
*
308316
* - @ref sd_ble_gattc_write (write without response only)
@@ -323,15 +331,15 @@ SVCALL(SD_BLE_TX_BUFFER_COUNT_GET, uint32_t, sd_ble_tx_buffer_count_get(uint8_t
323331
* @details This call enables the application to add a vendor specific UUID to the BLE stack's table,
324332
* for later use all other modules and APIs. This then allows the application to use the shorter,
325333
* 24-bit @ref ble_uuid_t format when dealing with both 16-bit and 128-bit UUIDs without having to
326-
* check for lengths and having split code paths. The way that this is accomplished is by extending the
327-
* grouping mechanism that the Bluetooth SIG standard base UUID uses for all other 128-bit UUIDs. The
328-
* type field in the @ref ble_uuid_t structure is an index (relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN)
329-
* to the table populated by multiple calls to this function, and the uuid field in the same structure
330-
* contains the 2 bytes at indices 12 and 13. The number of possible 128-bit UUIDs available to the
331-
* application is therefore the number of Vendor Specific UUIDs added with the help of this function times 65536,
334+
* check for lengths and having split code paths. The way that this is accomplished is by extending the
335+
* grouping mechanism that the Bluetooth SIG standard base UUID uses for all other 128-bit UUIDs. The
336+
* type field in the @ref ble_uuid_t structure is an index (relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN)
337+
* to the table populated by multiple calls to this function, and the uuid field in the same structure
338+
* contains the 2 bytes at indices 12 and 13. The number of possible 128-bit UUIDs available to the
339+
* application is therefore the number of Vendor Specific UUIDs added with the help of this function times 65536,
332340
* although restricted to modifying bytes 12 and 13 for each of the entries in the supplied array.
333341
*
334-
* @note Bytes 12 and 13 of the provided UUID will not be used internally, since those are always replaced by
342+
* @note Bytes 12 and 13 of the provided UUID will not be used internally, since those are always replaced by
335343
* the 16-bit uuid field in @ref ble_uuid_t.
336344
*
337345
*
@@ -348,11 +356,11 @@ SVCALL(SD_BLE_UUID_VS_ADD, uint32_t, sd_ble_uuid_vs_add(ble_uuid128_t const *p_v
348356

349357

350358
/** @brief Decode little endian raw UUID bytes (16-bit or 128-bit) into a 24 bit @ref ble_uuid_t structure.
351-
*
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
353-
* to the corresponding ones in each entry of the table of vendor specific UUIDs populated with @ref sd_ble_uuid_vs_add
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
355-
* relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN as p_uuid->type.
359+
*
360+
* @details The raw UUID bytes excluding bytes 12 and 13 (i.e. bytes 0-11 and 14-15) of p_uuid_le are compared
361+
* to the corresponding ones in each entry of the table of vendor specific UUIDs populated with @ref sd_ble_uuid_vs_add
362+
* to look for a match. If there is such a match, bytes 12 and 13 are returned as p_uuid->uuid and the index
363+
* relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN as p_uuid->type.
356364
*
357365
* @note If the UUID length supplied is 2, then the type set by this call will always be @ref BLE_UUID_TYPE_BLE.
358366
*
@@ -364,7 +372,7 @@ SVCALL(SD_BLE_UUID_VS_ADD, uint32_t, sd_ble_uuid_vs_add(ble_uuid128_t const *p_v
364372
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
365373
* @retval ::NRF_ERROR_INVALID_LENGTH Invalid UUID length.
366374
* @retval ::NRF_ERROR_NOT_FOUND For a 128-bit UUID, no match in the populated table of UUIDs.
367-
*/
375+
*/
368376
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));
369377

370378

utility/RFduino/ble_err.h

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
/*
1+
/*
22
* Copyright (c) Nordic Semiconductor ASA
33
* All rights reserved.
4-
*
4+
*
55
* Redistribution and use in source and binary forms, with or without modification,
66
* are permitted provided that the following conditions are met:
7-
*
7+
*
88
* 1. Redistributions of source code must retain the above copyright notice, this
99
* list of conditions and the following disclaimer.
10-
*
10+
*
1111
* 2. Redistributions in binary form must reproduce the above copyright notice, this
1212
* list of conditions and the following disclaimer in the documentation and/or
1313
* other materials provided with the distribution.
14-
*
14+
*
1515
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
1616
* contributors to this software may be used to endorse or promote products
1717
* derived from this software without specific prior written permission.
18-
*
18+
*
1919
* 4. This software must only be used in a processor manufactured by Nordic
2020
* Semiconductor ASA, or in a processor manufactured by a third party that
2121
* is used in combination with a processor manufactured by Nordic Semiconductor.
22-
*
23-
*
22+
*
23+
*
2424
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2525
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2626
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -31,7 +31,7 @@
3131
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3232
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3333
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34-
*
34+
*
3535
*/
3636

3737
/**
@@ -56,11 +56,17 @@
5656

5757
/* @defgroup BLE_ERRORS Error Codes
5858
* @{ */
59+
#ifndef __RFduino__
5960
#define BLE_ERROR_NOT_ENABLED (NRF_ERROR_STK_BASE_NUM+0x001) /**< @ref sd_ble_enable has not been called. */
6061
#define BLE_ERROR_INVALID_CONN_HANDLE (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid connection handle. */
6162
#define BLE_ERROR_INVALID_ATTR_HANDLE (NRF_ERROR_STK_BASE_NUM+0x003) /**< Invalid attribute handle. */
6263
#define BLE_ERROR_NO_TX_BUFFERS (NRF_ERROR_STK_BASE_NUM+0x004) /**< Buffer capacity exceeded. */
6364
#define BLE_ERROR_INVALID_ROLE (NRF_ERROR_STK_BASE_NUM+0x005) /**< Invalid role. */
65+
#else
66+
#define BLE_ERROR_INVALID_CONN_HANDLE (NRF_ERROR_STK_BASE_NUM+0x001) /**< Invalid connection handle. */
67+
#define BLE_ERROR_INVALID_ATTR_HANDLE (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid attribute handle. */
68+
#define BLE_ERROR_NO_TX_BUFFERS (NRF_ERROR_STK_BASE_NUM+0x003) /**< Buffer capacity exceeded. */
69+
#endif
6470
/** @} */
6571

6672

0 commit comments

Comments
 (0)