mediCAL's first BLE project
Fork of nRF51822 by
Revision 65:98215c4f3a25, committed 2014-09-08
- Comitter:
- Rohit Grover
- Date:
- Mon Sep 08 17:21:46 2014 +0100
- Parent:
- 64:5d5f5cbc7c79
- Child:
- 66:b3680699d9a4
- Commit message:
- Release 0.1.3
Update to v6.1.0 of Nordic's SDK.
Bugfixes
~~~~~~~~
- Handle all valid disconnection reasons.
Compatible with Release 0.1.1 of the BLE_API.
Changed in this revision
--- a/btle/btle.cpp Mon Sep 08 15:45:22 2014 +0000 +++ b/btle/btle.cpp Mon Sep 08 17:21:46 2014 +0100 @@ -141,9 +141,24 @@ ASSERT_STATUS_RET_VOID ( ble_bondmngr_bonded_centrals_store()); #endif - if (p_ble_evt->evt.gap_evt.params.disconnected.reason == BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION) { - nRF51Gap::getInstance().processDisconnectionEvent(handle, Gap::LOCAL_HOST_TERMINATED_CONNECTION); + Gap::DisconnectionReason_t reason; + switch (p_ble_evt->evt.gap_evt.params.disconnected.reason) { + case BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION: + reason = Gap::LOCAL_HOST_TERMINATED_CONNECTION; + break; + case BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION: + reason = Gap::REMOTE_USER_TERMINATED_CONNECTION; + break; + case BLE_HCI_CONN_INTERVAL_UNACCEPTABLE: + reason = Gap::CONN_INTERVAL_UNACCEPTABLE; + break; + default: + /* Please refer to the underlying transport library for an + * interpretion of this reason's value. */ + reason = static_cast<Gap::DisconnectionReason_t>(p_ble_evt->evt.gap_evt.params.disconnected.reason); + break; } + nRF51Gap::getInstance().processDisconnectionEvent(handle, reason); break; }
--- a/nordic/app_common/crc16.cpp Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/app_common/crc16.cpp Mon Sep 08 17:21:46 2014 +0100 @@ -20,12 +20,12 @@ for (i = 0; i < size; i++) { - crc = (unsigned char)(crc >> 8) | (crc << 8); + crc = (unsigned char)(crc >> 8) | (crc << 8); crc ^= p_data[i]; crc ^= (unsigned char)(crc & 0xff) >> 4; crc ^= (crc << 8) << 4; crc ^= ((crc & 0xff) << 4) << 1; } - + return crc; }
--- a/nordic/app_common/pstorage.cpp Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/app_common/pstorage.cpp Mon Sep 08 17:21:46 2014 +0100 @@ -80,7 +80,9 @@ * @brief Verifies block size requested by Application in registration API. */ #define BLOCK_COUNT_CHECK(COUNT, SIZE) \ - if (((COUNT) == 0) || ((m_next_page_addr + ((COUNT) *(SIZE)) > PSTORAGE_SWAP_ADDR))) \ + if (((COUNT) == 0) || \ + ((m_next_page_addr + ((COUNT) *(SIZE)) > PSTORAGE_SWAP_ADDR)) || \ + ((((COUNT) * (SIZE)) > PSTORAGE_FLASH_PAGE_SIZE) && (PSTORAGE_FLASH_PAGE_SIZE % (SIZE)))) \ { \ return NRF_ERROR_INVALID_PARAM; \ } @@ -372,13 +374,10 @@ { // Flash could be accessed by modules other than Bond Manager, hence a busy error is // acceptable, but any other error needs to be indicated to the bond manager. - if (retval != NRF_ERROR_BUSY) + if (retval == NRF_ERROR_BUSY) { - app_notify(retval); - } - else - { - // In case of busy next trigger will be a success or a failure event. + // In case of busy error code, it is possible to attempt to access flash. + retval = NRF_SUCCESS; } } }
--- a/nordic/ble/ble_advdata.cpp Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/ble/ble_advdata.cpp Mon Sep 08 17:21:46 2014 +0100 @@ -19,33 +19,33 @@ // Offset from where advertisement data other than flags information can start. -#define ADV_FLAG_OFFSET 2 +#define ADV_FLAG_OFFSET 2 // Offset for Advertising Data. // Offset is 2 as each Advertising Data contain 1 octet of Adveritising Data Type and // one octet Advertising Data Length. -#define ADV_DATA_OFFSET 2 +#define ADV_DATA_OFFSET 2 // NOTE: For now, Security Manager TK Value and Security Manager Out of Band Flags (OOB) are omitted // from the advertising data. static uint32_t name_encode(const ble_advdata_t * p_advdata, - uint8_t * p_encoded_data, - uint8_t * p_len) + uint8_t * p_encoded_data, + uint8_t * p_len) { uint32_t err_code; uint16_t rem_adv_data_len; uint16_t actual_length; uint8_t adv_data_format; uint8_t adv_offset; - + adv_offset = *p_len; - - + + // Check for buffer overflow. if ((adv_offset + ADV_DATA_OFFSET > BLE_GAP_ADV_MAX_SIZE) || - ((p_advdata->short_name_len + ADV_DATA_OFFSET) > BLE_GAP_ADV_MAX_SIZE)) + ((p_advdata->short_name_len + ADV_DATA_OFFSET) > BLE_GAP_ADV_MAX_SIZE)) { return NRF_ERROR_DATA_SIZE; } @@ -63,14 +63,14 @@ if ((p_advdata->name_type == BLE_ADVDATA_FULL_NAME) && (actual_length <= rem_adv_data_len)) { // Complete device name can fit, setting Complete Name in Adv Data. - adv_data_format = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME; + adv_data_format = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME; rem_adv_data_len = actual_length; } else { // Else short name needs to be used. Or application has requested use of short name. adv_data_format = BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME; - + // If application has set a preference on the short name size, it needs to be considered, // else fit what can be fit. if ((p_advdata->short_name_len != 0) && (p_advdata->short_name_len <= rem_adv_data_len)) @@ -84,12 +84,12 @@ rem_adv_data_len = actual_length; } } - + // Complete name field in encoded data. p_encoded_data[adv_offset++] = rem_adv_data_len + 1; p_encoded_data[adv_offset++] = adv_data_format; - (*p_len) += (rem_adv_data_len + ADV_DATA_OFFSET); - + (*p_len) += (rem_adv_data_len + ADV_DATA_OFFSET); + return NRF_SUCCESS; } @@ -111,21 +111,21 @@ { return err_code; } - + // Encode Length, AD Type and Appearance. p_encoded_data[(*p_len)++] = 3; p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_APPEARANCE; (*p_len) += uint16_encode(appearance, &p_encoded_data[*p_len]); - + return NRF_SUCCESS; } static uint32_t uint8_array_encode(const uint8_array_t * p_uint8_array, uint8_t adv_type, - uint8_t * p_encoded_data, - uint8_t * p_len) + uint8_t * p_encoded_data, + uint8_t * p_len) { // Check parameter consistency. if (p_uint8_array->p_data == NULL) @@ -142,11 +142,11 @@ // Encode Length and AD Type. p_encoded_data[(*p_len)++] = 1 + p_uint8_array->size; p_encoded_data[(*p_len)++] = adv_type; - + // Encode array. memcpy(&p_encoded_data[*p_len], p_uint8_array->p_data, p_uint8_array->size); (*p_len) += p_uint8_array->size; - + return NRF_SUCCESS; } @@ -165,7 +165,7 @@ p_encoded_data[(*p_len)++] = 2; p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_TX_POWER_LEVEL; p_encoded_data[(*p_len)++] = (uint8_t)tx_power_level; - + return NRF_SUCCESS; } @@ -173,13 +173,13 @@ static uint32_t uuid_list_sized_encode(const ble_advdata_uuid_list_t * p_uuid_list, uint8_t adv_type, uint8_t uuid_size, - uint8_t * p_encoded_data, - uint8_t * p_len) + uint8_t * p_encoded_data, + uint8_t * p_len) { int i; bool is_heading_written = false; - uint8_t start_pos = *p_len; - + uint8_t start_pos = *p_len; + for (i = 0; i < p_uuid_list->uuid_cnt; i++) { uint32_t err_code; @@ -192,7 +192,7 @@ { return err_code; } - + // Check size. if (encoded_size == uuid_size) { @@ -203,15 +203,15 @@ { return NRF_ERROR_DATA_SIZE; } - + if (!is_heading_written) { // Write AD structure heading. (*p_len)++; p_encoded_data[(*p_len)++] = adv_type; - is_heading_written = true; + is_heading_written = true; } - + // Write UUID. err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &p_encoded_data[*p_len]); if (err_code != NRF_SUCCESS) @@ -221,13 +221,13 @@ (*p_len) += encoded_size; } } - + if (is_heading_written) { // Write length. p_encoded_data[start_pos] = (*p_len) - (start_pos + 1); } - + return NRF_SUCCESS; } @@ -235,11 +235,11 @@ static uint32_t uuid_list_encode(const ble_advdata_uuid_list_t * p_uuid_list, uint8_t adv_type_16, uint8_t adv_type_128, - uint8_t * p_encoded_data, - uint8_t * p_len) + uint8_t * p_encoded_data, + uint8_t * p_len) { uint32_t err_code; - + // Encode 16 bit UUIDs. err_code = uuid_list_sized_encode(p_uuid_list, adv_type_16, @@ -250,7 +250,7 @@ { return err_code; } - + // Encode 128 bit UUIDs. err_code = uuid_list_sized_encode(p_uuid_list, adv_type_128, @@ -261,7 +261,7 @@ { return err_code; } - + return NRF_SUCCESS; } @@ -269,12 +269,12 @@ static uint32_t conn_int_check(const ble_advdata_conn_int_t *p_conn_int) { // Check Minimum Connection Interval. - if ((p_conn_int->min_conn_interval < 0x0006) || + if ((p_conn_int->min_conn_interval < 0x0006) || ( - (p_conn_int->min_conn_interval > 0x0c80) && + (p_conn_int->min_conn_interval > 0x0c80) && (p_conn_int->min_conn_interval != 0xffff) ) - ) + ) { return NRF_ERROR_INVALID_PARAM; } @@ -285,7 +285,7 @@ (p_conn_int->max_conn_interval > 0x0c80) && (p_conn_int->max_conn_interval != 0xffff) ) - ) + ) { return NRF_ERROR_INVALID_PARAM; } @@ -294,18 +294,18 @@ if ((p_conn_int->min_conn_interval != 0xffff) && (p_conn_int->max_conn_interval != 0xffff) && (p_conn_int->min_conn_interval > p_conn_int->max_conn_interval) - ) + ) { return NRF_ERROR_INVALID_PARAM; } - + return NRF_SUCCESS; } static uint32_t conn_int_encode(const ble_advdata_conn_int_t * p_conn_int, - uint8_t * p_encoded_data, - uint8_t * p_len) + uint8_t * p_encoded_data, + uint8_t * p_len) { uint32_t err_code; @@ -314,32 +314,32 @@ { return NRF_ERROR_DATA_SIZE; } - + // Check parameters. err_code = conn_int_check(p_conn_int); if (err_code != NRF_SUCCESS) { return err_code; } - + // Encode Length and AD Type. p_encoded_data[(*p_len)++] = 1 + 2 * sizeof(uint16_le_t); p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE; - + // Encode Minimum and Maximum Connection Intervals. (*p_len) += uint16_encode(p_conn_int->min_conn_interval, &p_encoded_data[*p_len]); (*p_len) += uint16_encode(p_conn_int->max_conn_interval, &p_encoded_data[*p_len]); - + return NRF_SUCCESS; } static uint32_t manuf_specific_data_encode(const ble_advdata_manuf_data_t * p_manuf_sp_data, - uint8_t * p_encoded_data, - uint8_t * p_len) + uint8_t * p_encoded_data, + uint8_t * p_len) { uint8_t data_size = sizeof(uint16_le_t) + p_manuf_sp_data->data.size; - + // Check for buffer overflow. if ((*p_len) + ADV_DATA_OFFSET + data_size > BLE_GAP_ADV_MAX_SIZE) { @@ -363,14 +363,14 @@ memcpy(&p_encoded_data[*p_len], p_manuf_sp_data->data.p_data, p_manuf_sp_data->data.size); (*p_len) += p_manuf_sp_data->data.size; } - + return NRF_SUCCESS; } static uint32_t service_data_encode(const ble_advdata_t * p_advdata, - uint8_t * p_encoded_data, - uint8_t * p_len) + uint8_t * p_encoded_data, + uint8_t * p_len) { uint8_t i; @@ -379,22 +379,22 @@ { return NRF_ERROR_INVALID_PARAM; } - + for (i = 0; i < p_advdata->service_data_count; i++) { ble_advdata_service_data_t * p_service_data; uint8_t data_size; - + p_service_data = &p_advdata->p_service_data_array[i]; data_size = sizeof(uint16_le_t) + p_service_data->data.size; - + // Encode Length and AD Type. p_encoded_data[(*p_len)++] = 1 + data_size; p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SERVICE_DATA; - + // Encode service UUID. (*p_len) += uint16_encode(p_service_data->service_uuid, &p_encoded_data[*p_len]); - + // Encode additional service data. if (p_service_data->data.size > 0) { @@ -406,19 +406,19 @@ (*p_len) += p_service_data->data.size; } } - + return NRF_SUCCESS; } static uint32_t adv_data_encode(const ble_advdata_t * p_advdata, - uint8_t * p_encoded_data, - uint8_t * p_len) + uint8_t * p_encoded_data, + uint8_t * p_len) { uint32_t err_code = NRF_SUCCESS; - + *p_len = 0; - + // Encode name. if (p_advdata->name_type != BLE_ADVDATA_NO_NAME) { @@ -428,7 +428,7 @@ return err_code; } } - + // Encode appearance. if (p_advdata->include_appearance) { @@ -438,7 +438,7 @@ return err_code; } } - + // Encode flags. if (p_advdata->flags.size > 0) { @@ -451,7 +451,7 @@ return err_code; } } - + // Encode TX power level. if (p_advdata->p_tx_power_level != NULL) { @@ -475,7 +475,7 @@ return err_code; } } - + // Encode 'complete' uuid list. if (p_advdata->uuids_complete.uuid_cnt > 0) { @@ -489,7 +489,7 @@ return err_code; } } - + // Encode 'solicited service' uuid list. if (p_advdata->uuids_solicited.uuid_cnt > 0) { @@ -503,7 +503,7 @@ return err_code; } } - + // Encode Slave Connection Interval Range. if (p_advdata->p_slave_conn_int != NULL) { @@ -513,7 +513,7 @@ return err_code; } } - + // Encode Manufacturer Specific Data. if (p_advdata->p_manuf_specific_data != NULL) { @@ -525,7 +525,7 @@ return err_code; } } - + // Encode Service Data. if (p_advdata->service_data_count > 0) { @@ -535,7 +535,7 @@ return err_code; } } - + return err_code; } @@ -546,11 +546,11 @@ if ((p_advdata->flags.size == 0) || (p_advdata->flags.p_data == NULL) || ((p_advdata->flags.p_data[0] & BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) == 0) - ) + ) { return NRF_ERROR_INVALID_PARAM; } - + return NRF_SUCCESS; } @@ -562,7 +562,7 @@ { return NRF_ERROR_INVALID_PARAM; } - + return NRF_SUCCESS; } @@ -571,7 +571,7 @@ { uint32_t err_code; uint8_t len_advdata = 0; - uint8_t len_srdata = 0; + uint8_t len_srdata = 0; uint8_t encoded_advdata[BLE_GAP_ADV_MAX_SIZE]; uint8_t encoded_srdata[BLE_GAP_ADV_MAX_SIZE]; uint8_t * p_encoded_advdata; @@ -585,7 +585,7 @@ { return err_code; } - + err_code = adv_data_encode(p_advdata, encoded_advdata, &len_advdata); if (err_code != NRF_SUCCESS) { @@ -597,7 +597,7 @@ { p_encoded_advdata = NULL; } - + // Encode scan response data (if supplied). if (p_srdata != NULL) { @@ -606,7 +606,7 @@ { return err_code; } - + err_code = adv_data_encode(p_srdata, encoded_srdata, &len_srdata); if (err_code != NRF_SUCCESS) {
--- a/nordic/ble/ble_conn_params.cpp Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/ble/ble_conn_params.cpp Mon Sep 08 17:21:46 2014 +0100 @@ -226,7 +226,7 @@ (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle) && (p_evt_write->len == 2) - ) + ) { // Check if this is a 'start notification' if (ble_srv_is_notification_enabled(p_evt_write->data)) @@ -280,7 +280,7 @@ default: // No implementation needed. - break; + break; } }
--- a/nordic/ble/ble_services/ble_srv_common.cpp Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/ble/ble_services/ble_srv_common.cpp Mon Sep 08 17:21:46 2014 +0100 @@ -21,14 +21,14 @@ #include "app_error.h" -uint8_t ble_srv_report_ref_encode(uint8_t * p_encoded_buffer, +uint8_t ble_srv_report_ref_encode(uint8_t * p_encoded_buffer, const ble_srv_report_ref_t * p_report_ref) { uint8_t len = 0; - + p_encoded_buffer[len++] = p_report_ref->report_id; p_encoded_buffer[len++] = p_report_ref->report_type; - + APP_ERROR_CHECK_BOOL(len == BLE_SRV_ENCODED_REPORT_REF_LEN); return len; }
--- a/nordic/nrf-sdk/app_common/app_button.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/app_common/app_button.h Mon Sep 08 17:21:46 2014 +0100 @@ -40,6 +40,7 @@ #include <stdint.h> #include <stdbool.h> +#include "nrf.h" #include "app_error.h" #include "app_scheduler.h" #include "nrf_gpio.h" @@ -97,7 +98,7 @@ (USE_SCHEDULER) ? app_button_evt_schedule : NULL); \ APP_ERROR_CHECK(ERR_CODE); \ } while (0) - + /**@brief Function for initializing the Buttons. * * @details This function will initialize the specified pins as buttons, and configure the Button @@ -106,7 +107,7 @@ * @note Normally initialization should be done using the APP_BUTTON_INIT() macro, as that will take * care of connecting the Buttons module to the scheduler (if specified). * - * @note app_button_enable() function must be called in order to enable the button detection. + * @note app_button_enable() function must be called in order to enable the button detection. * * @param[in] p_buttons Array of buttons to be used (NOTE: Must be static!). * @param[in] button_count Number of buttons. @@ -141,13 +142,13 @@ /**@brief Function for checking if a button is currently being pushed. * - * @param[in] pin_no Button pin to be checked. + * @param[in] button_id Button index (in the app_button_cfg_t array given to app_button_init) to be checked. * @param[out] p_is_pushed Button state. * * @retval NRF_SUCCESS State successfully read. - * @retval NRF_ERROR_INVALID_PARAM Invalid pin_no. + * @retval NRF_ERROR_INVALID_PARAM Invalid button index. */ -uint32_t app_button_is_pushed(uint8_t pin_no, bool * p_is_pushed); +uint32_t app_button_is_pushed(uint8_t button_id, bool * p_is_pushed); // Type and functions for connecting the Buttons module to the scheduler: @@ -163,7 +164,7 @@ static __INLINE void app_button_evt_get(void * p_event_data, uint16_t event_size) { app_button_event_t * p_buttons_event = (app_button_event_t *)p_event_data; - + APP_ERROR_CHECK_BOOL(event_size == sizeof(app_button_event_t)); p_buttons_event->button_handler(p_buttons_event->pin_no, p_buttons_event->button_action); } @@ -173,11 +174,11 @@ uint8_t button_action) { app_button_event_t buttons_event; - + buttons_event.button_handler = button_handler; buttons_event.pin_no = pin_no; buttons_event.button_action = button_action; - + return app_sched_event_put(&buttons_event, sizeof(buttons_event), app_button_evt_get); } /**@endcond */
--- a/nordic/nrf-sdk/app_common/app_error.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/app_common/app_error.h Mon Sep 08 17:21:46 2014 +0100 @@ -1,5 +1,6 @@ /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. * + * The information contained herein is property of Nordic Semiconductor ASA. * Terms and conditions of usage are described in detail in NORDIC * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. * @@ -8,7 +9,7 @@ * the file. * */ - + /** @file * * @defgroup app_error Common application error handler @@ -29,11 +30,11 @@ extern "C" { #endif -/**@brief Function for error handling, which is called when an error has occurred. +/**@brief Function for error handling, which is called when an error has occurred. * * @param[in] error_code Error code supplied to the handler. * @param[in] line_num Line number where the handler is called. - * @param[in] p_file_name Pointer to the file name. + * @param[in] p_file_name Pointer to the file name. */ void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name); @@ -41,7 +42,7 @@ } #endif -/**@brief Macro for calling error handler function. +/**@brief Macro for calling error handler function. * * @param[in] ERR_CODE Error code supplied to the error handler. */ @@ -51,10 +52,10 @@ app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__); \ } while (0) -/**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS. +/**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS. * * @param[in] ERR_CODE Error code supplied to the error handler. - */ + */ #define APP_ERROR_CHECK(ERR_CODE) \ do \ { \ @@ -63,12 +64,12 @@ { \ APP_ERROR_HANDLER(LOCAL_ERR_CODE); \ } \ - } while (0) - -/**@brief Macro for calling error handler function if supplied boolean value is false. + } while (0) + +/**@brief Macro for calling error handler function if supplied boolean value is false. * * @param[in] BOOLEAN_VALUE Boolean value to be evaluated. - */ + */ #define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE) \ do \ { \ @@ -77,7 +78,7 @@ { \ APP_ERROR_HANDLER(0); \ } \ - } while (0) + } while (0) #endif // APP_ERROR_H__
--- a/nordic/nrf-sdk/app_common/app_gpiote.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/app_common/app_gpiote.h Mon Sep 08 17:21:46 2014 +0100 @@ -42,7 +42,7 @@ #include <stdint.h> #include <stdbool.h> -// #include "nrf.h" +#include "nrf.h" #include "app_error.h" #include "app_util.h" @@ -97,7 +97,7 @@ * @param[in] max_users Maximum number of GPIOTE users. * @param[in] p_buffer Pointer to memory buffer for internal use in the app_gpiote * module. The size of the buffer can be computed using the - * APP_GPIOTE_BUF_SIZE() macro. The buffer must be aligned to + * APP_GPIOTE_BUF_SIZE() macro. The buffer must be aligned to * a 4 byte boundary. * * @retval NRF_SUCCESS Successful initialization. @@ -109,7 +109,7 @@ /**@brief Function for registering a GPIOTE user. * * @param[out] p_user_id Id for the new GPIOTE user. - * @param[in] pins_low_to_high_mask Mask defining which pins will generate events to this user + * @param[in] pins_low_to_high_mask Mask defining which pins will generate events to this user * when state is changed from low->high. * @param[in] pins_high_to_low_mask Mask defining which pins will generate events to this user * when state is changed from high->low.
--- a/nordic/nrf-sdk/app_common/app_timer.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/app_common/app_timer.h Mon Sep 08 17:21:46 2014 +0100 @@ -91,9 +91,9 @@ * * @param[in] MS Milliseconds. * @param[in] PRESCALER Value of the RTC1 PRESCALER register (must be the same value that was - * passed to APP_TIMER_INIT()). - * - * @note When using this macro, it is the responsibility of the developer to ensure that the + * passed to APP_TIMER_INIT()). + * + * @note When using this macro, it is the responsibility of the developer to ensure that the * values provided as input result in an output value that is supported by the * @ref app_timer_start function. For example, when the ticks for 1 ms is needed, the * maximum possible value of PRESCALER must be 6, when @ref APP_TIMER_CLOCK_FREQ is 32768. @@ -130,11 +130,11 @@ * making sure that the buffer is correctly aligned. It will also connect the timer module * to the scheduler (if specified). * - * @note This module assumes that the LFCLK is already running. If it isn't, the module will - * be non-functional, since the RTC will not run. If you don't use a softdevice, you'll - * have to start the LFCLK manually. See the rtc_example's \ref lfclk_config() function - * for an example of how to do this. If you use a softdevice, the LFCLK is started on - * softdevice init. + * @note This module assumes that the LFCLK is already running. If it isn't, the module will + * be non-functional, since the RTC will not run. If you don't use a softdevice, you'll + * have to start the LFCLK manually. See the rtc_example's \ref lfclk_config() function + * for an example of how to do this. If you use a softdevice, the LFCLK is started on + * softdevice init. * * * @param[in] PRESCALER Value of the RTC1 PRESCALER register. This will decide the @@ -186,7 +186,7 @@ * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte * boundary or NULL). */ -uint32_t app_timer_init(uint32_t prescaler, +uint32_t app_timer_init(uint32_t prescaler, uint8_t max_timers, uint8_t op_queues_size, void * p_buffer, @@ -287,7 +287,7 @@ static __INLINE void app_timer_evt_get(void * p_event_data, uint16_t event_size) { app_timer_event_t * p_timer_event = (app_timer_event_t *)p_event_data; - + APP_ERROR_CHECK_BOOL(event_size == sizeof(app_timer_event_t)); p_timer_event->timeout_handler(p_timer_event->p_context); } @@ -299,7 +299,7 @@ timer_event.timeout_handler = timeout_handler; timer_event.p_context = p_context; - + return app_sched_event_put(&timer_event, sizeof(timer_event), app_timer_evt_get); } /**@endcond */
--- a/nordic/nrf-sdk/app_common/crc16.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/app_common/crc16.h Mon Sep 08 17:21:46 2014 +0100 @@ -9,7 +9,7 @@ * the file. * */ - + /** @file * * @defgroup crc_compute CRC compute @@ -18,7 +18,7 @@ * * @brief This module implements the CRC-16 calculation in the blocks. */ - + #ifndef CRC16_H__ #define CRC16_H__ @@ -30,13 +30,13 @@ /**@brief Function for calculating CRC-16 in blocks. * - * Feed each consecutive data block into this function, along with the current value of p_crc as - * returned by the previous call of this function. The first call of this function should pass NULL + * Feed each consecutive data block into this function, along with the current value of p_crc as + * returned by the previous call of this function. The first call of this function should pass NULL * as the initial value of the crc in p_crc. * * @param[in] p_data The input data block for computation. * @param[in] size The size of the input data block in bytes. - * @param[in] p_crc The previous calculated CRC-16 value or NULL if first call. + * @param[in] p_crc The previous calculated CRC-16 value or NULL if first call. * * @return The updated CRC-16 value, based on the input supplied. */ @@ -48,5 +48,5 @@ #endif // CRC16_H__ - + /** @} */
--- a/nordic/nrf-sdk/app_common/hci_mem_pool_internal.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/app_common/hci_mem_pool_internal.h Mon Sep 08 17:21:46 2014 +0100 @@ -9,7 +9,7 @@ * the file. * */ - + /** @file * * @defgroup memory_pool_internal Memory Pool Internal @@ -18,7 +18,7 @@ * * @brief Memory pool internal definitions */ - + #ifndef MEM_POOL_INTERNAL_H__ #define MEM_POOL_INTERNAL_H__ @@ -28,5 +28,5 @@ #define RX_BUF_QUEUE_SIZE 4u /**< RX buffer element size. */ #endif // MEM_POOL_INTERNAL_H__ - + /** @} */
--- a/nordic/nrf-sdk/app_common/pstorage.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/app_common/pstorage.h Mon Sep 08 17:21:46 2014 +0100 @@ -60,22 +60,22 @@ /**@brief Persistent Storage Error Reporting Callback * * @details Persistent Storage Error Reporting Callback that is used by the interface to report - * success or failure of a flash operation. Therefore, for any operations, application - * can know when the procedure was complete. For store operation, since no data copy - * is made, receiving a success or failure notification, indicated by the reason - * parameter of callback is an indication that the resident memory could now be reused + * success or failure of a flash operation. Therefore, for any operations, application + * can know when the procedure was complete. For store operation, since no data copy + * is made, receiving a success or failure notification, indicated by the reason + * parameter of callback is an indication that the resident memory could now be reused * or freed, as the case may be. - * + * * @param[in] handle Identifies module and block for which callback is received. * @param[in] op_code Identifies the operation for which the event is notified. * @param[in] result Identifies the result of flash access operation. * NRF_SUCCESS implies, operation succeeded. - * @param[in] p_data Identifies the application data pointer. In case of store operation, this - * points to the resident source of application memory that application can now - * free or reuse. In case of clear, this is NULL as no application pointer is + * @param[in] p_data Identifies the application data pointer. In case of store operation, this + * points to the resident source of application memory that application can now + * free or reuse. In case of clear, this is NULL as no application pointer is * needed for this operation. * @param[in] data_len Length data application had provided for the operation. - * + * */ typedef void (*pstorage_ntf_cb_t)(pstorage_handle_t * p_handle, uint8_t op_code, @@ -120,11 +120,11 @@ /**@brief Register with persistent storage interface. * * @param[in] p_module_param Module registration param. - * @param[out] p_block_id Block identifier to identify persistent memory blocks in case - * registration succeeds. Application is expected to use the block ids - * for subsequent operations on requested persistent memory. Maximum - * registrations permitted is determined by configuration parameter - * PSTORAGE_MAX_APPLICATIONS. + * @param[out] p_block_id Block identifier to identify persistent memory blocks in case + * registration succeeds. Application is expected to use the block ids + * for subsequent operations on requested persistent memory. Maximum + * registrations permitted is determined by configuration parameter + * PSTORAGE_MAX_APPLICATIONS. * In case more than one memory blocks are requested, the identifier provided here is * the base identifier for the first block and to identify subsequent block, * application shall use \@ref pstorage_block_identifier_get with this base identifier @@ -133,6 +133,10 @@ * \@ref pstorage_block_identifier_get with based id and provide a block number of 5. * This way application is only expected to remember the base block identifier. * + * @note To register an area with a total size (block count * block size) larger than the + * page size (usually 1024 bytes), the block size must be a divisor of the page size + * (page size % block size == 0). + * * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. * @retval NRF_ERROR_NULL if NULL parameter has been passed. @@ -260,9 +264,9 @@ * * @param[in] size Size of data to be cleared from persistent memory expressed in bytes. * This parameter is to provision for clearing of certain blocks - * of memory, or all memory blocks in a registered module. If the total size + * of memory, or all memory blocks in a registered module. If the total size * of the application module is used (blocks * block size) in combination with - * the identifier for the first block in the module, all blocks in the + * the identifier for the first block in the module, all blocks in the * module will be erased. * * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. @@ -296,8 +300,8 @@ /**@brief Function for registering with persistent storage interface. * * @param[in] p_module_param Module registration param. - * @param[out] p_block_id Block identifier to identify persistent memory blocks in case - * registration succeeds. Application is expected to use the block ids + * @param[out] p_block_id Block identifier to identify persistent memory blocks in case + * registration succeeds. Application is expected to use the block ids * for subsequent operations on requested persistent memory. * In case more than one memory blocks are requested, the identifier provided here is * the base identifier for the first block and to identify subsequent block, @@ -373,7 +377,6 @@ } #endif /* #ifdef __cplusplus */ - /**@} */ /**@} */
--- a/nordic/nrf-sdk/ble/ble_advdata.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/ble/ble_advdata.h Mon Sep 08 17:21:46 2014 +0100 @@ -104,11 +104,11 @@ * @warning This API may override application's request to use the long name and use a short name * instead. This truncation will occur in case the long name does not fit advertisement data size. * Application is permitted to specify a preferred short name length in case truncation is required. - * For example, if the complete device name is ABCD_HRMonitor, application can specify short name + * For example, if the complete device name is ABCD_HRMonitor, application can specify short name * length to 8 such that short device name appears as ABCD_HRM instead of ABCD_HRMo or ABCD_HRMoni * etc if available size for short name is 9 or 12 respectively to have more apporpriate short name. * However, it should be noted that this is just a preference that application can specify and - * if the preference too large to fit in Advertisement Data, this can be further truncated. + * if the preference too large to fit in Advertisement Data, this can be further truncated. */ uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata);
--- a/nordic/nrf-sdk/ble/ble_conn_params.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/ble/ble_conn_params.h Mon Sep 08 17:21:46 2014 +0100 @@ -62,7 +62,7 @@ /**@brief Function for initializing the Connection Parameters module. * - * @note If the negotiation procedure should be triggered when notification/indication of + * @note If the negotiation procedure should be triggered when notification/indication of * any characteristic is enabled by the peer, then this function must be called after * having initialized the services. * @@ -87,7 +87,7 @@ /**@brief Function for changing the current connection parameters to a new set. * - * @details Use this function to change the connection parameters to a new set of parameter + * @details Use this function to change the connection parameters to a new set of parameter * (ie different from the ones given at init of the module). * This function is usefull for scenario where most of the time the application * needs a relatively big connection interval, and just sometimes, for a temporary
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nordic/nrf-sdk/ble/ble_db_discovery.h Mon Sep 08 17:21:46 2014 +0100 @@ -0,0 +1,234 @@ +/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + */ + + +/**@file + * + * @defgroup ble_sdk_lib_db_discovery Database Discovery + * @{ + * @ingroup nrf51_sdk_api + * @brief Database discovery module. + * + * @details This module contains the APIs and types exposed by the DB Discovery module. These APIs + * and types can be used by the application to perform discovery of a service and its + * characteristics at the peer server. This module can also be used to discover the + * desired services in multiple remote devices. + * A typical use of this library is described in the figure below. + * @image html db_discovery.jpg + * + * @warning The maximum number of characteristics per service that can be discovered by this module + * is indicated by the value of @ref BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV. If the peer + * has more than the supported number of characteristics, then the first found will be + * discovered and any further characteristics will be ignored. No descriptors other + * than Client Characteristic Configuration Descriptors will be searched for at the peer. + * + * @note Presently only one instance of a Primary Service can be discovered by this module. If + * there are multiple instances of the service at the peer, only the first instance + * of it at the peer is fetched and returned to the application. + * + * @note The application must propagate BLE stack events to this module by calling + * ble_db_discovery_on_ble_evt(). + * + */ + +#ifndef BLE_DB_DISCOVERY_H__ +#define BLE_DB_DISCOVERY_H__ + +#include <stdint.h> +#include "ble_gattc.h" +#include "ble.h" +#include "nrf_error.h" +#include "ble_srv_common.h" + +/** + * @defgroup db_disc_defines Defines + * @{ + */ + +#define BLE_DB_DISCOVERY_MAX_SRV 2 /**< Maximum number of services supported by this module. This also indicates the maximum number of users allowed to be registered to this module. (one user per service). */ +#define BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV 3 /**< Maximum number of characteristics per service supported by this module. */ + +/** @} */ + +/** + * @defgroup db_disc_enums Enumerations + * @{ + */ + +/**@brief Type of the DB Discovery event. + */ +typedef enum +{ + BLE_DB_DISCOVERY_COMPLETE, /**< Event indicating that the GATT Database discovery is complete. */ + BLE_DB_DISCOVERY_ERROR, /**< Event indicating that an internal error has occurred in the DB Discovery module. This could typically be because of the SoftDevice API returning an error code during the DB discover.*/ + BLE_DB_DISCOVERY_SRV_NOT_FOUND /**< Event indicating that the service was not found at the peer.*/ +} ble_db_discovery_evt_type_t; + +/** @} */ + +/** + * @defgroup db_disc_structs Structures + * @{ + */ + +/**@brief Structure for holding the characteristic and the handle of its CCCD found during the + * discovery process. + */ +typedef struct +{ + ble_gattc_char_t characteristic; /**< Structure containing information about the characteristic. */ + uint16_t cccd_handle; /**< CCCD Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if a CCCD is not present at the server. */ +} ble_db_discovery_char_t; + +/**@brief Structure for holding information about the service and the characteristics found during + * the discovery process. + */ +typedef struct +{ + ble_uuid_t srv_uuid; /**< UUID of the service. */ + uint8_t char_count; /**< Number of characteristics present in the service. */ + ble_db_discovery_char_t charateristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV]; /**< Array of information related to the characteristics present in the service. */ + ble_gattc_handle_range_t handle_range; /**< Service Handle Range. */ +} ble_db_discovery_srv_t; + +/**@brief Structure for holding the information related to the GATT database at the server. + * + * @details This module identifies a remote database. Use one instance of this structure per + * connection. + * + * @warning This structure must be zero-initialized. + */ +typedef struct +{ + ble_db_discovery_srv_t services[BLE_DB_DISCOVERY_MAX_SRV]; /**< Information related to the current service being discovered. This is intended for internal use during service discovery.*/ + uint16_t conn_handle; /**< Connection handle as provided by the SoftDevice. */ + uint8_t srv_count; /**< Number of services at the peers GATT database.*/ + uint8_t curr_char_ind; /**< Index of the current characteristic being discovered. This is intended for internal use during service discovery.*/ + uint8_t curr_srv_ind; /**< Index of the current service being discovered. This is intended for internal use during service discovery.*/ + bool discovery_in_progress; /**< Variable to indicate if there is a service discovery in progress. */ +} ble_db_discovery_t; + + +/**@brief Structure containing the event from the DB discovery module to the application. + */ +typedef struct +{ + ble_db_discovery_evt_type_t evt_type; /**< Type of event. */ + uint16_t conn_handle; /**< Handle of the connection for which this event has occurred. */ + union + { + ble_db_discovery_srv_t discovered_db; /**< Structure containing the information about the GATT Database at the server. This will be filled when the event type is @ref BLE_DB_DISCOVERY_COMPLETE.*/ + uint32_t err_code; /**< nRF Error code indicating the type of error which occurred in the DB Discovery module. This will be filled when the event type is @ref BLE_DB_DISCOVERY_ERROR. */ + } params; +} ble_db_discovery_evt_t; + +/** @} */ + +/** + * @defgroup db_disc_types Types + * @{ + */ + +/**@brief DB Discovery event handler type. */ +typedef void (* ble_db_discovery_evt_handler_t)(ble_db_discovery_evt_t * p_evt); + +/** @} */ + +/** + * @addtogroup db_disc_structs + * @{ + */ + +/** @} */ + +/** + * @defgroup db_disc_functions Functions + * @{ + */ + +/**@brief Function for initializing the DB Discovery module. + * + * @retval NRF_SUCCESS on successful initialization. + */ +uint32_t ble_db_discovery_init(void); + + +/**@brief Function for closing the DB Discovery module. + * + * @details This function will clear up any internal variables and states maintained by the + * module. To re-use the module after calling this function, the function @ref + * ble_db_discovery_init must be called again. + * + * @retval NRF_SUCCESS Operation success. + */ +uint32_t ble_db_discovery_close(void); + + +/**@brief Function for registering with the DB Discovery module. + * + * @details The application can use this function to inform which service it is interested in + * discovering at the server. + * + * @param[in] p_uuid Pointer to the UUID of the service to be discovered at the server. + * @param[in] evt_handler Event handler to be called by the DB discovery module when any event + * related to discovery of the registered service occurs. + * + * @note The total number of services that can be discovered by this module is @ref + * BLE_DB_DISCOVERY_MAX_SRV. This effectively means that the maximum number of + * registrations possible is equal to the @ref BLE_DB_DISCOVERY_MAX_SRV. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL When a NULL pointer is passed as input. + * @retval NRF_ERROR_INVALID_STATE If this function is called without calling the + * @ref ble_db_discovery_init. + * @retval NRF_ERROR_NOT_SUPPORTED The maximum number of registrations allowed by this module + * has been reached. + */ +uint32_t ble_db_discovery_evt_register(const ble_uuid_t * const p_uuid, + const ble_db_discovery_evt_handler_t evt_handler); + + +/**@brief Function for starting the discovery of the GATT database at the server. + * + * @warning p_db_discovery structure must be zero-initialized. + * + * @param[out] p_db_discovery Pointer to the DB Discovery structure. + * @param[in] conn_handle The handle of the connection for which the discovery should be + * started. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL When a NULL pointer is passed as input. + * @retval NRF_ERROR_INVALID_STATE If this function is called without calling the + * @ref ble_db_discovery_init, or without calling + * @ref ble_db_discovery_evt_register. + * @retval NRF_ERROR_BUSY If a discovery is already in progress for the current + * connection. + * + * @return This API propagates the error code returned by the + * SoftDevice API @ref sd_ble_gattc_primary_services_discover. + */ +uint32_t ble_db_discovery_start(ble_db_discovery_t * const p_db_discovery, + uint16_t conn_handle); + + +/**@brief Function for handling the Application's BLE Stack events. + * + * @param[in,out] p_db_discovery Pointer to the DB Discovery structure. + * @param[in] p_ble_evt Pointer to the BLE event received. + */ +void ble_db_discovery_on_ble_evt(ble_db_discovery_t * const p_db_discovery, + const ble_evt_t * const p_ble_evt); + +/** @} */ + +#endif // BLE_DB_DISCOVERY_H__ + +/** @} */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nordic/nrf-sdk/ble/ble_services/ble_bas_c.h Mon Sep 08 17:21:46 2014 +0100 @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is confidential property of Nordic Semiconductor. The use, + * copying, transfer or disclosure of such information is prohibited except by express written + * agreement with Nordic Semiconductor. + * + */ + +/**@file + * + * @defgroup ble_sdk_srv_bas_c Battery Service Client + * @{ + * @ingroup ble_sdk_srv + * @brief Battery Service Client module. + * + * @details This module contains APIs to read and interact with the Battery Service of a remote + * device. + * + * @note The application must propagate BLE stack events to this module by calling + * ble_hrs_c_on_ble_evt(). + * + */ + +#ifndef BLE_BAS_C_H__ +#define BLE_BAS_C_H__ + +#include <stdint.h> +#include "ble.h" + +/** + * @defgroup bas_c_enums Enumerations + * @{ + */ + +/**@brief Battery Service Client event type. */ +typedef enum +{ + BLE_BAS_C_EVT_DISCOVERY_COMPLETE, /**< Event indicating that the Battery Service has been discovered at the peer. */ + BLE_BAS_C_EVT_BATT_NOTIFICATION, /**< Event indicating that a notification of the Battery Level characteristic has been received from the peer. */ + BLE_BAS_C_EVT_BATT_READ_RESP /**< Event indicating that a read response on Battery Level characteristic has been received from peer. */ +} ble_bas_c_evt_type_t; + +/** @} */ + +/** + * @defgroup bas_c_structs Structures + * @{ + */ + +/**@brief Battery Service Client Event structure. */ +typedef struct +{ + ble_bas_c_evt_type_t evt_type; /**< Event Type. */ + union + { + uint8_t battery_level; /**< Battery level received from peer. This field will be used for the events @ref BLE_BAS_C_EVT_BATT_NOTIFICATION and @ref BLE_BAS_C_EVT_BATT_READ_RESP.*/ + } params; +} ble_bas_c_evt_t; + +/** @} */ + +/** + * @defgroup bas_c_types Types + * @{ + */ + +// Forward declaration of the ble_bas_t type. +typedef struct ble_bas_c_s ble_bas_c_t; + +/**@brief Event handler type. + * + * @details This is the type of the event handler that should be provided by the application + * of this module in order to receive events. + */ +typedef void (* ble_bas_c_evt_handler_t) (ble_bas_c_t * p_bas_bas_c, ble_bas_c_evt_t * p_evt); + +/** @} */ + +/** + * @addtogroup bas_c_structs + * @{ + */ + +/**@brief Battery Service Client structure. + + */ +typedef struct ble_bas_c_s +{ + uint16_t conn_handle; /**< Connection handle as provided by the SoftDevice. */ + uint16_t bl_cccd_handle; /**< Handle of the CCCD of the Battery Level characteristic. */ + uint16_t bl_handle; /**< Handle of the Battery Level characteristic as provided by the SoftDevice. */ + ble_bas_c_evt_handler_t evt_handler; /**< Application event handler to be called when there is an event related to the Battery service. */ +} ble_bas_c_t; + +/**@brief Battery Service Client initialization structure. + */ +typedef struct +{ + ble_bas_c_evt_handler_t evt_handler; /**< Event handler to be called by the Battery Service Client module whenever there is an event related to the Battery Service. */ +} ble_bas_c_init_t; + +/** @} */ + +/** + * @defgroup bas_c_functions Functions + * @{ + */ + +/**@brief Function for initializing the Battery Service Client module. + * + * @details This function will initialize the module and set up Database Discovery to discover + * the Battery Service. After calling this function, call @ref ble_db_discovery_start + * to start discovery. + * + * @param[out] p_ble_bas_c Pointer to the Battery Service client structure. + * @param[in] p_ble_bas_c_init Pointer to the Battery Service initialization structure containing + * the initialization information. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL A parameter is NULL. + * Otherwise, an error code returned by @ref ble_db_discovery_register. + */ +uint32_t ble_bas_c_init(ble_bas_c_t * p_ble_bas_c, ble_bas_c_init_t * p_ble_bas_c_init); + + +/**@brief Function for handling BLE events from the SoftDevice. + * + * @details This function will handle the BLE events received from the SoftDevice. If the BLE + * event is relevant for the Battery Service Client module, then it is used to update + * interval variables and, if necessary, send events to the application. + * + * @note This function must be called by the application. + * + * @param[in] p_ble_bas_c Pointer to the Battery Service client structure. + * @param[in] p_ble_evt Pointer to the BLE event. + */ +void ble_bas_c_on_ble_evt(ble_bas_c_t * p_ble_bas_c, const ble_evt_t * p_ble_evt); + + +/**@brief Function for enabling notifications on the Battery Level characteristic. + * + * @details This function will enable to notification of the Battery Level characteristic at the + * peer by writing to the CCCD of the Battery Level Characteristic. + * + * @param p_ble_bas_c Pointer to the Battery Service client structure. + * + * @retval NRF_SUCCESS If the SoftDevice has been requested to write to the CCCD of the peer. + * NRF_ERROR_NULL Parameter is NULL. + * Otherwise, an error code returned by the SoftDevice API @ref + * sd_ble_gattc_write. + */ +uint32_t ble_bas_c_bl_notif_enable(ble_bas_c_t * p_ble_bas_c); + + +/**@brief Function for reading the Battery Level characteristic. + * + * @param p_ble_bas_c Pointer to the Battery Service client structure. + * + * @retval NRF_SUCCESS If the read request was successfully queued to be sent to peer. + */ +uint32_t ble_bas_c_bl_read(ble_bas_c_t * p_ble_bas_c); + + +/** @} */ // End tag for Function group. + +#endif // BLE_BAS_C_H__ + +/** @} */ // End tag for the file.
--- a/nordic/nrf-sdk/ble/ble_services/ble_dis.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/ble/ble_services/ble_dis.h Mon Sep 08 17:21:46 2014 +0100 @@ -70,9 +70,9 @@ ble_srv_utf8_str_t hw_rev_str; /**< Hardware Revision String. */ ble_srv_utf8_str_t fw_rev_str; /**< Firmware Revision String. */ ble_srv_utf8_str_t sw_rev_str; /**< Software Revision String. */ - ble_dis_sys_id_t * p_sys_id; /**< System ID. The helper function @ref dis_sys_id_encode can be used to encode the value of this characteristic. */ + ble_dis_sys_id_t * p_sys_id; /**< System ID. */ ble_dis_reg_cert_data_list_t * p_reg_cert_data_list; /**< IEEE 11073-20601 Regulatory Certification Data List. */ - ble_dis_pnp_id_t * p_pnp_id; /**< PnP ID. The helper function @ref dis_pnp_id_encode can be used to encode the value of this characteristic. */ + ble_dis_pnp_id_t * p_pnp_id; /**< PnP ID. */ ble_srv_security_mode_t dis_attr_md; /**< Initial Security Setting for Device Information Characteristics. */ } ble_dis_init_t;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nordic/nrf-sdk/ble/ble_services/ble_hrs_c.h Mon Sep 08 17:21:46 2014 +0100 @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is confidential property of Nordic Semiconductor. The use, + * copying, transfer or disclosure of such information is prohibited except by express written + * agreement with Nordic Semiconductor. + * + */ + +/**@file + * + * @defgroup ble_sdk_srv_hrs_c Heart Rate Service Client + * @{ + * @ingroup ble_sdk_srv + * @brief Heart Rate Service Client module. + * + * @details This module contains the APIs and types exposed by the Heart Rate Service Client + * module. These APIs and types can be used by the application to perform discovery of + * Heart Rate Service at the peer and interact with it. + * + * @warning Currently this module only has support for Heart Rate Measurement characteristic. This + * means that it will be able to enable notification of the characteristic at the peer and + * be able to receive Heart Rate Measurement notifications from the peer. It does not + * support the Body Sensor Location and the Heart Rate Control Point characteristics. + * When a Heart Rate Measurement is received, this module will decode only the + * Heart Rate Measurement Value (both 8 bit and 16 bit) field from it and provide it to + * the application. + * + * @note The application must propagate BLE stack events to this module by calling + * ble_hrs_c_on_ble_evt(). + * + */ + +#ifndef BLE_HRS_C_H__ +#define BLE_HRS_C_H__ + +#include <stdint.h> +#include "ble.h" + +/** + * @defgroup hrs_c_enums Enumerations + * @{ + */ + +/**@brief HRS Client event type. */ +typedef enum +{ + BLE_HRS_C_EVT_DISCOVERY_COMPLETE = 1, /**< Event indicating that the Heart Rate Service has been discovered at the peer. */ + BLE_HRS_C_EVT_HRM_NOTIFICATION /**< Event indicating that a notification of the Heart Rate Measurement characteristic has been received from the peer. */ +} ble_hrs_c_evt_type_t; + +/** @} */ + +/** + * @defgroup hrs_c_structs Structures + * @{ + */ + +/**@brief Structure containing the heart rate measurement received from the peer. */ +typedef struct +{ + uint16_t hr_value; /**< Heart Rate Value. */ +} ble_hrm_t; + +/**@brief Heart Rate Event structure. */ +typedef struct +{ + ble_hrs_c_evt_type_t evt_type; /**< Type of the event. */ + union + { + ble_hrm_t hrm; /**< Heart rate measurement received. This will be filled if the evt_type is @ref BLE_HRS_C_EVT_HRM_NOTIFICATION. */ + } params; +} ble_hrs_c_evt_t; + +/** @} */ + +/** + * @defgroup hrs_c_types Types + * @{ + */ + +// Forward declaration of the ble_bas_t type. +typedef struct ble_hrs_c_s ble_hrs_c_t; + +/**@brief Event handler type. + * + * @details This is the type of the event handler that should be provided by the application + * of this module in order to receive events. + */ +typedef void (* ble_hrs_c_evt_handler_t) (ble_hrs_c_t * p_ble_hrs_c, ble_hrs_c_evt_t * p_evt); + +/** @} */ + +/** + * @addtogroup hrs_c_structs + * @{ + */ + +/**@brief Heart Rate Client structure. + */ +typedef struct ble_hrs_c_s +{ + uint16_t conn_handle; /**< Connection handle as provided by the SoftDevice. */ + uint16_t hrm_cccd_handle; /**< Handle of the CCCD of the Heart Rate Measurement characteristic. */ + uint16_t hrm_handle; /**< Handle of the Heart Rate Measurement characteristic as provided by the SoftDevice. */ + ble_hrs_c_evt_handler_t evt_handler; /**< Application event handler to be called when there is an event related to the heart rate service. */ +} ble_hrs_c_t; + +/**@brief Heart Rate Client initialization structure. + */ +typedef struct +{ + ble_hrs_c_evt_handler_t evt_handler; /**< Event handler to be called by the Heart Rate Client module whenever there is an event related to the Heart Rate Service. */ +} ble_hrs_c_init_t; + +/** @} */ + +/** + * @defgroup hrs_c_functions Functions + * @{ + */ + +/**@brief Function for initializing the heart rate client module. + * + * @details This function will register with the DB Discovery module. There it + * registers for the Heart Rate Service. Doing so will make the DB Discovery + * module look for the presence of a Heart Rate Service instance at the peer when a + * discovery is started. + * + * @param[in] p_ble_hrs_c Pointer to the heart rate client structure. + * @param[in] p_ble_hrs_c_init Pointer to the heart rate initialization structure containing the + * initialization information. + * + * @retval NRF_SUCCESS On successful initialization. Otherwise an error code. This function + * propagates the error code returned by the Database Discovery module API + * @ref ble_db_discovery_evt_register. + */ +uint32_t ble_hrs_c_init(ble_hrs_c_t * p_ble_hrs_c, ble_hrs_c_init_t * p_ble_hrs_c_init); + +/**@brief Function for handling BLE events from the SoftDevice. + * + * @details This function will handle the BLE events received from the SoftDevice. If a BLE + * event is relevant to the Heart Rate Client module, then it uses it to update + * interval variables and, if necessary, send events to the application. + * + * @param[in] p_ble_hrs_c Pointer to the heart rate client structure. + * @param[in] p_ble_evt Pointer to the BLE event. + */ +void ble_hrs_c_on_ble_evt(ble_hrs_c_t * p_ble_hrs_c, const ble_evt_t * p_ble_evt); + + +/**@brief Function for requesting the peer to start sending notification of Heart Rate + * Measurement. + * + * @details This function will enable to notification of the Heart Rate Measurement at the peer + * by writing to the CCCD of the Heart Rate Measurement Characteristic. + * + * @param p_ble_hrs_c Pointer to the heart rate client structure. + * + * @retval NRF_SUCCESS If the SoftDevice has been requested to write to the CCCD of the peer. + * Otherwise, an error code. This function propagates the error code returned + * by the SoftDevice API @ref sd_ble_gattc_write. + */ +uint32_t ble_hrs_c_hrm_notif_enable(ble_hrs_c_t * p_ble_hrs_c); + +/** @} */ // End tag for Function group. + +#endif // BLE_HRS_C_H__ + +/** @} */ // End tag for the file.
--- a/nordic/nrf-sdk/nrf_assert.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/nrf_assert.h Mon Sep 08 17:21:46 2014 +0100 @@ -57,7 +57,6 @@ #else #define ASSERT(expr) //!< Assert empty when disabled void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name); - #endif /* defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) */ #ifdef __cplusplus
--- a/nordic/nrf-sdk/s110/ble_types.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/s110/ble_types.h Mon Sep 08 17:21:46 2014 +0100 @@ -29,7 +29,31 @@ /** @} */ - +/** @defgroup BLE_UUID_VALUES Assigned Values for BLE UUIDs + * @{ */ +/* Generic UUIDs, applicable to all services */ +#define BLE_UUID_UNKNOWN 0x0000 /**< Reserved UUID. */ +#define BLE_UUID_SERVICE_PRIMARY 0x2800 /**< Primary Service. */ +#define BLE_UUID_SERVICE_SECONDARY 0x2801 /**< Secondary Service. */ +#define BLE_UUID_SERVICE_INCLUDE 0x2802 /**< Include. */ +#define BLE_UUID_CHARACTERISTIC 0x2803 /**< Characteristic. */ +#define BLE_UUID_DESCRIPTOR_CHAR_EXT_PROP 0x2900 /**< Characteristic Extended Properties Descriptor. */ +#define BLE_UUID_DESCRIPTOR_CHAR_USER_DESC 0x2901 /**< Characteristic User Description Descriptor. */ +#define BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG 0x2902 /**< Client Characteristic Configuration Descriptor. */ +#define BLE_UUID_DESCRIPTOR_SERVER_CHAR_CONFIG 0x2903 /**< Server Characteristic Configuration Descriptor. */ +#define BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT 0x2904 /**< Characteristic Presentation Format Descriptor. */ +#define BLE_UUID_DESCRIPTOR_CHAR_AGGREGATE_FORMAT 0x2905 /**< Characteristic Aggregate Format Descriptor. */ +/* GATT specific UUIDs */ +#define BLE_UUID_GATT 0x1801 /**< Generic Attribute Profile. */ +#define BLE_UUID_GATT_CHARACTERISTIC_SERVICE_CHANGED 0x2A05 /**< Service Changed Characteristic. */ +/* GAP specific UUIDs */ +#define BLE_UUID_GAP 0x1800 /**< Generic Access Profile. */ +#define BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME 0x2A00 /**< Device Name Characteristic. */ +#define BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE 0x2A01 /**< Appearance Characteristic. */ +#define BLE_UUID_GAP_CHARACTERISTIC_PPF 0x2A02 /**< Peripheral Privacy Flag Characteristic. */ +#define BLE_UUID_GAP_CHARACTERISTIC_RECONN_ADDR 0x2A03 /**< Reconnection Address Characteristic. */ +#define BLE_UUID_GAP_CHARACTERISTIC_PPCP 0x2A04 /**< Peripheral Preferred Connection Parameters Characteristic. */ +/** @} */ /** @defgroup BLE_UUID_TYPES Types of UUID @@ -39,6 +63,61 @@ #define BLE_UUID_TYPE_VENDOR_BEGIN 0x02 /**< Vendor UUID types start at this index (128-bit). */ /** @} */ + +/** @defgroup BLE_APPEARANCES Bluetooth Appearance values + * @note Retrieved from http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml + * @{ */ +#define BLE_APPEARANCE_UNKNOWN 0 /**< Unknown. */ +#define BLE_APPEARANCE_GENERIC_PHONE 64 /**< Generic Phone. */ +#define BLE_APPEARANCE_GENERIC_COMPUTER 128 /**< Generic Computer. */ +#define BLE_APPEARANCE_GENERIC_WATCH 192 /**< Generic Watch. */ +#define BLE_APPEARANCE_WATCH_SPORTS_WATCH 193 /**< Watch: Sports Watch. */ +#define BLE_APPEARANCE_GENERIC_CLOCK 256 /**< Generic Clock. */ +#define BLE_APPEARANCE_GENERIC_DISPLAY 320 /**< Generic Display. */ +#define BLE_APPEARANCE_GENERIC_REMOTE_CONTROL 384 /**< Generic Remote Control. */ +#define BLE_APPEARANCE_GENERIC_EYE_GLASSES 448 /**< Generic Eye-glasses. */ +#define BLE_APPEARANCE_GENERIC_TAG 512 /**< Generic Tag. */ +#define BLE_APPEARANCE_GENERIC_KEYRING 576 /**< Generic Keyring. */ +#define BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 640 /**< Generic Media Player. */ +#define BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 704 /**< Generic Barcode Scanner. */ +#define BLE_APPEARANCE_GENERIC_THERMOMETER 768 /**< Generic Thermometer. */ +#define BLE_APPEARANCE_THERMOMETER_EAR 769 /**< Thermometer: Ear. */ +#define BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR 832 /**< Generic Heart rate Sensor. */ +#define BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT 833 /**< Heart Rate Sensor: Heart Rate Belt. */ +#define BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 896 /**< Generic Blood Pressure. */ +#define BLE_APPEARANCE_BLOOD_PRESSURE_ARM 897 /**< Blood Pressure: Arm. */ +#define BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 898 /**< Blood Pressure: Wrist. */ +#define BLE_APPEARANCE_GENERIC_HID 960 /**< Human Interface Device (HID). */ +#define BLE_APPEARANCE_HID_KEYBOARD 961 /**< Keyboard (HID Subtype). */ +#define BLE_APPEARANCE_HID_MOUSE 962 /**< Mouse (HID Subtype). */ +#define BLE_APPEARANCE_HID_JOYSTICK 963 /**< Joystiq (HID Subtype). */ +#define BLE_APPEARANCE_HID_GAMEPAD 964 /**< Gamepad (HID Subtype). */ +#define BLE_APPEARANCE_HID_DIGITIZERSUBTYPE 965 /**< Digitizer Tablet (HID Subtype). */ +#define BLE_APPEARANCE_HID_CARD_READER 966 /**< Card Reader (HID Subtype). */ +#define BLE_APPEARANCE_HID_DIGITAL_PEN 967 /**< Digital Pen (HID Subtype). */ +#define BLE_APPEARANCE_HID_BARCODE 968 /**< Barcode Scanner (HID Subtype). */ +#define BLE_APPEARANCE_GENERIC_GLUCOSE_METER 1024 /**< Generic Glucose Meter. */ +#define BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR 1088 /**< Generic Running Walking Sensor. */ +#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE 1089 /**< Running Walking Sensor: In-Shoe. */ +#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE 1090 /**< Running Walking Sensor: On-Shoe. */ +#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP 1091 /**< Running Walking Sensor: On-Hip. */ +#define BLE_APPEARANCE_GENERIC_CYCLING 1152 /**< Generic Cycling. */ +#define BLE_APPEARANCE_CYCLING_CYCLING_COMPUTER 1153 /**< Cycling: Cycling Computer. */ +#define BLE_APPEARANCE_CYCLING_SPEED_SENSOR 1154 /**< Cycling: Speed Sensor. */ +#define BLE_APPEARANCE_CYCLING_CADENCE_SENSOR 1155 /**< Cycling: Cadence Sensor. */ +#define BLE_APPEARANCE_CYCLING_POWER_SENSOR 1156 /**< Cycling: Power Sensor. */ +#define BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR 1157 /**< Cycling: Speed and Cadence Sensor. */ +#define BLE_APPEARANCE_GENERIC_PULSE_OXIMETER 3136 /**< Generic Pulse Oximeter. */ +#define BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP 3137 /**< Fingertip (Pulse Oximeter subtype). */ +#define BLE_APPEARANCE_PULSE_OXIMETER_WRIST_WORN 3138 /**< Wrist Worn(Pulse Oximeter subtype). */ +#define BLE_APPEARANCE_GENERIC_WEIGHT_SCALE 3200 /**< Generic Weight Scale. */ +#define BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS_ACT 5184 /**< Generic Outdoor Sports Activity. */ +#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_DISP 5185 /**< Location Display Device (Outdoor Sports Activity subtype). */ +#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_DISP 5186 /**< Location and Navigation Display Device (Outdoor Sports Activity subtype). */ +#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_POD 5187 /**< Location Pod (Outdoor Sports Activity subtype). */ +#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_POD 5188 /**< Location and Navigation Pod (Outdoor Sports Activity subtype). */ +/** @} */ + /** @brief Set .type and .uuid fields of ble_uuid_struct to specified uuid value. */ #define BLE_UUID_BLE_ASSIGN(instance, value) do {\ instance.type = BLE_UUID_TYPE_BLE; \ @@ -69,7 +148,7 @@ /** @brief 128 bit UUID values. */ typedef struct -{ +{ unsigned char uuid128[16]; } ble_uuid128_t;
--- a/nordic/nrf-sdk/sd_common/app_util_platform.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/sd_common/app_util_platform.h Mon Sep 08 17:21:46 2014 +0100 @@ -63,8 +63,8 @@ { \ APP_ERROR_CHECK(ERR_CODE); \ } \ - } - + } + /**@brief Macro for leaving a critical region. * * @note Due to implementation details, there must exist one and only one call to @@ -83,7 +83,7 @@ } \ } \ } - + /**@brief Function for finding the current interrupt level. * * @return Current interrupt level.
--- a/nordic/nrf-sdk/sd_common/softdevice_handler.h Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/nrf-sdk/sd_common/softdevice_handler.h Mon Sep 08 17:21:46 2014 +0100 @@ -71,12 +71,21 @@ * reinitialization). */ /*lint -emacro(506, SOFTDEVICE_HANDLER_INIT) */ /* Suppress "Constant value Boolean */ -#define SOFTDEVICE_HANDLER_INIT(CLOCK_SOURCE, USE_SCHEDULER) \ +#define SOFTDEVICE_HANDLER_INIT(CLOCK_SOURCE, \ + USE_SCHEDULER) \ do \ { \ - static uint32_t EVT_BUFFER[CEIL_DIV(MAX(MAX(BLE_STACK_EVT_MSG_BUF_SIZE, ANT_STACK_EVT_STRUCT_SIZE), SYS_EVT_MSG_BUF_SIZE), sizeof(uint32_t))]; \ + static uint32_t EVT_BUFFER[CEIL_DIV(MAX( \ + MAX(BLE_STACK_EVT_MSG_BUF_SIZE, \ + ANT_STACK_EVT_STRUCT_SIZE), \ + SYS_EVT_MSG_BUF_SIZE \ + ), \ + sizeof(uint32_t))]; \ uint32_t ERR_CODE; \ - ERR_CODE = softdevice_handler_init((CLOCK_SOURCE), EVT_BUFFER, sizeof(EVT_BUFFER), (USE_SCHEDULER) ? softdevice_evt_schedule : NULL); \ + ERR_CODE = softdevice_handler_init((CLOCK_SOURCE), \ + EVT_BUFFER, \ + sizeof(EVT_BUFFER), \ + (USE_SCHEDULER) ? softdevice_evt_schedule : NULL); \ APP_ERROR_CHECK(ERR_CODE); \ } while (0)
--- a/nordic/softdevice_handler.cpp Mon Sep 08 15:45:22 2014 +0000 +++ b/nordic/softdevice_handler.cpp Mon Sep 08 17:21:46 2014 +0100 @@ -236,6 +236,7 @@ } m_softdevice_enabled = true; + // Enable BLE event interrupt (interrupt priority has already been set by the stack). return sd_nvic_EnableIRQ(SWI2_IRQn); }