xref: /btstack/port/stm32-wb55xx-nucleo-freertos/Middlewares/STM32_WPAN/interface/patterns/ble_thread/tl/tl.h (revision 0561b2d8d5dba972c7daa57d5e677f7a1327edfd)
1 /**
2  ******************************************************************************
3  * @file    tl.h
4  * @author  MCD Application Team
5  * @brief   Header for tl module
6  ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; 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 /* Define to prevent recursive inclusion -------------------------------------*/
22 #ifndef __TL_H
23 #define __TL_H
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 
30 /* Includes ------------------------------------------------------------------*/
31 #include "stm32_wpan_common.h"
32 
33 /* Exported defines -----------------------------------------------------------*/
34 #define TL_BLECMD_PKT_TYPE                                              ( 0x01 )
35 #define TL_ACL_DATA_PKT_TYPE                                            ( 0x02 )
36 #define TL_BLEEVT_PKT_TYPE                                              ( 0x04 )
37 #define TL_OTCMD_PKT_TYPE                                               ( 0x08 )
38 #define TL_OTRSP_PKT_TYPE                                               ( 0x09 )
39 #define TL_CLICMD_PKT_TYPE                                              ( 0x0A )
40 #define TL_OTNOT_PKT_TYPE                                               ( 0x0C )
41 #define TL_OTACK_PKT_TYPE                                               ( 0x0D )
42 #define TL_CLINOT_PKT_TYPE                                              ( 0x0E )
43 #define TL_CLIACK_PKT_TYPE                                              ( 0x0F )
44 #define TL_SYSCMD_PKT_TYPE  	                                        ( 0x10 )
45 #define TL_SYSRSP_PKT_TYPE  	                                        ( 0x11 )
46 #define TL_SYSEVT_PKT_TYPE  	                                        ( 0x12 )
47 #define TL_LOCCMD_PKT_TYPE  	                                        ( 0x20 )
48 #define TL_LOCRSP_PKT_TYPE  	                                        ( 0x21 )
49 #define TL_TRACES_APP_PKT_TYPE                                          ( 0x40 )
50 #define TL_TRACES_WL_PKT_TYPE                                           ( 0x41 )
51 
52 #define TL_CMD_HDR_SIZE                                                      (4)
53 #define TL_EVT_HDR_SIZE                                                      (3)
54 #define TL_EVT_CS_PAYLOAD_SIZE                                               (4)
55 
56 #define TL_BLEEVT_CC_OPCODE                                               (0x0E)
57 #define TL_BLEEVT_CS_OPCODE                                               (0x0F)
58 
59 #define TL_BLEEVT_CS_PACKET_SIZE        (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t))
60 #define TL_BLEEVT_CS_BUFFER_SIZE        (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE)
61 
62 /* Exported types ------------------------------------------------------------*/
63 /**< Packet header */
64 typedef PACKED_STRUCT
65 {
66   uint32_t *next;
67   uint32_t *prev;
68 } TL_PacketHeader_t;
69 
70 /*******************************************************************************
71  * Event type
72  */
73 
74 /**
75  * This the payload of TL_Evt_t for a command status event
76  */
77 typedef PACKED_STRUCT
78 {
79   uint8_t   status;
80   uint8_t   numcmd;
81   uint16_t  cmdcode;
82 } TL_CsEvt_t;
83 
84 /**
85  * This the payload of TL_Evt_t for a command complete event
86  */
87 typedef PACKED_STRUCT
88 {
89   uint8_t   numcmd;
90   uint16_t  cmdcode;
91   uint8_t   payload[1];
92 } TL_CcEvt_t;
93 
94 /**
95  * This the payload of TL_Evt_t for an asynchronous event
96  */
97 typedef PACKED_STRUCT
98 {
99   uint16_t  subevtcode;
100   uint8_t   payload[1];
101 } TL_AsynchEvt_t;
102 
103 typedef PACKED_STRUCT
104 {
105   uint8_t   evtcode;
106   uint8_t   plen;
107   uint8_t   payload[1];
108 } TL_Evt_t;
109 
110 typedef PACKED_STRUCT
111 {
112   uint8_t   type;
113   TL_Evt_t  evt;
114 } TL_EvtSerial_t;
115 
116 /**
117  * This format shall be used for all events (asynchronous and command response) reported
118  * by the CPU2 except for the command response of a system command where the header is not there
119  * and the format to be used shall be TL_EvtSerial_t.
120  * Note: Be careful that the asynchronous events reported by the CPU2 on the system channel do
121  * include the header and shall use TL_EvtPacket_t format. Only the command response format on the
122  * system channel is different.
123  */
124 typedef PACKED_STRUCT
125 {
126   TL_PacketHeader_t  header;
127   TL_EvtSerial_t     evtserial;
128 } TL_EvtPacket_t;
129 
130 /*****************************************************************************************
131  * Command type
132  */
133 
134 typedef PACKED_STRUCT
135 {
136   uint16_t   cmdcode;
137   uint8_t   plen;
138   uint8_t   payload[255];
139 } TL_Cmd_t;
140 
141 typedef PACKED_STRUCT
142 {
143   uint8_t   type;
144   TL_Cmd_t  cmd;
145 } TL_CmdSerial_t;
146 
147 typedef PACKED_STRUCT
148 {
149   TL_PacketHeader_t  header;
150   TL_CmdSerial_t     cmdserial;
151 } TL_CmdPacket_t;
152 
153 /*****************************************************************************************
154  * HCI ACL DATA type
155  */
156 typedef PACKED_STRUCT
157 {
158   uint8_t   type;
159   uint16_t  handle;
160   uint16_t  length;
161   uint8_t   acl_data[1];
162 } TL_AclDataSerial_t;
163 
164 typedef PACKED_STRUCT
165 {
166   TL_PacketHeader_t  header;
167   TL_AclDataSerial_t   AclDataSerial;
168 } TL_AclDataPacket_t;
169 
170 typedef struct
171 {
172   uint8_t  *p_BleSpareEvtBuffer;
173   uint8_t  *p_SystemSpareEvtBuffer;
174   uint8_t  *p_AsynchEvtPool;
175   uint32_t AsynchEvtPoolSize;
176   uint8_t  *p_TracesEvtPool;
177   uint32_t TracesEvtPoolSize;
178 } TL_MM_Config_t;
179 
180 typedef struct
181 {
182   uint8_t *p_ThreadOtCmdRspBuffer;
183   uint8_t *p_ThreadCliRspBuffer;
184   uint8_t *p_ThreadNotAckBuffer;
185 } TL_TH_Config_t;
186 
187 typedef struct
188 {
189   uint8_t *p_LldTestsCliRspBuffer;
190   uint8_t *p_LldTestsNotAckBuffer;
191 } TL_LLD_tests_Config_t;
192 
193 typedef struct
194 {
195   uint8_t *p_Mac_802_15_4_CmdRspBuffer;
196   uint8_t *p_Mac_802_15_4_NotAckBuffer;
197 } TL_MAC_802_15_4_Config_t;
198 
199 typedef struct
200 {
201   uint8_t *p_ZigbeeOtCmdRspBuffer;
202   uint8_t *p_ZigbeeNotAckBuffer;
203   uint8_t *p_ZigbeeLoggingBuffer;
204 } TL_ZIGBEE_Config_t;
205 
206 /**
207  * @brief Contain the BLE HCI Init Configuration
208  * @{
209  */
210 typedef struct
211 {
212   void (* IoBusEvtCallBack) ( TL_EvtPacket_t *phcievt );
213   void (* IoBusAclDataTxAck) ( void );
214   uint8_t *p_cmdbuffer;
215   uint8_t *p_AclDataBuffer;
216 } TL_BLE_InitConf_t;
217 
218 /**
219  * @brief Contain the SYSTEM HCI Init Configuration
220  * @{
221  */
222 typedef struct
223 {
224   void (* IoBusCallBackCmdEvt) (TL_EvtPacket_t *phcievt);
225   void (* IoBusCallBackUserEvt) (TL_EvtPacket_t *phcievt);
226   uint8_t *p_cmdbuffer;
227 } TL_SYS_InitConf_t;
228 
229 /* Exported constants --------------------------------------------------------*/
230 /* External variables --------------------------------------------------------*/
231 /* Exported macros -----------------------------------------------------------*/
232 /* Exported functions ------------------------------------------------------- */
233 
234 /******************************************************************************
235  * GENERAL
236  ******************************************************************************/
237 void TL_Enable( void );
238 void TL_Init( void );
239 
240 /******************************************************************************
241  * BLE
242  ******************************************************************************/
243 int32_t TL_BLE_Init( void* pConf );
244 int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size );
245 int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size );
246 
247 /******************************************************************************
248  * SYSTEM
249  ******************************************************************************/
250 int32_t TL_SYS_Init( void* pConf  );
251 int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size );
252 
253 /******************************************************************************
254  * THREAD
255  ******************************************************************************/
256 void TL_THREAD_Init( TL_TH_Config_t *p_Config );
257 void TL_OT_SendCmd( void );
258 void TL_CLI_SendCmd( void );
259 void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer );
260 void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer );
261 void TL_THREAD_SendAck ( void );
262 void TL_THREAD_CliSendAck ( void );
263 void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer );
264 
265 /******************************************************************************
266  * LLD tests
267  ******************************************************************************/
268 void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config );
269 void TL_LLDTESTS_CliSendCmd( void );
270 void TL_LLDTESTS_NotReceived( TL_EvtPacket_t * Notbuffer );
271 void TL_LLDTESTS_CliSendAck ( void );
272 void TL_LLDTESTS_CliNotReceived( TL_EvtPacket_t * Notbuffer );
273 
274 /******************************************************************************
275  * MEMORY MANAGER
276  ******************************************************************************/
277 void TL_MM_Init( TL_MM_Config_t *p_Config );
278 void TL_MM_EvtDone( TL_EvtPacket_t * hcievt );
279 
280 /******************************************************************************
281  * TRACES
282  ******************************************************************************/
283 void TL_TRACES_Init( void );
284 void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt );
285 
286 /******************************************************************************
287  * MAC 802.15.4
288  ******************************************************************************/
289 void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config );
290 void TL_MAC_802_15_4_SendCmd( void );
291 void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer );
292 void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer );
293 void TL_MAC_802_15_4_SendAck ( void );
294 
295 /******************************************************************************
296  * ZIGBEE
297  ******************************************************************************/
298 void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config );
299 void TL_ZIGBEE_SendAppliCmdToM0( void );
300 void TL_ZIGBEE_SendAckAfterAppliNotifFromM0 ( void );
301 void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer );
302 void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer );
303 void TL_ZIGBEE_LoggingReceived(TL_EvtPacket_t * Otbuffer );
304 void TL_ZIGBEE_SendAckAfterAppliLoggingFromM0 ( void );
305 
306 #ifdef __cplusplus
307 } /* extern "C" */
308 #endif
309 
310 #endif /*__TL_H */
311 
312 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
313