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 
21 #include <stdint.h>
22 #include <string.h>
23 
24 #include "boards.h"
25 #include "app_print.h"
26 #include "debug.h"
27 #include "ptu.h"
28 #include "softdevice_handler.h"
29 #include "ptu_config.h"
30 #include "app_util_platform.h"
31 #include "nrf_nvic.h"
32 
33 
34 #ifdef DFU_SUPPORT
35  #include "common_hal_buttons.h"
36 #endif
37 
38 #define CENTRAL_LINK_COUNT 8
39 #define PERIPHERAL_LINK_COUNT 0
45 static void m_ble_evt_dispatch(ble_evt_t * p_evt)
46 {
47  ptu_on_ble_evt(p_evt);
48 }
49 
52 static void m_ble_stack_init(void)
53 {
54  uint32_t err_code;
55  ble_conn_bw_counts_t count = {{0,0,CENTRAL_LINK_COUNT},{0,0,CENTRAL_LINK_COUNT}};
56 
57  // Initialize the SoftDevice handler module.
58  nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
59  SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
60 
61  // Enable BLE stack.
62  ble_enable_params_t ble_enable_params = {0};
63  ble_enable_params.gap_enable_params.central_conn_count = CENTRAL_LINK_COUNT;
64  ble_enable_params.gap_enable_params.central_sec_count = CENTRAL_LINK_COUNT;
65 
66  ble_enable_params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
67  ble_enable_params.common_enable_params.p_conn_bw_counts = &count;
68 
69  ble_opt_t opt = {0};
70  opt.common_opt.conn_bw.conn_bw.conn_bw_rx = BLE_CONN_BW_LOW;
71  opt.common_opt.conn_bw.conn_bw.conn_bw_tx = BLE_CONN_BW_LOW;
72  opt.common_opt.conn_bw.role = BLE_GAP_ROLE_CENTRAL;
73 
74  //Check the ram settings against the used number of links
75  CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT);
76 
77  err_code = softdevice_enable(&ble_enable_params);
78  APP_ERROR_CHECK(err_code);
79 
80  err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_BW, &opt);
81  APP_ERROR_CHECK(err_code);
82 
83  err_code = softdevice_ble_evt_handler_set(m_ble_evt_dispatch);
84  APP_ERROR_CHECK(err_code);
85 
86  err_code = sd_ble_gap_tx_power_set(PTU_OUTPUT_TX_POWER);
87  APP_ERROR_CHECK(err_code);
88 
89  // It is important that this is set to the same priority as the
90  // timers in the system.
91  err_code = sd_nvic_SetPriority(SD_EVT_IRQn, APP_IRQ_PRIORITY_LOW);
92  APP_ERROR_CHECK(err_code);
93 }
94 
97 int main()
98 {
99  APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
100 
101 #ifdef DFU_SUPPORT
102  // Set up button used for entering DFU mode
104 #endif
105 
107 
108  // Initialize PTU state machine
109  ptu_init(NULL);
110 
111  // Start PTU
112  ptu_start();
113 
114  while(1)
115  {
116  #ifdef DEBUG_OUT_ENABLE
117  debug();
118  #endif
119  }
120 }
121 
122 //lint -restore
#define PERIPHERAL_LINK_COUNT
Definition: main.c:39
int main()
Application main function.
Definition: main.c:90
#define PTU_BUTTON_PRESS_LENGTH_DFU_MS
Definition: ptu_config.h:227
void common_hal_buttons_init(uint32_t button_press_duration_ms, uint8_t app_timer_prescaler)
Initialize button functionality. Used only for starting DFU.
#define APP_TIMER_OP_QUEUE_SIZE
Definition: pru.h:34
static void m_ble_evt_dispatch(ble_evt_t *p_evt)
Dispatches BLE events to all profiles.
Definition: main.c:45
void ptu_start(void)
Start ptu profile. Here "start" means that profile can start generating events through ptu_evt_handle...
Definition: ptu.c:364
#define PTU_OUTPUT_TX_POWER
Definition: ptu_config.h:31
#define CENTRAL_LINK_COUNT
Definition: main.c:38
void ptu_on_ble_evt(ble_evt_t *p_ble_evt)
Dispatches a BLE stack event to PTU.
Definition: ptu.c:319
#define APP_TIMER_PRESCALER
Definition: pru.h:33
void debug(void)
Process debug commands.
Definition: pru_debug.c:564
void ptu_init(app_sm_evt_handler_t sm_evt_handler)
Initialize PTU. This function must be called before any other PTU function can be called...
Definition: ptu.c:331
static void m_ble_stack_init(void)
Initialize the BLE sofdevice and IRQ handler.
Definition: main.c:52