Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0

Macros

#define DEAD_BEEF   0xDEADBEEF
 
#define VRECT_MEAS_INTERVAL   APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
 
#define VRECT_MEAS_INTERVAL   APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
 
#define PRU_MULTI_PROFILE_TIMER_OP_QUEUE_SIZE   (8 + PRU_MAX_APP_TIMERS)
 
#define CENTRAL_LINK_COUNT   0
 
#define PERIPHERAL_LINK_COUNT   1
 
#define DEAD_BEEF   0xDEADBEEF
 

Enumerations

enum  device_profile_t { PROFILE_WPT, PROFILE_APPLICATION }
 Enum representing the current active profile.
 

Functions

 APP_TIMER_DEF (m_vrect_read_timer)
 
static void m_ble_evt_dispatch (ble_evt_t *p_ble_evt)
 Dispatches a BLE stack event to all profiles. More...
 
static void m_sys_evt_dispatch (uint32_t evt)
 Dispatch system events to all profiles that require it.
 
static void m_ble_stack_init (void)
 BLE stack initialization. More...
 
static void vrect_read_timeout_handler (void *p_context)
 Handler for reading VRECT.
 
static void m_timers_init (void)
 Init timers required by this module.
 
static void m_on_pru_sm_evt (pru_sm_signal_type_t signal, const pru_sm_state_vars_t *p_state_vars)
 PRU state machine event handler. Used to see when charging has stopped.
 
int main ()
 Application main function. More...
 

Variables

static nrf_clock_lf_cfg_t clk_cfg
 
static bool m_connected = false
 
static bool m_profile_has_been_switched = false
 
static const ble_gap_addr_t PRU_ADDR
 
static const ble_gap_addr_t APP_PROFILE_ADDR
 
static ble_enable_params_t m_ble_enable_params
 BLE Enable params. More...
 
device_profile_t m_current_profile = PROFILE_APPLICATION
 

Detailed Description

Macro Definition Documentation

#define DEAD_BEEF   0xDEADBEEF

Error code to signify a SoftDevice assert.

Definition at line 38 of file main.c.

#define VRECT_MEAS_INTERVAL   APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)

Heart rate measurement interval (ticks).

Definition at line 42 of file main.c.

#define VRECT_MEAS_INTERVAL   APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)

Heart rate measurement interval (ticks).

Definition at line 42 of file main.c.

#define PRU_MULTI_PROFILE_TIMER_OP_QUEUE_SIZE   (8 + PRU_MAX_APP_TIMERS)

Max number of internal timers.

Definition at line 43 of file main.c.

#define CENTRAL_LINK_COUNT   0

Number of central links used by the application. When changing this number remember to adjust the RAM settings

Definition at line 34 of file main.c.

#define PERIPHERAL_LINK_COUNT   1

Number of peripheral links used by the application. When changing this number remember to adjust the RAM settings

Definition at line 35 of file main.c.

#define DEAD_BEEF   0xDEADBEEF

Error code to signify a SoftDevice assert.

Definition at line 38 of file main.c.

Function Documentation

APP_TIMER_DEF ( m_vrect_read_timer  )

Timer used for measuring VRECT

static void m_ble_evt_dispatch ( ble_evt_t *  p_ble_evt)
static

Dispatches a BLE stack event to all profiles.

This function is called from the BLE Stack event interrupt handler after a BLE stack event has been received.

Parameters
[in]p_ble_evtBluetooth stack event.

Definition at line 83 of file main.c.

84 {
85  switch(p_ble_evt->header.evt_id)
86  {
87  case BLE_GAP_EVT_CONNECTED:
88  m_connected = true;
89  break;
90  }
91 
92  switch(m_current_profile)
93  {
94  case PROFILE_WPT:
95  pru_on_ble_evt(p_ble_evt);
96  break;
97 
98  case PROFILE_APPLICATION:
99  app_profile_on_ble_evt(p_ble_evt);
100  break;
101  }
102 }
void pru_on_ble_evt(ble_evt_t *p_ble_evt)
Handle BLE event.
Definition: pru.c:510
void app_profile_on_ble_evt(ble_evt_t *p_ble_evt)
Handle BLE event.
Definition: ble_app_hrs.c:726
device_profile_t m_current_profile
Definition: main.c:73
static bool m_connected
Definition: main.c:49
static void m_ble_stack_init ( void  )
static

BLE stack initialization.

Initializes the SoftDevice and the BLE event interrupt.

Definition at line 114 of file main.c.

115 {
116  uint32_t err_code;
117 
118  SOFTDEVICE_HANDLER_INIT(&clk_cfg, NULL);
119 
120  err_code = softdevice_enable(&m_ble_enable_params);
121  APP_ERROR_CHECK(err_code);
122 
123  err_code = softdevice_ble_evt_handler_set(m_ble_evt_dispatch);
124  APP_ERROR_CHECK(err_code);
125 
126  err_code = softdevice_sys_evt_handler_set(m_sys_evt_dispatch);
127  APP_ERROR_CHECK(err_code);
128 
129  // It is important that this is set to the same priority as the
130  // timers in the system.
131  err_code = sd_nvic_SetPriority(SD_EVT_IRQn, APP_IRQ_PRIORITY_LOW);
132  APP_ERROR_CHECK(err_code);
133 }
static void m_ble_evt_dispatch(ble_evt_t *p_ble_evt)
Dispatches a BLE stack event to all profiles.
Definition: main.c:83
static void m_sys_evt_dispatch(uint32_t evt)
Dispatch system events to all profiles that require it.
Definition: main.c:105
static nrf_clock_lf_cfg_t clk_cfg
Definition: main.c:45
static ble_enable_params_t m_ble_enable_params
BLE Enable params.
Definition: main.c:62
int main ( )

Application main function.

Returns
Ignored.

Definition at line 207 of file main.c.

208 {
209  uint32_t err_code;
210 
211  pru_sensors_init(NULL); // Initialize sensors with NULL value to allow sensor reading, event generation will not be enabled.
213  m_timers_init();
214 
215 #ifdef DFU_SUPPORT
216  // Set up button used for entering DFU mode
218 #endif
219 
220  err_code = app_timer_start(m_vrect_read_timer, VRECT_MEAS_INTERVAL, NULL);
221  APP_ERROR_CHECK(err_code);
222 
224 
227 
228  // We need to get to main context before switching profile in order to ensure that all
229  // softdevice events has been handled.
230  while(1)
231  {
233  {
234  (void)sd_softdevice_enable(&clk_cfg, app_error_fault_handler);
235 
236  err_code = softdevice_enable(&m_ble_enable_params);
237  APP_ERROR_CHECK(err_code);
238 
239  if(m_current_profile == PROFILE_WPT)
240  {
241  err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &PRU_ADDR);
242  APP_ERROR_CHECK(err_code);
243 
244  pru_start();
245  }
246  else
247  {
248  err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &APP_PROFILE_ADDR);
249  APP_ERROR_CHECK(err_code);
250 
252  }
254  }
255 
256  #ifdef DEBUG_OUT_ENABLE
257  debug();
258  #endif
259  }
260 }
static void m_ble_stack_init(void)
BLE stack initialization.
Definition: main.c:114
static bool m_profile_has_been_switched
Definition: main.c:53
void app_profile_start(void)
Start profile. Is called every time profile is activated.
Definition: ble_app_hrs.c:736
void common_hal_buttons_init(uint32_t button_press_duration_ms, uint8_t app_timer_prescaler)
Initialize button functionality. Used only for starting DFU.
void pru_init(app_sm_evt_handler_t sm_evt_handler)
Initialize PRU. This function must be called before any other PRU function can be called...
Definition: pru.c:480
void pru_sensors_init(pru_sm_handler_t pru_sm_handler)
Initialize sensors and read default values.
Definition: pru_sensors.c:42
device_profile_t m_current_profile
Definition: main.c:73
static bool m_connected
Definition: main.c:49
static nrf_clock_lf_cfg_t clk_cfg
Definition: main.c:45
static void m_timers_init(void)
Init timers required by this module.
Definition: main.c:167
#define VRECT_MEAS_INTERVAL
Definition: main.c:42
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
Callback function for asserts in the SoftDevice.
static const ble_gap_addr_t PRU_ADDR
Definition: main.c:55
#define APP_TIMER_PRESCALER
Definition: pru.h:33
#define PRU_BUTTON_PRESS_LENGTH_DFU_MS
Definition: pru_config.h:42
static ble_enable_params_t m_ble_enable_params
BLE Enable params.
Definition: main.c:62
void debug(void)
Process debug commands.
Definition: pru_debug.c:564
void pru_start(void)
Enable the PRU profile. When enabled sensor reading and signal generation will be enabled...
Definition: pru.c:487
static const ble_gap_addr_t APP_PROFILE_ADDR
Definition: main.c:58
void app_profile_init(void)
Initialize profile. Is only called once.
Definition: ble_app_hrs.c:716
static void m_on_pru_sm_evt(pru_sm_signal_type_t signal, const pru_sm_state_vars_t *p_state_vars)
PRU state machine event handler. Used to see when charging has stopped.
Definition: main.c:178

Variable Documentation

nrf_clock_lf_cfg_t clk_cfg
static
Initial value:
= {
.source = NRF_CLOCK_LF_SRC_XTAL,
.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}

Same clock source as 'softdevice_handler.c'.

Definition at line 45 of file main.c.

bool m_connected = false
static

Is the device currently connected?

Definition at line 49 of file main.c.

bool m_profile_has_been_switched = false
static

Do we have an unhandled profile switch?

Definition at line 53 of file main.c.

const ble_gap_addr_t PRU_ADDR
static
Initial value:
= {.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
.addr = {0xe4, 0x33, 0xba, 0xab, 0xea, 0xee}}

Address used for PRU

Definition at line 55 of file main.c.

const ble_gap_addr_t APP_PROFILE_ADDR
static
Initial value:
= {.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
.addr = {0xc9, 0xff, 0xcc, 0xee, 0x11, 0xcc}}

Address used for Application profile

Definition at line 58 of file main.c.

ble_enable_params_t m_ble_enable_params
static
Initial value:
= {.common_enable_params.vs_uuid_count = BLE_UUID_VS_COUNT_DEFAULT,
.gap_enable_params.periph_conn_count = 1,
.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT}

BLE Enable params.

Definition at line 62 of file main.c.

device_profile_t m_current_profile = PROFILE_APPLICATION

What profile is currently running?

Definition at line 73 of file main.c.