tl.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. uint32_t* next;
  58. uint32_t* prev;
  59. }
  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. uint8_t status;
  69. uint8_t numcmd;
  70. uint16_t cmdcode;
  71. }
  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. uint8_t numcmd;
  78. uint16_t cmdcode;
  79. uint8_t payload[2];
  80. }
  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. uint16_t subevtcode;
  87. uint8_t payload[2];
  88. }
  89. TL_AsynchEvt_t;
  90. /**
  91. * This the payload of TL_Evt_t, only used a pointer
  92. */
  93. typedef PACKED_STRUCT {
  94. uint8_t evtcode;
  95. uint8_t plen;
  96. uint8_t payload[2];
  97. }
  98. TL_Evt_t;
  99. typedef PACKED_STRUCT {
  100. uint8_t type;
  101. TL_Evt_t evt;
  102. }
  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. TL_PacketHeader_t header;
  114. TL_EvtSerial_t evtserial;
  115. }
  116. TL_EvtPacket_t;
  117. /*****************************************************************************************
  118. * Command type
  119. */
  120. typedef PACKED_STRUCT {
  121. uint16_t cmdcode;
  122. uint8_t plen;
  123. uint8_t payload[255];
  124. }
  125. TL_Cmd_t;
  126. typedef PACKED_STRUCT {
  127. uint8_t type;
  128. TL_Cmd_t cmd;
  129. }
  130. TL_CmdSerial_t;
  131. typedef PACKED_STRUCT {
  132. TL_PacketHeader_t header;
  133. TL_CmdSerial_t cmdserial;
  134. }
  135. TL_CmdPacket_t;
  136. /*****************************************************************************************
  137. * HCI ACL DATA type
  138. */
  139. typedef PACKED_STRUCT {
  140. uint8_t type;
  141. uint16_t handle;
  142. uint16_t length;
  143. uint8_t acl_data[1];
  144. }
  145. TL_AclDataSerial_t;
  146. typedef PACKED_STRUCT {
  147. TL_PacketHeader_t header;
  148. TL_AclDataSerial_t AclDataSerial;
  149. }
  150. TL_AclDataPacket_t;
  151. typedef struct {
  152. uint8_t* p_BleSpareEvtBuffer;
  153. uint8_t* p_SystemSpareEvtBuffer;
  154. uint8_t* p_AsynchEvtPool;
  155. uint32_t AsynchEvtPoolSize;
  156. uint8_t* p_TracesEvtPool;
  157. uint32_t TracesEvtPoolSize;
  158. } TL_MM_Config_t;
  159. typedef struct {
  160. uint8_t* p_ThreadOtCmdRspBuffer;
  161. uint8_t* p_ThreadCliRspBuffer;
  162. uint8_t* p_ThreadNotAckBuffer;
  163. uint8_t* p_ThreadCliNotBuffer;
  164. } TL_TH_Config_t;
  165. typedef struct {
  166. uint8_t* p_LldTestsCliCmdRspBuffer;
  167. uint8_t* p_LldTestsM0CmdBuffer;
  168. } TL_LLD_tests_Config_t;
  169. typedef struct {
  170. uint8_t* p_BleLldCmdRspBuffer;
  171. uint8_t* p_BleLldM0CmdBuffer;
  172. } TL_BLE_LLD_Config_t;
  173. typedef struct {
  174. uint8_t* p_Mac_802_15_4_CmdRspBuffer;
  175. uint8_t* p_Mac_802_15_4_NotAckBuffer;
  176. } TL_MAC_802_15_4_Config_t;
  177. typedef struct {
  178. uint8_t* p_ZigbeeOtCmdRspBuffer;
  179. uint8_t* p_ZigbeeNotAckBuffer;
  180. uint8_t* p_ZigbeeNotifRequestBuffer;
  181. } TL_ZIGBEE_Config_t;
  182. /**
  183. * @brief Contain the BLE HCI Init Configuration
  184. * @{
  185. */
  186. typedef struct {
  187. void (*IoBusEvtCallBack)(TL_EvtPacket_t* phcievt);
  188. void (*IoBusAclDataTxAck)(void);
  189. uint8_t* p_cmdbuffer;
  190. uint8_t* p_AclDataBuffer;
  191. } TL_BLE_InitConf_t;
  192. /**
  193. * @brief Contain the SYSTEM HCI Init Configuration
  194. * @{
  195. */
  196. typedef struct {
  197. void (*IoBusCallBackCmdEvt)(TL_EvtPacket_t* phcievt);
  198. void (*IoBusCallBackUserEvt)(TL_EvtPacket_t* phcievt);
  199. uint8_t* p_cmdbuffer;
  200. } TL_SYS_InitConf_t;
  201. /*****************************************************************************************
  202. * Event type copied from ble_legacy.h
  203. */
  204. typedef PACKED_STRUCT {
  205. uint8_t type;
  206. uint8_t data[1];
  207. }
  208. hci_uart_pckt;
  209. typedef PACKED_STRUCT {
  210. uint8_t evt;
  211. uint8_t plen;
  212. uint8_t data[1];
  213. }
  214. hci_event_pckt;
  215. typedef PACKED_STRUCT {
  216. uint8_t subevent;
  217. uint8_t data[1];
  218. }
  219. evt_le_meta_event;
  220. /**
  221. * Vendor specific event for BLE core.
  222. */
  223. typedef PACKED_STRUCT {
  224. uint16_t ecode; /**< One of the BLE core event codes. */
  225. uint8_t data[1];
  226. }
  227. evt_blecore_aci;
  228. /* Bluetooth 48 bit address (in little-endian order).
  229. */
  230. typedef uint8_t tBDAddr[6];
  231. /* Exported constants --------------------------------------------------------*/
  232. /* External variables --------------------------------------------------------*/
  233. /* Exported macros -----------------------------------------------------------*/
  234. /* Exported functions ------------------------------------------------------- */
  235. /******************************************************************************
  236. * GENERAL
  237. ******************************************************************************/
  238. void TL_Enable(void);
  239. void TL_Init(void);
  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. * SYSTEM
  248. ******************************************************************************/
  249. int32_t TL_SYS_Init(void* pConf);
  250. int32_t TL_SYS_SendCmd(uint8_t* buffer, uint16_t size);
  251. /******************************************************************************
  252. * THREAD
  253. ******************************************************************************/
  254. void TL_THREAD_Init(TL_TH_Config_t* p_Config);
  255. void TL_OT_SendCmd(void);
  256. void TL_CLI_SendCmd(void);
  257. void TL_OT_CmdEvtReceived(TL_EvtPacket_t* Otbuffer);
  258. void TL_THREAD_NotReceived(TL_EvtPacket_t* Notbuffer);
  259. void TL_THREAD_SendAck(void);
  260. void TL_THREAD_CliSendAck(void);
  261. void TL_THREAD_CliNotReceived(TL_EvtPacket_t* Notbuffer);
  262. /******************************************************************************
  263. * LLD TESTS
  264. ******************************************************************************/
  265. void TL_LLDTESTS_Init(TL_LLD_tests_Config_t* p_Config);
  266. void TL_LLDTESTS_SendCliCmd(void);
  267. void TL_LLDTESTS_ReceiveCliRsp(TL_CmdPacket_t* Notbuffer);
  268. void TL_LLDTESTS_SendCliRspAck(void);
  269. void TL_LLDTESTS_ReceiveM0Cmd(TL_CmdPacket_t* Notbuffer);
  270. void TL_LLDTESTS_SendM0CmdAck(void);
  271. /******************************************************************************
  272. * BLE LLD
  273. ******************************************************************************/
  274. void TL_BLE_LLD_Init(TL_BLE_LLD_Config_t* p_Config);
  275. void TL_BLE_LLD_SendCliCmd(void);
  276. void TL_BLE_LLD_ReceiveCliRsp(TL_CmdPacket_t* Notbuffer);
  277. void TL_BLE_LLD_SendCliRspAck(void);
  278. void TL_BLE_LLD_ReceiveM0Cmd(TL_CmdPacket_t* Notbuffer);
  279. void TL_BLE_LLD_SendM0CmdAck(void);
  280. void TL_BLE_LLD_SendCmd(void);
  281. void TL_BLE_LLD_ReceiveRsp(TL_CmdPacket_t* Notbuffer);
  282. void TL_BLE_LLD_SendRspAck(void);
  283. /******************************************************************************
  284. * MEMORY MANAGER
  285. ******************************************************************************/
  286. void TL_MM_Init(TL_MM_Config_t* p_Config);
  287. void TL_MM_EvtDone(TL_EvtPacket_t* hcievt);
  288. /******************************************************************************
  289. * TRACES
  290. ******************************************************************************/
  291. void TL_TRACES_Init(void);
  292. void TL_TRACES_EvtReceived(TL_EvtPacket_t* hcievt);
  293. /******************************************************************************
  294. * MAC 802.15.4
  295. ******************************************************************************/
  296. void TL_MAC_802_15_4_Init(TL_MAC_802_15_4_Config_t* p_Config);
  297. void TL_MAC_802_15_4_SendCmd(void);
  298. void TL_MAC_802_15_4_CmdEvtReceived(TL_EvtPacket_t* Otbuffer);
  299. void TL_MAC_802_15_4_NotReceived(TL_EvtPacket_t* Notbuffer);
  300. void TL_MAC_802_15_4_SendAck(void);
  301. /******************************************************************************
  302. * ZIGBEE
  303. ******************************************************************************/
  304. void TL_ZIGBEE_Init(TL_ZIGBEE_Config_t* p_Config);
  305. void TL_ZIGBEE_SendM4RequestToM0(void);
  306. void TL_ZIGBEE_SendM4AckToM0Notify(void);
  307. void TL_ZIGBEE_NotReceived(TL_EvtPacket_t* Notbuffer);
  308. void TL_ZIGBEE_CmdEvtReceived(TL_EvtPacket_t* Otbuffer);
  309. void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t* Otbuffer);
  310. void TL_ZIGBEE_SendM4AckToM0Request(void);
  311. #ifdef __cplusplus
  312. } /* extern "C" */
  313. #endif
  314. #endif /*__TL_H */