usb_host.h 31 KB

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