usb_host_ehci.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /*
  2. * Copyright (c) 2015, 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_CONTROLLER_EHCI_H_
  9. #define _USB_HOST_CONTROLLER_EHCI_H_
  10. /*******************************************************************************
  11. * KHCI private public structures, enumerations, macros, functions
  12. ******************************************************************************/
  13. /*******************************************************************************
  14. * Definitions
  15. ******************************************************************************/
  16. /* EHCI host macros */
  17. #define EHCI_HOST_T_INVALID_VALUE (1U)
  18. #define EHCI_HOST_POINTER_TYPE_ITD (0x00U)
  19. #define EHCI_HOST_POINTER_TYPE_QH (0x00000002U)
  20. #define EHCI_HOST_POINTER_TYPE_SITD (0x00000004U)
  21. #define EHCI_HOST_POINTER_TYPE_FSTN (0x00000006U)
  22. #define EHCI_HOST_POINTER_TYPE_MASK (0x00000006U)
  23. #define EHCI_HOST_POINTER_ADDRESS_MASK (0xFFFFFFE0U)
  24. #define EHCI_HOST_PID_OUT (0UL)
  25. #define EHCI_HOST_PID_IN (1UL)
  26. #define EHCI_HOST_PID_SETUP (2UL)
  27. #define EHCI_HOST_QH_RL_SHIFT (28U)
  28. #define EHCI_HOST_QH_RL_MASK (0xF0000000U)
  29. #define EHCI_HOST_QH_C_SHIFT (27U)
  30. #define EHCI_HOST_QH_MAX_PACKET_LENGTH_SHIFT (16U)
  31. #define EHCI_HOST_QH_MAX_PACKET_LENGTH_MASK (0x07FF0000U)
  32. #define EHCI_HOST_QH_H_SHIFT (15U)
  33. #define EHCI_HOST_QH_DTC_SHIFT (14U)
  34. #define EHCI_HOST_QH_EPS_SHIFT (12U)
  35. #define EHCI_HOST_QH_ENDPT_SHIFT (8U)
  36. #define EHCI_HOST_QH_I_SHIFT (7U)
  37. #define EHCI_HOST_QH_DEVICE_ADDRESS_SHIFT (0U)
  38. #define EHCI_HOST_QH_MULT_SHIFT (30U)
  39. #define EHCI_HOST_QH_PORT_NUMBER_SHIFT (23U)
  40. #define EHCI_HOST_QH_HUB_ADDR_SHIFT (16U)
  41. #define EHCI_HOST_QH_UFRAME_CMASK_SHIFT (8U)
  42. #define EHCI_HOST_QH_UFRAME_SMASK_SHIFT (0U)
  43. #define EHCI_HOST_QH_STATUS_ERROR_MASK (0x0000007EU)
  44. #define EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK (0x0000003EU)
  45. #define EHCI_HOST_QTD_DT_SHIFT (31U)
  46. #define EHCI_HOST_QTD_DT_MASK (0x80000000U)
  47. #define EHCI_HOST_QTD_TOTAL_BYTES_SHIFT (16U)
  48. #define EHCI_HOST_QTD_TOTAL_BYTES_MASK (0x7FFF0000U)
  49. #define EHCI_HOST_QTD_IOC_MASK (0x00008000U)
  50. #define EHCI_HOST_QTD_C_PAGE_SHIFT (12U)
  51. #define EHCI_HOST_QTD_CERR_SHIFT (10U)
  52. #define EHCI_HOST_QTD_CERR_MAX_VALUE (0x00000003UL)
  53. #define EHCI_HOST_QTD_PID_CODE_SHIFT (8U)
  54. #define EHCI_HOST_QTD_STATUS_SHIFT (0U)
  55. #define EHCI_HOST_QTD_CURRENT_OFFSET_MASK (0x00000FFFU)
  56. #define EHCI_HOST_QTD_BUFFER_POINTER_SHIFT (12U)
  57. #define EHCI_HOST_QTD_STATUS_ACTIVE_MASK (0x00000080U)
  58. #define EHCI_HOST_QTD_STATUS_MASK (0x000000ffU)
  59. #define EHCI_HOST_QTD_STATUS_ERROR_MASK (0x0000007EU)
  60. #define EHCI_HOST_QTD_STATUS_STALL_ERROR_MASK (0x00000040U)
  61. #define EHCI_HOST_ITD_STATUS_ACTIVE_MASK (0x80000000U)
  62. #define EHCI_HOST_ITD_TRANSACTION_LEN_SHIFT (16U)
  63. #define EHCI_HOST_ITD_TRANSACTION_LEN_MASK (0x0FFF0000U)
  64. #define EHCI_HOST_ITD_IOC_SHIFT (15U)
  65. #define EHCI_HOST_ITD_PG_SHIFT (12U)
  66. #define EHCI_HOST_ITD_TRANSACTION_OFFSET_SHIFT (0U)
  67. #define EHCI_HOST_ITD_TRANSACTION_OFFSET_MASK (0x00000FFFU)
  68. #define EHCI_HOST_ITD_BUFFER_POINTER_SHIFT (12U)
  69. #define EHCI_HOST_ITD_ENDPT_SHIFT (8U)
  70. #define EHCI_HOST_ITD_DEVICE_ADDRESS_SHIFT (0U)
  71. #define EHCI_HOST_ITD_MAX_PACKET_SIZE_SHIFT (0U)
  72. #define EHCI_HOST_ITD_MULT_SHIFT (0U)
  73. #define EHCI_HOST_ITD_DIRECTION_SHIFT (11U)
  74. #define EHCI_HOST_SITD_STATUS_ACTIVE_MASK (0x00000080U)
  75. #define EHCI_HOST_SITD_DIRECTION_SHIFT (31U)
  76. #define EHCI_HOST_SITD_PORT_NUMBER_SHIFT (24U)
  77. #define EHCI_HOST_SITD_HUB_ADDR_SHIFT (16U)
  78. #define EHCI_HOST_SITD_ENDPT_SHIFT (8U)
  79. #define EHCI_HOST_SITD_DEVICE_ADDRESS_SHIFT (0U)
  80. #define EHCI_HOST_SITD_CMASK_SHIFT (8U)
  81. #define EHCI_HOST_SITD_SMASK_SHIFT (0U)
  82. #define EHCI_HOST_SITD_TOTAL_BYTES_SHIFT (16U)
  83. #define EHCI_HOST_SITD_TOTAL_BYTES_MASK (0x03FF0000U)
  84. #define EHCI_HOST_SITD_TP_SHIFT (3U)
  85. #define EHCI_HOST_SITD_TCOUNT_SHIFT (0U)
  86. #define EHCI_HOST_SITD_IOC_SHIFT (31U)
  87. /* register related MACROs */
  88. #define EHCI_PORTSC1_W1_BITS (0x0000002AU)
  89. #define EHCI_MAX_UFRAME_VALUE (0x00003FFFU)
  90. /* task event */
  91. #define EHCI_TASK_EVENT_DEVICE_ATTACH (0x01U)
  92. #define EHCI_TASK_EVENT_TRANSACTION_DONE (0x02U)
  93. #define EHCI_TASK_EVENT_DEVICE_DETACH (0x04U)
  94. #define EHCI_TASK_EVENT_PORT_CHANGE (0x08U)
  95. #define EHCI_TASK_EVENT_TIMER0 (0x10U)
  96. #define EHCI_TASK_EVENT_TIMER1 (0x20U)
  97. #define USB_HostEhciLock() (void)OSA_MutexLock(ehciInstance->ehciMutex, USB_OSA_WAIT_TIMEOUT)
  98. #define USB_HostEhciUnlock() (void)OSA_MutexUnlock(ehciInstance->ehciMutex)
  99. /*******************************************************************************
  100. * KHCI driver public structures, enumerations, macros, functions
  101. ******************************************************************************/
  102. /*!
  103. * @addtogroup usb_host_controller_ehci
  104. * @{
  105. */
  106. /*! @brief The maximum supported ISO pipe number */
  107. #define USB_HOST_EHCI_ISO_NUMBER USB_HOST_CONFIG_EHCI_MAX_ITD
  108. /*! @brief Check the port connect state delay if the state is unstable */
  109. #define USB_HOST_EHCI_PORT_CONNECT_DEBOUNCE_DELAY (101U)
  110. /*! @brief Delay for port reset */
  111. #define USB_HOST_EHCI_PORT_RESET_DELAY (11U)
  112. /*! @brief The MAX continuous transfers that application can send. */
  113. #define USB_HOST_EHCI_ISO_MAX_CONTINUOUS_TRANSFER (8U)
  114. /*! @brief The SITD inserts a frame interval for putting more SITD continuously.
  115. * There is an interval when an application sends two FS/LS ISO transfers.
  116. * When the interval is less than the macro, the two transfers are continuous in the frame list. Otherwise, the two
  117. * transfers
  118. * are not continuous.
  119. * For example:
  120. * - Use case 1: when inserting the SITD first, the inserted frame = the current frame value + this MACRO value.
  121. * - Use case 2: when inserting SITD is not first, choose between the last inserted frame value and the
  122. * current frame value according to the following criteria:
  123. * If the interval is less than the MACRO value, the new SITD is continuous with the last SITD.
  124. * If not, the new SITD inserting frame = the current frame value + this MACRO value.
  125. */
  126. #define USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER (2U)
  127. /*! @brief The ITD inserts a micro-frame interval for putting more ITD continuously.
  128. * There is an interval when an application sends two HS ISO transfers.
  129. * When the interval is less than the macro, the two transfers are continuous in the frame list. Otherwise, the two
  130. * transfers
  131. * are not continuous.
  132. * For example:
  133. * - Use case 1: when inserting ITD first, the inserted micro-frame = the current micro-frame value + this MACRO value.
  134. * - Use case 2: when inserting ITD is not first, choose between the last inserted micro-frame value and the
  135. * current micro-frame value according to the following criteria:
  136. * If the interval is less than this MACRO value, the new ITD is continuous with the last ITD.
  137. * If not, the new ITD inserting micro-frame = the current micro-frame value + this MACRO value.
  138. */
  139. #define USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER (16U)
  140. /*! @brief Control or bulk transaction timeout value (unit: 100 ms) */
  141. #define USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE (50U)
  142. #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
  143. typedef enum _bus_ehci_suspend_request_state
  144. {
  145. kBus_EhciIdle = 0U,
  146. kBus_EhciStartSuspend,
  147. kBus_EhciSuspended,
  148. kBus_EhciStartResume,
  149. } bus_ehci_suspend_request_state_t;
  150. #endif
  151. /*! @brief EHCI state for device attachment/detachment. */
  152. typedef enum _host_ehci_device_state_
  153. {
  154. kEHCIDevicePhyAttached = 1, /*!< Device is physically attached */
  155. kEHCIDeviceAttached, /*!< Device is attached and initialized */
  156. kEHCIDeviceDetached, /*!< Device is detached and de-initialized */
  157. } host_ehci_device_state_t;
  158. /*! @brief EHCI pipe structure */
  159. typedef struct _usb_host_ehci_pipe
  160. {
  161. usb_host_pipe_t pipeCommon; /*!< Common pipe information */
  162. void *ehciQh; /*!< Control/bulk/interrupt: QH; ISO: usb_host_ehci_iso_t*/
  163. /* bandwidth */
  164. uint16_t uframeInterval; /*!< Micro-frame interval value */
  165. uint16_t startFrame; /*!<
  166. Bandwidth start frame: its value is from 0 to frame_list.
  167. */
  168. uint16_t dataTime; /*!<
  169. Bandwidth time value:
  170. - When the host works as HS: it's the data bandwidth value.
  171. - When the host works as FS/LS:
  172. - For FS/LS device, it's the data bandwidth value when transferring the data by FS/LS.
  173. - For HS device, it's the data bandwidth value when transferring the data by HS.
  174. */
  175. uint16_t startSplitTime; /*!<
  176. Start splitting the bandwidth time value:
  177. - When the host works as HS, it is the start split bandwidth value.
  178. */
  179. uint16_t completeSplitTime; /*!<
  180. Complete splitting the bandwidth time value:
  181. - When host works as HS, it is the complete split bandwidth value.
  182. */
  183. uint8_t startUframe; /*!<
  184. Bandwidth start micro-frame: its value is from 0 to 7.
  185. */
  186. uint8_t uframeSmask; /*!<
  187. Start micro-frame.
  188. - When host works as an HS:
  189. - For FS/LS device, it's the interrupt or ISO transfer start-split mask.
  190. - For HS device, it's the interrupt transfer start micro-frame mask.
  191. - When host works as FS/LS, it's the interrupt and ISO start micro-frame mask
  192. */
  193. uint8_t uframeCmask; /*!<
  194. Complete micro-frame
  195. - When host works as HS:
  196. - For FS/LS device, it's the interrupt or ISO transfer complete-split mask.
  197. */
  198. } usb_host_ehci_pipe_t;
  199. /*! @brief EHCI QH structure. See the USB EHCI specification */
  200. typedef struct _usb_host_ehci_qh
  201. {
  202. uint32_t horizontalLinkPointer; /*!< QH specification filed, queue head a horizontal link pointer */
  203. uint32_t
  204. staticEndpointStates[2]; /*!< QH specification filed, static endpoint state and configuration information */
  205. uint32_t currentQtdPointer; /*!< QH specification filed, current qTD pointer */
  206. uint32_t nextQtdPointer; /*!< QH specification filed, next qTD pointer */
  207. uint32_t alternateNextQtdPointer; /*!< QH specification filed, alternate next qTD pointer */
  208. uint32_t
  209. transferOverlayResults[6]; /*!< QH specification filed, transfer overlay configuration and transfer results */
  210. /* reserved space */
  211. usb_host_ehci_pipe_t *ehciPipePointer; /*!< EHCI pipe pointer */
  212. usb_host_transfer_t *ehciTransferHead; /*!< Transfer list head on this QH */
  213. usb_host_transfer_t *ehciTransferTail; /*!< Transfer list tail on this QH */
  214. uint16_t timeOutValue; /*!< Its maximum value is USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE. When the value is
  215. zero, the transfer times out. */
  216. uint16_t timeOutLabel; /*!< It's used to judge the transfer timeout. The EHCI driver maintain the value */
  217. } usb_host_ehci_qh_t;
  218. /*! @brief EHCI QTD structure. See the USB EHCI specification. */
  219. typedef struct _usb_host_ehci_qtd
  220. {
  221. uint32_t nextQtdPointer; /*!< QTD specification filed, the next QTD pointer */
  222. uint32_t alternateNextQtdPointer; /*!< QTD specification filed, alternate next QTD pointer */
  223. uint32_t transferResults[2]; /*!< QTD specification filed, transfer results fields */
  224. uint32_t bufferPointers[4]; /*!< QTD specification filed, transfer buffer fields */
  225. } usb_host_ehci_qtd_t;
  226. /*! @brief EHCI ITD structure. See the USB EHCI specification. */
  227. typedef struct _usb_host_ehci_itd
  228. {
  229. uint32_t nextLinkPointer; /*!< ITD specification filed, the next linker pointer */
  230. uint32_t transactions[8]; /*!< ITD specification filed, transactions information */
  231. uint32_t bufferPointers[7]; /*!< ITD specification filed, transfer buffer fields */
  232. /* add space */
  233. struct _usb_host_ehci_itd *nextItdPointer; /*!< Next ITD pointer */
  234. uint32_t frameEntryIndex; /*!< The ITD inserted frame value */
  235. uint32_t reserved[6]; /*!< Reserved fields for 32 bytes align */
  236. } usb_host_ehci_itd_t;
  237. /*! @brief EHCI SITD structure. See the USB EHCI specification. */
  238. typedef struct _usb_host_ehci_sitd
  239. {
  240. uint32_t nextLinkPointer; /*!< SITD specification filed, the next linker pointer */
  241. uint32_t endpointStates[2]; /*!< SITD specification filed, endpoint configuration information */
  242. uint32_t transferResults[3]; /*!< SITD specification filed, transfer result fields */
  243. uint32_t backPointer; /*!< SITD specification filed, back pointer */
  244. /* reserved space */
  245. uint16_t frameEntryIndex; /*!< The SITD inserted frame value */
  246. uint8_t nextSitdIndex; /*!< The next SITD index; Get the next SITD pointer through adding base address with the
  247. index. 0xFF means invalid. */
  248. uint8_t reserved; /*!< Reserved fields for 32 bytes align */
  249. } usb_host_ehci_sitd_t;
  250. /*! @brief EHCI ISO structure; An ISO pipe has an instance of this structure to keep the ISO pipe-specific information.
  251. */
  252. typedef struct _usb_host_ehci_iso
  253. {
  254. struct _usb_host_ehci_iso *next; /*!< Next instance pointer */
  255. usb_host_pipe_t *ehciPipePointer; /*!< This ISO's EHCI pipe pointer */
  256. usb_host_transfer_t *ehciTransferHead; /*!< Transfer list head on this ISO pipe */
  257. usb_host_transfer_t *ehciTransferTail; /*!< Transfer list head on this ISO pipe */
  258. uint16_t lastLinkFrame; /*!< It means that the inserted frame for ISO ITD/SITD. 0xFFFF is invalid. For ITD, it is a
  259. micro-frame value. For SITD, it is a frame value */
  260. } usb_host_ehci_iso_t;
  261. /*! @brief EHCI instance structure */
  262. typedef struct _usb_host_ehci_instance
  263. {
  264. usb_host_handle hostHandle; /*!< Related host handle*/
  265. uint32_t *ehciUnitBase; /*!< Keep the QH/QTD/ITD/SITD buffer pointer for release*/
  266. uint8_t *ehciFrameList; /*!< The frame list of the current ehci instance*/
  267. usb_host_ehci_qh_t *ehciQhList; /*!< Idle QH list pointer */
  268. usb_host_ehci_qtd_t *ehciQtdHead; /*!< Idle QTD list pointer head */
  269. usb_host_ehci_qtd_t *ehciQtdTail; /*!< Idle QTD list pointer tail (recently used qTD will be used)*/
  270. usb_host_ehci_itd_t *ehciItdList; /*!< Idle ITD list pointer*/
  271. usb_host_ehci_sitd_t *ehciSitdIndexBase; /*!< SITD buffer's start pointer*/
  272. usb_host_ehci_sitd_t *ehciSitdList; /*!< Idle SITD list pointer*/
  273. usb_host_ehci_iso_t *ehciIsoList; /*!< Idle ISO list pointer*/
  274. USBHS_Type *ehciIpBase; /*!< EHCI IP base address*/
  275. usb_host_ehci_qh_t *shedFirstQh; /*!< First async QH*/
  276. usb_host_ehci_pipe_t *ehciPipeIndexBase; /*!< Pipe buffer's start pointer*/
  277. usb_host_ehci_pipe_t *ehciPipeList; /*!< Idle pipe list pointer*/
  278. usb_host_ehci_pipe_t *ehciRunningPipeList; /*!< Running pipe list pointer*/
  279. osa_mutex_handle_t ehciMutex; /*!< EHCI mutex*/
  280. uint32_t mutexBuffer[(OSA_MUTEX_HANDLE_SIZE + 3) / 4]; /*!< The mutex buffer. */
  281. osa_event_handle_t taskEventHandle; /*!< EHCI task event*/
  282. uint32_t taskEventHandleBuffer[(OSA_EVENT_HANDLE_SIZE + 3) / 4]; /*!< EHCI task event handle buffer*/
  283. #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
  284. uint64_t matchTick;
  285. USBPHY_Type *registerPhyBase; /*!< The base address of the PHY register */
  286. #if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U))
  287. USBNC_Type *registerNcBase; /*!< The base address of the USBNC register */
  288. #endif
  289. #endif
  290. uint8_t controllerId; /*!< EHCI controller ID*/
  291. uint8_t deviceAttached; /*!< Device attach/detach state, see #host_ehci_device_state_t */
  292. uint8_t firstDeviceSpeed; /*!< The first device's speed, the controller's work speed*/
  293. uint8_t ehciItdNumber; /*!< Idle ITD number*/
  294. uint8_t ehciSitdNumber; /*!< Idle SITD number*/
  295. uint8_t ehciQtdNumber; /*!< Idle QTD number*/
  296. #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
  297. bus_ehci_suspend_request_state_t busSuspendStatus; /*!< Bus Suspend Status*/
  298. #endif
  299. } usb_host_ehci_instance_t;
  300. /*! @brief EHCI data structure */
  301. typedef struct _usb_host_ehci_data
  302. {
  303. #if ((defined(USB_HOST_CONFIG_EHCI_MAX_QH)) && (USB_HOST_CONFIG_EHCI_MAX_QH > 0U))
  304. usb_host_ehci_qh_t ehciQh[USB_HOST_CONFIG_EHCI_MAX_QH]; /*!< Idle QH list array*/
  305. #endif
  306. #if ((defined(USB_HOST_CONFIG_EHCI_MAX_QTD)) && (USB_HOST_CONFIG_EHCI_MAX_QTD > 0U))
  307. usb_host_ehci_qtd_t ehciQtd[USB_HOST_CONFIG_EHCI_MAX_QTD]; /*!< Idle QTD list array*/
  308. #endif
  309. #if ((defined(USB_HOST_CONFIG_EHCI_MAX_ITD)) && (USB_HOST_CONFIG_EHCI_MAX_ITD > 0U))
  310. usb_host_ehci_itd_t ehciItd[USB_HOST_CONFIG_EHCI_MAX_ITD]; /*!< Idle ITD list array*/
  311. /* add additional 32bytes because the itd cannot cross over 4K boundary,
  312. * If one ITD cross over 4K boundary, the code will move 32 bytes for ITD.
  313. */
  314. uint32_t reserved[8];
  315. #endif
  316. #if ((defined(USB_HOST_CONFIG_EHCI_MAX_SITD)) && (USB_HOST_CONFIG_EHCI_MAX_SITD > 0U))
  317. usb_host_ehci_sitd_t ehciSitd[USB_HOST_CONFIG_EHCI_MAX_SITD]; /*!< Idle SITD list array*/
  318. #endif
  319. #if ((defined(USB_HOST_EHCI_ISO_NUMBER)) && (USB_HOST_EHCI_ISO_NUMBER > 0U))
  320. usb_host_ehci_iso_t ehciIso[USB_HOST_EHCI_ISO_NUMBER]; /*!< Idle ISO list array*/
  321. #endif
  322. #if ((defined(USB_HOST_CONFIG_MAX_PIPES)) && (USB_HOST_CONFIG_MAX_PIPES > 0U))
  323. usb_host_ehci_pipe_t ehciPipe[USB_HOST_CONFIG_MAX_PIPES]; /*!< Idle pipe list array*/
  324. #endif
  325. } usb_host_ehci_data_t;
  326. /*******************************************************************************
  327. * API
  328. ******************************************************************************/
  329. #ifdef __cplusplus
  330. extern "C" {
  331. #endif
  332. /*!
  333. * @name USB host EHCI APIs
  334. * @{
  335. */
  336. /*!
  337. * @brief Creates the USB host EHCI instance.
  338. *
  339. * This function initializes the USB host EHCI controller driver.
  340. *
  341. * @param[in] controllerId The controller ID of the USB IP. Please refer to the enumeration usb_controller_index_t.
  342. * @param[in] upperLayerHandle The host level handle.
  343. * @param[out] controllerHandle return the controller instance handle.
  344. *
  345. * @retval kStatus_USB_Success The host is initialized successfully.
  346. * @retval kStatus_USB_AllocFail Allocating memory failed.
  347. * @retval kStatus_USB_Error Host mutex create fail, KHCI/EHCI mutex or KHCI/EHCI event create fail.
  348. * Or, KHCI/EHCI IP initialize fail.
  349. */
  350. extern usb_status_t USB_HostEhciCreate(uint8_t controllerId,
  351. usb_host_handle upperLayerHandle,
  352. usb_host_controller_handle *controllerHandle);
  353. /*!
  354. * @brief Destroys the USB host EHCI instance.
  355. *
  356. * This function de-initializes The USB host EHCI controller driver.
  357. *
  358. * @param[in] controllerHandle The controller handle.
  359. *
  360. * @retval kStatus_USB_Success The host is initialized successfully.
  361. */
  362. extern usb_status_t USB_HostEhciDestory(usb_host_controller_handle controllerHandle);
  363. /*!
  364. * @brief Opens the USB host pipe.
  365. *
  366. * This function opens a pipe according to the pipe_init_ptr parameter.
  367. *
  368. * @param[in] controllerHandle The controller handle.
  369. * @param[out] pipeHandle The pipe handle pointer, it is used to return the pipe handle.
  370. * @param[in] pipeInit It is used to initialize the pipe.
  371. *
  372. * @retval kStatus_USB_Success The host is initialized successfully.
  373. * @retval kStatus_USB_Error There is no idle pipe.
  374. * Or, there is no idle QH for EHCI.
  375. * Or, bandwidth allocate fail for EHCI.
  376. */
  377. extern usb_status_t USB_HostEhciOpenPipe(usb_host_controller_handle controllerHandle,
  378. usb_host_pipe_handle *pipeHandle,
  379. usb_host_pipe_init_t *pipeInit);
  380. /*!
  381. * @brief Closes the USB host pipe.
  382. *
  383. * This function closes a pipe and releases related resources.
  384. *
  385. * @param[in] controllerHandle The controller handle.
  386. * @param[in] pipeHandle The closing pipe handle.
  387. *
  388. * @retval kStatus_USB_Success The host is initialized successfully.
  389. */
  390. extern usb_status_t USB_HostEhciClosePipe(usb_host_controller_handle controllerHandle, usb_host_pipe_handle pipeHandle);
  391. /*!
  392. * @brief Sends data to the pipe.
  393. *
  394. * This function requests to send the transfer to the specified pipe.
  395. *
  396. * @param[in] controllerHandle The controller handle.
  397. * @param[in] pipeHandle The sending pipe handle.
  398. * @param[in] transfer The transfer information.
  399. *
  400. * @retval kStatus_USB_Success Sent successfully.
  401. * @retval kStatus_USB_LackSwapBuffer There is no swap buffer for KHCI.
  402. * @retval kStatus_USB_Error There is no idle QTD/ITD/SITD for EHCI.
  403. */
  404. extern usb_status_t USB_HostEhciWritePipe(usb_host_controller_handle controllerHandle,
  405. usb_host_pipe_handle pipeHandle,
  406. usb_host_transfer_t *transfer);
  407. /*!
  408. * @brief Receives data from the pipe.
  409. *
  410. * This function requests to receive the transfer from the specified pipe.
  411. *
  412. * @param[in] controllerHandle The controller handle.
  413. * @param[in] pipeHandle The receiving pipe handle.
  414. * @param[in] transfer The transfer information.
  415. * @retval kStatus_USB_Success Send successfully.
  416. * @retval kStatus_USB_LackSwapBuffer There is no swap buffer for KHCI.
  417. * @retval kStatus_USB_Error There is no idle QTD/ITD/SITD for EHCI.
  418. */
  419. extern usb_status_t USB_HostEhciReadpipe(usb_host_controller_handle controllerHandle,
  420. usb_host_pipe_handle pipeHandle,
  421. usb_host_transfer_t *transfer);
  422. /*!
  423. * @brief Controls the EHCI.
  424. *
  425. * This function controls the EHCI.
  426. *
  427. * @param[in] controllerHandle The controller handle.
  428. * @param[in] ioctlEvent See enumeration host_bus_control_t.
  429. * @param[in] ioctlParam The control parameter.
  430. *
  431. * @retval kStatus_USB_Success Cancel successfully.
  432. * @retval kStatus_USB_InvalidHandle The controllerHandle is a NULL pointer.
  433. */
  434. extern usb_status_t USB_HostEhciIoctl(usb_host_controller_handle controllerHandle,
  435. uint32_t ioctlEvent,
  436. void *ioctlParam);
  437. /*!
  438. * @brief control ehci bus.
  439. *
  440. * @param ehciInstance ehci instance pointer.
  441. * @param bus_control control code.
  442. *
  443. * @return kStatus_USB_Success or error codes.
  444. */
  445. extern usb_status_t USB_HostEhciControlBus(usb_host_ehci_instance_t *ehciInstance, uint8_t busControl);
  446. /*!
  447. * @brief ehci port change interrupt process function.
  448. *
  449. * @param ehciInstance ehci instance pointer.
  450. */
  451. extern void USB_HostEhciPortChange(usb_host_ehci_instance_t *ehciInstance);
  452. /*!
  453. * @brief ehci timer0 interrupt process function.
  454. * cancel control/bulk transfer that time out.
  455. *
  456. * @param ehciInstance ehci instance pointer.
  457. */
  458. extern void USB_HostEhciTimer0(usb_host_ehci_instance_t *ehciInstance);
  459. /*!
  460. * @brief host ehci start async schedule.
  461. *
  462. * @param ehciInstance ehci instance pointer.
  463. */
  464. extern void USB_HostEhciStartAsync(usb_host_ehci_instance_t *ehciInstance);
  465. /*!
  466. * @brief host ehci start periodic schedule.
  467. *
  468. * @param ehciInstance ehci instance pointer.
  469. */
  470. extern void USB_HostEhciStartPeriodic(usb_host_ehci_instance_t *ehciInstance);
  471. /*! @}*/
  472. #ifdef __cplusplus
  473. }
  474. #endif
  475. /*! @}*/
  476. #endif /* _USB_HOST_CONTROLLER_EHCI_H_ */