-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
222 lines (190 loc) · 6.7 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*************************************************************************************************/
/*!
* @file main.c
* @brief Maxim custom Bluetooth profile and service that advertises as "BCV" and accepts
* connection requests.
*
* Copyright (c) 2013-2019 Arm Ltd. All Rights Reserved.
*
* Copyright (c) 2019 Packetcraft, Inc.
*
* Portions Copyright (c) 2022-2023 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*************************************************************************************************/
#include <string.h>
#include "wsf_types.h"
#include "wsf_trace.h"
#include "wsf_bufio.h"
#include "wsf_msg.h"
#include "wsf_assert.h"
#include "wsf_buf.h"
#include "wsf_heap.h"
#include "wsf_cs.h"
#include "wsf_timer.h"
#include "wsf_os.h"
#include "sec_api.h"
#include "hci_handler.h"
#include "dm_handler.h"
#include "l2c_handler.h"
#include "att_handler.h"
#include "smp_handler.h"
#include "l2c_api.h"
#include "att_api.h"
#include "smp_api.h"
#include "app_api.h"
#include "hci_core.h"
#include "app_terminal.h"
#if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1)
#include "ll_init_api.h"
#endif
#include "pal_bb.h"
#include "pal_cfg.h"
#include "bcv_app_api.h"
#include "app_ui.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
/*! \brief UART TX buffer size */
#define PLATFORM_UART_TERMINAL_BUFFER_SIZE 2048U
#define DEFAULT_TX_POWER 0 /* dBm */
/**************************************************************************************************
Global Variables
**************************************************************************************************/
/*! \brief Pool runtime configuration. */
static wsfBufPoolDesc_t mainPoolDesc[] = { { 16, 8 }, { 32, 4 }, { 192, 8 }, { 256, 16 },{ 512, 8 } };
#if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1)
static LlRtCfg_t mainLlRtCfg;
#endif
/**************************************************************************************************
Functions
**************************************************************************************************/
/*! \brief Stack initialization for app. */
extern void StackInitBcvApp(void);
/*************************************************************************************************/
/*!
* \brief Initialize WSF.
*
* \return None.
*/
/*************************************************************************************************/
static void mainWsfInit(void)
{
#if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1)
/* +12 for message headroom, + 2 event header, +255 maximum parameter length. */
const uint16_t maxRptBufSize = 12 + 2 + 255;
/* +12 for message headroom, +4 for header. */
const uint16_t aclBufSize = 12 + mainLlRtCfg.maxAclLen + 4 + BB_DATA_PDU_TAILROOM;
/* Adjust buffer allocation based on platform configuration. */
mainPoolDesc[2].len = maxRptBufSize;
mainPoolDesc[2].num = mainLlRtCfg.maxAdvReports;
mainPoolDesc[3].len = aclBufSize;
mainPoolDesc[3].num = mainLlRtCfg.numTxBufs + mainLlRtCfg.numRxBufs;
#endif
const uint8_t numPools = sizeof(mainPoolDesc) / sizeof(mainPoolDesc[0]);
uint16_t memUsed;
WsfCsEnter();
memUsed = WsfBufInit(numPools, mainPoolDesc);
WsfHeapAlloc(memUsed);
WsfCsExit();
WsfOsInit();
WsfTimerInit();
#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE)
WsfTraceRegisterHandler(WsfBufIoWrite);
WsfTraceEnable(TRUE);
#endif
}
/*************************************************************************************************/
/*!
* \fn setAdvTxPower
*
* \brief Set the default advertising TX power.
*
* \return None.
*/
/*************************************************************************************************/
void setAdvTxPower(void)
{
LlSetAdvTxPower(DEFAULT_TX_POWER);
}
/*************************************************************************************************/
/*!
* \fn main
*
* \brief Entry point for demo software.
*
* \param None.
*
* \return None.
*/
/*************************************************************************************************/
int main(void)
{
#if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1)
/* Configurations must be persistent. */
static BbRtCfg_t mainBbRtCfg;
PalBbLoadCfg((PalBbCfg_t *)&mainBbRtCfg);
LlGetDefaultRunTimeCfg(&mainLlRtCfg);
#if (BT_VER >= LL_VER_BT_CORE_SPEC_5_0)
/* Set 5.0 requirements. */
mainLlRtCfg.btVer = LL_VER_BT_CORE_SPEC_5_0;
#endif
PalCfgLoadData(PAL_CFG_ID_LL_PARAM, &mainLlRtCfg.maxAdvSets, sizeof(LlRtCfg_t) - 9);
#if (BT_VER >= LL_VER_BT_CORE_SPEC_5_0)
PalCfgLoadData(PAL_CFG_ID_BLE_PHY, &mainLlRtCfg.phy2mSup, 4);
#endif
/* Set the 32k sleep clock accuracy into one of the following bins, default is 20
HCI_CLOCK_500PPM
HCI_CLOCK_250PPM
HCI_CLOCK_150PPM
HCI_CLOCK_100PPM
HCI_CLOCK_75PPM
HCI_CLOCK_50PPM
HCI_CLOCK_30PPM
HCI_CLOCK_20PPM
*/
mainBbRtCfg.clkPpm = 20;
/* Set the default connection power level */
mainLlRtCfg.defTxPwrLvl = DEFAULT_TX_POWER;
#endif
uint32_t memUsed;
WsfCsEnter();
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfHeapAlloc(memUsed);
WsfCsExit();
mainWsfInit();
AppTerminalInit();
#if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1)
WsfCsEnter();
LlInitRtCfg_t llCfg = { .pBbRtCfg = &mainBbRtCfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &mainLlRtCfg,
.pFreeMem = WsfHeapGetFreeStartAddress(),
.freeMemAvail = WsfHeapCountAvailable() };
memUsed = LlInit(&llCfg);
WsfHeapAlloc(memUsed);
WsfCsExit();
bdAddr_t bdAddr;
PalCfgLoadData(PAL_CFG_ID_BD_ADDR, bdAddr, sizeof(bdAddr_t));
LlSetBdAddr((uint8_t *)&bdAddr);
#endif
StackInitBcvApp();
BcvAppStart();
APP_TRACE_INFO1("AVAI: %u", WsfHeapCountAvailable());
WsfOsEnterMainLoop();
/* Does not return. */
return 0;
}