Merge pull request #10476 from radiolinkW/RADIOLINKF722
[inav.git] / lib / main / STM32_USB_OTG_Driver / src / usb_hcd.c
blobd24027c1e6022418da85d96caa25fa96edd24ab6
1 /**
2 ******************************************************************************
3 * @file usb_hcd.c
4 * @author MCD Application Team
5 * @version V2.2.0
6 * @date 09-November-2015
7 * @brief Host Interface Layer
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
17 * http://www.st.com/software_license_agreement_liberty_v2
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 ******************************************************************************
28 /* Includes ------------------------------------------------------------------*/
29 #include "usb_core.h"
30 #include "usb_hcd.h"
31 #include "usb_conf.h"
32 #include "usb_bsp.h"
35 /** @addtogroup USB_OTG_DRIVER
36 * @{
39 /** @defgroup USB_HCD
40 * @brief This file is the interface between EFSL ans Host mass-storage class
41 * @{
45 /** @defgroup USB_HCD_Private_Defines
46 * @{
47 */
48 /**
49 * @}
50 */
53 /** @defgroup USB_HCD_Private_TypesDefinitions
54 * @{
55 */
56 /**
57 * @}
58 */
62 /** @defgroup USB_HCD_Private_Macros
63 * @{
64 */
65 /**
66 * @}
67 */
70 /** @defgroup USB_HCD_Private_Variables
71 * @{
72 */
73 /**
74 * @}
75 */
78 /** @defgroup USB_HCD_Private_FunctionPrototypes
79 * @{
80 */
81 /**
82 * @}
83 */
86 /** @defgroup USB_HCD_Private_Functions
87 * @{
88 */
90 /**
91 * @brief HCD_Init
92 * Initialize the HOST portion of the driver.
93 * @param pdev: Selected device
94 * @param base_address: OTG base address
95 * @retval Status
97 uint32_t HCD_Init(USB_OTG_CORE_HANDLE *pdev ,
98 USB_OTG_CORE_ID_TypeDef coreID)
100 uint8_t i = 0;
101 pdev->host.ConnSts = 0;
103 for (i= 0; i< USB_OTG_MAX_TX_FIFOS; i++)
105 pdev->host.ErrCnt[i] = 0;
106 pdev->host.XferCnt[i] = 0;
107 pdev->host.HC_Status[i] = HC_IDLE;
109 pdev->host.hc[0].max_packet = 8;
111 USB_OTG_SelectCore(pdev, coreID);
112 #ifndef DUAL_ROLE_MODE_ENABLED
113 USB_OTG_DisableGlobalInt(pdev);
114 USB_OTG_CoreInit(pdev);
116 /* Force Host Mode*/
117 USB_OTG_SetCurrentMode(pdev , HOST_MODE);
118 USB_OTG_CoreInitHost(pdev);
119 USB_OTG_EnableGlobalInt(pdev);
120 #endif
122 return 0;
127 * @brief HCD_GetCurrentSpeed
128 * Get Current device Speed.
129 * @param pdev : Selected device
130 * @retval Status
133 uint32_t HCD_GetCurrentSpeed (USB_OTG_CORE_HANDLE *pdev)
135 USB_OTG_HPRT0_TypeDef HPRT0;
136 HPRT0.d32 = USB_OTG_READ_REG32(pdev->regs.HPRT0);
138 return HPRT0.b.prtspd;
142 * @brief HCD_ResetPort
143 * Issues the reset command to device
144 * @param pdev : Selected device
145 * @retval Status
147 uint32_t HCD_ResetPort(USB_OTG_CORE_HANDLE *pdev)
150 Before starting to drive a USB reset, the application waits for the OTG
151 interrupt triggered by the denounce done bit (DBCDNE bit in OTG_FS_GOTGINT),
152 which indicates that the bus is stable again after the electrical denounce
153 caused by the attachment of a pull-up resistor on DP (FS) or DM (LS).
156 USB_OTG_ResetPort(pdev);
157 return 0;
161 * @brief HCD_IsDeviceConnected
162 * Check if the device is connected.
163 * @param pdev : Selected device
164 * @retval Device connection status. 1 -> connected and 0 -> disconnected
167 uint32_t HCD_IsDeviceConnected(USB_OTG_CORE_HANDLE *pdev)
169 return (pdev->host.ConnSts);
174 * @brief HCD_IsPortEnabled
175 * This function checks if port is enabled
176 * @param pdev : Selected device
177 * @retval Frame number
180 uint32_t HCD_IsPortEnabled(USB_OTG_CORE_HANDLE *pdev)
182 return (pdev->host.PortEnabled);
186 * @brief HCD_GetCurrentFrame
187 * This function returns the frame number for sof packet
188 * @param pdev : Selected device
189 * @retval Frame number
192 uint32_t HCD_GetCurrentFrame (USB_OTG_CORE_HANDLE *pdev)
194 return (USB_OTG_READ_REG32(&pdev->regs.HREGS->HFNUM) & 0xFFFF) ;
198 * @brief HCD_GetURB_State
199 * This function returns the last URBstate
200 * @param pdev: Selected device
201 * @retval URB_STATE
204 URB_STATE HCD_GetURB_State (USB_OTG_CORE_HANDLE *pdev , uint8_t ch_num)
206 return pdev->host.URB_State[ch_num] ;
210 * @brief HCD_GetXferCnt
211 * This function returns the last URBstate
212 * @param pdev: Selected device
213 * @retval No. of data bytes transferred
216 uint32_t HCD_GetXferCnt (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num)
218 return pdev->host.XferCnt[ch_num] ;
224 * @brief HCD_GetHCState
225 * This function returns the HC Status
226 * @param pdev: Selected device
227 * @retval HC_STATUS
230 HC_STATUS HCD_GetHCState (USB_OTG_CORE_HANDLE *pdev , uint8_t ch_num)
232 return pdev->host.HC_Status[ch_num] ;
236 * @brief HCD_HC_Init
237 * This function prepare a HC and start a transfer
238 * @param pdev: Selected device
239 * @param hc_num: Channel number
240 * @retval status
242 uint32_t HCD_HC_Init (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
244 return USB_OTG_HC_Init(pdev, hc_num);
248 * @brief HCD_SubmitRequest
249 * This function prepare a HC and start a transfer
250 * @param pdev: Selected device
251 * @param hc_num: Channel number
252 * @retval status
254 uint32_t HCD_SubmitRequest (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
257 pdev->host.URB_State[hc_num] = URB_IDLE;
258 pdev->host.hc[hc_num].xfer_count = 0 ;
259 return USB_OTG_HC_StartXfer(pdev, hc_num);
264 * @}
268 * @}
272 * @}
275 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/