usb_device_ehci.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (c) 2015, 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_DEVICE_EHCI_H__
  31. #define __USB_DEVICE_EHCI_H__
  32. #include <usb/include/usb_ehci.h>
  33. /*!
  34. * @addtogroup usb_device_controller_ehci_driver
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. /*! @brief The maximum value of ISO type maximum packet size for HS in USB specification 2.0 */
  41. #define USB_DEVICE_MAX_HS_ISO_MAX_PACKET_SIZE (1024U)
  42. /*! @brief The maximum value of interrupt type maximum packet size for HS in USB specification 2.0 */
  43. #define USB_DEVICE_MAX_HS_INTERUPT_MAX_PACKET_SIZE (1024U)
  44. /*! @brief The maximum value of bulk type maximum packet size for HS in USB specification 2.0 */
  45. #define USB_DEVICE_MAX_HS_BULK_MAX_PACKET_SIZE (512U)
  46. /*! @brief The maximum value of control type maximum packet size for HS in USB specification 2.0 */
  47. #define USB_DEVICE_MAX_HS_CONTROL_MAX_PACKET_SIZE (64U)
  48. /*! @brief EHCI state structure */
  49. typedef struct _usb_device_ehci_state_struct
  50. {
  51. usb_device_struct_t *deviceHandle; /*!< Device handle used to identify the device object is belonged to */
  52. USBHS_Type *registerBase; /*!< The base address of the register */
  53. #if (defined(USB_DEVICE_CONFIG_LOW_POWER_MODE) && (USB_DEVICE_CONFIG_LOW_POWER_MODE > 0U))
  54. USBPHY_Type *registerPhyBase; /*!< The base address of the PHY register */
  55. #if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U))
  56. USBNC_Type *registerNcBase; /*!< The base address of the USBNC register */
  57. #endif
  58. #endif
  59. usb_device_ehci_qh_struct_t *qh; /*!< The QH structure base address */
  60. usb_device_ehci_dtd_struct_t *dtd; /*!< The DTD structure base address */
  61. usb_device_ehci_dtd_struct_t *dtdFree; /*!< The idle DTD list head */
  62. usb_device_ehci_dtd_struct_t
  63. *dtdHard[USB_DEVICE_CONFIG_ENDPOINTS * 2]; /*!< The transferring DTD list head for each endpoint */
  64. usb_device_ehci_dtd_struct_t
  65. *dtdTail[USB_DEVICE_CONFIG_ENDPOINTS * 2]; /*!< The transferring DTD list tail for each endpoint */
  66. int8_t dtdCount; /*!< The idle DTD node count */
  67. uint8_t endpointCount; /*!< The endpoint number of EHCI */
  68. uint8_t isResetting; /*!< Whether a PORT reset is occurring or not */
  69. uint8_t controllerId; /*!< Controller ID */
  70. uint8_t speed; /*!< Current speed of EHCI */
  71. uint8_t isSuspending; /*!< Is suspending of the PORT */
  72. } usb_device_ehci_state_struct_t;
  73. #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U)) && \
  74. (defined(FSL_FEATURE_SOC_USBHSDCD_COUNT) && (FSL_FEATURE_SOC_USBHSDCD_COUNT > 0U))
  75. typedef struct _usb_device_dcd_state_struct
  76. {
  77. usb_device_struct_t *deviceHandle; /*!< Device handle used to identify the device object belongs to */
  78. USBHSDCD_Type *dcdRegisterBase; /*!< The base address of the dcd module */
  79. uint8_t controllerId; /*!< Controller ID */
  80. } usb_device_dcd_state_struct_t;
  81. #endif
  82. #if defined(__cplusplus)
  83. extern "C" {
  84. #endif
  85. /*!
  86. * @name USB device EHCI functions
  87. * @{
  88. */
  89. /*******************************************************************************
  90. * API
  91. ******************************************************************************/
  92. /*!
  93. * @brief Initializes the USB device EHCI instance.
  94. *
  95. * This function initializes the USB device EHCI module specified by the controllerId.
  96. *
  97. * @param[in] controllerId The controller ID of the USB IP. See the enumeration type usb_controller_index_t.
  98. * @param[in] handle Pointer of the device handle used to identify the device object is belonged to.
  99. * @param[out] ehciHandle An out parameter used to return the pointer of the device EHCI handle to the caller.
  100. *
  101. * @return A USB error code or kStatus_USB_Success.
  102. */
  103. usb_status_t USB_DeviceEhciInit(uint8_t controllerId,
  104. usb_device_handle handle,
  105. usb_device_controller_handle *ehciHandle);
  106. /*!
  107. * @brief Deinitializes the USB device EHCI instance.
  108. *
  109. * This function deinitializes the USB device EHCI module.
  110. *
  111. * @param[in] ehciHandle Pointer of the device EHCI handle.
  112. *
  113. * @return A USB error code or kStatus_USB_Success.
  114. */
  115. usb_status_t USB_DeviceEhciDeinit(usb_device_controller_handle ehciHandle);
  116. /*!
  117. * @brief Sends data through a specified endpoint.
  118. *
  119. * This function sends data through a specified endpoint.
  120. *
  121. * @param[in] ehciHandle Pointer of the device EHCI handle.
  122. * @param[in] endpointAddress Endpoint index.
  123. * @param[in] buffer The memory address to hold the data need to be sent.
  124. * @param[in] length The data length to be sent.
  125. *
  126. * @return A USB error code or kStatus_USB_Success.
  127. *
  128. * @note The return value means whether the sending request is successful or not. The transfer completion is indicated
  129. * by the
  130. * corresponding callback function.
  131. * Currently, only one transfer request can be supported for a specific endpoint.
  132. * If there is a specific requirement to support multiple transfer requests for a specific endpoint, the application
  133. * should implement a queue in the application level.
  134. * The subsequent transfer can begin only when the previous transfer is done (a notification is received through the
  135. * endpoint
  136. * callback).
  137. */
  138. usb_status_t USB_DeviceEhciSend(usb_device_controller_handle ehciHandle,
  139. uint8_t endpointAddress,
  140. uint8_t *buffer,
  141. uint32_t length);
  142. /*!
  143. * @brief Receive data through a specified endpoint.
  144. *
  145. * This function Receives data through a specified endpoint.
  146. *
  147. * @param[in] ehciHandle Pointer of the device EHCI handle.
  148. * @param[in] endpointAddress Endpoint index.
  149. * @param[in] buffer The memory address to save the received data.
  150. * @param[in] length The data length want to be received.
  151. *
  152. * @return A USB error code or kStatus_USB_Success.
  153. *
  154. * @note The return value just means if the receiving request is successful or not; the transfer done is notified by the
  155. * corresponding callback function.
  156. * Currently, only one transfer request can be supported for one specific endpoint.
  157. * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application
  158. * should implement a queue in the application level.
  159. * The subsequent transfer could begin only when the previous transfer is done (get notification through the endpoint
  160. * callback).
  161. */
  162. usb_status_t USB_DeviceEhciRecv(usb_device_controller_handle ehciHandle,
  163. uint8_t endpointAddress,
  164. uint8_t *buffer,
  165. uint32_t length);
  166. /*!
  167. * @brief Cancels the pending transfer in a specified endpoint.
  168. *
  169. * The function is used to cancel the pending transfer in a specified endpoint.
  170. *
  171. * @param[in] ehciHandle Pointer of the device EHCI handle.
  172. * @param[in] ep Endpoint address, bit7 is the direction of endpoint, 1U - IN, 0U - OUT.
  173. *
  174. * @return A USB error code or kStatus_USB_Success.
  175. */
  176. usb_status_t USB_DeviceEhciCancel(usb_device_controller_handle ehciHandle, uint8_t ep);
  177. /*!
  178. * @brief Controls the status of the selected item.
  179. *
  180. * The function is used to control the status of the selected item.
  181. *
  182. * @param[in] ehciHandle Pointer of the device EHCI handle.
  183. * @param[in] type The selected item. See enumeration type usb_device_control_type_t.
  184. * @param[in,out] param The parameter type is determined by the selected item.
  185. *
  186. * @return A USB error code or kStatus_USB_Success.
  187. */
  188. usb_status_t USB_DeviceEhciControl(usb_device_controller_handle ehciHandle,
  189. usb_device_control_type_t type,
  190. void *param);
  191. /*! @} */
  192. #if defined(__cplusplus)
  193. }
  194. #endif
  195. /*! @} */
  196. #endif /* __USB_DEVICE_EHCI_H__ */