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

Template project main file. More...

Macros

#define WAKEUP_BUTTON_PIN   NRF6310_BUTTON_0
 
#define DEVICE_NAME   "Nordic_Template"
 
#define APP_ADV_INTERVAL   64
 
#define APP_ADV_TIMEOUT_IN_SECONDS   180
 
#define APP_TIMER_PRESCALER   0
 
#define APP_TIMER_MAX_TIMERS   2
 
#define APP_TIMER_OP_QUEUE_SIZE   4
 
#define MIN_CONN_INTERVAL   MSEC_TO_UNITS(500, UNIT_1_25_MS)
 
#define MAX_CONN_INTERVAL   MSEC_TO_UNITS(1000, UNIT_1_25_MS)
 
#define SLAVE_LATENCY   0
 
#define CONN_SUP_TIMEOUT   MSEC_TO_UNITS(4000, UNIT_10_MS)
 
#define FIRST_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(20000, APP_TIMER_PRESCALER)
 
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER)
 
#define MAX_CONN_PARAMS_UPDATE_COUNT   3
 
#define APP_GPIOTE_MAX_USERS   1
 
#define BUTTON_DETECTION_DELAY   APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
 
#define SEC_PARAM_TIMEOUT   30
 
#define SEC_PARAM_BOND   1
 
#define SEC_PARAM_MITM   0
 
#define SEC_PARAM_IO_CAPABILITIES   BLE_GAP_IO_CAPS_NONE
 
#define SEC_PARAM_OOB   0
 
#define SEC_PARAM_MIN_KEY_SIZE   7
 
#define SEC_PARAM_MAX_KEY_SIZE   16
 
#define DEAD_BEEF   0xDEADBEEF
 
#define SCHED_MAX_EVENT_DATA_SIZE   sizeof(app_timer_event_t)
 
#define SCHED_QUEUE_SIZE   10
 

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 leds_init (void)
 Function for handling Service errors. More...
 
static void timers_init (void)
 Function for the Timer initialization. More...
 
static void gap_params_init (void)
 Function for the GAP initialization. More...
 
static void advertising_init (void)
 Function for initializing the Advertising functionality. More...
 
static void services_init (void)
 Function for initializing services that will be used by the application.
 
static void sec_params_init (void)
 Function for initializing security parameters.
 
static void on_conn_params_evt (ble_conn_params_evt_t *p_evt)
 Function for handling the Connection Parameters Module. More...
 
static void conn_params_error_handler (uint32_t nrf_error)
 Function for handling a Connection Parameters error. More...
 
static void conn_params_init (void)
 Function for initializing the Connection Parameters module.
 
static void timers_start (void)
 Function for starting timers.
 
static void advertising_start (void)
 Function for starting advertising.
 
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 scheduler_init (void)
 Function for the Event Scheduler initialization.
 
static void gpiote_init (void)
 Function for initializing the GPIOTE handler module.
 
static void buttons_init (void)
 Function for initializing the button handler module.
 
static void power_manage (void)
 Function for the Power manager.
 
int main (void)
 Function for application main entry.
 

Variables

static ble_gap_sec_params_t m_sec_params
 
static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID
 

Detailed Description

This file contains a template for creating a new application. It has the code necessary to wakeup from button, advertise, get a connection restart advertising on disconnect and if no new connection created go back to system-off mode. It can easily be used as a starting point for creating a new application, the comments identified with 'YOUR_JOB' indicates where and how you can customize.

Macro Definition Documentation

#define WAKEUP_BUTTON_PIN   NRF6310_BUTTON_0

Button used to wake up the application.

#define DEVICE_NAME   "Nordic_Template"

Name of device. Will be included in the advertising data.

#define APP_ADV_INTERVAL   64

The advertising interval (in units of 0.625 ms. This value corresponds to 40 ms).

#define APP_ADV_TIMEOUT_IN_SECONDS   180

The advertising timeout (in units of seconds).

#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 MIN_CONN_INTERVAL   MSEC_TO_UNITS(500, UNIT_1_25_MS)

Minimum acceptable connection interval (0.5 seconds).

#define MAX_CONN_INTERVAL   MSEC_TO_UNITS(1000, UNIT_1_25_MS)

Maximum acceptable connection interval (1 second).

#define SLAVE_LATENCY   0

Slave latency.

#define CONN_SUP_TIMEOUT   MSEC_TO_UNITS(4000, UNIT_10_MS)

Connection supervisory timeout (4 seconds).

#define FIRST_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(20000, APP_TIMER_PRESCALER)

Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (15 seconds).

#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER)

Time between each call to sd_ble_gap_conn_param_update after the first (5 seconds).

#define MAX_CONN_PARAMS_UPDATE_COUNT   3

Number of attempts before giving up the connection parameter negotiation.

#define APP_GPIOTE_MAX_USERS   1

Maximum number of users of the GPIOTE handler.

#define BUTTON_DETECTION_DELAY   APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)

Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks).

#define SEC_PARAM_TIMEOUT   30

Timeout for Pairing Request or Security Request (in seconds).

#define SEC_PARAM_BOND   1

Perform bonding.

#define SEC_PARAM_MITM   0

Man In The Middle protection not required.

#define SEC_PARAM_IO_CAPABILITIES   BLE_GAP_IO_CAPS_NONE

No I/O capabilities.

#define SEC_PARAM_OOB   0

Out Of Band data not available.

#define SEC_PARAM_MIN_KEY_SIZE   7

Minimum encryption key size.

#define SEC_PARAM_MAX_KEY_SIZE   16

Maximum encryption key size.

#define DEAD_BEEF   0xDEADBEEF

Value used as error code on stack dump, can be used to identify stack location on stack unwind.

#define SCHED_MAX_EVENT_DATA_SIZE   sizeof(app_timer_event_t)

Maximum size of scheduler events. Note that scheduler BLE stack events do not contain any data, as the events are being pulled from the stack in the event handler.

#define SCHED_QUEUE_SIZE   10

Maximum number of events in the scheduler queue.

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

A pointer to this function will be passed to each service which may need to inform the application about an error.

Parameters
[in]nrf_errorError code containing information about what went wrong.Function for the LEDs initialization.

Initializes all LEDs used by the application.

static void timers_init ( void  )
static

Initializes the timer module.

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 and appearance.

static void advertising_init ( void  )
static

Encodes the required advertising data and passes it to the stack. Also builds a structure to be passed to the stack when starting advertising.

static void on_conn_params_evt ( ble_conn_params_evt_t p_evt)
static

This function will be called for all events in the Connection Parameters Module which are passed to the application.

Note
All this function does is to disconnect. This could have been done by simply setting the disconnect_on_fail config parameter, but instead we use the event handler mechanism to demonstrate its use.
Parameters
[in]p_evtEvent received from the Connection Parameters Module.
static void conn_params_error_handler ( uint32_t  nrf_error)
static
Parameters
[in]nrf_errorError code containing information about what went wrong.
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 scheduler in the main loop 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

ble_gap_sec_params_t m_sec_params
static

Security requirements for this application.

uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID
static

Handle of the current connection.