Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
main.c
Go to the documentation of this file.
1 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
2  *
3  * The information contained herein is property of Nordic Semiconductor ASA.
4  * Terms and conditions of usage are described in detail in NORDIC
5  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
6  *
7  * Licensees are granted free, non-transferable use of the information. NO
8  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
9  * the file.
10  *
11  */
12 
19 #include <stdint.h>
20 #include "boards.h"
21 #include "debug.h"
22 #include "pru.h"
23 #include "softdevice_handler.h"
24 #include "pru_config.h"
25 #include "app_util_platform.h"
26 #include "wireless_debug.h"
27 #include "nrf_nvic.h"
28 
29 
30 #ifdef DFU_SUPPORT
31  #include "common_hal_buttons.h"
32 #endif
33 
34 #define CENTRAL_LINK_COUNT 0
35 #define PERIPHERAL_LINK_COUNT 1
37 // Assert setup
38 #define DEAD_BEEF 0xDEADBEEF
47 static void m_ble_evt_dispatch(ble_evt_t * p_ble_evt)
48 {
49  pru_on_ble_evt(p_ble_evt);
50 }
51 
56 static void m_ble_stack_init(void)
57 {
58  uint32_t err_code;
59  ble_conn_bw_counts_t count = {{1,0,0},{1,0,0}};
60 
61  // Initialize the SoftDevice handler module.
62  nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
63  SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
64 
65  // Enable BLE stack.
66  ble_enable_params_t ble_enable_params = {0};
67  ble_enable_params.gap_enable_params.periph_conn_count = PERIPHERAL_LINK_COUNT;
68  ble_enable_params.common_enable_params.p_conn_bw_counts = &count;
69 
70  ble_opt_t opt;
71  opt.common_opt.conn_bw.conn_bw.conn_bw_rx = BLE_CONN_BW_HIGH;
72  opt.common_opt.conn_bw.conn_bw.conn_bw_tx = BLE_CONN_BW_HIGH;
73  opt.common_opt.conn_bw.role = BLE_GAP_ROLE_PERIPH;
74 
75  //Check the ram settings against the used number of links
76  CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT);
77 
78  err_code = softdevice_enable(&ble_enable_params);
79  APP_ERROR_CHECK(err_code);
80 
81  err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_BW, &opt);
82  APP_ERROR_CHECK(err_code);
83 
84  err_code = softdevice_ble_evt_handler_set(m_ble_evt_dispatch);
85  APP_ERROR_CHECK(err_code);
86 
87  // It is important that this is set to the same priority as the
88  // timers in the system.
89  err_code = sd_nvic_SetPriority(SD_EVT_IRQn, APP_IRQ_PRIORITY_LOW);
90  APP_ERROR_CHECK(err_code);
91 }
92 
96 int main()
97 {
98  uint32_t err_code;
99 
100  APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
101 
103  err_code = sd_radio_init();
104  APP_ERROR_CHECK(err_code);
105  pru_init(NULL);
106 
107 #ifdef DFU_SUPPORT
108  // Set up button used for entering DFU mode
110 #endif
111 
112  pru_start();
113 
114  while(1)
115  {
116  #ifdef DEBUG_OUT_ENABLE
117  debug();
118  #endif
119  }
120 }
121 
122 
124 //lint -restore
void pru_on_ble_evt(ble_evt_t *p_ble_evt)
Handle BLE event.
Definition: pru.c:510
uint32_t sd_radio_init(void)
Initialize SD Radio API.
int main()
Application main function.
Definition: main.c:90
void common_hal_buttons_init(uint32_t button_press_duration_ms, uint8_t app_timer_prescaler)
Initialize button functionality. Used only for starting DFU.
static void m_ble_evt_dispatch(ble_evt_t *p_ble_evt)
Dispatches a BLE stack event to all profiles.
Definition: main.c:47
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 CENTRAL_LINK_COUNT
Definition: main.c: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
#define PERIPHERAL_LINK_COUNT
Definition: main.c:35
static void m_ble_stack_init(void)
BLE stack initialization.
Definition: main.c:56