1 /** 2 ****************************************************************************** 3 * @file shci_tl.h 4 * @author MCD Application Team 5 * @brief System HCI command header for the system channel 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 #ifndef __SHCI_TL_H_ 20 #define __SHCI_TL_H_ 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #include "tl.h" 27 28 /* Exported defines -----------------------------------------------------------*/ 29 typedef enum 30 { 31 SHCI_TL_UserEventFlow_Disable, 32 SHCI_TL_UserEventFlow_Enable, 33 } SHCI_TL_UserEventFlowStatus_t; 34 35 typedef enum 36 { 37 SHCI_TL_CmdBusy, 38 SHCI_TL_CmdAvailable 39 } SHCI_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 SHCI TL function for the IO Bus initialization */ 49 int32_t (* DeInit) (void); /**< Pointer to SHCI TL function for the IO Bus de-initialization */ 50 int32_t (* Reset) (void); /**< Pointer to SHCI TL function for the IO Bus reset */ 51 int32_t (* Receive) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data reception */ 52 int32_t (* Send) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data transmission */ 53 int32_t (* DataAck) (uint8_t*, uint16_t* len); /**< Pointer to SHCI 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 } tSHciIO; 56 /** 57 * @} 58 */ 59 60 /** 61 * @brief Contain the SHCI context 62 * @{ 63 */ 64 typedef struct 65 { 66 tSHciIO io; /**< Manage the BUS IO operations */ 67 void (* UserEvtRx) (void * pData); /**< User System events callback function pointer */ 68 } tSHciContext; 69 70 typedef struct 71 { 72 SHCI_TL_UserEventFlowStatus_t status; 73 TL_EvtPacket_t *pckt; 74 } tSHCI_UserEvtRxParam; 75 76 typedef struct 77 { 78 uint8_t *p_cmdbuffer; 79 void (* StatusNotCallBack) (SHCI_TL_CmdStatus_t status); 80 } SHCI_TL_HciInitConf_t; 81 82 /** 83 * shci_send 84 * @brief Send an System HCI Command 85 * 86 * @param : cmd_code = Opcode of the command 87 * @param : len_cmd_payload = Length of the command payload 88 * @param : p_cmd_payload = Address of the command payload 89 * @param : p_rsp_status = Address of the full buffer holding the command complete event 90 * @retval : None 91 */ 92 void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp_status ); 93 94 /** 95 * @brief Register IO bus services. 96 * @param fops The SHCI IO structure managing the IO BUS 97 * @retval None 98 */ 99 void shci_register_io_bus(tSHciIO* fops); 100 101 /** 102 * @brief Interrupt service routine that must be called when the system channel 103 * reports a packet has been received 104 * 105 * @param pdata Packet or event pointer 106 * @retval None 107 */ 108 void shci_notify_asynch_evt(void* pdata); 109 110 /** 111 * @brief This function resume the User Event Flow which has been stopped on return 112 * from UserEvtRx() when the User Event has not been processed. 113 * 114 * @param None 115 * @retval None 116 */ 117 void shci_resume_flow(void); 118 119 120 /** 121 * @brief This function is called when an System HCI Command is sent to the CPU2 and the response is waited. 122 * It is called from the same context the System HCI command has been sent. 123 * It shall not return until the command response notified by shci_cmd_resp_release() is received. 124 * A weak implementation is available in shci_tl.c based on polling mechanism 125 * The user may re-implement this function in the application to improve performance : 126 * - It may use UTIL_SEQ_WaitEvt() API when using the Sequencer 127 * - It may use a semaphore when using cmsis_os interface 128 * 129 * @param timeout: Waiting timeout 130 * @retval None 131 */ 132 void shci_cmd_resp_wait(uint32_t timeout); 133 134 /** 135 * @brief This function is called when an System HCI command is received from the CPU2. 136 * A weak implementation is available in shci_tl.c based on polling mechanism 137 * The user may re-implement this function in the application to improve performance : 138 * - It may use UTIL_SEQ_SetEvt() API when using the Sequencer 139 * - It may use a semaphore when using cmsis_os interface 140 * 141 * 142 * @param flag: Release flag 143 * @retval None 144 */ 145 void shci_cmd_resp_release(uint32_t flag); 146 147 148 /** 149 * @brief This process shall be called each time the shci_notify_asynch_evt notification is received 150 * 151 * @param None 152 * @retval None 153 */ 154 155 void shci_user_evt_proc(void); 156 157 /** 158 * @brief Initialize the System Host Controller Interface. 159 * This function must be called before any communication on the System Channel 160 * 161 * @param UserEvtRx: System events callback function pointer 162 * This callback is triggered when an user event is received on 163 * the System Channel from CPU2. 164 * @param pConf: Configuration structure pointer 165 * @retval None 166 */ 167 void shci_init(void(* UserEvtRx)(void* pData), void* pConf); 168 169 #ifdef __cplusplus 170 } 171 #endif 172 173 #endif /* __SHCI_TL_H_ */ 174