nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Power profiling sample application main file. More...

Macros

#define APP_CFG_NON_CONN_ADV_TIMEOUT   30
 
#define APP_CFG_CHAR_NOTIF_TIMEOUT   5000
 
#define APP_CFG_ADV_DATA_LEN   31
 
#define APP_CFG_CONNECTION_INTERVAL   20
 
#define APP_CFG_CHAR_LEN   20
 
#define NOTIF_BUTTON_PIN_NO   NRF6310_BUTTON_0
 
#define NON_CONN_ADV_BUTTON_PIN_NO   NRF6310_BUTTON_1
 
#define DEVICE_NAME   "Nordic_Power_Mgmt"
 
#define APP_TIMER_PRESCALER   0
 
#define APP_TIMER_MAX_TIMERS   2
 
#define APP_TIMER_OP_QUEUE_SIZE   4
 
#define CHAR_NOTIF_TIMEOUT_IN_TKS
 
#define CONNECTABLE_ADV_INTERVAL   MSEC_TO_UNITS(20, UNIT_0_625_MS)
 
#define NON_CONNECTABLE_ADV_INTERVAL   MSEC_TO_UNITS(100, UNIT_0_625_MS)
 
#define CONNECTABLE_ADV_TIMEOUT   30
 
#define SLAVE_LATENCY   0
 
#define CONN_SUP_TIMEOUT   MSEC_TO_UNITS(4000, UNIT_10_MS)
 
#define ADV_ENCODED_AD_TYPE_LEN   1
 
#define ADV_ENCODED_AD_TYPE_LEN_LEN   1
 
#define ADV_FLAGS_LEN   1
 
#define ADV_ENCODED_FLAGS_LEN
 
#define ADV_ENCODED_COMPANY_ID_LEN   2
 
#define ADV_ADDL_MANUF_DATA_LEN
 
#define COMPANY_IDENTIFIER   0x0059
 
#define LOCAL_SERVICE_UUID   0x1523
 
#define LOCAL_CHAR_UUID   0x1524
 
#define DEAD_BEEF   0xDEADBEEF
 

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
 

Detailed Description

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.

Macro Definition Documentation

#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
Value:

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
Value:
ADV_ENCODED_AD_TYPE_LEN_LEN + \
ADV_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
Value:
( \
ADV_ENCODED_FLAGS_LEN + \
( \
ADV_ENCODED_AD_TYPE_LEN + \
ADV_ENCODED_AD_TYPE_LEN_LEN + \
ADV_ENCODED_COMPANY_ID_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.

Function Documentation

void app_error_handler ( uint32_t  error_code,
uint32_t  line_num,
const uint8_t *  p_file_name 
)
Warning
This handler is an example only and does not fit a final product. You need to analyze how your product is supposed to react in case of error.
Parameters
[in]error_codeError code supplied to the handler.
[in]line_numLine number where the handler is called.
[in]p_file_namePointer 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.

Warning
This handler is an example only and does not fit a final product. You need to analyze how your product is supposed to react in case of Assert.
On assert from the SoftDevice, the system can only recover on reset.
Parameters
[in]line_numLine number of the failing ASSERT call.
[in]file_nameFile name of the failing ASSERT call.
static void char_notify ( void  )
static

Sends one characteristic value notification to peer if connected to it and the notification is enabled.

static void gap_params_init ( void  )
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 void connectable_adv_init ( void  )
static

This function initializes the advertisement parameters to values that will put the application in connectable mode.

static void non_connectable_adv_init ( void  )
static

This function initializes the advertisement parameters to values that will put the application in non-connectable mode.

static void advertising_data_init ( void  )
static

This function initializes the data that is to be placed in an advertisement packet in both connectable and non-connectable modes.

static void char_add ( const uint8_t  uuid_type)
static

This function adds the characteristic to the local db.

Parameters
[in]uuid_typeType of service UUID assigned by the S110 SoftDevice.
static void service_add ( void  )
static

This function adds the service and the characteristic within it to the local db.

static void notif_timeout_handler ( void *  p_context)
static

This function will be called when the notification timer expires. This will stop the timer for connection interval and disconnect from the peer.

Parameters
[in]p_contextPointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler.
static void connection_interval_timeout_handler ( void *  p_context)
static

This function will be called when the connection interval timer expires. This will trigger another characteristic notification to the peer.

Parameters
[in]p_contextPointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler.
static void application_timers_start ( void  )
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 void timers_init ( void  )
static

Initializes the timer module.

static void on_write ( ble_evt_t p_ble_evt)
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.

Parameters
[in]p_ble_evtBluetooth stack event.
static void on_ble_evt ( ble_evt_t p_ble_evt)
static
Parameters
[in]p_ble_evtBluetooth stack event.
static void ble_evt_dispatch ( ble_evt_t p_ble_evt)
static

This function is called from the BLE Stack event interrupt handler after a BLE stack event has been received.

Parameters
[in]p_ble_evtBluetooth stack event.
static void ble_stack_init ( void  )
static

Initializes the SoftDevice and the BLE event interrupt.

Variable Documentation

const ble_uuid128_t m_base_uuid128
static
Initial value:
=
{
{
0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00
}
}
ble_gap_adv_params_t m_adv_params
static

Parameters to be passed to the stack when starting advertising.

uint8_t m_char_value[APP_CFG_CHAR_LEN]
static

Value of the characteristic that will be sent as a notification to the master.

uint8_t m_addl_adv_manuf_data[ADV_ADDL_MANUF_DATA_LEN]
static

Value of the additional manufacturer specific data that will be placed in air (initialized to all zeros).

ble_gatts_char_handles_t m_char_handles
static

Handles of local characteristic (as provided by the BLE stack).

uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID
static

Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection).

uint16_t m_service_handle
static

Handle of local service (as provided by the BLE stack).

bool m_is_notifying_enabled = false
static

Variable to indicate whether the notification is enabled by the peer.

app_timer_id_t m_conn_int_timer_id
static

Connection interval timer.

app_timer_id_t m_notif_timer_id
static

Notification timer.