Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
main.c File Reference
#include <stdint.h>
#include "boards.h"
#include "debug.h"
#include "pru.h"
#include "softdevice_handler.h"
#include "pru_config.h"
#include "app_util_platform.h"
#include "app_print.h"
#include "nrf_nvic.h"
#include "common_hal_buttons.h"

Go to the source code of this file.

Macros

#define CENTRAL_LINK_COUNT   0
 
#define PERIPHERAL_LINK_COUNT   1
 

Functions

static void m_ble_evt_dispatch (ble_evt_t *p_ble_evt)
 Dispatches a BLE stack event to all profiles. More...
 
static void m_ble_stack_init (void)
 BLE stack initialization. More...
 
int main ()
 Application main function. More...
 

Macro Definition Documentation

#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 31 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 32 of file main.c.

Function Documentation

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 41 of file main.c.

42 {
43  pru_on_ble_evt(p_ble_evt);
44 }
void pru_on_ble_evt(ble_evt_t *p_ble_evt)
Handle BLE event.
Definition: pru.c:510
static void m_ble_stack_init ( void  )
static

BLE stack initialization.

Initializes the SoftDevice and the BLE event interrupt.

Definition at line 50 of file main.c.

51 {
52  uint32_t err_code;
53  ble_conn_bw_counts_t count = {{1,0,0},{1,0,0}};
54 
55  // Initialize the SoftDevice handler module.
56  nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
57  SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
58 
59  // Enable BLE stack.
60  ble_enable_params_t ble_enable_params = {0};
61  ble_enable_params.gap_enable_params.periph_conn_count = PERIPHERAL_LINK_COUNT;
62  ble_enable_params.common_enable_params.p_conn_bw_counts = &count;
63 
64  ble_opt_t opt;
65  opt.common_opt.conn_bw.conn_bw.conn_bw_rx = BLE_CONN_BW_HIGH;
66  opt.common_opt.conn_bw.conn_bw.conn_bw_tx = BLE_CONN_BW_HIGH;
67  opt.common_opt.conn_bw.role = BLE_GAP_ROLE_PERIPH;
68 
69  //Check the ram settings against the used number of links
70  CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT);
71 
72  err_code = softdevice_enable(&ble_enable_params);
73  APP_ERROR_CHECK(err_code);
74 
75  err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_BW, &opt);
76  APP_ERROR_CHECK(err_code);
77 
78  err_code = softdevice_ble_evt_handler_set(m_ble_evt_dispatch);
79  APP_ERROR_CHECK(err_code);
80 
81  // It is important that this is set to the same priority as the
82  // timers in the system.
83  err_code = sd_nvic_SetPriority(SD_EVT_IRQn, APP_IRQ_PRIORITY_LOW);
84  APP_ERROR_CHECK(err_code);
85 }
#define CENTRAL_LINK_COUNT
Definition: main.c:31
#define PERIPHERAL_LINK_COUNT
Definition: main.c:32
static void m_ble_evt_dispatch(ble_evt_t *p_ble_evt)
Dispatches a BLE stack event to all profiles.
Definition: main.c:41
int main ( )

Application main function.

Returns
Ignored.

Definition at line 90 of file main.c.

91 {
92  APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
93 
95 
96  pru_init(NULL);
97 
98 #ifdef DFU_SUPPORT
99  // Set up button used for entering DFU mode
101 #endif
102 
103  pru_start();
104 
105  while(1)
106  {
107  #ifdef DEBUG_OUT_ENABLE
108  debug();
109  #endif
110  }
111 }
static void m_ble_stack_init(void)
BLE stack initialization.
Definition: main.c:50
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
#define APP_TIMER_OP_QUEUE_SIZE
Definition: pru.h:34
#define APP_TIMER_PRESCALER
Definition: pru.h:33
#define PRU_BUTTON_PRESS_LENGTH_DFU_MS
Definition: pru_config.h:42
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