nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ANT bicycle power minimum receiver example

The bicycle power minimum receiver implementation. More...

Macros

#define BP_RX_ANT_CHANNEL   0
 
#define BP_PAGE_1   0x01u
 
#define BP_PAGE_16   0x10u
 
#define BP_PAGE_17   0x11u
 
#define BP_PAGE_18   0x12u
 
#define BP_PAGE_32   0x20u
 
#define BP_CID_170   0xAAu
 
#define BP_CID_172   0xACu
 
#define BP_CID_175   0xAFu
 
#define BP_PAGE_RESERVE_BYTE   0xFFu
 
#define COMMON_PAGE_80   0x50u
 
#define COMMON_PAGE_81   0x51u
 
#define APP_TIMER_PRESCALER   0
 
#define UART_TX_BUF_SIZE   256u
 
#define UART_RX_BUF_SIZE   1u
 
#define ANTPLUS_NETWORK_NUMBER   0
 
#define ANT_EVENT_MSG_BUFFER_MIN_SIZE   32u
 
#define BP_RX_CHANNEL_TYPE   CHANNEL_TYPE_SLAVE
 
#define BP_RX_TRANS_TYPE   0
 
#define BP_RX_DEVICE_NUMBER   0
 
#define BP_EXT_ASSIGN   0
 
#define BP_DEVICE_TYPE   0x0Bu
 
#define BP_RF_FREQ   0x39u
 
#define BP_MSG_PERIOD   0x1FF6u
 
#define BP_NETWORK_KEY   {0,0,0,0,0,0,0,0}
 
#define APP_TIMER_MAX_TIMERS   2u
 
#define APP_TIMER_OP_QUEUE_SIZE   2u
 
#define APP_GPIOTE_MAX_USERS   1u
 
#define BUTTON_DETECTION_DELAY   APP_TIMER_TICKS(50u, APP_TIMER_PRESCALER)
 
#define EVT_BUTTON_0   (1u << 0)
 
#define EVT_CALIBRATION_RESPONSE_TIMEOUT   (1u << 1u)
 
#define EVT_ANT_STACK   (1u << 2u)
 

Typedefs

typedef void(* calibration_process_callback_t )(calibration_notif_event_t event)
 

Enumerations

enum  calibration_notif_event_t {
  CALIBRATION_NOT_ACTIVE_STATE_ENTER,
  CALIBRATION_RESPONSE_TIMEOUT,
  CALIBRATION_NOT_ACTIVE_STATE_ENTER,
  CALIBRATION_RESPONSE_TIMEOUT
}
 
enum  antplus_event_t {
  ANTPLUS_EVENT_PAGE,
  ANTPLUS_EVENT_MAX,
  ANTPLUS_EVENT_NONE,
  ANTPLUS_EVENT_CALIBRATION_REQUEST,
  ANTPLUS_EVENT_PAGE,
  ANTPLUS_EVENT_MAX,
  ANTPLUS_EVENT_NONE,
  ANTPLUS_EVENT_CALIBRATION_REQUEST
}
 Bicycle Power profile application events. More...
 

Functions

void bicycle_power_rx_init (void)
 Function for initializing the module.
 
void bp_rx_calibration_cb_register (calibration_process_callback_t callback)
 Function for registering a calibration process statemachine callback client. More...
 
bool bp_rx_channel_event_handle (uint32_t event, uint8_t const *const p_event_message_buffer, antplus_event_return_t *p_event_return)
 Function for processing received ANT channel event message. More...
 
void bp_rx_calibration_start (void)
 Function for starting manual zero-offset calibration procedure. More...
 
void bp_rx_calibration_tout_handle (void)
 Function for handling a calibration response timeout event.
 
bp_page16_data_tbp_rx_data_page16_get (void)
 Function for getting the reference to data page 16, which is the standard power-only main data page. More...
 
bp_page17_data_tbp_rx_data_page17_get (void)
 Function for getting the reference to data page 17, which is the standard wheel torque main data page. More...
 
bp_page18_data_tbp_rx_data_page18_get (void)
 Function for getting the reference to data page 18, which is the standard crank torque main data page. More...
 
bp_page32_data_tbp_rx_data_page32_get (void)
 Function for getting the reference to data page 32, which is the crank torque frequency (CTF) main data page. More...
 
bp_page1_response_data_tbp_rx_data_page1_response_get (void)
 Function for getting the reference to data page 1, which is the general calibration response main data page. More...
 
page80_data_tbp_rx_data_page80_get (void)
 Function for getting the reference to data page 80, which is the manufacturer's identification common page. More...
 
page81_data_tbp_rx_data_page81_get (void)
 Function for getting the reference to data page 81, which is the product information common page. More...
 
void bicycle_power_rx_main_loop_run (void)
 Function for running the bicycle power RX main processing loop. Does not return.
 
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...
 
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...
 
static __INLINE void softdevice_setup (void)
 Function for configuring and setting up the SoftDevice.
 
int main ()
 Function for main application entry. Does not return.
 
void button_event_handle (uint8_t pin_no)
 Function for handling button events. More...
 
static void calibration_process_cb_handle (calibration_notif_event_t event)
 Function for handling calibration process statemachine callback events. More...
 
static __INLINE void button_press_handle (void)
 Function for handling user button presses. More...
 
static __INLINE void bicycle_power_channel_open (void)
 Function for configuring the ANT channel.
 
static __INLINE void profile_event_page_handle (const antplus_event_return_t *const p_event_return)
 Function for processing received profile page events. More...
 
static __INLINE void profile_event_handle (const antplus_event_return_t *const p_event_return)
 Function for processing received profile events. More...
 
void PROTOCOL_EVENT_IRQHandler (void)
 Function for handling stack interrupts.
 

Variables

static const uint8_t m_network_key [] = BP_NETWORK_KEY
 
static volatile uint32_t m_event_flags = 0
 

Data Structures

struct  bp_page16_data_t
 Bicycle Power page 16 data structure. More...
 
struct  bp_page17_data_t
 Bicycle Power page 17 data structure. More...
 
struct  bp_page18_data_t
 Bicycle Power page 18 data structure. More...
 
struct  bp_page32_data_t
 Bicycle Power page 32 data structure. More...
 
struct  bp_page1_response_data_t
 Bicycle Power page 1 general calibration response data structure. More...
 
struct  page80_data_t
 Common page 80 data structure. More...
 
struct  page81_data_t
 Common page 81 data structure. More...
 
struct  antplus_event_return_t
 Bicycle Power profile to application communication object. More...
 

Detailed Description

The Bicycle Power receiver implementation implements all of the features, which are required for the receiver to be fully compliant with the ANT+ Bike Power profile, as defined by the ANT+ Bicycle Power Profile specification:

The general architecture of the bicycle power minimum receiver is illustrated in the picture below.

bicycle_power_rx_design.png
Architecture overview
User interface

A simple user interface exists consisting of button0, which allows the user to start a manual zero-offset calibration procedure.

The calibration process statemachine is illustrated in the picture below.

bicycle_power_rx_calibration_sm.png
Calibration process statemachine
Bicycle power receiver configuration options

The following compile time configuration options are available to suit various bicycle power receiver implementations:

Development phase configuration options

The bicycle power receiver will trace profile specific information to the UART depending on the selected compile time configuration options.

The following compile time configuration options are available, and enabled by default, to assist in the development phase of the bicycle power receiver 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 BP_RX_ANT_CHANNEL   0

Default ANT Channel used.

#define BP_PAGE_1   0x01u

Calibration message main data page.

#define BP_PAGE_16   0x10u

Standard Power only main data page.

#define BP_PAGE_17   0x11u

Wheel Torque (WT) main data page.

#define BP_PAGE_18   0x12u

Standard Crank Torque (CT) main data page.

#define BP_PAGE_32   0x20u

Standard Crank Torque Frequency (CTF) main data page.

#define BP_CID_170   0xAAu

Calibration ID 0xAA = generic calibration request.

#define BP_CID_172   0xACu

Calibration ID 0xAC = calibration response manual zero success.

#define BP_CID_175   0xAFu

Calibration ID 0xAF = calibration response failure.

#define BP_PAGE_RESERVE_BYTE   0xFFu

Page reserved value.

#define COMMON_PAGE_80   0x50u

Manufacturer's identification common data page.

#define COMMON_PAGE_81   0x51u

Product information common data page.

#define APP_TIMER_PRESCALER   0

Value of the RTC1 PRESCALER register.

#define UART_TX_BUF_SIZE   256u

UART TX buffer size.

#define UART_RX_BUF_SIZE   1u

UART RX buffer size.

#define ANTPLUS_NETWORK_NUMBER   0

Network number.

#define ANT_EVENT_MSG_BUFFER_MIN_SIZE   32u

Minimum size of ANT event message buffer.

#define BP_RX_CHANNEL_TYPE   CHANNEL_TYPE_SLAVE

Slave.

#define BP_RX_TRANS_TYPE   0

Transmission Type.

#define BP_RX_DEVICE_NUMBER   0

Device Number.

#define BP_EXT_ASSIGN   0

ANT Ext Assign.

#define BP_DEVICE_TYPE   0x0Bu

Bike Power Device Type.

#define BP_RF_FREQ   0x39u

RF Channel 57 (2457 MHz).

#define BP_MSG_PERIOD   0x1FF6u

Decimal 8182 (~4.00Hz).

#define BP_NETWORK_KEY   {0,0,0,0,0,0,0,0}

The network key used.

#define APP_TIMER_MAX_TIMERS   2u

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).

#define EVT_BUTTON_0   (1u << 0)

Event for: button 0 pressed.

#define EVT_CALIBRATION_RESPONSE_TIMEOUT   (1u << 1u)

Event for: calibration response timeout.

#define EVT_ANT_STACK   (1u << 2u)

Event for: ANT stack interrupt received.

Enumeration Type Documentation

Enumerator
CALIBRATION_NOT_ACTIVE_STATE_ENTER 

Calibration process not running state entry event.

CALIBRATION_RESPONSE_TIMEOUT 

Calibration process response timeout event.

CALIBRATION_NOT_ACTIVE_STATE_ENTER 

Calibration process not running state entry event.

CALIBRATION_RESPONSE_TIMEOUT 

Calibration process response timeout event.

Enumerator
ANTPLUS_EVENT_PAGE 

Received a data page.

ANTPLUS_EVENT_MAX 

Upper limit.

ANTPLUS_EVENT_NONE 

No event.

ANTPLUS_EVENT_CALIBRATION_REQUEST 

Calibration request received event.

ANTPLUS_EVENT_PAGE 

Received a data page.

ANTPLUS_EVENT_MAX 

Upper limit.

ANTPLUS_EVENT_NONE 

No event.

ANTPLUS_EVENT_CALIBRATION_REQUEST 

Calibration request received event.

Function Documentation

void bp_rx_calibration_cb_register ( calibration_process_callback_t  callback)
Parameters
[in]callbackThe callback, which is called when various calibration process statemachine events occur.
bool bp_rx_channel_event_handle ( uint32_t  event,
uint8_t const *const  p_event_message_buffer,
antplus_event_return_t p_event_return 
)
Parameters
[in]eventANT event received.
[in]p_event_message_bufferANT event message buffer.
[out]p_event_returnOutput data from the profile.
Returns
true if p_event_return contains valid data, false otherwise.
void bp_rx_calibration_start ( void  )
Note
If this method is called when the calibration process is running, the end result is undefined.
bp_page16_data_t* bp_rx_data_page16_get ( void  )
Returns
Reference to data page 16.
bp_page17_data_t* bp_rx_data_page17_get ( void  )
Returns
Reference to data page 17.
bp_page18_data_t* bp_rx_data_page18_get ( void  )
Returns
Reference to data page 18.
bp_page32_data_t* bp_rx_data_page32_get ( void  )
Returns
Reference to data page 32.
bp_page1_response_data_t* bp_rx_data_page1_response_get ( void  )
Returns
Reference to data page 1 general response.
page80_data_t* bp_rx_data_page80_get ( void  )
Returns
Reference to data page 80.
page81_data_t* bp_rx_data_page81_get ( void  )
Returns
Reference to data page 81.
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 occured.
[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 
)
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 button_event_handle ( uint8_t  pin_no)
Parameters
[in]pin_noThe pin number of the button pressed.
static void calibration_process_cb_handle ( calibration_notif_event_t  event)
static
Parameters
[in]eventThe event to be handled.
static __INLINE void button_press_handle ( void  )
static

This function starts the calibration process that is triggered when a user presses a button. Disable the app_button module until the calibration process has been finished.

static __INLINE void profile_event_page_handle ( const antplus_event_return_t *const  p_event_return)
static
Parameters
[in]p_event_returnProfile page event to be processed.
static __INLINE void profile_event_handle ( const antplus_event_return_t *const  p_event_return)
static
Parameters
[in]p_event_returnProfile event to be processed.

Variable Documentation

const uint8_t m_network_key[] = BP_NETWORK_KEY
static

ANT network key.

volatile uint32_t m_event_flags = 0
static

Event flags used for deferred event processing in application main loop context.