tl.h 11 KB

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