usb_host.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. /*
  2. * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016 - 2019 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _USB_HOST_H_
  9. #define _USB_HOST_H_
  10. #include <usb/include/usb.h>
  11. #include <usb/include/usb_misc.h>
  12. #include <usb/include/usb_spec.h>
  13. /*******************************************************************************
  14. * Definitions
  15. ******************************************************************************/
  16. struct _usb_host_transfer; /* for cross reference */
  17. /*!
  18. * @addtogroup usb_host_drv
  19. * @{
  20. */
  21. /*! @brief USB host class handle type define */
  22. typedef void *usb_host_class_handle;
  23. /*! @brief USB host controller handle type define */
  24. typedef void *usb_host_controller_handle;
  25. /*! @brief USB host configuration handle type define */
  26. typedef void *usb_host_configuration_handle;
  27. /*! @brief USB host interface handle type define */
  28. typedef void *usb_host_interface_handle;
  29. /*! @brief USB host pipe handle type define */
  30. typedef void *usb_host_pipe_handle;
  31. /*! @brief Event codes for device attach/detach */
  32. typedef enum _usb_host_event
  33. {
  34. kUSB_HostEventAttach = 1U, /*!< Device is attached */
  35. kUSB_HostEventDetach, /*!< Device is detached */
  36. kUSB_HostEventEnumerationDone, /*!< Device's enumeration is done and the device is supported */
  37. kUSB_HostEventNotSupported, /*!< Device's enumeration is done and the device is not supported */
  38. /*! Device's enumeration failed due to errors
  39. * fail reason is put in the high 2 bytes of callback event code.
  40. * kStatus_USB_TransferFailed - the transfer failed.
  41. * kStatus_USB_TransferCancel - transfer is canceled by application.
  42. * kStatus_USB_Error - parsing descriptor failed, the power cannot satisfy device's requirement,
  43. * device addresss allocation failed, transfer is not enough
  44. * or the transfer API failed.
  45. * kStatus_USB_AllocFail - malloc failed.
  46. */
  47. kUSB_HostEventEnumerationFail,
  48. #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
  49. kUSB_HostEventNotSuspended, /*!< Suspend failed */
  50. kUSB_HostEventSuspended, /*!< Suspend successful */
  51. kUSB_HostEventNotResumed, /*!< Resume failed */
  52. kUSB_HostEventDetectResume, /*!< Detect resume signal */
  53. kUSB_HostEventResumed, /*!< Resume successful */
  54. kUSB_HostEventL1Sleeped, /*!< L1 Sleep successful,state transition was successful (ACK) */
  55. kUSB_HostEventL1SleepNYET, /*!< Device was unable to enter the L1 state at this time (NYET) */
  56. kUSB_HostEventL1SleepNotSupport, /*!< Device does not support the L1 state (STALL) */
  57. kUSB_HostEventL1SleepError, /*!< Device failed to respond or an error occurred */
  58. kUSB_HostEventL1NotResumed, /*!< Resume failed */
  59. kUSB_HostEventL1DetectResume, /*!< Detect resume signal */
  60. kUSB_HostEventL1Resumed, /*!< Resume successful */
  61. #endif
  62. } usb_host_event_t;
  63. /*! @brief USB host device information code */
  64. typedef enum _usb_host_dev_info
  65. {
  66. kUSB_HostGetDeviceAddress = 1U, /*!< Device's address */
  67. kUSB_HostGetDeviceHubNumber, /*!< Device's first hub address */
  68. kUSB_HostGetDevicePortNumber, /*!< Device's first hub port number */
  69. kUSB_HostGetDeviceSpeed, /*!< Device's speed */
  70. kUSB_HostGetDeviceHSHubNumber, /*!< Device's first high-speed hub address */
  71. kUSB_HostGetDeviceHSHubPort, /*!< Device's first high-speed hub number */
  72. kUSB_HostGetDeviceLevel, /*!< Device's hub level */
  73. kUSB_HostGetHostHandle, /*!< Device's host handle */
  74. kUSB_HostGetDeviceControlPipe, /*!< Device's control pipe handle */
  75. kUSB_HostGetDevicePID, /*!< Device's PID */
  76. kUSB_HostGetDeviceVID, /*!< Device's VID */
  77. kUSB_HostGetHubThinkTime, /*!< Device's hub total think time */
  78. kUSB_HostGetDeviceConfigIndex, /*!< Device's running zero-based config index */
  79. kUSB_HostGetConfigurationDes, /*!< Device's configuration descriptor pointer */
  80. kUSB_HostGetConfigurationLength, /*!< Device's configuration descriptor pointer */
  81. } usb_host_dev_info_t;
  82. /*! @brief Request type */
  83. typedef enum _usb_host_request_type
  84. {
  85. kRequestDevice = 1U, /*!< Control request object is device */
  86. kRequestInterface, /*!< Control request object is interface */
  87. kRequestEndpoint, /*!< Control request object is endpoint */
  88. } usb_host_request_type_t;
  89. /*! @brief For USB_REQUEST_STANDARD_GET_DESCRIPTOR and USB_REQUEST_STANDARD_SET_DESCRIPTOR */
  90. typedef struct _usb_host_process_descriptor_param
  91. {
  92. uint8_t descriptorType; /*!< See the usb_spec.h, such as the USB_DESCRIPTOR_TYPE_DEVICE */
  93. uint8_t descriptorIndex; /*!< The descriptor index is used to select a specific descriptor (only for configuration
  94. and string descriptors) when several descriptors of the same type are implemented in a
  95. device */
  96. #ifdef SOC_IMXRT1170_SERIES
  97. uint16_t languageId; /*!< It specifies the language ID for string descriptors or is reset to zero for other
  98. descriptors */
  99. #else
  100. uint8_t languageId; /*!< It specifies the language ID for string descriptors or is reset to zero for other
  101. descriptors */
  102. #endif
  103. uint8_t *descriptorBuffer; /*!< Buffer pointer */
  104. uint16_t descriptorLength; /*!< Buffer data length */
  105. } usb_host_process_descriptor_param_t;
  106. /*! @brief For USB_REQUEST_STANDARD_CLEAR_FEATURE and USB_REQUEST_STANDARD_SET_FEATURE */
  107. typedef struct _usb_host_process_feature_param
  108. {
  109. uint8_t requestType; /*!< See the #usb_host_request_type_t */
  110. uint8_t featureSelector; /*!< Set/cleared feature */
  111. uint8_t interfaceOrEndpoint; /*!< Interface or end pointer */
  112. } usb_host_process_feature_param_t;
  113. /*! @brief For USB_REQUEST_STANDARD_GET_INTERFACE */
  114. typedef struct _usb_host_get_interface_param
  115. {
  116. uint8_t interface; /*!< Interface number */
  117. uint8_t *alternateInterfaceBuffer; /*!< Save the transfer result */
  118. } usb_host_get_interface_param_t;
  119. /*! @brief For USB_REQUEST_STANDARD_GET_STATUS */
  120. typedef struct _usb_host_get_status_param
  121. {
  122. uint16_t statusSelector; /*!< Interface number, the end pointer number or OTG status selector */
  123. uint8_t requestType; /*!< See the #usb_host_request_type_t */
  124. uint8_t *statusBuffer; /*!< Save the transfer result */
  125. } usb_host_get_status_param_t;
  126. /*! @brief For USB_REQUEST_STANDARD_SET_INTERFACE */
  127. typedef struct _usb_host_set_interface_param
  128. {
  129. uint8_t alternateSetting; /*!< Alternate setting value */
  130. uint8_t interface; /*!< Interface number */
  131. } usb_host_set_interface_param_t;
  132. /*! @brief For USB_REQUEST_STANDARD_SYNCH_FRAME */
  133. typedef struct _usb_host_synch_frame_param
  134. {
  135. uint8_t endpoint; /*!< Endpoint number */
  136. uint8_t *frameNumberBuffer; /*!< Frame number data buffer */
  137. } usb_host_synch_frame_param_t;
  138. /*!
  139. * @brief Host callback function typedef.
  140. *
  141. * This callback function is used to notify application device attach/detach event.
  142. * This callback pointer is passed when initializing the host.
  143. *
  144. * @param deviceHandle The device handle, which indicates the attached device.
  145. * @param configurationHandle The configuration handle contains the attached device's configuration information.
  146. * @param event_code The callback event code; See the enumeration host_event_t.
  147. *
  148. * @return A USB error code or kStatus_USB_Success.
  149. * @retval kStatus_USB_Success Application handles the attached device successfully.
  150. * @retval kStatus_USB_NotSupported Application don't support the attached device.
  151. * @retval kStatus_USB_Error Application handles the attached device falsely.
  152. */
  153. typedef usb_status_t (*host_callback_t)(usb_device_handle deviceHandle,
  154. usb_host_configuration_handle configurationHandle,
  155. uint32_t eventCode);
  156. /*!
  157. * @brief Transfer callback function typedef.
  158. *
  159. * This callback function is used to notify the upper layer the result of the transfer.
  160. * This callback pointer is passed when calling the send/receive APIs.
  161. *
  162. * @param param The parameter pointer, which is passed when calling the send/receive APIs.
  163. * @param data The data buffer pointer.
  164. * @param data_len The result data length.
  165. * @param status A USB error code or kStatus_USB_Success.
  166. */
  167. typedef void (*transfer_callback_t)(void *param, uint8_t *data, uint32_t dataLen, usb_status_t status);
  168. /*!
  169. * @brief Host stack inner transfer callback function typedef.
  170. *
  171. * This callback function is used to notify the upper layer the result of a transfer.
  172. * This callback pointer is passed when initializing the structure usb_host_transfer_t.
  173. *
  174. * @param param The parameter pointer, which is passed when calling the send/receive APIs.
  175. * @param transfer The transfer information; See the structure usb_host_transfer_t.
  176. * @param status A USB error code or kStatus_USB_Success.
  177. */
  178. typedef void (*host_inner_transfer_callback_t)(void *param, struct _usb_host_transfer *transfer, usb_status_t status);
  179. /*! @brief USB host endpoint information structure */
  180. typedef struct _usb_host_ep
  181. {
  182. usb_descriptor_endpoint_t *epDesc; /*!< Endpoint descriptor pointer*/
  183. uint8_t *epExtension; /*!< Endpoint extended descriptor pointer*/
  184. uint16_t epExtensionLength; /*!< Extended descriptor length*/
  185. } usb_host_ep_t;
  186. /*! @brief USB host interface information structure */
  187. typedef struct _usb_host_interface
  188. {
  189. usb_host_ep_t epList[USB_HOST_CONFIG_INTERFACE_MAX_EP]; /*!< Endpoint array*/
  190. usb_descriptor_interface_t *interfaceDesc; /*!< Interface descriptor pointer*/
  191. uint8_t *interfaceExtension; /*!< Interface extended descriptor pointer*/
  192. uint16_t interfaceExtensionLength; /*!< Extended descriptor length*/
  193. uint8_t interfaceIndex; /*!< The interface index*/
  194. uint8_t alternateSettingNumber; /*!< The interface alternate setting value*/
  195. uint8_t epCount; /*!< Interface's endpoint number*/
  196. } usb_host_interface_t;
  197. /*! @brief USB host configuration information structure */
  198. typedef struct _usb_host_configuration
  199. {
  200. usb_host_interface_t interfaceList[USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE]; /*!< Interface array*/
  201. usb_descriptor_configuration_t *configurationDesc; /*!< Configuration descriptor pointer*/
  202. uint8_t *configurationExtension; /*!< Configuration extended descriptor pointer*/
  203. uint16_t configurationExtensionLength; /*!< Extended descriptor length*/
  204. uint8_t interfaceCount; /*!< The configuration's interface number*/
  205. } usb_host_configuration_t;
  206. /*! @brief USB host pipe common structure */
  207. typedef struct _usb_host_pipe
  208. {
  209. struct _usb_host_pipe *next; /*!< Link the idle pipes*/
  210. usb_device_handle deviceHandle; /*!< This pipe's device's handle*/
  211. uint16_t currentCount; /*!< For KHCI transfer*/
  212. uint16_t nakCount; /*!< Maximum NAK count*/
  213. uint16_t maxPacketSize; /*!< Maximum packet size*/
  214. uint16_t interval; /*!< FS/LS: frame unit; HS: micro-frame unit*/
  215. uint8_t open; /*!< 0 - closed, 1 - open*/
  216. uint8_t nextdata01; /*!< Data toggle*/
  217. uint8_t endpointAddress; /*!< Endpoint address*/
  218. uint8_t direction; /*!< Pipe direction*/
  219. uint8_t pipeType; /*!< Pipe type, for example USB_ENDPOINT_BULK*/
  220. uint8_t numberPerUframe; /*!< Transaction number per micro-frame*/
  221. } usb_host_pipe_t;
  222. /*! @brief USB host transfer structure */
  223. typedef struct _usb_host_transfer
  224. {
  225. struct _usb_host_transfer *next; /*!< The next transfer structure*/
  226. uint8_t *transferBuffer; /*!< Transfer data buffer*/
  227. uint32_t transferLength; /*!< Transfer data length*/
  228. uint32_t transferSofar; /*!< Length transferred so far*/
  229. host_inner_transfer_callback_t callbackFn; /*!< Transfer callback function*/
  230. void *callbackParam; /*!< Transfer callback parameter*/
  231. usb_host_pipe_t *transferPipe; /*!< Transfer pipe pointer*/
  232. usb_setup_struct_t *setupPacket; /*!< Set up packet buffer*/
  233. uint8_t direction; /*!< Transfer direction; it's values are USB_OUT or USB_IN*/
  234. uint8_t setupStatus; /*!< Set up the transfer status*/
  235. union
  236. {
  237. uint32_t unitHead; /*!< xTD head for this transfer*/
  238. int32_t transferResult; /*!< KHCI transfer result */
  239. } union1;
  240. union
  241. {
  242. uint32_t unitTail; /*!<xTD tail for this transfer*/
  243. uint32_t frame; /*!< KHCI transfer frame number */
  244. } union2;
  245. #if USB_HOST_CONFIG_KHCI
  246. uint16_t nakTimeout; /*!< KHCI transfer NAK timeout */
  247. uint16_t retry; /*!< KHCI transfer retry */
  248. #endif
  249. } usb_host_transfer_t;
  250. /*! @brief USB host pipe information structure for opening pipe */
  251. typedef struct _usb_host_pipe_init
  252. {
  253. void *devInstance; /*!< Device instance handle*/
  254. uint16_t nakCount; /*!< Maximum NAK retry count. MUST be zero for interrupt*/
  255. uint16_t maxPacketSize; /*!< Pipe's maximum packet size*/
  256. uint8_t interval; /*!< Pipe's interval*/
  257. uint8_t endpointAddress; /*!< Endpoint address*/
  258. uint8_t direction; /*!< Endpoint direction*/
  259. uint8_t pipeType; /*!< Endpoint type, the value is USB_ENDPOINT_INTERRUPT, USB_ENDPOINT_CONTROL,
  260. USB_ENDPOINT_ISOCHRONOUS, USB_ENDPOINT_BULK*/
  261. uint8_t numberPerUframe; /*!< Transaction number for each micro-frame*/
  262. } usb_host_pipe_init_t;
  263. /*! @brief Cancel transfer parameter structure */
  264. typedef struct _usb_host_cancel_param
  265. {
  266. usb_host_pipe_handle pipeHandle; /*!< Canceling pipe handle*/
  267. usb_host_transfer_t *transfer; /*!< Canceling transfer*/
  268. } usb_host_cancel_param_t;
  269. /*******************************************************************************
  270. * API
  271. ******************************************************************************/
  272. #ifdef __cplusplus
  273. extern "C" {
  274. #endif
  275. /*!
  276. * @name USB host APIs Part 1
  277. * The following APIs are recommended for application use.
  278. * @{
  279. */
  280. /*!
  281. * @brief Initializes the USB host stack.
  282. *
  283. * This function initializes the USB host module specified by the controllerId.
  284. *
  285. * @param[in] controllerId The controller ID of the USB IP. See the enumeration usb_controller_index_t.
  286. * @param[out] hostHandle Returns the host handle.
  287. * @param[in] callbackFn Host callback function notifies device attach/detach.
  288. *
  289. * @retval kStatus_USB_Success The host is initialized successfully.
  290. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer.
  291. * @retval kStatus_USB_ControllerNotFound Cannot find the controller according to the controller ID.
  292. * @retval kStatus_USB_AllocFail Allocation memory fail.
  293. * @retval kStatus_USB_Error Host mutex create fail; KHCI/EHCI mutex or KHCI/EHCI event create fail,
  294. * or, KHCI/EHCI IP initialize fail.
  295. */
  296. extern usb_status_t USB_HostInit(uint8_t controllerId, usb_host_handle *hostHandle, host_callback_t callbackFn);
  297. /*!
  298. * @brief Deinitializes the USB host stack.
  299. *
  300. * This function deinitializes the USB host module specified by the hostHandle.
  301. *
  302. * @param[in] hostHandle The host handle.
  303. *
  304. * @retval kStatus_USB_Success The host is initialized successfully.
  305. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer.
  306. * @retval kStatus_USB_Error Controller deinitialization fail.
  307. */
  308. extern usb_status_t USB_HostDeinit(usb_host_handle hostHandle);
  309. /*!
  310. * @brief Gets the device information.
  311. *
  312. * This function gets the device information.
  313. *
  314. * @param[in] deviceHandle Removing device handle.
  315. * @param[in] infoCode See the enumeration host_dev_info_t.
  316. * @param[out] infoValue Return the information value.
  317. *
  318. * @retval kStatus_USB_Success Close successfully.
  319. * @retval kStatus_USB_InvalidParameter The deviceHandle or info_value is a NULL pointer.
  320. * @retval kStatus_USB_Error The info_code is not the host_dev_info_t value.
  321. */
  322. extern usb_status_t USB_HostHelperGetPeripheralInformation(usb_device_handle deviceHandle,
  323. uint32_t infoCode,
  324. uint32_t *infoValue);
  325. /*!
  326. * @brief Parses the alternate interface descriptor.
  327. *
  328. * This function parses the alternate interface descriptor and returns an interface information through the structure
  329. * usb_host_interface_t.
  330. *
  331. * @param[in] interfaceHandle The whole interface handle.
  332. * @param[in] alternateSetting Alternate setting value.
  333. * @param[out] interface Return interface information.
  334. *
  335. * @retval kStatus_USB_Success Close successfully.
  336. * @retval kStatus_USB_InvalidHandle The interfaceHandle is a NULL pointer.
  337. * @retval kStatus_USB_InvalidParameter The alternateSetting is 0.
  338. * @retval kStatus_USB_Error The interface descriptor is wrong.
  339. */
  340. extern usb_status_t USB_HostHelperParseAlternateSetting(usb_host_interface_handle interfaceHandle,
  341. uint8_t alternateSetting,
  342. usb_host_interface_t *interface);
  343. /*!
  344. * @brief Removes the attached device.
  345. *
  346. * This function removes the attached device.
  347. * This function should not be used all the time.
  348. *
  349. * @param[in] hostHandle The host handle.
  350. * @param[in] deviceHandle Removing device handle.
  351. *
  352. * @retval kStatus_USB_Success Remove successfully.
  353. * @retval kStatus_USB_InvalidHandle The hostHandle or deviceHandle is a NULL pointer.
  354. * @retval kStatus_USB_InvalidParameter The deviceHandle instance don't belong to hostHandle instance.
  355. */
  356. extern usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_handle deviceHandle);
  357. #if (defined(USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI > 0U))
  358. /*!
  359. * @brief KHCI task function.
  360. *
  361. * The function is used to handle the KHCI controller message.
  362. * In the bare metal environment, this function should be called periodically in the main function.
  363. * In the RTOS environment, this function should be used as a function entry to create a task.
  364. *
  365. * @param[in] hostHandle The host handle.
  366. */
  367. extern void USB_HostKhciTaskFunction(void *hostHandle);
  368. #endif
  369. #if (defined(USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
  370. /*!
  371. * @brief EHCI task function.
  372. *
  373. * The function is used to handle the EHCI controller message.
  374. * In the bare metal environment, this function should be called periodically in the main function.
  375. * In the RTOS environment, this function should be used as a function entry to create a task.
  376. *
  377. * @param[in] hostHandle The host handle.
  378. */
  379. extern void USB_HostEhciTaskFunction(void *hostHandle);
  380. #endif
  381. #if (defined(USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
  382. /*!
  383. * @brief OHCI task function.
  384. *
  385. * The function is used to handle the OHCI controller message.
  386. * In the bare metal environment, this function should be called periodically in the main function.
  387. * In the RTOS environment, this function should be used as a function entry to create a task.
  388. *
  389. * @param[in] hostHandle The host handle.
  390. */
  391. extern void USB_HostOhciTaskFunction(void *hostHandle);
  392. #endif
  393. #if (defined(USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
  394. /*!
  395. * @brief IP3516HS task function.
  396. *
  397. * The function is used to handle the IP3516HS controller message.
  398. * In the bare metal environment, this function should be called periodically in the main function.
  399. * In the RTOS environment, this function should be used as a function entry to create a task.
  400. *
  401. * @param[in] hostHandle The host handle.
  402. */
  403. extern void USB_HostIp3516HsTaskFunction(void *hostHandle);
  404. #endif
  405. #if (defined(USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI > 0U))
  406. /*!
  407. * @brief Device KHCI ISR function.
  408. *
  409. * The function is the KHCI interrupt service routine.
  410. *
  411. * @param[in] hostHandle The host handle.
  412. */
  413. extern void USB_HostKhciIsrFunction(void *hostHandle);
  414. #endif
  415. #if (defined(USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
  416. /*!
  417. * @brief Device EHCI ISR function.
  418. *
  419. * The function is the EHCI interrupt service routine.
  420. *
  421. * @param[in] hostHandle The host handle.
  422. */
  423. extern void USB_HostEhciIsrFunction(void *hostHandle);
  424. #endif
  425. #if (defined(USB_HOST_CONFIG_OHCI) && (USB_HOST_CONFIG_OHCI > 0U))
  426. /*!
  427. * @brief Device OHCI ISR function.
  428. *
  429. * The function is the OHCI interrupt service routine.
  430. *
  431. * @param[in] hostHandle The host handle.
  432. */
  433. extern void USB_HostOhciIsrFunction(void *hostHandle);
  434. #endif
  435. #if (defined(USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
  436. /*!
  437. * @brief Device IP3516HS ISR function.
  438. *
  439. * The function is the IP3516HS interrupt service routine.
  440. *
  441. * @param[in] hostHandle The host handle.
  442. */
  443. extern void USB_HostIp3516HsIsrFunction(void *hostHandle);
  444. #endif
  445. /*! @}*/
  446. /*!
  447. * @name USB host APIs Part 2.
  448. * The following APIs are not recommended for application use. They are mainly used in the class driver.
  449. * @{
  450. */
  451. /*!
  452. * @brief Opens the USB host pipe.
  453. *
  454. * This function opens a pipe according to the pipe_init_ptr parameter.
  455. *
  456. * @param[in] hostHandle The host handle.
  457. * @param[out] pipeHandle The pipe handle pointer used to return the pipe handle.
  458. * @param[in] pipeInit Used to initialize the pipe.
  459. *
  460. * @retval kStatus_USB_Success The host is initialized successfully.
  461. * @retval kStatus_USB_InvalidHandle The hostHandle or pipe_handle_ptr is a NULL pointer.
  462. * @retval kStatus_USB_Error There is no idle pipe.
  463. * Or, there is no idle QH for EHCI.
  464. * Or, bandwidth allocate fail for EHCI.
  465. */
  466. extern usb_status_t USB_HostOpenPipe(usb_host_handle hostHandle,
  467. usb_host_pipe_handle *pipeHandle,
  468. usb_host_pipe_init_t *pipeInit);
  469. /*!
  470. * @brief Closes the USB host pipe.
  471. *
  472. * This function closes a pipe and frees the related resources.
  473. *
  474. * @param[in] hostHandle The host handle.
  475. * @param[in] pipeHandle The closing pipe handle.
  476. *
  477. * @retval kStatus_USB_Success The host is initialized successfully.
  478. * @retval kStatus_USB_InvalidHandle The hostHandle or pipeHandle is a NULL pointer.
  479. */
  480. extern usb_status_t USB_HostClosePipe(usb_host_handle hostHandle, usb_host_pipe_handle pipeHandle);
  481. /*!
  482. * @brief Sends data to a pipe.
  483. *
  484. * This function requests to send the transfer to the specified pipe.
  485. *
  486. * @param[in] hostHandle The host handle.
  487. * @param[in] pipeHandle The sending pipe handle.
  488. * @param[in] transfer The transfer information.
  489. *
  490. * @retval kStatus_USB_Success Send successfully.
  491. * @retval kStatus_USB_InvalidHandle The hostHandle, pipeHandle or transfer is a NULL pointer.
  492. * @retval kStatus_USB_LackSwapBuffer There is no swap buffer for KHCI.
  493. * @retval kStatus_USB_Error There is no idle QTD/ITD/SITD for EHCI.
  494. */
  495. extern usb_status_t USB_HostSend(usb_host_handle hostHandle,
  496. usb_host_pipe_handle pipeHandle,
  497. usb_host_transfer_t *transfer);
  498. /*!
  499. * @brief Sends a setup transfer to the pipe.
  500. *
  501. * This function request to send the setup transfer to the specified pipe.
  502. *
  503. * @param[in] hostHandle The host handle.
  504. * @param[in] pipeHandle The sending pipe handle.
  505. * @param[in] transfer The transfer information.
  506. *
  507. * @retval kStatus_USB_Success Send successfully.
  508. * @retval kStatus_USB_InvalidHandle The hostHandle, pipeHandle or transfer is a NULL pointer.
  509. * @retval kStatus_USB_LackSwapBuffer There is no swap buffer for KHCI.
  510. * @retval kStatus_USB_Error There is no idle QTD/ITD/SITD for EHCI.
  511. */
  512. extern usb_status_t USB_HostSendSetup(usb_host_handle hostHandle,
  513. usb_host_pipe_handle pipeHandle,
  514. usb_host_transfer_t *transfer);
  515. /*!
  516. * @brief Receives the data from the pipe.
  517. *
  518. * This function requests to receive the transfer from the specified pipe.
  519. *
  520. * @param[in] hostHandle The host handle.
  521. * @param[in] pipeHandle The receiving pipe handle.
  522. * @param[in] transfer The transfer information.
  523. *
  524. * @retval kStatus_USB_Success Receive successfully.
  525. * @retval kStatus_USB_InvalidHandle The hostHandle, pipeHandle or transfer is a NULL pointer.
  526. * @retval kStatus_USB_LackSwapBuffer There is no swap buffer for KHCI.
  527. * @retval kStatus_USB_Error There is no idle QTD/ITD/SITD for EHCI.
  528. */
  529. extern usb_status_t USB_HostRecv(usb_host_handle hostHandle,
  530. usb_host_pipe_handle pipeHandle,
  531. usb_host_transfer_t *transfer);
  532. /*!
  533. * @brief Cancel the pipe's transfers.
  534. *
  535. * This function cancels all pipe's transfers when the parameter transfer is NULL or cancels the transfers altogether.
  536. *
  537. * @param[in] hostHandle The host handle.
  538. * @param[in] pipeHandle The receiving pipe handle.
  539. * @param[in] transfer The transfer information.
  540. *
  541. * @retval kStatus_USB_Success Cancel successfully.
  542. * @retval kStatus_USB_InvalidHandle The hostHandle or pipeHandle is a NULL pointer.
  543. */
  544. extern usb_status_t USB_HostCancelTransfer(usb_host_handle hostHandle,
  545. usb_host_pipe_handle pipeHandle,
  546. usb_host_transfer_t *transfer);
  547. /*!
  548. * @brief Allocates a transfer resource.
  549. *
  550. * This function allocates a transfer. This transfer is used to pass data information to a low level stack.
  551. *
  552. * @param[in] hostHandle The host handle.
  553. * @param[out] transfer Return the transfer.
  554. *
  555. * @retval kStatus_USB_Success Allocate successfully.
  556. * @retval kStatus_USB_InvalidHandle The hostHandle or transfer is a NULL pointer.
  557. * @retval kStatus_USB_Error There is no idle transfer.
  558. */
  559. extern usb_status_t USB_HostMallocTransfer(usb_host_handle hostHandle, usb_host_transfer_t **transfer);
  560. /*!
  561. * @brief Frees a transfer resource.
  562. *
  563. * This function frees a transfer. This transfer is used to pass data information to a low level stack.
  564. *
  565. * @param[in] hostHandle The host handle.
  566. * @param[in] transfer Release the transfer.
  567. *
  568. * @retval kStatus_USB_Success Free successfully.
  569. * @retval kStatus_USB_InvalidHandle The hostHandle or transfer is a NULL pointer.
  570. */
  571. extern usb_status_t USB_HostFreeTransfer(usb_host_handle hostHandle, usb_host_transfer_t *transfer);
  572. /*!
  573. * @brief Requests the USB standard request.
  574. *
  575. * This function sends the USB standard request packet.
  576. *
  577. * @param[in] deviceHandle The device handle for control transfer.
  578. * @param[in] usbRequest A USB standard request code. See the usb_spec.h.
  579. * @param[in] transfer The used transfer.
  580. * @param[in] param The parameter structure is different for different request, see
  581. * usb_host_framework.h.
  582. *
  583. * @retval kStatus_USB_Success Send successfully.
  584. * @retval kStatus_USB_InvalidHandle The deviceHandle is a NULL pointer.
  585. * @retval kStatus_USB_LackSwapBuffer There is no swap buffer for KHCI.
  586. * @retval kStatus_USB_Error There is no idle QTD/ITD/SITD for EHCI,
  587. * Or, the request is not standard request.
  588. */
  589. extern usb_status_t USB_HostRequestControl(usb_device_handle deviceHandle,
  590. uint8_t usbRequest,
  591. usb_host_transfer_t *transfer,
  592. void *param);
  593. /*!
  594. * @brief Opens the interface.
  595. *
  596. * This function opens the interface. It is used to notify the host driver the interface is used by APP or class driver.
  597. *
  598. * @param[in] deviceHandle Removing device handle.
  599. * @param[in] interfaceHandle Opening interface handle.
  600. *
  601. * @retval kStatus_USB_Success Open successfully.
  602. * @retval kStatus_USB_InvalidHandle The deviceHandle or interfaceHandle is a NULL pointer.
  603. */
  604. extern usb_status_t USB_HostOpenDeviceInterface(usb_device_handle deviceHandle,
  605. usb_host_interface_handle interfaceHandle);
  606. /*!
  607. * @brief Closes an interface.
  608. *
  609. * This function opens an interface. It is used to notify the host driver the interface is not used by APP or class
  610. * driver.
  611. *
  612. * @param[in] deviceHandle Removing device handle.
  613. * @param[in] interfaceHandle Opening interface handle.
  614. *
  615. * @retval kStatus_USB_Success Close successfully.
  616. * @retval kStatus_USB_InvalidHandle The deviceHandle is a NULL pointer.
  617. */
  618. extern usb_status_t USB_HostCloseDeviceInterface(usb_device_handle deviceHandle,
  619. usb_host_interface_handle interfaceHandle);
  620. /*!
  621. * @brief Gets a host stack version function.
  622. *
  623. * The function is used to get the host stack version.
  624. *
  625. * @param[out] version The version structure pointer to keep the host stack version.
  626. *
  627. */
  628. extern void USB_HostGetVersion(uint32_t *version);
  629. #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
  630. /*!
  631. * @brief Send a bus or device suspend request.
  632. *
  633. * This function is used to send a bus or device suspend request.
  634. *
  635. * @param[in] hostHandle The host handle.
  636. * @param[in] deviceHandle The device handle.
  637. *
  638. * @retval kStatus_USB_Success Request successfully.
  639. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer. Or the controller handle is invalid.
  640. * @retval kStatus_USB_Error There is no idle transfer.
  641. * Or, the deviceHandle is invalid.
  642. * Or, the request is invalid.
  643. */
  644. extern usb_status_t USB_HostSuspendDeviceResquest(usb_host_handle hostHandle, usb_device_handle deviceHandle);
  645. /*!
  646. * @brief Send a bus or device resume request.
  647. *
  648. * This function is used to send a bus or device resume request.
  649. *
  650. * @param[in] hostHandle The host handle.
  651. * @param[in] deviceHandle The device handle.
  652. *
  653. * @retval kStatus_USB_Success Request successfully.
  654. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer. Or the controller handle is invalid.
  655. * @retval kStatus_USB_Error There is no idle transfer.
  656. * Or, the deviceHandle is invalid.
  657. * Or, the request is invalid.
  658. */
  659. extern usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device_handle deviceHandle);
  660. #if ((defined(USB_HOST_CONFIG_LPM_L1)) && (USB_HOST_CONFIG_LPM_L1 > 0U))
  661. /*!
  662. * @brief Send a bus or device suspend request.
  663. *
  664. * This function is used to send a bus or device suspend request.
  665. *
  666. * @param[in] hostHandle The host handle.
  667. * @param[in] deviceHandle The device handle.
  668. *@param[in] sleeptype Bus suspend or single device suspend.
  669. *
  670. * @retval kStatus_USB_Success Request successfully.
  671. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer. Or the controller handle is invalid.
  672. * @retval kStatus_USB_Error There is no idle transfer.
  673. * Or, the deviceHandle is invalid.
  674. * Or, the request is invalid.
  675. */
  676. extern usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle,
  677. usb_device_handle deviceHandle,
  678. uint8_t sleeptype);
  679. /*!
  680. * @brief Send a bus or device resume request.
  681. *
  682. * This function is used to send a bus or device resume request.
  683. *
  684. * @param[in] hostHandle The host handle.
  685. * @param[in] deviceHandle The device handle.
  686. * *@param[in] sleeptype Bus suspend or single device suspend.
  687. *
  688. * @retval kStatus_USB_Success Request successfully.
  689. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer. Or the controller handle is invalid.
  690. * @retval kStatus_USB_Error There is no idle transfer.
  691. * Or, the deviceHandle is invalid.
  692. * Or, the request is invalid.
  693. */
  694. extern usb_status_t USB_HostL1ResumeDeviceResquest(usb_host_handle hostHandle,
  695. usb_device_handle deviceHandle,
  696. uint8_t sleepType);
  697. /*!
  698. * @brief Update the lpm param.
  699. *
  700. * The function is used to configure the lpm token.
  701. *
  702. * @param[in] hostHandle The host handle.
  703. * @param[in] lpmParam HIRD value and whether enable remotewakeup.
  704. *
  705. */
  706. extern usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uint8_t *lpmParam);
  707. #endif
  708. /*!
  709. * @brief Update the hardware tick.
  710. *
  711. * The function is used to update the hardware tick.
  712. *
  713. * @param[in] hostHandle The host handle.
  714. * @param[in] tick Current hardware tick(uint is ms).
  715. *
  716. */
  717. extern usb_status_t USB_HostUpdateHwTick(usb_host_handle hostHandle, uint64_t tick);
  718. #endif
  719. #if ((defined(USB_HOST_CONFIG_BATTERY_CHARGER)) && (USB_HOST_CONFIG_BATTERY_CHARGER > 0U))
  720. /*!
  721. * @brief Set the charger type. It is only supported on RT600 currently.
  722. *
  723. * The set charger type becomes valid in next attach.
  724. *
  725. * @param[in] hostHandle The host handle.
  726. * @param[in] type.
  727. *
  728. */
  729. extern usb_status_t USB_HostSetChargerType(usb_host_handle hostHandle, uint8_t type);
  730. #endif
  731. /*! @}*/
  732. #ifdef __cplusplus
  733. }
  734. #endif
  735. /*! @}*/
  736. #endif /* _USB_HOST_H_ */