nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ANT HRM TX example - user controlled computed heart rate

Example of ANT HRM TX profile where the user can directly control the computed heart rate value using buttons. More...

Macros

#define HRMTX_MSG_PERIOD_IN_MSECS   246u
 
#define HIGH_BYTE(word)   (uint8_t)((word >> 8u) & 0x00FFu)
 
#define LOW_BYTE(word)   (uint8_t)(word & 0x00FFu)
 
#define HRM_PAGE_1   1u
 
#define HRM_PAGE_2   2u
 
#define HRM_PAGE_3   3u
 
#define HRM_PAGE_4   4u
 
#define INITIAL_HEART_RATE_VALUE   60u
 
#define MIN_HEART_RATE_VALUE   1u
 
#define MAX_HEART_RATE_VALUE   255u
 
#define HEART_RATE_VALUE_INCREMENT   2u
 
#define HEART_RATE_VALUE_DECREMENT   HEART_RATE_VALUE_INCREMENT
 
#define HRM_DEVICE_NUMBER   49u
 
#define HRM_TRANSMISSION_TYPE   5u
 
#define HRMTX_ANT_CHANNEL   1u
 
#define HRMTX_MFG_ID   2u
 
#define HRMTX_SERIAL_NUMBER   0xABCDu
 
#define HRMTX_HW_VERSION   5u
 
#define HRMTX_SW_VERSION   0u
 
#define HRMTX_MODEL_NUMBER   2u
 
#define ANTPLUS_NETWORK_NUMBER   0
 
#define ANTPLUS_RF_FREQ   0x39u
 
#define UART_TX_BUF_SIZE   256u
 
#define UART_RX_BUF_SIZE   1u
 
#define ANT_EVENT_MSG_BUFFER_MIN_SIZE   32u
 
#define HRMTX_DEVICE_TYPE   0x78
 
#define HRMTX_MSG_PERIOD   0x1F86u
 
#define HRMTX_NETWORK_KEY   {0, 0, 0, 0, 0, 0, 0, 0}
 
#define APP_TIMER_PRESCALER   0
 
#define APP_TIMER_MAX_TIMERS   1u
 
#define APP_TIMER_OP_QUEUE_SIZE   2u
 
#define APP_GPIOTE_MAX_USERS   1u
 
#define BUTTON_DETECTION_DELAY   APP_TIMER_TICKS(50u, APP_TIMER_PRESCALER)
 

Functions

static __INLINE void datamessage_transmit (void)
 Function for constructing and transmitting ANT broadcast data message as a response to a ANT EVENT_TX.
 
static __INLINE void pulse_event_simulate (void)
 Function for simulating a device event. More...
 
static __INLINE void module_init (void)
 Function for initializing all state variables.
 
uint32_t hrm_tx_open (void)
 Function for initializing the HRM transmitter. More...
 
uint32_t hrm_tx_channel_event_handle (uint32_t ant_event)
 Function for processing an ANT channel event. More...
 
uint32_t hrm_tx_heart_rate_increment (void)
 Function for incrementing the current instantaneous heart rate value. More...
 
uint32_t hrm_tx_heart_rate_decrement (void)
 Function for decrementing the current instantaneous heart rate value. More...
 
void main_hrm_tx_run (void)
 Function for configuring the device simulator and HRM TX channel. Does not return. More...
 
void softdevice_assert_callback (uint32_t pc, uint16_t line_num, const uint8_t *p_file_name)
 Function for handling SoftDevice asserts. Does not return. More...
 
static __INLINE void softdevice_setup (void)
 Function for configuring and setting up the SoftDevice.
 
void app_error_handler (uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name)
 Function for handling an error. More...
 
int main (void)
 Function for application main entry. Does not return.
 
static __INLINE void ant_channel_tx_broadcast_setup (void)
 Function for setting up the ANT module for TX broadcast.
 
static __INLINE void application_event_process (void)
 Function for processing application specific events.
 
void button_event_handle (uint8_t pin_no)
 Function for handling button events. More...
 
void PROTOCOL_EVENT_IRQHandler (void)
 Function for handling protocol stack IRQ. More...
 

Variables

static uint32_t m_page_change
 
static uint32_t m_message_counter
 
static uint32_t m_ext_page_number_tracker
 
static uint32_t m_event_tx_counter
 
static uint8_t m_tx_buffer [8] = {0}
 
static uint32_t m_heart_rate_value = INITIAL_HEART_RATE_VALUE
 
static const uint8_t m_network_key [] = HRMTX_NETWORK_KEY
 
static volatile bool m_is_ant_event_received
 

Detailed Description

This example is a Heart Rate Monitor (HRM) transmitter simulator. It will transmit the users heart rate information in the main data page (page 4).

A simple user interface exists consisting of 2 keypad buttons, which allow the user to decrease or increase the computed heart rate value.

Device specific information is transmitted at a slower rate in the background data pages (pages 1-3). It will print out profile state information to UART when data is transmitted out of the device.

HRM specific configuration options

The following compile time configuration options are available to suit various HRM transmitter implementations:

Development phase configuration options

The HRM transmitter simulator will trace out state information to UART depending on the selected compile time configuration options.

The following compile time configuration options are available to assist in the development phase of the HRM transmitter implementation:

Note
The ANT+ Network Key is available for ANT+ Adopters. Please refer to http://thisisant.com to become an ANT+ Adopter and access the key.

Macro Definition Documentation

#define HRMTX_MSG_PERIOD_IN_MSECS   246u

HR TX message period in mseconds.

#define HIGH_BYTE (   word)    (uint8_t)((word >> 8u) & 0x00FFu)

Get high byte of a uint16_t.

#define LOW_BYTE (   word)    (uint8_t)(word & 0x00FFu)

Get low byte of a uint16_t.

#define HRM_PAGE_1   1u

HRM page 1 constant.

#define HRM_PAGE_2   2u

HRM page 2 constant.

#define HRM_PAGE_3   3u

HRM page 3 constant.

#define HRM_PAGE_4   4u

HRM page 4 constant.

#define INITIAL_HEART_RATE_VALUE   60u

Initial value for instantaneous heart rate value.

#define MIN_HEART_RATE_VALUE   1u

Minimum allowed instantaneous heart rate value.

#define MAX_HEART_RATE_VALUE   255u

Maximum allowed instantaneous heart rate value.

#define HEART_RATE_VALUE_INCREMENT   2u

Instantaneous heart rate value increment amount.

#define HEART_RATE_VALUE_DECREMENT   HEART_RATE_VALUE_INCREMENT

Instantaneous heart rate value decrement amount.

#define HRM_DEVICE_NUMBER   49u

ANT device number.

#define HRM_TRANSMISSION_TYPE   5u

ANT transmission type.

#define HRMTX_ANT_CHANNEL   1u

Default ANT Channel.

#define HRMTX_MFG_ID   2u

Manufacturer ID.

#define HRMTX_SERIAL_NUMBER   0xABCDu

Serial Number.

#define HRMTX_HW_VERSION   5u

HW Version.

#define HRMTX_SW_VERSION   0u

SW Version.

#define HRMTX_MODEL_NUMBER   2u

Model Number.

#define ANTPLUS_NETWORK_NUMBER   0

Network number.

#define ANTPLUS_RF_FREQ   0x39u

Frequency, Decimal 57 (2457 MHz).

#define UART_TX_BUF_SIZE   256u

UART TX buffer size.

#define UART_RX_BUF_SIZE   1u

UART RX buffer size.

#define ANT_EVENT_MSG_BUFFER_MIN_SIZE   32u

Minimum size of ANT event message buffer.

#define HRMTX_DEVICE_TYPE   0x78

Channel ID.

#define HRMTX_MSG_PERIOD   0x1F86u

Decimal 8070 (4.06Hz).

#define HRMTX_NETWORK_KEY   {0, 0, 0, 0, 0, 0, 0, 0}

The default network key used.

#define APP_TIMER_PRESCALER   0

Value of the RTC1 PRESCALER register.

#define APP_TIMER_MAX_TIMERS   1u

Maximum number of simultaneously created timers.

#define APP_TIMER_OP_QUEUE_SIZE   2u

Size of timer operation queues.

#define APP_GPIOTE_MAX_USERS   1u

Maximum number of users of the GPIOTE handler.

#define BUTTON_DETECTION_DELAY   APP_TIMER_TICKS(50u, APP_TIMER_PRESCALER)

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

Function Documentation

static __INLINE void pulse_event_simulate ( void  )
static

Based on this event, the transmitter data is simulated.

uint32_t hrm_tx_open ( void  )

Function for initializing HRM transmitter.

Return values
NRF_SUCCESSOperation success.
NRF_ANT_ERROR_CHANNEL_IN_WRONG_STATEOperation failure. Attempt to perform an action in a wrong channel state.
NRF_ANT_ERROR_INVALID_NETWORK_NUMBEROperation failure. Invalid network number provided.
NRF_ANT_ERROR_INVALID_PARAMETER_PROVIDEDOperation failure. Invalid parameter specified in a configuration message.
uint32_t hrm_tx_channel_event_handle ( uint32_t  ant_event)

Function for processing ANT channel event.

Parameters
[in]ant_eventANT channel event.
Return values
NRF_SUCCESSOperation success.
uint32_t hrm_tx_heart_rate_increment ( void  )
Return values
NRF_SUCCESSOperation success.
uint32_t hrm_tx_heart_rate_decrement ( void  )
Return values
NRF_SUCCESSOperation success.
void main_hrm_tx_run ( void  )

Function for configuring the device simulator and HRM TX channel, does not return.

void softdevice_assert_callback ( uint32_t  pc,
uint16_t  line_num,
const uint8_t *  p_file_name 
)

Traces out the user supplied parameters and busy loops.

Parameters
[in]pcValue of the program counter.
[in]line_numLine number where the assert occurred.
[in]p_file_namePointer to the file name.
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.

Parameters
[in]error_codeError code supplied to the handler.
[in]line_numLine number where the error occurred.
[in]p_file_namePointer to the file name.
void button_event_handle ( uint8_t  pin_no)
Parameters
[in]pin_noThe pin number of the button pressed.
void PROTOCOL_EVENT_IRQHandler ( void  )

Interrupt is generated by the ANT stack upon sending an event to the application.

Variable Documentation

uint32_t m_page_change
static

Page change bit.

uint32_t m_message_counter
static

Message counter.

uint32_t m_ext_page_number_tracker
static

Extended page number tracker.

uint32_t m_event_tx_counter
static

Counter for TX event from the ANT stack.

uint8_t m_tx_buffer[8] = {0}
static

Primary transmit buffer.

uint32_t m_heart_rate_value = INITIAL_HEART_RATE_VALUE
static

Instantaneous heart rate value.

const uint8_t m_network_key[] = HRMTX_NETWORK_KEY
static

ANT PLUS network key.

volatile bool m_is_ant_event_received
static

Flag value to determine is ANT stack interrupt received.