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 
15 #include <stdint.h>
16 
17 #include "boards.h"
18 #include "debug.h"
19 #include "pru.h"
20 #include "softdevice_handler.h"
21 #include "pru_config.h"
22 #include "app_util_platform.h"
23 #include "app_print.h"
24 #include "nrf_nvic.h"
25 
26 
27 #ifdef DFU_SUPPORT
28  #include "common_hal_buttons.h"
29 #endif
30 
31 #define CENTRAL_LINK_COUNT 0
32 #define PERIPHERAL_LINK_COUNT 1
41 static void m_ble_evt_dispatch(ble_evt_t * p_ble_evt)
42 {
43  pru_on_ble_evt(p_ble_evt);
44 }
45 
50 static void m_ble_stack_init(void)
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 }
86 
90 int main()
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 }
112 
113 
115 //lint -restore
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)
BLE stack initialization.
Definition: main.c:50
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.
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:31
#define PERIPHERAL_LINK_COUNT
Definition: main.c:32
#define APP_TIMER_PRESCALER
Definition: pru.h:33
static void m_ble_evt_dispatch(ble_evt_t *p_ble_evt)
Dispatches a BLE stack event to all profiles.
Definition: main.c:41
#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