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