nRF51 SDK
|
Heart Rate Service 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 | 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 | heart_rate_meas_timeout_handler (void *p_context) |
Function for handling the Heart rate measurement timer timeout. More... | |
static void | rr_interval_timeout_handler (void *p_context) |
Function for handling the RR interval timer timeout. More... | |
static void | sensor_contact_detected_timeout_handler (void *p_context) |
Function for handling the Sensor Contact Detected 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 | 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. More... | |
static void | sensor_sim_init (void) |
Function for initializing the sensor simulators. | |
static void | sec_params_init (void) |
Function for initializing security parameters. | |
static void | application_timers_start (void) |
Function for starting application timers. | |
static void | advertising_start (void) |
Function for starting advertising. | |
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 | 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 initializing buttons. | |
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 | power_manage (void) |
Function for the Power manager. | |
int | main (void) |
Function for application main entry. | |
void | hci_transport_timeout_handle (void *p_context) |
uint32_t | timer_event_schedule (app_timer_timeout_handler_t timeout_handler, void *p_context) |
Function for the scheduler to be used by the Application Timer module on timeouts. More... | |
static void | connectivity_chip_reset (void) |
static void | scheduler_init (void) |
Function for the Event Scheduler initialization. | |
Definition of HCI Transport Layer configurable parameters.
This file contains the source code for a sample application using the Heart Rate service (and also Battery and Device Information services). This application uses the srvlib_conn_params module.
#define WAKEUP_BUTTON_PIN NRF6310_BUTTON_0 |
Button used to wake up the application.
#define BONDMNGR_DELETE_BUTTON_PIN_NO NRF6310_BUTTON_1 |
Button used for deleting all bonded masters during startup.
#define DEVICE_NAME "Nordic_HRM" |
Name of device. Will be included in the advertising data.
#define MANUFACTURER_NAME "NordicSemiconductor" |
Manufacturer. Will be passed to Device Information Service.
#define APP_ADV_INTERVAL 40 |
The advertising interval (in units of 0.625 ms. This value corresponds to 25 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 5 |
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 HEART_RATE_MEAS_INTERVAL APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) |
Heart rate measurement interval (ticks).
#define MIN_HEART_RATE 140 |
Minimum heart rate as returned by the simulated measurement function.
#define MAX_HEART_RATE 300 |
Maximum heart rate as returned by the simulated measurement function.
#define HEART_RATE_INCREMENT 10 |
Value by which the heart rate is incremented/decremented for each call to the simulated measurement function.
#define RR_INTERVAL_INTERVAL APP_TIMER_TICKS(300, APP_TIMER_PRESCALER) |
RR interval interval (ticks).
#define MIN_RR_INTERVAL 100 |
Minimum RR interval as returned by the simulated measurement function.
#define MAX_RR_INTERVAL 500 |
Maximum RR interval as returned by the simulated measurement function.
#define RR_INTERVAL_INCREMENT 1 |
Value by which the RR interval is incremented/decremented for each call to the simulated measurement function.
#define SENSOR_CONTACT_DETECTED_INTERVAL APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER) |
Sensor Contact Detected toggle interval (ticks).
#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(5000, 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(5000, 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 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 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 WAKEUP_BUTTON_PIN NRF6310_BUTTON_0 |
Button used to wake up the application.
#define BONDMNGR_DELETE_BUTTON_PIN_NO NRF6310_BUTTON_1 |
Button used for deleting all bonded masters during startup.
#define DEVICE_NAME "Nordic_HRM" |
Name of device. Will be included in the advertising data.
#define MANUFACTURER_NAME "NordicSemiconductor" |
Manufacturer. Will be passed to Device Information Service.
#define APP_ADV_INTERVAL 40 |
The advertising interval (in units of 0.625 ms. This value corresponds to 25 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 6 |
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 HEART_RATE_MEAS_INTERVAL APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) |
Heart rate measurement interval (ticks).
#define MIN_HEART_RATE 140 |
Minimum heart rate as returned by the simulated measurement function.
#define MAX_HEART_RATE 300 |
Maximum heart rate as returned by the simulated measurement function.
#define HEART_RATE_INCREMENT 10 |
Value by which the heart rate is incremented/decremented for each call to the simulated measurement function.
#define RR_INTERVAL_INTERVAL APP_TIMER_TICKS(300, APP_TIMER_PRESCALER) |
RR interval interval (ticks).
#define MIN_RR_INTERVAL 100 |
Minimum RR interval as returned by the simulated measurement function.
#define MAX_RR_INTERVAL 500 |
Maximum RR interval as returned by the simulated measurement function.
#define RR_INTERVAL_INCREMENT 1 |
Value by which the RR interval is incremented/decremented for each call to the simulated measurement function.
#define SENSOR_CONTACT_DETECTED_INTERVAL APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER) |
Sensor Contact Detected toggle interval (ticks).
#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(5000, 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(5000, 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 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 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 CONN_CHIP_RESET_PIN_NO 30 |
Pin used for reseting the connectivity chip.
#define CONN_CHIP_RESET_TIME 50 |
The time to keep the reset line to the connectivity chip low (in milliseconds).
#define CONN_CHIP_WAKEUP_TIME 500 |
The time for connectivity chip to reset and become ready to receive serialized commands (in milliseconds).
#define SCHED_MAX_EVENT_DATA_SIZE |
Maximum size of scheduler events.
#define SCHED_QUEUE_SIZE 30 |
Maximum number of events in the scheduler queue.
#define HCI_SLIP_UART_RX_PIN_NUMBER RX_PIN_NUMBER |
< Default include for boards.h which means that default pin numbers will be used for RX, TX, CTS, and RTS on the UART. Other pin number can be used if desired. This section covers configurable parameters for the HCI Transport SLIP layer. Defines the UART RX pin number. The default pin for the board is chosen, but can be overwritten.
#define HCI_SLIP_UART_TX_PIN_NUMBER TX_PIN_NUMBER |
Defines the UART TX pin number. The default pin for the board is chosen, but can be overwritten.
#define HCI_SLIP_UART_RTS_PIN_NUMBER RTS_PIN_NUMBER |
Defines the UART RTS pin number. The default pin for the board is chosen, but can be overwritten.
#define HCI_SLIP_UART_CTS_PIN_NUMBER CTS_PIN_NUMBER |
Defines the UART CTS pin number. The default pin for the board is chosen, but can be overwritten.
#define HCI_SLIP_UART_MODE APP_UART_FLOW_CONTROL_ENABLED |
Defines the UART mode to be used. Use UART Low Power with Flow Control - Valid values are defined in app_uart_flow_control_t. For further information on the UART Low Power mode, please refer to: UART module .
#define HCI_SLIP_UART_BAUDRATE UART_BAUDRATE_BAUDRATE_Baud38400 |
Defines the UART Baud rate. Default is 38400 baud.
#define MAX_PACKET_SIZE_IN_BITS 8000u |
This section covers configurable parameters for the HCI Transport layer that are used for calculating correct value for the retransmission timer timeout. Maximum size of a single application packet in bits.
#define USED_BAUD_RATE 38400u |
The used uart baudrate.
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 |
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 |
This function will be called each time the heart rate measurement timer expires. It will exclude RR Interval data from every third measurement.
[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 RR interval timer expires.
[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 Sensor Contact Detected 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 |
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 |
Initialize the Heart Rate, Battery and Device Information services.
|
static |
This function will be called for all events in the Connection Parameters Module which are passed to the application.
[in] | p_evt | Event received from the Connection Parameters Module. |
|
static |
[in] | nrf_error | Error code containing information about what went wrong. |
|
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. |
void hci_transport_timeout_handle | ( | void * | p_context | ) |
Declaration of HCI Transport timeout handler. This timeout handler must be handled in APP-LO to ensure correct behavior accrording to 'HCI- Transport Layer - System integration'.
uint32_t timer_event_schedule | ( | app_timer_timeout_handler_t | timeout_handler, |
void * | p_context | ||
) |
This function schedules the timeout handler to be executed in the main thread. Timeout handles are scheduled using the Scheduler, except hci_transport_timeout_handle. hci_transport_timeout_handle will be executed immidiately according to requirements.
[in] | timeout_handler | Function to be executed or scheduled. |
[in] | p_context | General purpose pointer. Will be passed to the timeout handler upon execution of the timeout handler. |
|
static |
Handle of the current connection.
|
static |
Security requirements for this application.
|
static |
Parameters to be passed to the stack when starting advertising.
|
static |
Structure used to identify the battery service.
|
static |
Structure used to identify the heart rate service.
|
static |
Flag for enabling and disabling the registration of new RR interval measurements (the purpose of disabling this is just to test sending HRM without RR interval data.
|
static |
Battery Level sensor simulator configuration.
|
static |
Battery Level sensor simulator state.
|
static |
Heart Rate sensor simulator configuration.
|
static |
Heart Rate sensor simulator state.
|
static |
RR Interval sensor simulator configuration.
|
static |
RR Interval sensor simulator state.
|
static |
Battery timer.
|
static |
Heart rate measurement timer.
|
static |
RR interval timer.
|
static |
Sensor contact detected timer.
|
static |
Handle of the current connection.
|
static |
Security requirements for this application.
|
static |
Parameters to be passed to the stack when starting advertising.
|
static |
Structure used to identify the battery service.
|
static |
Structure used to identify the heart rate service.
|
static |
Flag for enabling and disabling the registration of new RR interval measurements (the purpose of disabling this is just to test sending HRM without RR interval data.
|
static |
Battery Level sensor simulator configuration.
|
static |
Battery Level sensor simulator state.
|
static |
Heart Rate sensor simulator configuration.
|
static |
Heart Rate sensor simulator state.
|
static |
RR Interval sensor simulator configuration.
|
static |
RR Interval sensor simulator state.
|
static |
Battery timer.
|
static |
Heart rate measurement timer.
|
static |
RR interval timer.
|
static |
Sensor contact detected timer.