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   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
11   * All rights reserved.</center></h2>
12   *
13   * This software component is licensed by ST under BSD 3-Clause license,
14   * the "License"; You may not use this file except in compliance with the
15   * License. You may obtain a copy of the License at:
16   *                        opensource.org/licenses/BSD-3-Clause
17   *
18   ******************************************************************************
19  */
20 
21 
22 #ifndef __HCI_TL_H_
23 #define __HCI_TL_H_
24 
25 #include "stm32_wpan_common.h"
26 #include "tl.h"
27 
28 /* Exported defines -----------------------------------------------------------*/
29 typedef enum
30 {
31   HCI_TL_UserEventFlow_Disable,
32   HCI_TL_UserEventFlow_Enable,
33 } HCI_TL_UserEventFlowStatus_t;
34 
35 typedef enum
36 {
37   HCI_TL_CmdBusy,
38   HCI_TL_CmdAvailable
39 } HCI_TL_CmdStatus_t;
40 
41 /**
42  * @brief Structure used to manage the BUS IO operations.
43  *        All the structure fields will point to functions defined at user level.
44  * @{
45  */
46 typedef struct
47 {
48   int32_t (* Init)    (void* pConf); /**< Pointer to HCI TL function for the IO Bus initialization */
49   int32_t (* DeInit)  (void); /**< Pointer to HCI TL function for the IO Bus de-initialization */
50   int32_t (* Reset)   (void); /**< Pointer to HCI TL function for the IO Bus reset */
51   int32_t (* Receive) (uint8_t*, uint16_t); /**< Pointer to HCI TL function for the IO Bus data reception */
52   int32_t (* Send)    (uint8_t*, uint16_t); /**< Pointer to HCI TL function for the IO Bus data transmission */
53   int32_t (* DataAck) (uint8_t*, uint16_t* len); /**< Pointer to HCI TL function for the IO Bus data ack reception */
54   int32_t (* GetTick) (void); /**< Pointer to BSP function for getting the HAL time base timestamp */
55 } tHciIO;
56 /**
57  * @}
58  */
59 
60 /**
61  * @brief Contain the HCI context
62  * @{
63  */
64 typedef struct
65 {
66   tHciIO io; /**< Manage the BUS IO operations */
67   void (* UserEvtRx) (void * pData); /**< ACI events callback function pointer */
68 } tHciContext;
69 
70 typedef struct
71 {
72   HCI_TL_UserEventFlowStatus_t status;
73   TL_EvtPacket_t *pckt;
74 } tHCI_UserEvtRxParam;
75 
76 typedef struct
77 {
78   uint8_t *p_cmdbuffer;
79   void (* StatusNotCallBack) (HCI_TL_CmdStatus_t status);
80 } HCI_TL_HciInitConf_t;
81 
82 /**
83  * @brief  Register IO bus services.
84  * @param  fops The HCI IO structure managing the IO BUS
85  * @retval None
86  */
87 void hci_register_io_bus(tHciIO* fops);
88 
89 /**
90  * @brief  Interrupt service routine that must be called when the BLE core
91  *         reports a packet received or an event to the host through the
92  *         related IPCC RX interrupt line.
93  *
94  * @param  pdata Packet or event pointer
95  * @retval None
96  */
97 void hci_notify_asynch_evt(void* pdata);
98 
99 /**
100  * @brief  This function resume the User Event Flow which has been stopped on return
101  *         from UserEvtRx() when the User Event has not been processed.
102  *
103  * @param  None
104  * @retval None
105  */
106 void hci_resume_flow(void);
107 
108 
109 /**
110  * @brief  This function is called when an ACI/HCI command is sent and the response
111  *         is waited from the BLE core.
112  *         The application shall implement a mechanism to not return from this function
113  *         until the waited event is received.
114  *         This is notified to the application with hci_cmd_resp_release().
115  *         It is called from the same context the HCI command has been sent.
116  *
117  * @param  timeout: Waiting timeout
118  * @retval None
119  */
120 void hci_cmd_resp_wait(uint32_t timeout);
121 
122 /**
123  * @brief  This function is called when an ACI/HCI command is sent and the response is
124  *         received from the BLE core.
125  *
126  * @param  flag: Release flag
127  * @retval None
128  */
129 void hci_cmd_resp_release(uint32_t flag);
130 
131 
132 
133 /**
134  * END OF SECTION - FUNCTIONS TO BE IMPLEMENTED BY THE APPLICATION
135  *********************************************************************************************************************
136  */
137 
138 
139 /**
140  *********************************************************************************************************************
141  * START OF SECTION - PROCESS TO BE CALLED BY THE SCHEDULER
142  */
143 
144 /**
145  * @brief  This process shall be called by the scheduler each time it is requested with TL_BLE_HCI_UserEvtProcReq()
146  *         This process may send an ACI/HCI command when the svc_ctl.c module is used
147  *
148  * @param  None
149  * @retval None
150  */
151 
152 void hci_user_evt_proc(void);
153 
154 /**
155  * END OF SECTION - PROCESS TO BE CALLED BY THE SCHEDULER
156  *********************************************************************************************************************
157  */
158 
159 
160 /**
161  *********************************************************************************************************************
162  * START OF SECTION - INTERFACES USED BY THE BLE DRIVER
163  */
164 
165 /**
166  * @brief Initialize the Host Controller Interface.
167  *        This function must be called before any data can be received
168  *        from BLE controller.
169  *
170  * @param  pData: ACI events callback function pointer
171  *         This callback is triggered when an user event is received from
172  *         the BLE core device.
173  * @param  pConf: Configuration structure pointer
174  * @retval None
175  */
176 void hci_init(void(* UserEvtRx)(void* pData), void* pConf);
177 
178 /**
179  * END OF SECTION - INTERFACES USED BY THE BLE DRIVER
180  *********************************************************************************************************************
181  */
182 
183 #endif /* __TL_BLE_HCI_H_ */
184