1 /**
2 ******************************************************************************
3 * @file tl_mbox.c
4 * @author MCD Application Team
5 * @brief Transport layer for the mailbox interface
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2018-2021 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19 /* Includes ------------------------------------------------------------------*/
20 #include "stm32_wpan_common.h"
21 #include "hw.h"
22
23 #include "stm_list.h"
24 #include "tl.h"
25 #include "mbox_def.h"
26 #include "tl_dbg_conf.h"
27
28 /* Private typedef -----------------------------------------------------------*/
29 typedef enum
30 {
31 TL_MB_MM_RELEASE_BUFFER,
32 TL_MB_BLE_CMD,
33 TL_MB_BLE_CMD_RSP,
34 TL_MB_BLE_ASYNCH_EVT,
35 TL_MB_SYS_CMD,
36 TL_MB_SYS_CMD_RSP,
37 TL_MB_SYS_ASYNCH_EVT,
38 } TL_MB_PacketType_t;
39
40 /* Private defines -----------------------------------------------------------*/
41 /* Private macros ------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43
44 /**< reference table */
45 PLACE_IN_SECTION("MAPPING_TABLE") static volatile MB_RefTable_t TL_RefTable;
46 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_DeviceInfoTable_t TL_DeviceInfoTable;
47 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleTable_t TL_BleTable;
48 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ThreadTable_t TL_ThreadTable;
49 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldTestsTable_t TL_LldTestsTable;
50 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable;
51 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable;
52 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable;
53 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable;
54 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table;
55 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table;
56
57 /**< tables */
58 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue;
59 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue;
60 PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)];
61 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue;
62 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue;
63
64
65 static tListNode LocalFreeBufQueue;
66 static void (* BLE_IoBusEvtCallBackFunction) (TL_EvtPacket_t *phcievt);
67 static void (* BLE_IoBusAclDataTxAck) ( void );
68 static void (* SYS_CMD_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt);
69 static void (* SYS_EVT_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt);
70
71
72 /* Global variables ----------------------------------------------------------*/
73 /* Private function prototypes -----------------------------------------------*/
74 static void SendFreeBuf( void );
75 static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer);
76
77 /* Public Functions Definition ------------------------------------------------------*/
78
79 /******************************************************************************
80 * GENERAL - refer to AN5289 for functions description.
81 ******************************************************************************/
TL_Enable(void)82 void TL_Enable( void )
83 {
84 HW_IPCC_Enable();
85
86 return;
87 }
88
89
TL_Init(void)90 void TL_Init( void )
91 {
92 TL_RefTable.p_device_info_table = &TL_DeviceInfoTable;
93 TL_RefTable.p_ble_table = &TL_BleTable;
94 TL_RefTable.p_thread_table = &TL_ThreadTable;
95 TL_RefTable.p_lld_tests_table = &TL_LldTestsTable;
96 TL_RefTable.p_ble_lld_table = &TL_BleLldTable;
97 TL_RefTable.p_sys_table = &TL_SysTable;
98 TL_RefTable.p_mem_manager_table = &TL_MemManagerTable;
99 TL_RefTable.p_traces_table = &TL_TracesTable;
100 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table;
101 TL_RefTable.p_zigbee_table = &TL_Zigbee_Table;
102 HW_IPCC_Init();
103
104 return;
105 }
106
107 /******************************************************************************
108 * BLE
109 ******************************************************************************/
TL_BLE_Init(void * pConf)110 int32_t TL_BLE_Init( void* pConf )
111 {
112 MB_BleTable_t * p_bletable;
113
114 TL_BLE_InitConf_t *pInitHciConf = (TL_BLE_InitConf_t *) pConf;
115
116 LST_init_head (&EvtQueue);
117
118 p_bletable = TL_RefTable.p_ble_table;
119
120 p_bletable->pcmd_buffer = pInitHciConf->p_cmdbuffer;
121 p_bletable->phci_acl_data_buffer = pInitHciConf->p_AclDataBuffer;
122 p_bletable->pcs_buffer = (uint8_t*)CsBuffer;
123 p_bletable->pevt_queue = (uint8_t*)&EvtQueue;
124
125 HW_IPCC_BLE_Init();
126
127 BLE_IoBusEvtCallBackFunction = pInitHciConf->IoBusEvtCallBack;
128 BLE_IoBusAclDataTxAck = pInitHciConf->IoBusAclDataTxAck;
129
130 return 0;
131 }
132
TL_BLE_SendCmd(uint8_t * buffer,uint16_t size)133 int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size )
134 {
135 (void)(buffer);
136 (void)(size);
137
138 ((TL_CmdPacket_t*)(TL_RefTable.p_ble_table->pcmd_buffer))->cmdserial.type = TL_BLECMD_PKT_TYPE;
139
140 OutputDbgTrace(TL_MB_BLE_CMD, TL_RefTable.p_ble_table->pcmd_buffer);
141
142 HW_IPCC_BLE_SendCmd();
143
144 return 0;
145 }
146
HW_IPCC_BLE_RxEvtNot(void)147 void HW_IPCC_BLE_RxEvtNot(void)
148 {
149 TL_EvtPacket_t *phcievt;
150
151 while(LST_is_empty(&EvtQueue) == FALSE)
152 {
153 LST_remove_head (&EvtQueue, (tListNode **)&phcievt);
154
155 if ( ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CS_OPCODE) || ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CC_OPCODE ) )
156 {
157 OutputDbgTrace(TL_MB_BLE_CMD_RSP, (uint8_t*)phcievt);
158 }
159 else
160 {
161 OutputDbgTrace(TL_MB_BLE_ASYNCH_EVT, (uint8_t*)phcievt);
162 }
163
164 BLE_IoBusEvtCallBackFunction(phcievt);
165 }
166
167 return;
168 }
169
TL_BLE_SendAclData(uint8_t * buffer,uint16_t size)170 int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size )
171 {
172 (void)(buffer);
173 (void)(size);
174
175 ((TL_AclDataPacket_t *)(TL_RefTable.p_ble_table->phci_acl_data_buffer))->AclDataSerial.type = TL_ACL_DATA_PKT_TYPE;
176
177 HW_IPCC_BLE_SendAclData();
178
179 return 0;
180 }
181
HW_IPCC_BLE_AclDataAckNot(void)182 void HW_IPCC_BLE_AclDataAckNot(void)
183 {
184 BLE_IoBusAclDataTxAck( );
185
186 return;
187 }
188
189 /******************************************************************************
190 * SYSTEM
191 ******************************************************************************/
TL_SYS_Init(void * pConf)192 int32_t TL_SYS_Init( void* pConf )
193 {
194 MB_SysTable_t * p_systable;
195
196 TL_SYS_InitConf_t *pInitHciConf = (TL_SYS_InitConf_t *) pConf;
197
198 LST_init_head (&SystemEvtQueue);
199 p_systable = TL_RefTable.p_sys_table;
200 p_systable->pcmd_buffer = pInitHciConf->p_cmdbuffer;
201 p_systable->sys_queue = (uint8_t*)&SystemEvtQueue;
202
203 HW_IPCC_SYS_Init();
204
205 SYS_CMD_IoBusCallBackFunction = pInitHciConf->IoBusCallBackCmdEvt;
206 SYS_EVT_IoBusCallBackFunction = pInitHciConf->IoBusCallBackUserEvt;
207
208 return 0;
209 }
210
TL_SYS_SendCmd(uint8_t * buffer,uint16_t size)211 int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size )
212 {
213 (void)(buffer);
214 (void)(size);
215
216 ((TL_CmdPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer))->cmdserial.type = TL_SYSCMD_PKT_TYPE;
217
218 OutputDbgTrace(TL_MB_SYS_CMD, TL_RefTable.p_sys_table->pcmd_buffer);
219
220 HW_IPCC_SYS_SendCmd();
221
222 return 0;
223 }
224
HW_IPCC_SYS_CmdEvtNot(void)225 void HW_IPCC_SYS_CmdEvtNot(void)
226 {
227 OutputDbgTrace(TL_MB_SYS_CMD_RSP, (uint8_t*)(TL_RefTable.p_sys_table->pcmd_buffer) );
228
229 SYS_CMD_IoBusCallBackFunction( (TL_EvtPacket_t*)(TL_RefTable.p_sys_table->pcmd_buffer) );
230
231 return;
232 }
233
HW_IPCC_SYS_EvtNot(void)234 void HW_IPCC_SYS_EvtNot( void )
235 {
236 TL_EvtPacket_t *p_evt;
237
238 while(LST_is_empty(&SystemEvtQueue) == FALSE)
239 {
240 LST_remove_head (&SystemEvtQueue, (tListNode **)&p_evt);
241
242 OutputDbgTrace(TL_MB_SYS_ASYNCH_EVT, (uint8_t*)p_evt );
243
244 SYS_EVT_IoBusCallBackFunction( p_evt );
245 }
246
247 return;
248 }
249
250 /******************************************************************************
251 * THREAD
252 ******************************************************************************/
253 #ifdef THREAD_WB
TL_THREAD_Init(TL_TH_Config_t * p_Config)254 void TL_THREAD_Init( TL_TH_Config_t *p_Config )
255 {
256 MB_ThreadTable_t * p_thread_table;
257
258 p_thread_table = TL_RefTable.p_thread_table;
259
260 p_thread_table->clicmdrsp_buffer = p_Config->p_ThreadCliRspBuffer;
261 p_thread_table->otcmdrsp_buffer = p_Config->p_ThreadOtCmdRspBuffer;
262 p_thread_table->notack_buffer = p_Config->p_ThreadNotAckBuffer;
263 p_thread_table->clinot_buffer = p_Config->p_ThreadCliNotBuffer;
264
265 HW_IPCC_THREAD_Init();
266
267 return;
268 }
269
TL_OT_SendCmd(void)270 void TL_OT_SendCmd( void )
271 {
272 ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->otcmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE;
273
274 HW_IPCC_OT_SendCmd();
275
276 return;
277 }
278
TL_CLI_SendCmd(void)279 void TL_CLI_SendCmd( void )
280 {
281 ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE;
282
283 HW_IPCC_CLI_SendCmd();
284
285 return;
286 }
287
TL_THREAD_SendAck(void)288 void TL_THREAD_SendAck ( void )
289 {
290 ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
291
292 HW_IPCC_THREAD_SendAck();
293
294 return;
295 }
296
TL_THREAD_CliSendAck(void)297 void TL_THREAD_CliSendAck ( void )
298 {
299 ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
300
301 HW_IPCC_THREAD_CliSendAck();
302
303 return;
304 }
305
HW_IPCC_OT_CmdEvtNot(void)306 void HW_IPCC_OT_CmdEvtNot(void)
307 {
308 TL_OT_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->otcmdrsp_buffer) );
309
310 return;
311 }
312
HW_IPCC_THREAD_EvtNot(void)313 void HW_IPCC_THREAD_EvtNot( void )
314 {
315 TL_THREAD_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->notack_buffer) );
316
317 return;
318 }
319
HW_IPCC_THREAD_CliEvtNot(void)320 void HW_IPCC_THREAD_CliEvtNot( void )
321 {
322 TL_THREAD_CliNotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->clinot_buffer) );
323
324 return;
325 }
326
TL_OT_CmdEvtReceived(TL_EvtPacket_t * Otbuffer)327 __WEAK void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){};
TL_THREAD_NotReceived(TL_EvtPacket_t * Notbuffer)328 __WEAK void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer ){};
TL_THREAD_CliNotReceived(TL_EvtPacket_t * Notbuffer)329 __WEAK void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer ){};
330
331 #endif /* THREAD_WB */
332
333 /******************************************************************************
334 * LLD TESTS
335 ******************************************************************************/
336 #ifdef LLD_TESTS_WB
TL_LLDTESTS_Init(TL_LLD_tests_Config_t * p_Config)337 void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config )
338 {
339 MB_LldTestsTable_t * p_lld_tests_table;
340
341 p_lld_tests_table = TL_RefTable.p_lld_tests_table;
342 p_lld_tests_table->clicmdrsp_buffer = p_Config->p_LldTestsCliCmdRspBuffer;
343 p_lld_tests_table->m0cmd_buffer = p_Config->p_LldTestsM0CmdBuffer;
344 HW_IPCC_LLDTESTS_Init();
345 return;
346 }
347
TL_LLDTESTS_SendCliCmd(void)348 void TL_LLDTESTS_SendCliCmd( void )
349 {
350 ((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE;
351 HW_IPCC_LLDTESTS_SendCliCmd();
352 return;
353 }
354
HW_IPCC_LLDTESTS_ReceiveCliRsp(void)355 void HW_IPCC_LLDTESTS_ReceiveCliRsp( void )
356 {
357 TL_LLDTESTS_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer) );
358 return;
359 }
360
TL_LLDTESTS_SendCliRspAck(void)361 void TL_LLDTESTS_SendCliRspAck( void )
362 {
363 HW_IPCC_LLDTESTS_SendCliRspAck();
364 return;
365 }
366
HW_IPCC_LLDTESTS_ReceiveM0Cmd(void)367 void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void )
368 {
369 TL_LLDTESTS_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->m0cmd_buffer) );
370 return;
371 }
372
373
TL_LLDTESTS_SendM0CmdAck(void)374 void TL_LLDTESTS_SendM0CmdAck( void )
375 {
376 HW_IPCC_LLDTESTS_SendM0CmdAck();
377 return;
378 }
379
TL_LLDTESTS_ReceiveCliRsp(TL_CmdPacket_t * Notbuffer)380 __WEAK void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){};
TL_LLDTESTS_ReceiveM0Cmd(TL_CmdPacket_t * Notbuffer)381 __WEAK void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){};
382 #endif /* LLD_TESTS_WB */
383
384 /******************************************************************************
385 * BLE LLD
386 ******************************************************************************/
387 #ifdef BLE_LLD_WB
TL_BLE_LLD_Init(TL_BLE_LLD_Config_t * p_Config)388 void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config )
389 {
390 MB_BleLldTable_t * p_ble_lld_table;
391
392 p_ble_lld_table = TL_RefTable.p_ble_lld_table;
393 p_ble_lld_table->cmdrsp_buffer = p_Config->p_BleLldCmdRspBuffer;
394 p_ble_lld_table->m0cmd_buffer = p_Config->p_BleLldM0CmdBuffer;
395 HW_IPCC_BLE_LLD_Init();
396 return;
397 }
398
TL_BLE_LLD_SendCliCmd(void)399 void TL_BLE_LLD_SendCliCmd( void )
400 {
401 ((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE;
402 HW_IPCC_BLE_LLD_SendCliCmd();
403 return;
404 }
405
HW_IPCC_BLE_LLD_ReceiveCliRsp(void)406 void HW_IPCC_BLE_LLD_ReceiveCliRsp( void )
407 {
408 TL_BLE_LLD_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) );
409 return;
410 }
411
TL_BLE_LLD_SendCliRspAck(void)412 void TL_BLE_LLD_SendCliRspAck( void )
413 {
414 HW_IPCC_BLE_LLD_SendCliRspAck();
415 return;
416 }
417
HW_IPCC_BLE_LLD_ReceiveM0Cmd(void)418 void HW_IPCC_BLE_LLD_ReceiveM0Cmd( void )
419 {
420 TL_BLE_LLD_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->m0cmd_buffer) );
421 return;
422 }
423
424
TL_BLE_LLD_SendM0CmdAck(void)425 void TL_BLE_LLD_SendM0CmdAck( void )
426 {
427 HW_IPCC_BLE_LLD_SendM0CmdAck();
428 return;
429 }
430
TL_BLE_LLD_ReceiveCliRsp(TL_CmdPacket_t * Notbuffer)431 __WEAK void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){};
TL_BLE_LLD_ReceiveM0Cmd(TL_CmdPacket_t * Notbuffer)432 __WEAK void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){};
433
434 /* Transparent Mode */
TL_BLE_LLD_SendCmd(void)435 void TL_BLE_LLD_SendCmd( void )
436 {
437 ((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE;
438 HW_IPCC_BLE_LLD_SendCmd();
439 return;
440 }
441
HW_IPCC_BLE_LLD_ReceiveRsp(void)442 void HW_IPCC_BLE_LLD_ReceiveRsp( void )
443 {
444 TL_BLE_LLD_ReceiveRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) );
445 return;
446 }
447
TL_BLE_LLD_SendRspAck(void)448 void TL_BLE_LLD_SendRspAck( void )
449 {
450 HW_IPCC_BLE_LLD_SendRspAck();
451 return;
452 }
453 #endif /* BLE_LLD_WB */
454
455 #ifdef MAC_802_15_4_WB
456 /******************************************************************************
457 * MAC 802.15.4
458 ******************************************************************************/
TL_MAC_802_15_4_Init(TL_MAC_802_15_4_Config_t * p_Config)459 void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config )
460 {
461 MB_Mac_802_15_4_t * p_mac_802_15_4_table;
462
463 p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table;
464
465 p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer;
466 p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer;
467
468 HW_IPCC_MAC_802_15_4_Init();
469
470 return;
471 }
472
TL_MAC_802_15_4_SendCmd(void)473 void TL_MAC_802_15_4_SendCmd( void )
474 {
475 ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE;
476
477 HW_IPCC_MAC_802_15_4_SendCmd();
478
479 return;
480 }
481
TL_MAC_802_15_4_SendAck(void)482 void TL_MAC_802_15_4_SendAck ( void )
483 {
484 ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
485
486 HW_IPCC_MAC_802_15_4_SendAck();
487
488 return;
489 }
490
HW_IPCC_MAC_802_15_4_CmdEvtNot(void)491 void HW_IPCC_MAC_802_15_4_CmdEvtNot(void)
492 {
493 TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) );
494
495 return;
496 }
497
HW_IPCC_MAC_802_15_4_EvtNot(void)498 void HW_IPCC_MAC_802_15_4_EvtNot( void )
499 {
500 TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) );
501
502 return;
503 }
504
TL_MAC_802_15_4_CmdEvtReceived(TL_EvtPacket_t * Otbuffer)505 __WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){};
TL_MAC_802_15_4_NotReceived(TL_EvtPacket_t * Notbuffer)506 __WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){};
507 #endif
508
509 #ifdef ZIGBEE_WB
510 /******************************************************************************
511 * ZIGBEE
512 ******************************************************************************/
TL_ZIGBEE_Init(TL_ZIGBEE_Config_t * p_Config)513 void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config )
514 {
515 MB_ZigbeeTable_t * p_zigbee_table;
516
517 p_zigbee_table = TL_RefTable.p_zigbee_table;
518 p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer;
519 p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer;
520 p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer;
521
522 HW_IPCC_ZIGBEE_Init();
523
524 return;
525 }
526
527 /* Zigbee M4 to M0 Request */
TL_ZIGBEE_SendM4RequestToM0(void)528 void TL_ZIGBEE_SendM4RequestToM0( void )
529 {
530 ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE;
531
532 HW_IPCC_ZIGBEE_SendM4RequestToM0();
533
534 return;
535 }
536
537 /* Used to receive an ACK from the M0 */
HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void)538 void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void)
539 {
540 TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) );
541
542 return;
543 }
544
545 /* Zigbee notification from M0 to M4 */
HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void)546 void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void )
547 {
548 TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) );
549
550 return;
551 }
552
553 /* Send an ACK to the M0 for a Notification */
TL_ZIGBEE_SendM4AckToM0Notify(void)554 void TL_ZIGBEE_SendM4AckToM0Notify ( void )
555 {
556 ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
557
558 HW_IPCC_ZIGBEE_SendM4AckToM0Notify();
559
560 return;
561 }
562
563 /* Zigbee M0 to M4 Request */
HW_IPCC_ZIGBEE_RecvM0RequestToM4(void)564 void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void )
565 {
566 TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) );
567
568 return;
569 }
570
571 /* Send an ACK to the M0 for a Request */
TL_ZIGBEE_SendM4AckToM0Request(void)572 void TL_ZIGBEE_SendM4AckToM0Request(void)
573 {
574 ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
575
576 HW_IPCC_ZIGBEE_SendM4AckToM0Request();
577
578 return;
579 }
580
581
TL_ZIGBEE_CmdEvtReceived(TL_EvtPacket_t * Otbuffer)582 __WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){};
TL_ZIGBEE_NotReceived(TL_EvtPacket_t * Notbuffer)583 __WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){};
584 #endif
585
586
587
588 /******************************************************************************
589 * MEMORY MANAGER
590 ******************************************************************************/
TL_MM_Init(TL_MM_Config_t * p_Config)591 void TL_MM_Init( TL_MM_Config_t *p_Config )
592 {
593 static MB_MemManagerTable_t * p_mem_manager_table;
594
595 LST_init_head (&FreeBufQueue);
596 LST_init_head (&LocalFreeBufQueue);
597
598 p_mem_manager_table = TL_RefTable.p_mem_manager_table;
599
600 p_mem_manager_table->blepool = p_Config->p_AsynchEvtPool;
601 p_mem_manager_table->blepoolsize = p_Config->AsynchEvtPoolSize;
602 p_mem_manager_table->pevt_free_buffer_queue = (uint8_t*)&FreeBufQueue;
603 p_mem_manager_table->spare_ble_buffer = p_Config->p_BleSpareEvtBuffer;
604 p_mem_manager_table->spare_sys_buffer = p_Config->p_SystemSpareEvtBuffer;
605 p_mem_manager_table->traces_evt_pool = p_Config->p_TracesEvtPool;
606 p_mem_manager_table->tracespoolsize = p_Config->TracesEvtPoolSize;
607
608 return;
609 }
610
TL_MM_EvtDone(TL_EvtPacket_t * phcievt)611 void TL_MM_EvtDone(TL_EvtPacket_t * phcievt)
612 {
613 LST_insert_tail(&LocalFreeBufQueue, (tListNode *)phcievt);
614
615 OutputDbgTrace(TL_MB_MM_RELEASE_BUFFER, (uint8_t*)phcievt);
616
617 HW_IPCC_MM_SendFreeBuf( SendFreeBuf );
618
619 return;
620 }
621
SendFreeBuf(void)622 static void SendFreeBuf( void )
623 {
624 tListNode *p_node;
625
626 while ( FALSE == LST_is_empty (&LocalFreeBufQueue) )
627 {
628 LST_remove_head( &LocalFreeBufQueue, (tListNode **)&p_node );
629 LST_insert_tail( (tListNode*)(TL_RefTable.p_mem_manager_table->pevt_free_buffer_queue), p_node );
630 }
631
632 return;
633 }
634
635 /******************************************************************************
636 * TRACES
637 ******************************************************************************/
TL_TRACES_Init(void)638 void TL_TRACES_Init( void )
639 {
640 LST_init_head (&TracesEvtQueue);
641
642 TL_RefTable.p_traces_table->traces_queue = (uint8_t*)&TracesEvtQueue;
643
644 HW_IPCC_TRACES_Init();
645
646 return;
647 }
648
HW_IPCC_TRACES_EvtNot(void)649 void HW_IPCC_TRACES_EvtNot(void)
650 {
651 TL_EvtPacket_t *phcievt;
652
653 while(LST_is_empty(&TracesEvtQueue) == FALSE)
654 {
655 LST_remove_head (&TracesEvtQueue, (tListNode **)&phcievt);
656 TL_TRACES_EvtReceived( phcievt );
657 }
658
659 return;
660 }
661
TL_TRACES_EvtReceived(TL_EvtPacket_t * hcievt)662 __WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt )
663 {
664 (void)(hcievt);
665 }
666
667 /******************************************************************************
668 * DEBUG INFORMATION
669 ******************************************************************************/
OutputDbgTrace(TL_MB_PacketType_t packet_type,uint8_t * buffer)670 static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer)
671 {
672 TL_EvtPacket_t *p_evt_packet;
673 TL_CmdPacket_t *p_cmd_packet;
674
675 switch(packet_type)
676 {
677 case TL_MB_MM_RELEASE_BUFFER:
678 p_evt_packet = (TL_EvtPacket_t*)buffer;
679 switch(p_evt_packet->evtserial.evt.evtcode)
680 {
681 case TL_BLEEVT_CS_OPCODE:
682 TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
683 TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode);
684 TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet);
685 break;
686
687 case TL_BLEEVT_CC_OPCODE:
688 TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
689 TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode);
690 TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet);
691 break;
692
693 case TL_BLEEVT_VS_OPCODE:
694 TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
695 TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode);
696 TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet);
697 break;
698
699 default:
700 TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
701 TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet);
702 break;
703 }
704
705 TL_MM_DBG_MSG("\r\n");
706 break;
707
708 case TL_MB_BLE_CMD:
709 p_cmd_packet = (TL_CmdPacket_t*)buffer;
710 TL_HCI_CMD_DBG_MSG("ble cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode);
711 if(p_cmd_packet->cmdserial.cmd.plen != 0)
712 {
713 TL_HCI_CMD_DBG_MSG(" payload:");
714 TL_HCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, "");
715 }
716 TL_HCI_CMD_DBG_MSG("\r\n");
717
718 TL_HCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE);
719 break;
720
721 case TL_MB_BLE_CMD_RSP:
722 p_evt_packet = (TL_EvtPacket_t*)buffer;
723 switch(p_evt_packet->evtserial.evt.evtcode)
724 {
725 case TL_BLEEVT_CS_OPCODE:
726 TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
727 TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode);
728 TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd);
729 TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->status);
730 break;
731
732 case TL_BLEEVT_CC_OPCODE:
733 TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
734 TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode);
735 TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd);
736 TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]);
737 if((p_evt_packet->evtserial.evt.plen-4) != 0)
738 {
739 TL_HCI_CMD_DBG_MSG(" payload:");
740 TL_HCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, "");
741 }
742 break;
743
744 default:
745 TL_HCI_CMD_DBG_MSG("unknown ble rsp received: %02X", p_evt_packet->evtserial.evt.evtcode);
746 break;
747 }
748
749 TL_HCI_CMD_DBG_MSG("\r\n");
750
751 TL_HCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE);
752 break;
753
754 case TL_MB_BLE_ASYNCH_EVT:
755 p_evt_packet = (TL_EvtPacket_t*)buffer;
756 if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE)
757 {
758 TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
759 if((p_evt_packet->evtserial.evt.plen) != 0)
760 {
761 TL_HCI_EVT_DBG_MSG(" payload:");
762 TL_HCI_EVT_DBG_BUF(p_evt_packet->evtserial.evt.payload, p_evt_packet->evtserial.evt.plen, "");
763 }
764 }
765 else
766 {
767 TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
768 TL_HCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode);
769 if((p_evt_packet->evtserial.evt.plen-2) != 0)
770 {
771 TL_HCI_EVT_DBG_MSG(" payload:");
772 TL_HCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, "");
773 }
774 }
775
776 TL_HCI_EVT_DBG_MSG("\r\n");
777
778 TL_HCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE);
779 break;
780
781 case TL_MB_SYS_CMD:
782 p_cmd_packet = (TL_CmdPacket_t*)buffer;
783
784 TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode);
785
786 if(p_cmd_packet->cmdserial.cmd.plen != 0)
787 {
788 TL_SHCI_CMD_DBG_MSG(" payload:");
789 TL_SHCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, "");
790 }
791 TL_SHCI_CMD_DBG_MSG("\r\n");
792
793 TL_SHCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE);
794 break;
795
796 case TL_MB_SYS_CMD_RSP:
797 p_evt_packet = (TL_EvtPacket_t*)buffer;
798 switch(p_evt_packet->evtserial.evt.evtcode)
799 {
800 case TL_BLEEVT_CC_OPCODE:
801 TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
802 TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode);
803 TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]);
804 if((p_evt_packet->evtserial.evt.plen-4) != 0)
805 {
806 TL_SHCI_CMD_DBG_MSG(" payload:");
807 TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, "");
808 }
809 break;
810
811 default:
812 TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_evt_packet->evtserial.evt.evtcode);
813 break;
814 }
815
816 TL_SHCI_CMD_DBG_MSG("\r\n");
817
818 TL_SHCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE);
819 break;
820
821 case TL_MB_SYS_ASYNCH_EVT:
822 p_evt_packet = (TL_EvtPacket_t*)buffer;
823 if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE)
824 {
825 TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", p_evt_packet->evtserial.evt.evtcode);
826 }
827 else
828 {
829 TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
830 TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode);
831 if((p_evt_packet->evtserial.evt.plen-2) != 0)
832 {
833 TL_SHCI_EVT_DBG_MSG(" payload:");
834 TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, "");
835 }
836 }
837
838 TL_SHCI_EVT_DBG_MSG("\r\n");
839
840 TL_SHCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE);
841 break;
842
843 default:
844 break;
845 }
846
847 return;
848 }
849
850