2 ******************************************************************************
4 * @author MCD Application Team
7 * @brief Host Interface Layer
8 ******************************************************************************
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
29 /** @addtogroup USB_OTG_DRIVER
34 * @brief This file is the interface between EFSL ans Host mass-storage class
39 /** @defgroup USB_HCD_Private_Defines
47 /** @defgroup USB_HCD_Private_TypesDefinitions
56 /** @defgroup USB_HCD_Private_Macros
64 /** @defgroup USB_HCD_Private_Variables
72 /** @defgroup USB_HCD_Private_FunctionPrototypes
80 /** @defgroup USB_HCD_Private_Functions
86 * Initialize the HOST portion of the driver.
87 * @param pdev: Selected device
88 * @param base_address: OTG base address
91 uint32_t HCD_Init(USB_OTG_CORE_HANDLE *pdev ,
92 USB_OTG_CORE_ID_TypeDef coreID)
95 pdev->host.ConnSts = 0;
97 for (i= 0; i< USB_OTG_MAX_TX_FIFOS; i++)
99 pdev->host.ErrCnt[i] = 0;
100 pdev->host.XferCnt[i] = 0;
101 pdev->host.HC_Status[i] = HC_IDLE;
103 pdev->host.hc[0].max_packet = 8;
105 USB_OTG_SelectCore(pdev, coreID);
106 #ifndef DUAL_ROLE_MODE_ENABLED
107 USB_OTG_DisableGlobalInt(pdev);
108 USB_OTG_CoreInit(pdev);
111 USB_OTG_SetCurrentMode(pdev , HOST_MODE);
112 USB_OTG_CoreInitHost(pdev);
113 USB_OTG_EnableGlobalInt(pdev);
121 * @brief HCD_GetCurrentSpeed
122 * Get Current device Speed.
123 * @param pdev : Selected device
127 uint32_t HCD_GetCurrentSpeed (USB_OTG_CORE_HANDLE *pdev)
129 USB_OTG_HPRT0_TypeDef HPRT0;
130 HPRT0.d32 = USB_OTG_READ_REG32(pdev->regs.HPRT0);
132 return HPRT0.b.prtspd;
136 * @brief HCD_ResetPort
137 * Issues the reset command to device
138 * @param pdev : Selected device
141 uint32_t HCD_ResetPort(USB_OTG_CORE_HANDLE *pdev)
144 Before starting to drive a USB reset, the application waits for the OTG
145 interrupt triggered by the debounce done bit (DBCDNE bit in OTG_FS_GOTGINT),
146 which indicates that the bus is stable again after the electrical debounce
147 caused by the attachment of a pull-up resistor on DP (FS) or DM (LS).
150 USB_OTG_ResetPort(pdev);
155 * @brief HCD_IsDeviceConnected
156 * Check if the device is connected.
157 * @param pdev : Selected device
158 * @retval Device connection status. 1 -> connected and 0 -> disconnected
161 uint32_t HCD_IsDeviceConnected(USB_OTG_CORE_HANDLE *pdev)
163 return (pdev->host.ConnSts);
167 * @brief HCD_GetCurrentFrame
168 * This function returns the frame number for sof packet
169 * @param pdev : Selected device
170 * @retval Frame number
173 uint32_t HCD_GetCurrentFrame (USB_OTG_CORE_HANDLE *pdev)
175 return (USB_OTG_READ_REG32(&pdev->regs.HREGS->HFNUM) & 0xFFFF) ;
179 * @brief HCD_GetURB_State
180 * This function returns the last URBstate
181 * @param pdev: Selected device
185 URB_STATE HCD_GetURB_State (USB_OTG_CORE_HANDLE *pdev , uint8_t ch_num)
187 return pdev->host.URB_State[ch_num] ;
191 * @brief HCD_GetXferCnt
192 * This function returns the last URBstate
193 * @param pdev: Selected device
194 * @retval No. of data bytes transferred
197 uint32_t HCD_GetXferCnt (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num)
199 return pdev->host.XferCnt[ch_num] ;
205 * @brief HCD_GetHCState
206 * This function returns the HC Status
207 * @param pdev: Selected device
211 HC_STATUS HCD_GetHCState (USB_OTG_CORE_HANDLE *pdev , uint8_t ch_num)
213 return pdev->host.HC_Status[ch_num] ;
218 * This function prepare a HC and start a transfer
219 * @param pdev: Selected device
220 * @param hc_num: Channel number
223 uint32_t HCD_HC_Init (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
225 return USB_OTG_HC_Init(pdev, hc_num);
229 * @brief HCD_SubmitRequest
230 * This function prepare a HC and start a transfer
231 * @param pdev: Selected device
232 * @param hc_num: Channel number
235 uint32_t HCD_SubmitRequest (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
238 pdev->host.URB_State[hc_num] = URB_IDLE;
239 pdev->host.hc[hc_num].xfer_count = 0 ;
240 return USB_OTG_HC_StartXfer(pdev, hc_num);
256 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/