nRF51 SDK
|
Power profiling sample application main file. More...
Functions | |
void | app_error_handler (uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name) |
Function for error handling, which is called when an error has occurred. More... | |
void | assert_nrf_callback (uint16_t line_num, const uint8_t *p_file_name) |
Callback function for asserts in the SoftDevice. More... | |
static void | char_notify (void) |
Function for the Characteristic notification. More... | |
static void | gap_params_init (void) |
Function for the GAP initialization. More... | |
static void | connectable_adv_init (void) |
Function for initializing the connectable advertisement parameters. More... | |
static void | non_connectable_adv_init (void) |
Function for initializing the non-connectable advertisement parameters. More... | |
static void | advertising_data_init (void) |
Function for initializing the Advertisement packet. More... | |
static void | char_add (const uint8_t uuid_type) |
Function for adding the Characteristic. More... | |
static void | service_add (void) |
Function for adding the Service. More... | |
static void | notif_timeout_handler (void *p_context) |
Function for handling the Notification timeout. More... | |
static void | connection_interval_timeout_handler (void *p_context) |
Function for handling the Connection interval timeout. More... | |
static void | application_timers_start (void) |
Function for starting application timers. More... | |
static void | application_timers_stop (void) |
Function for Stopping application timers. | |
static void | advertising_start (void) |
Function for starting advertising. | |
static void | timers_init (void) |
Function for the Timer initialization. More... | |
static void | on_write (ble_evt_t *p_ble_evt) |
Function for evaluating the value written in CCCD. More... | |
static void | on_ble_evt (ble_evt_t *p_ble_evt) |
Function for handling the Application's BLE Stack events. More... | |
static void | ble_evt_dispatch (ble_evt_t *p_ble_evt) |
Function for dispatching a BLE stack event to all modules with a BLE stack event handler. More... | |
static void | ble_stack_init (void) |
Function for initializing the BLE stack. More... | |
static void | buttons_init (void) |
Function for using the GPIO module to configure the required buttons. | |
static void | power_manage (void) |
Function for the Power manager. | |
int | main (void) |
Function for application main entry. | |
Variables | |
static const ble_uuid128_t | m_base_uuid128 |
128-bit UUID base List. More... | |
static ble_gap_adv_params_t | m_adv_params |
static uint8_t | m_char_value [APP_CFG_CHAR_LEN] |
static uint8_t | m_addl_adv_manuf_data [ADV_ADDL_MANUF_DATA_LEN] |
static ble_gatts_char_handles_t | m_char_handles |
static uint16_t | m_conn_handle = BLE_CONN_HANDLE_INVALID |
static uint16_t | m_service_handle |
static bool | m_is_notifying_enabled = false |
static app_timer_id_t | m_conn_int_timer_id |
static app_timer_id_t | m_notif_timer_id |
This file contains the source code for a sample application to demonstrate/measure the power consumption by the nRF51822 chip while sending notifications for a given duration and while advertising in non-connectable mode for a given duration. The values of macros that begin with APP_CFG_ prefix can be changed to alter the power consumption of the application.
srvlib_conn_params module.
#define APP_CFG_NON_CONN_ADV_TIMEOUT 30 |
Time for which the device must be advertising in non-connectable mode (in seconds).
#define APP_CFG_CHAR_NOTIF_TIMEOUT 5000 |
Time for which the device must continue to send notifications once connected to master (in milli seconds).
#define APP_CFG_ADV_DATA_LEN 31 |
Required length of the complete advertisement packet. This should be atleast 8 in order to accommodate flag field and other mandatory fields and one byte of manufacturer specific data.
#define APP_CFG_CONNECTION_INTERVAL 20 |
Connection interval used by the master (in milli seconds). This application will be sending one notification per connection interval. A repeating timer will be started with timeout value equal to this value and one notification will be sent everytime this timer expires.
#define APP_CFG_CHAR_LEN 20 |
Size of the characteristic value being notified (in bytes).
#define NOTIF_BUTTON_PIN_NO NRF6310_BUTTON_0 |
Button used for initializing the application in connectable mode.
#define NON_CONN_ADV_BUTTON_PIN_NO NRF6310_BUTTON_1 |
Button used for initializing the application in non-connectable mode.
#define DEVICE_NAME "Nordic_Power_Mgmt" |
Name of device. Will be included in the advertising data.
#define APP_TIMER_PRESCALER 0 |
Value of the RTC1 PRESCALER register.
#define APP_TIMER_MAX_TIMERS 2 |
Maximum number of simultaneously created timers.
#define APP_TIMER_OP_QUEUE_SIZE 4 |
Size of timer operation queues.
#define CHAR_NOTIF_TIMEOUT_IN_TKS |
Time for which the device must continue to send notifications once connected to master (in ticks).
#define CONNECTABLE_ADV_INTERVAL MSEC_TO_UNITS(20, UNIT_0_625_MS) |
The advertising interval for connectable advertisement (20 ms). This value can vary between 20ms to 10.24s.
#define NON_CONNECTABLE_ADV_INTERVAL MSEC_TO_UNITS(100, UNIT_0_625_MS) |
The advertising interval for non-connectable advertisement (100 ms). This value can vary between 100ms to 10.24s).
#define CONNECTABLE_ADV_TIMEOUT 30 |
Time for which the device must be advertising in connectable mode (in seconds).
#define SLAVE_LATENCY 0 |
Slave latency.
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) |
Connection supervisory timeout (4 seconds).
#define ADV_ENCODED_AD_TYPE_LEN 1 |
Length of encoded ad type in advertisement data.
#define ADV_ENCODED_AD_TYPE_LEN_LEN 1 |
Length of the 'length field' of each ad type in advertisement data.
#define ADV_FLAGS_LEN 1 |
Length of flags field that will be placed in advertisement data.
#define ADV_ENCODED_FLAGS_LEN |
Length of flags field in advertisement packet. (1 byte for encoded ad type plus 1 byte for length of flags plus the length of the flags itself).
#define ADV_ENCODED_COMPANY_ID_LEN 2 |
Length of the encoded Company Identifier in the Manufacturer Specific Data part of the advertisement data.
#define ADV_ADDL_MANUF_DATA_LEN |
Length of Manufacturer Specific Data field that will be placed on the air during advertisement. This is computed based on the value of APP_CFG_ADV_DATA_LEN (required advertisement data length).
#define COMPANY_IDENTIFIER 0x0059 |
Company identifier for Nordic Semiconductor ASA as per www.bluetooth.org.
#define LOCAL_SERVICE_UUID 0x1523 |
Proprietary UUID for local service.
#define LOCAL_CHAR_UUID 0x1524 |
Proprietary UUID for local characteristic.
#define DEAD_BEEF 0xDEADBEEF |
Value used as error code on stack dump, can be used to identify stack location on stack unwind.
void app_error_handler | ( | uint32_t | error_code, |
uint32_t | line_num, | ||
const uint8_t * | p_file_name | ||
) |
[in] | error_code | Error code supplied to the handler. |
[in] | line_num | Line number where the handler is called. |
[in] | p_file_name | Pointer to the file name. |
void assert_nrf_callback | ( | uint16_t | line_num, |
const uint8_t * | p_file_name | ||
) |
This function will be called in case of an assert in the SoftDevice.
[in] | line_num | Line number of the failing ASSERT call. |
[in] | file_name | File name of the failing ASSERT call. |
|
static |
Sends one characteristic value notification to peer if connected to it and the notification is enabled.
|
static |
This function shall be used to setup all the necessary GAP (Generic Access Profile) parameters of the device. It also sets the permissions.
|
static |
This function initializes the advertisement parameters to values that will put the application in connectable mode.
|
static |
This function initializes the advertisement parameters to values that will put the application in non-connectable mode.
|
static |
This function initializes the data that is to be placed in an advertisement packet in both connectable and non-connectable modes.
|
static |
This function adds the characteristic to the local db.
[in] | uuid_type | Type of service UUID assigned by the S110 SoftDevice. |
|
static |
This function adds the service and the characteristic within it to the local db.
|
static |
This function will be called when the notification timer expires. This will stop the timer for connection interval and disconnect from the peer.
[in] | p_context | Pointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler. |
|
static |
This function will be called when the connection interval timer expires. This will trigger another characteristic notification to the peer.
[in] | p_context | Pointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler. |
|
static |
This function will be start two timers - one for the time duration for which notifications have to be sent to the peer and another for the interval between two notifications (which is also the connection interval).
|
static |
Initializes the timer module.
|
static |
This shall be called when there is a write event received from the stack. This function will evaluate whether or not the peer has enabled notifications and start/stop notifications accordingly.
[in] | p_ble_evt | Bluetooth stack event. |
|
static |
[in] | p_ble_evt | Bluetooth stack event. |
|
static |
This function is called from the BLE Stack event interrupt handler after a BLE stack event has been received.
[in] | p_ble_evt | Bluetooth stack event. |
|
static |
Initializes the SoftDevice and the BLE event interrupt.
|
static |
|
static |
Parameters to be passed to the stack when starting advertising.
|
static |
Value of the characteristic that will be sent as a notification to the master.
|
static |
Value of the additional manufacturer specific data that will be placed in air (initialized to all zeros).
|
static |
Handles of local characteristic (as provided by the BLE stack).
|
static |
Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection).
|
static |
Handle of local service (as provided by the BLE stack).
|
static |
Variable to indicate whether the notification is enabled by the peer.
|
static |
Connection interval timer.
|
static |
Notification timer.