-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
127 lines (113 loc) · 4.93 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/***************************************************************************//**
* @file
* @brief Silicon Labs Empty Example Project
*
* This example demonstrates the bare minimum needed for a Blue Gecko C application
* that allows Over-the-Air Device Firmware Upgrading (OTA DFU). The application
* starts advertising after boot and restarts advertising after a connection is closed.
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
/* Board headers */
#include "init_mcu.h"
#include "init_board.h"
#include "init_app.h"
#include "ble-configuration.h"
#include "board_features.h"
/* Bluetooth stack headers */
#include "bg_types.h"
#include "native_gecko.h"
#include "gatt_db.h"
#include "rail.h"
/* Libraries containing default Gecko configuration values */
#include "em_emu.h"
#include "em_cmu.h"
#include "em_chip.h"
/* Device initialization header */
#include "hal-config.h"
#if defined(HAL_CONFIG)
#include "bsphalconfig.h"
#else
#include "bspconfig.h"
#endif
/* Application header */
#include "app.h"
/***********************************************************************************************//**
* @addtogroup Application
* @{
**************************************************************************************************/
/***********************************************************************************************//**
* @addtogroup app
* @{
**************************************************************************************************/
#ifndef MAX_ADVERTISERS
#define MAX_ADVERTISERS 1
#endif
#ifndef MAX_CONNECTIONS
#define MAX_CONNECTIONS 4
#endif
uint8_t bluetooth_stack_heap[DEFAULT_BLUETOOTH_HEAP(MAX_CONNECTIONS)];
/* Bluetooth stack configuration parameters (see "UG136: Silicon Labs Bluetooth C Application Developer's Guide" for details on each parameter) */
static gecko_configuration_t config = {
.config_flags = 0, /* Check flag options from UG136 */
#if defined(FEATURE_LFXO) || defined(PLFRCO_PRESENT)
.sleep.flags = SLEEP_FLAGS_DEEP_SLEEP_ENABLE, /* Sleep is enabled */
#else
.sleep.flags = 0,
#endif
.bluetooth.max_connections = MAX_CONNECTIONS, /* Maximum number of simultaneous connections */
.bluetooth.max_advertisers = MAX_ADVERTISERS, /* Maximum number of advertisement sets */
.bluetooth.heap = bluetooth_stack_heap, /* Bluetooth stack memory for connection management */
.bluetooth.heap_size = sizeof(bluetooth_stack_heap), /* Bluetooth stack memory for connection management */
#if defined(FEATURE_LFXO)
.bluetooth.sleep_clock_accuracy = 100, /* Accuracy of the Low Frequency Crystal Oscillator in ppm. *
* Do not modify if you are using a module */
#elif defined(PLFRCO_PRESENT)
.bluetooth.sleep_clock_accuracy = 500, /* In case of internal RCO the sleep clock accuracy is 500 ppm */
#endif
.gattdb = &bg_gattdb_data, /* Pointer to GATT database */
.ota.flags = 0, /* Check flag options from UG136 */
.ota.device_name_len = 3, /* Length of the device name in OTA DFU mode */
.ota.device_name_ptr = "OTA", /* Device name in OTA DFU mode */
.ota.antenna_defined = APP_RF_CONFIG_ANTENNA,
.ota.antenna = APP_RF_ANTENNA,
.pa.config_enable = 1, /* Set this to be a valid PA config */
#if defined(FEATURE_PA_INPUT_FROM_VBAT)
.pa.input = GECKO_RADIO_PA_INPUT_VBAT, /* Configure PA input to VBAT */
#else
.pa.input = GECKO_RADIO_PA_INPUT_DCDC, /* Configure PA input to DCDC */
.pa.pa_mode = RAIL_TX_POWER_MODE_2P4GIG_HP, /* Use low power mode PA */
#endif // defined(FEATURE_PA_INPUT_FROM_VBAT)
.rf.flags = APP_RF_CONFIG_ANTENNA, /* Enable antenna configuration. */
.rf.antenna = APP_RF_ANTENNA, /* Select antenna path! */
};
/**
* @brief Main function
*/
int main(void)
{
CHIP_Init();
/* Initialize device */
initMcu();
/* Initialize board */
initBoard();
/* Initialize application */
initApp();
#if DEBUG_LEVEL
initVcomEnable();
#endif
/* Start application */
appMain(&config);
}
/** @} (end addtogroup app) */
/** @} (end addtogroup Application) */