nRF51 SDK
|
Proximity Sample Application main file. More...
Functions | |
static void | on_ias_evt (ble_ias_t *p_ias, ble_ias_evt_t *p_evt) |
Function for handling Immediate Alert events. More... | |
static void | on_lls_evt (ble_lls_t *p_lls, ble_lls_evt_t *p_evt) |
Function for handling Link Loss events. More... | |
static void | on_ias_c_evt (ble_ias_c_t *p_ias_c, ble_ias_c_evt_t *p_evt) |
Function for handling IAS Client events. More... | |
static void | advertising_init (uint8_t adv_flags) |
Function for initializing the Advertising functionality. More... | |
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 | service_error_handler (uint32_t nrf_error) |
Function for handling Service errors. More... | |
static void | advertising_start (void) |
Function for starting advertising. | |
static void | battery_level_update (void) |
Function for performing a battery measurement, and update the Battery Level characteristic in the Battery Service. | |
static void | battery_level_meas_timeout_handler (void *p_context) |
Function for handling the Battery measurement timer timeout. More... | |
static void | leds_init (void) |
Function for the LEDs initialization. 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 | tps_init (void) |
Function for initializing the Tx Power Service. | |
static void | ias_init (void) |
Function for initializing the Immediate Alert Service. | |
static void | lls_init (void) |
Function for initializing the Link Loss Service. | |
static void | bas_init (void) |
Function for initializing the Battery Service. | |
static void | ias_client_init (void) |
Function for initializing the immediate alert service client. More... | |
static void | services_init (void) |
Function for initializing the services that will be used by the application. | |
static void | sensor_sim_init (void) |
Function for initializing the battery sensor simulator. | |
static void | sec_params_init (void) |
Function for initializing the security parameters. | |
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 | alert_signal (uint8_t alert_level) |
Function for signaling alert event from Immediate Alert or Link Loss services. 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 | bond_manager_error_handler (uint32_t nrf_error) |
Function for handling a Bond Manager error. More... | |
static void | bond_manager_init (void) |
Function for the Bond Manager initialization. | |
static void | radio_notification_init (void) |
Function for initializing the Radio Notification event. | |
static void | button_event_handler (uint8_t pin_no) |
Function for handling button events. More... | |
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. | |
static void | on_bas_evt (ble_bas_t *p_bas, ble_bas_evt_t *p_evt) |
Function for handling the Battery Service events. More... | |
void | ADC_IRQHandler (void) |
Function for handling the ADC interrupt. More... | |
static void | adc_start (void) |
Function for making the ADC start a battery level conversion. | |
static void | adv_led_blink_start (void) |
Function for starting the blinking of the Advertisement LED. | |
static void | adv_led_blink_stop (void) |
Function for stopping the blinking of the Advertisement LED. | |
static void | alert_led_blink_start (void) |
Function for starting the blinking of the Alert LED. | |
static void | alert_led_blink_stop (void) |
Function for stopping the blinking of the Alert LED. | |
static void | mild_alert_timeout_handler (void *p_context) |
Function for handling the timeout that is responsible for toggling the Alert LED. More... | |
static void | adv_led_blink_timeout_handler (void *p_context) |
Function for handling the timeout that is responsible for toggling the Advertisement LED. More... | |
Variables | |
static ble_tps_t | m_tps |
static ble_ias_t | m_ias |
static ble_lls_t | m_lls |
static bool | m_is_link_loss_alerting |
static ble_bas_t | m_bas |
static ble_ias_c_t | m_ias_c |
static ble_gap_sec_params_t | m_sec_params |
static ble_advertising_mode_t | m_advertising_mode |
static ble_sensorsim_cfg_t | m_battery_sim_cfg |
static ble_sensorsim_state_t | m_battery_sim_state |
static volatile bool | m_is_high_alert_signalled |
static app_timer_id_t | m_battery_timer_id |
static ble_tps_t | m_tps |
static ble_ias_t | m_ias |
static ble_lls_t | m_lls |
static bool | m_is_link_loss_alerting |
static bool | m_is_alert_led_blinking |
static bool | m_is_adv_led_blinking |
static ble_bas_t | m_bas |
static ble_ias_c_t | m_ias_c |
static ble_gap_sec_params_t | m_sec_params |
static ble_advertising_mode_t | m_advertising_mode |
static volatile bool | m_is_high_alert_signalled |
static app_timer_id_t | m_battery_timer_id |
static app_timer_id_t | m_alert_led_blink_timer_id |
static app_timer_id_t | m_adv_led_blink_timer_id |
Proximity Application main file.
This file contains is the source code for a sample proximity application using the Immediate Alert, Link Loss and Tx Power services.
This application would accept pairing requests from any peer device.
It demonstrates the use of fast and slow advertising intervals.
#define SIGNAL_ALERT_BUTTON NRF6310_BUTTON_0 |
Button used for send or cancel High Alert to the peer.
#define BONDMNGR_DELETE_BUTTON_PIN_NO NRF6310_BUTTON_1 |
Button used for deleting all bonded masters during startup.
#define ALERT_LEVEL_MILD_LED_PIN_NO NRF6310_LED_2 |
Is on when we are in Mild Alert state.
#define ALERT_LEVEL_HIGH_LED_PIN_NO NRF6310_LED_3 |
Is on when we are in High Alert state.
#define ADV_INTERVAL_SLOW_LED_PIN_NO NRF6310_LED_4 |
Is on when we are doing slow advertising.
#define PEER_SRV_DISC_LED_PIN_NO NRF6310_LED_5 |
Is on when the Immediate Alert Service has been discovered at the peer.
#define ADV_WHITELIST_LED_PIN_NO NRF6310_LED_6 |
Is on when we are doing advertising with whitelist.
#define DEVICE_NAME "Nordic_Prox" |
Name of device. Will be included in the advertising data.
#define APP_ADV_INTERVAL_FAST 0x0028 |
Fast advertising interval (in units of 0.625 ms. This value corresponds to 25 ms.).
#define APP_ADV_INTERVAL_SLOW 0x0C80 |
Slow advertising interval (in units of 0.625 ms. This value corrsponds to 2 seconds).
#define APP_SLOW_ADV_TIMEOUT 180 |
The duration of the slow advertising period (in seconds).
#define APP_FAST_ADV_TIMEOUT 40 |
The duration of the fast advertising period (in seconds).
#define APP_FAST_ADV_WHITELIST_TIMEOUT 20 |
The duration of the fast advertising with whitelist period (in seconds).
#define APP_TIMER_PRESCALER 0 |
Value of the RTC1 PRESCALER register.
#define APP_TIMER_MAX_TIMERS 3 |
Maximum number of simultaneously created timers.
#define APP_TIMER_OP_QUEUE_SIZE 4 |
Size of timer operation queues.
#define BATTERY_LEVEL_MEAS_INTERVAL APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER) |
Battery level measurement interval (ticks).
#define MIN_BATTERY_LEVEL 81 |
Minimum simulated battery level.
#define MAX_BATTERY_LEVEL 100 |
Maximum simulated battery level.
#define BATTERY_LEVEL_INCREMENT 1 |
Increment between each simulated battery level measurement.
#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(20 * 1000, APP_TIMER_PRESCALER) |
Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds).
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5 * 1000, APP_TIMER_PRESCALER) |
Time between each call to sd_ble_gap_conn_param_update after the first (30 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 INITIAL_LLS_ALERT_LEVEL BLE_CHAR_ALERT_LEVEL_NO_ALERT |
Initial value for the Alert Level characteristic in the Link Loss service.
#define TX_POWER_LEVEL (-8) |
TX Power Level value. This will be set both in the TX Power service, in the advertising data, and also used to set the radio transmit power.
#define FLASH_PAGE_SYS_ATTR (BLE_FLASH_PAGE_END - 3) |
Flash page used for bond manager system attribute information.
#define FLASH_PAGE_BOND (BLE_FLASH_PAGE_END - 1) |
Flash page used for bond manager bonding information.
#define DEAD_BEEF 0xDEADBEEF |
Value used as error code on stack dump, can be used to identify stack location on stack unwind.
#define SIGNAL_ALERT_BUTTON EVAL_BOARD_BUTTON_0 |
Button used for send or cancel High Alert to the peer.
#define STOP_ALERTING_BUTTON EVAL_BOARD_BUTTON_1 |
Button used for clearing the Alert LED that may be blinking or turned ON because of alerts from the master.
#define BONDMNGR_DELETE_BUTTON_PIN_NO EVAL_BOARD_BUTTON_1 |
Button used for deleting all bonded masters during startup.
#define ALERT_PIN_NO EVAL_BOARD_LED_1 |
Pin used as LED to signal an alert.
#define DEVICE_NAME "Nordic_Prox" |
Name of device. Will be included in the advertising data.
#define APP_ADV_INTERVAL_FAST 0x0028 |
Fast advertising interval (in units of 0.625 ms. This value corresponds to 25 ms.).
#define APP_ADV_INTERVAL_SLOW 0x0C80 |
Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds).
#define APP_SLOW_ADV_TIMEOUT 180 |
The duration of the slow advertising period (in seconds).
#define APP_FAST_ADV_TIMEOUT 30 |
The duration of the fast advertising period (in seconds).
#define APP_TIMER_PRESCALER 0 |
Value of the RTC1 PRESCALER register.
#define APP_TIMER_MAX_TIMERS 5 |
Maximum number of simultaneously created timers. 1 for Battery measurement, 2 for flashing Advertising LED and Alert LED, 1 for connection parameters module, 1 for button polling timer needed by the app_button module,
#define APP_TIMER_OP_QUEUE_SIZE 6 |
Size of timer operation queues.
#define BATTERY_LEVEL_MEAS_INTERVAL APP_TIMER_TICKS(120000, APP_TIMER_PRESCALER) |
Battery level measurement interval (ticks). This value corresponds to 120 seconds.
#define ADV_LED_ON_TIME APP_TIMER_TICKS(100, APP_TIMER_PRESCALER) |
Advertisement LED ON period when in blinking state.
#define ADV_LED_OFF_TIME APP_TIMER_TICKS(900, APP_TIMER_PRESCALER) |
Advertisement LED OFF period when in blinking state.
#define MILD_ALERT_LED_ON_TIME APP_TIMER_TICKS(100, APP_TIMER_PRESCALER) |
Alert LED ON period when in blinking state.
#define MILD_ALERT_LED_OFF_TIME APP_TIMER_TICKS(900, APP_TIMER_PRESCALER) |
Alert LED OFF period when in blinking state.
#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(5 * 1000, APP_TIMER_PRESCALER) |
Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds).
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5 * 1000, APP_TIMER_PRESCALER) |
Time between each call to sd_ble_gap_conn_param_update after the first (30 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 INITIAL_LLS_ALERT_LEVEL BLE_CHAR_ALERT_LEVEL_NO_ALERT |
Initial value for the Alert Level characteristic in the Link Loss service.
#define TX_POWER_LEVEL (-8) |
TX Power Level value. This will be set both in the TX Power service, in the advertising data, and also used to set the radio transmit power.
#define FLASH_PAGE_SYS_ATTR (BLE_FLASH_PAGE_END - 3) |
Flash page used for bond manager system attribute information.
#define FLASH_PAGE_BOND (BLE_FLASH_PAGE_END - 1) |
Flash page used for bond manager bonding information.
#define ADC_REF_VOLTAGE_IN_MILLIVOLTS 1200 |
Reference voltage (in milli volts) used by ADC while doing conversion.
#define ADC_PRE_SCALING_COMPENSATION 3 |
The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.
#define DIODE_FWD_VOLT_DROP_MILLIVOLTS 270 |
Typical forward voltage drop of the diode (Part no: SD103ATW-7-F) that is connected in series with the voltage supply. This is the voltage drop when the forward current is 1mA. Source: Data sheet of 'SURFACE MOUNT SCHOTTKY BARRIER DIODE ARRAY' available at www.diodes.com.
#define DEAD_BEEF 0xDEADBEEF |
Value used as error code on stack dump, can be used to identify stack location on stack unwind.
#define ADC_RESULT_IN_MILLI_VOLTS | ( | ADC_VALUE | ) | ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / 255) * ADC_PRE_SCALING_COMPENSATION) |
[in] | ADC_VALUE | ADC result. |
Result | converted to millivolts. |
|
static |
This function will be called for all Immediate Alert events which are passed to the application.
[in] | p_ias | Immediate Alert stucture. |
[in] | p_evt | Event received from the Immediate Alert service. |
|
static |
This function will be called for all Link Loss events which are passed to the application.
[in] | p_lls | Link Loss stucture. |
[in] | p_evt | Event received from the Link Loss service. |
|
static |
This function will be called for all IAS Client events which are passed to the application.
[in] | p_ias_c | IAS Client stucture. |
[in] | p_evt | Event received. |
|
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.
[in] | adv_flags | Indicates which type of advertisement to use, see GAP Discovery modes. |
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 |
A pointer to this function will be passed to each service which may need to inform the application about an error.
[in] | nrf_error | Error code containing information about what went wrong. |
|
static |
This function will be called each time the battery level measurement timer expires.
[in] | p_context | Pointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler. |
|
static |
Initializes all LEDs used by this application.
|
static |
Initializes the timer module. This creates and starts application timers.
|
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 |
This will initialize the client side functionality of the Find Me profile.
|
static |
[in] | nrf_error | Error code containing information about what went wrong. |
|
static |
[in] | alert_level | Requested alert level. |
|
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 |
[in] | nrf_error | Error code containing information about what went wrong. |
|
static |
[in] | pin_no | The pin number of the button pressed. |
|
static |
This function will be called for all Battery Service events which are passed to the | application.
[in] | p_bas | Battery Service stucture. |
[in] | p_evt | Event received from the Battery Service. |
void ADC_IRQHandler | ( | void | ) |
This function will fetch the conversion result from the ADC, convert the value into percentage and send it to peer.
|
static |
This function will be called each time the timer that was started for the sake of blinking the Alert LED expires. This function toggle the state of the Alert LED.
[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 each time the timer that was started for the sake of blinking the Advertisement LED expires. This function toggle the state of the Advertisement LED.
[in] | p_context | Pointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler. |
|
static |
Structure used to identify the TX Power service.
|
static |
Structure used to identify the Immediate Alert service.
|
static |
Structure used to identify the Link Loss service.
|
static |
Variable to indicate if a link loss has been detected.
|
static |
Structure used to identify the battery service.
|
static |
Structure used to identify the client to the Immediate Alert Service at peer.
|
static |
Security requirements for this application.
|
static |
Variable to keep track of when we are advertising.
|
static |
Battery Level sensor simulator configuration.
|
static |
Battery Level sensor simulator state.
|
static |
Variable to indicate whether or not high alert is signalled to the peer.
|
static |
Battery timer.
|
static |
Structure used to identify the TX Power service.
|
static |
Structure used to identify the Immediate Alert service.
|
static |
Structure used to identify the Link Loss service.
|
static |
Variable to indicate if a link loss has been detected.
|
static |
Variable to indicate if the alert LED is blinking (indicating a mild alert).
|
static |
Variable to indicate if the advertising LED is blinking.
|
static |
Structure used to identify the battery service.
|
static |
Structure used to identify the client to the Immediate Alert Service at peer.
|
static |
Security requirements for this application.
|
static |
Variable to keep track of when we are advertising.
|
static |
Variable to indicate whether or not high alert is signalled to the peer.
|
static |
Battery measurement timer.
|
static |
Timer to realize the blinking of Alert LED.
|
static |
Timer to realize the blinking of Advertisement LED.