2 ******************************************************************************
4 * @author MCD Application Team
6 * @date 09-November-2015
7 * @brief Host Interface Layer
8 ******************************************************************************
11 * <h2><center>© 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 ------------------------------------------------------------------*/
35 /** @addtogroup USB_OTG_DRIVER
40 * @brief This file is the interface between EFSL ans Host mass-storage class
45 /** @defgroup USB_HCD_Private_Defines
53 /** @defgroup USB_HCD_Private_TypesDefinitions
62 /** @defgroup USB_HCD_Private_Macros
70 /** @defgroup USB_HCD_Private_Variables
78 /** @defgroup USB_HCD_Private_FunctionPrototypes
86 /** @defgroup USB_HCD_Private_Functions
92 * Initialize the HOST portion of the driver.
93 * @param pdev: Selected device
94 * @param base_address: OTG base address
97 uint32_t HCD_Init(USB_OTG_CORE_HANDLE
*pdev
,
98 USB_OTG_CORE_ID_TypeDef coreID
)
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
);
117 USB_OTG_SetCurrentMode(pdev
, HOST_MODE
);
118 USB_OTG_CoreInitHost(pdev
);
119 USB_OTG_EnableGlobalInt(pdev
);
127 * @brief HCD_GetCurrentSpeed
128 * Get Current device Speed.
129 * @param pdev : Selected device
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
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
);
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
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
230 HC_STATUS
HCD_GetHCState (USB_OTG_CORE_HANDLE
*pdev
, uint8_t ch_num
)
232 return pdev
->host
.HC_Status
[ch_num
] ;
237 * This function prepare a HC and start a transfer
238 * @param pdev: Selected device
239 * @param hc_num: Channel number
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
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
);
275 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/