1 /** 2 ****************************************************************************** 3 * @file tl.h 4 * @author MCD Application Team 5 * @brief Header for tl module 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 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef __TL_H 22 #define __TL_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 29 /* Includes ------------------------------------------------------------------*/ 30 #include "stm32_wpan_common.h" 31 32 /* Exported defines -----------------------------------------------------------*/ 33 #define TL_BLECMD_PKT_TYPE ( 0x01 ) 34 #define TL_ACL_DATA_PKT_TYPE ( 0x02 ) 35 #define TL_BLEEVT_PKT_TYPE ( 0x04 ) 36 #define TL_OTCMD_PKT_TYPE ( 0x08 ) 37 #define TL_OTRSP_PKT_TYPE ( 0x09 ) 38 #define TL_CLICMD_PKT_TYPE ( 0x0A ) 39 #define TL_OTNOT_PKT_TYPE ( 0x0C ) 40 #define TL_OTACK_PKT_TYPE ( 0x0D ) 41 #define TL_CLINOT_PKT_TYPE ( 0x0E ) 42 #define TL_CLIACK_PKT_TYPE ( 0x0F ) 43 #define TL_SYSCMD_PKT_TYPE ( 0x10 ) 44 #define TL_SYSRSP_PKT_TYPE ( 0x11 ) 45 #define TL_SYSEVT_PKT_TYPE ( 0x12 ) 46 #define TL_CLIRESP_PKT_TYPE ( 0x15 ) 47 #define TL_M0CMD_PKT_TYPE ( 0x16 ) 48 #define TL_LOCCMD_PKT_TYPE ( 0x20 ) 49 #define TL_LOCRSP_PKT_TYPE ( 0x21 ) 50 #define TL_TRACES_APP_PKT_TYPE ( 0x40 ) 51 #define TL_TRACES_WL_PKT_TYPE ( 0x41 ) 52 53 #define TL_CMD_HDR_SIZE (4) 54 #define TL_EVT_HDR_SIZE (3) 55 #define TL_EVT_CS_PAYLOAD_SIZE (4) 56 57 #define TL_BLEEVT_CC_OPCODE (0x0E) 58 #define TL_BLEEVT_CS_OPCODE (0x0F) 59 #define TL_BLEEVT_VS_OPCODE (0xFF) 60 61 #define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t)) 62 #define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE) 63 /* Exported types ------------------------------------------------------------*/ 64 /**< Packet header */ 65 typedef PACKED_STRUCT 66 { 67 uint32_t *next; 68 uint32_t *prev; 69 } TL_PacketHeader_t; 70 71 /******************************************************************************* 72 * Event type 73 */ 74 75 /** 76 * This the payload of TL_Evt_t for a command status event 77 */ 78 typedef PACKED_STRUCT 79 { 80 uint8_t status; 81 uint8_t numcmd; 82 uint16_t cmdcode; 83 } TL_CsEvt_t; 84 85 /** 86 * This the payload of TL_Evt_t for a command complete event, only used a pointer 87 */ 88 typedef PACKED_STRUCT 89 { 90 uint8_t numcmd; 91 uint16_t cmdcode; 92 uint8_t payload[2]; 93 } TL_CcEvt_t; 94 95 /** 96 * This the payload of TL_Evt_t for an asynchronous event, only used a pointer 97 */ 98 typedef PACKED_STRUCT 99 { 100 uint16_t subevtcode; 101 uint8_t payload[2]; 102 } TL_AsynchEvt_t; 103 104 /** 105 * This the payload of TL_Evt_t, only used a pointer 106 */ 107 typedef PACKED_STRUCT 108 { 109 uint8_t evtcode; 110 uint8_t plen; 111 uint8_t payload[2]; 112 } TL_Evt_t; 113 114 typedef PACKED_STRUCT 115 { 116 uint8_t type; 117 TL_Evt_t evt; 118 } TL_EvtSerial_t; 119 120 /** 121 * This format shall be used for all events (asynchronous and command response) reported 122 * by the CPU2 except for the command response of a system command where the header is not there 123 * and the format to be used shall be TL_EvtSerial_t. 124 * Note: Be careful that the asynchronous events reported by the CPU2 on the system channel do 125 * include the header and shall use TL_EvtPacket_t format. Only the command response format on the 126 * system channel is different. 127 */ 128 typedef PACKED_STRUCT 129 { 130 TL_PacketHeader_t header; 131 TL_EvtSerial_t evtserial; 132 } TL_EvtPacket_t; 133 134 /***************************************************************************************** 135 * Command type 136 */ 137 138 typedef PACKED_STRUCT 139 { 140 uint16_t cmdcode; 141 uint8_t plen; 142 uint8_t payload[255]; 143 } TL_Cmd_t; 144 145 typedef PACKED_STRUCT 146 { 147 uint8_t type; 148 TL_Cmd_t cmd; 149 } TL_CmdSerial_t; 150 151 typedef PACKED_STRUCT 152 { 153 TL_PacketHeader_t header; 154 TL_CmdSerial_t cmdserial; 155 } TL_CmdPacket_t; 156 157 /***************************************************************************************** 158 * HCI ACL DATA type 159 */ 160 typedef PACKED_STRUCT 161 { 162 uint8_t type; 163 uint16_t handle; 164 uint16_t length; 165 uint8_t acl_data[1]; 166 } TL_AclDataSerial_t; 167 168 typedef PACKED_STRUCT 169 { 170 TL_PacketHeader_t header; 171 TL_AclDataSerial_t AclDataSerial; 172 } TL_AclDataPacket_t; 173 174 typedef struct 175 { 176 uint8_t *p_BleSpareEvtBuffer; 177 uint8_t *p_SystemSpareEvtBuffer; 178 uint8_t *p_AsynchEvtPool; 179 uint32_t AsynchEvtPoolSize; 180 uint8_t *p_TracesEvtPool; 181 uint32_t TracesEvtPoolSize; 182 } TL_MM_Config_t; 183 184 typedef struct 185 { 186 uint8_t *p_ThreadOtCmdRspBuffer; 187 uint8_t *p_ThreadCliRspBuffer; 188 uint8_t *p_ThreadNotAckBuffer; 189 uint8_t *p_ThreadCliNotBuffer; 190 } TL_TH_Config_t; 191 192 typedef struct 193 { 194 uint8_t *p_LldTestsCliCmdRspBuffer; 195 uint8_t *p_LldTestsM0CmdBuffer; 196 } TL_LLD_tests_Config_t; 197 198 typedef struct 199 { 200 uint8_t *p_BleLldCmdRspBuffer; 201 uint8_t *p_BleLldM0CmdBuffer; 202 } TL_BLE_LLD_Config_t; 203 204 typedef struct 205 { 206 uint8_t *p_Mac_802_15_4_CmdRspBuffer; 207 uint8_t *p_Mac_802_15_4_NotAckBuffer; 208 } TL_MAC_802_15_4_Config_t; 209 210 typedef struct 211 { 212 uint8_t *p_ZigbeeOtCmdRspBuffer; 213 uint8_t *p_ZigbeeNotAckBuffer; 214 uint8_t *p_ZigbeeNotifRequestBuffer; 215 } TL_ZIGBEE_Config_t; 216 217 /** 218 * @brief Contain the BLE HCI Init Configuration 219 * @{ 220 */ 221 typedef struct 222 { 223 void (* IoBusEvtCallBack) ( TL_EvtPacket_t *phcievt ); 224 void (* IoBusAclDataTxAck) ( void ); 225 uint8_t *p_cmdbuffer; 226 uint8_t *p_AclDataBuffer; 227 } TL_BLE_InitConf_t; 228 229 /** 230 * @brief Contain the SYSTEM HCI Init Configuration 231 * @{ 232 */ 233 typedef struct 234 { 235 void (* IoBusCallBackCmdEvt) (TL_EvtPacket_t *phcievt); 236 void (* IoBusCallBackUserEvt) (TL_EvtPacket_t *phcievt); 237 uint8_t *p_cmdbuffer; 238 } TL_SYS_InitConf_t; 239 240 /***************************************************************************************** 241 * Event type copied from ble_legacy.h 242 */ 243 244 typedef PACKED_STRUCT 245 { 246 uint8_t type; 247 uint8_t data[1]; 248 } hci_uart_pckt; 249 250 typedef PACKED_STRUCT 251 { 252 uint8_t evt; 253 uint8_t plen; 254 uint8_t data[1]; 255 } hci_event_pckt; 256 257 typedef PACKED_STRUCT 258 { 259 uint8_t subevent; 260 uint8_t data[1]; 261 } evt_le_meta_event; 262 263 /** 264 * Vendor specific event for BLE core. 265 */ 266 typedef PACKED_STRUCT 267 { 268 uint16_t ecode; /**< One of the BLE core event codes. */ 269 uint8_t data[1]; 270 } evt_blecore_aci; 271 272 /* Bluetooth 48 bit address (in little-endian order). 273 */ 274 typedef uint8_t tBDAddr[6]; 275 276 277 /* Exported constants --------------------------------------------------------*/ 278 /* External variables --------------------------------------------------------*/ 279 /* Exported macros -----------------------------------------------------------*/ 280 /* Exported functions ------------------------------------------------------- */ 281 282 /****************************************************************************** 283 * GENERAL 284 ******************************************************************************/ 285 void TL_Enable( void ); 286 void TL_Init( void ); 287 288 /****************************************************************************** 289 * BLE 290 ******************************************************************************/ 291 int32_t TL_BLE_Init( void* pConf ); 292 int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size ); 293 int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size ); 294 295 /****************************************************************************** 296 * SYSTEM 297 ******************************************************************************/ 298 int32_t TL_SYS_Init( void* pConf ); 299 int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size ); 300 301 /****************************************************************************** 302 * THREAD 303 ******************************************************************************/ 304 void TL_THREAD_Init( TL_TH_Config_t *p_Config ); 305 void TL_OT_SendCmd( void ); 306 void TL_CLI_SendCmd( void ); 307 void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); 308 void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer ); 309 void TL_THREAD_SendAck ( void ); 310 void TL_THREAD_CliSendAck ( void ); 311 void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer ); 312 313 /****************************************************************************** 314 * LLD TESTS 315 ******************************************************************************/ 316 void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config ); 317 void TL_LLDTESTS_SendCliCmd( void ); 318 void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); 319 void TL_LLDTESTS_SendCliRspAck( void ); 320 void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); 321 void TL_LLDTESTS_SendM0CmdAck( void ); 322 323 /****************************************************************************** 324 * BLE LLD 325 ******************************************************************************/ 326 void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config ); 327 void TL_BLE_LLD_SendCliCmd( void ); 328 void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); 329 void TL_BLE_LLD_SendCliRspAck( void ); 330 void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); 331 void TL_BLE_LLD_SendM0CmdAck( void ); 332 void TL_BLE_LLD_SendCmd( void ); 333 void TL_BLE_LLD_ReceiveRsp( TL_CmdPacket_t * Notbuffer ); 334 void TL_BLE_LLD_SendRspAck( void ); 335 /****************************************************************************** 336 * MEMORY MANAGER 337 ******************************************************************************/ 338 void TL_MM_Init( TL_MM_Config_t *p_Config ); 339 void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); 340 341 /****************************************************************************** 342 * TRACES 343 ******************************************************************************/ 344 void TL_TRACES_Init( void ); 345 void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); 346 347 /****************************************************************************** 348 * MAC 802.15.4 349 ******************************************************************************/ 350 void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); 351 void TL_MAC_802_15_4_SendCmd( void ); 352 void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); 353 void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); 354 void TL_MAC_802_15_4_SendAck ( void ); 355 356 /****************************************************************************** 357 * ZIGBEE 358 ******************************************************************************/ 359 void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); 360 void TL_ZIGBEE_SendM4RequestToM0( void ); 361 void TL_ZIGBEE_SendM4AckToM0Notify ( void ); 362 void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); 363 void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); 364 void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); 365 void TL_ZIGBEE_SendM4AckToM0Request(void); 366 367 #ifdef __cplusplus 368 } /* extern "C" */ 369 #endif 370 371 #endif /*__TL_H */ 372 373