1 /**
2  ******************************************************************************
3  * @file    hci_tl.h
4  * @author  MCD Application Team
5  * @brief   Constants and functions for HCI layer. See Bluetooth Core
6  *          v 4.0, Vol. 2, Part E.
7  ******************************************************************************
8  * @attention
9  *
10  * Copyright (c) 2018-2021 STMicroelectronics.
11  * All rights reserved.
12  *
13  * This software is licensed under terms that can be found in the LICENSE file
14  * in the root directory of this software component.
15  * If no LICENSE file comes with this software, it is provided AS-IS.
16  *
17  ******************************************************************************
18  */
19 
20 
21 #ifndef __HCI_TL_H_
22 #define __HCI_TL_H_
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #include "stm32_wpan_common.h"
29 #include "tl.h"
30 
31 /* Exported defines -----------------------------------------------------------*/
32 typedef enum
33 {
34   HCI_TL_UserEventFlow_Disable,
35   HCI_TL_UserEventFlow_Enable,
36 } HCI_TL_UserEventFlowStatus_t;
37 
38 typedef enum
39 {
40   HCI_TL_CmdBusy,
41   HCI_TL_CmdAvailable
42 } HCI_TL_CmdStatus_t;
43 
44 /**
45  * @brief Structure used to manage the BUS IO operations.
46  *        All the structure fields will point to functions defined at user level.
47  * @{
48  */
49 typedef struct
50 {
51   int32_t (* Init)    (void* pConf); /**< Pointer to HCI TL function for the IO Bus initialization */
52   int32_t (* DeInit)  (void); /**< Pointer to HCI TL function for the IO Bus de-initialization */
53   int32_t (* Reset)   (void); /**< Pointer to HCI TL function for the IO Bus reset */
54   int32_t (* Receive) (uint8_t*, uint16_t); /**< Pointer to HCI TL function for the IO Bus data reception */
55   int32_t (* Send)    (uint8_t*, uint16_t); /**< Pointer to HCI TL function for the IO Bus data transmission */
56   int32_t (* DataAck) (uint8_t*, uint16_t* len); /**< Pointer to HCI TL function for the IO Bus data ack reception */
57   int32_t (* GetTick) (void); /**< Pointer to BSP function for getting the HAL time base timestamp */
58 } tHciIO;
59 /**
60  * @}
61  */
62 
63 /**
64  * @brief Contain the HCI context
65  * @{
66  */
67 typedef struct
68 {
69   tHciIO io; /**< Manage the BUS IO operations */
70   void (* UserEvtRx) (void * pData); /**< ACI events callback function pointer */
71 } tHciContext;
72 
73 typedef struct
74 {
75   HCI_TL_UserEventFlowStatus_t status;
76   TL_EvtPacket_t *pckt;
77 } tHCI_UserEvtRxParam;
78 
79 typedef struct
80 {
81   uint8_t *p_cmdbuffer;
82   void (* StatusNotCallBack) (HCI_TL_CmdStatus_t status);
83 } HCI_TL_HciInitConf_t;
84 
85 /**
86  * @brief  Register IO bus services.
87  * @param  fops The HCI IO structure managing the IO BUS
88  * @retval None
89  */
90 void hci_register_io_bus(tHciIO* fops);
91 
92 /**
93  * @brief  This callback is called from either
94  *          - IPCC RX interrupt context
95  *          - hci_user_evt_proc() context.
96  *          - hci_resume_flow() context
97  *         It requests hci_user_evt_proc() to be executed.
98  *
99  * @param  pdata Packet or event pointer
100  * @retval None
101  */
102 void hci_notify_asynch_evt(void* pdata);
103 
104 /**
105  * @brief  This function resume the User Event Flow which has been stopped on return
106  *         from UserEvtRx() when the User Event has not been processed.
107  *
108  * @param  None
109  * @retval None
110  */
111 void hci_resume_flow(void);
112 
113 
114 /**
115  * @brief  This function is called when an ACI/HCI command is sent to the CPU2 and the response is waited.
116  *         It is called from the same context the HCI command has been sent.
117  *         It shall not return until the command response notified by hci_cmd_resp_release() is received.
118  *         A weak implementation is available in hci_tl.c based on polling mechanism
119  *         The user may re-implement this function in the application to improve performance :
120  *         - It may use UTIL_SEQ_WaitEvt() API when using the Sequencer
121  *         - It may use a semaphore when using cmsis_os interface
122  *
123  * @param  timeout: Waiting timeout
124  * @retval None
125  */
126 void hci_cmd_resp_wait(uint32_t timeout);
127 
128 /**
129  * @brief  This function is called when an ACI/HCI command response is received from the CPU2.
130  *         A weak implementation is available in hci_tl.c based on polling mechanism
131  *         The user may re-implement this function in the application to improve performance :
132  *         - It may use UTIL_SEQ_SetEvt() API when using the Sequencer
133  *         - It may use a semaphore when using cmsis_os interface
134  *
135  * @param  flag: Release flag
136  * @retval None
137  */
138 void hci_cmd_resp_release(uint32_t flag);
139 
140 
141 
142 /**
143  * END OF SECTION - FUNCTIONS TO BE IMPLEMENTED BY THE APPLICATION
144  *********************************************************************************************************************
145  */
146 
147 
148 /**
149  *********************************************************************************************************************
150  * START OF SECTION - PROCESS TO BE CALLED BY THE SCHEDULER
151  */
152 
153 /**
154  * @brief  This process shall be called by the scheduler each time it is requested with hci_notify_asynch_evt()
155  *         This process may send an ACI/HCI command when the svc_ctl.c module is used
156  *
157  * @param  None
158  * @retval None
159  */
160 
161 void hci_user_evt_proc(void);
162 
163 /**
164  * END OF SECTION - PROCESS TO BE CALLED BY THE SCHEDULER
165  *********************************************************************************************************************
166  */
167 
168 
169 /**
170  *********************************************************************************************************************
171  * START OF SECTION - INTERFACES USED BY THE BLE DRIVER
172  */
173 
174 /**
175  * @brief Initialize the Host Controller Interface.
176  *        This function must be called before any data can be received
177  *        from BLE controller.
178  *
179  * @param  pData: ACI events callback function pointer
180  *         This callback is triggered when an user event is received from
181  *         the BLE core device.
182  * @param  pConf: Configuration structure pointer
183  * @retval None
184  */
185 void hci_init(void(* UserEvtRx)(void* pData), void* pConf);
186 
187 /**
188  * END OF SECTION - INTERFACES USED BY THE BLE DRIVER
189  *********************************************************************************************************************
190  */
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif /* __TL_BLE_HCI_H_ */
197