usb_host_hci.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_HOST_HCI_H_
  31. #define _USB_HOST_HCI_H_
  32. /*******************************************************************************
  33. * Definitions
  34. ******************************************************************************/
  35. /*! @brief USB host lock */
  36. #define USB_HostLock() USB_OsaMutexLock(hostInstance->hostMutex)
  37. /*! @brief USB host unlock */
  38. #define USB_HostUnlock() USB_OsaMutexUnlock(hostInstance->hostMutex)
  39. /*!
  40. * @addtogroup usb_host_controller_driver
  41. * @{
  42. */
  43. /*! @brief USB host controller control code */
  44. typedef enum _usb_host_controller_control
  45. {
  46. kUSB_HostCancelTransfer = 1U, /*!< Cancel transfer code */
  47. kUSB_HostBusControl, /*!< Bus control code */
  48. kUSB_HostGetFrameNumber, /*!< Get frame number code */
  49. kUSB_HostUpdateControlEndpointAddress, /*!< Update control endpoint address */
  50. kUSB_HostUpdateControlPacketSize, /*!< Update control endpoint maximum packet size */
  51. kUSB_HostPortAttachDisable, /*!< Disable the port attach event */
  52. kUSB_HostPortAttachEnable, /*!< Enable the port attach event */
  53. kUSB_HostL1Config, /*!< L1 suspend Bus control code */
  54. } usb_host_controller_control_t;
  55. /*! @brief USB host controller bus control code */
  56. typedef enum _usb_host_bus_control
  57. {
  58. kUSB_HostBusReset = 1U, /*!< Reset bus */
  59. kUSB_HostBusRestart, /*!< Restart bus */
  60. kUSB_HostBusEnableAttach, /*!< Enable attach */
  61. kUSB_HostBusDisableAttach, /*!< Disable attach */
  62. kUSB_HostBusSuspend, /*!< Suspend BUS */
  63. kUSB_HostBusResume, /*!< Resume BUS */
  64. kUSB_HostBusL1SuspendInit, /*!< L1 Suspend BUS */
  65. kUSB_HostBusL1Sleep, /*!< L1 Suspend BUS */
  66. kUSB_HostBusL1Resume, /*!< L1 Resume BUS */
  67. } usb_host_bus_control_t;
  68. /*! @brief USB host controller interface structure */
  69. typedef struct _usb_host_controller_interface
  70. {
  71. usb_status_t (*controllerCreate)(
  72. uint8_t controllerId,
  73. usb_host_handle upperLayerHandle,
  74. usb_host_controller_handle *controllerHandle); /*!< Create a controller instance function prototype*/
  75. usb_status_t (*controllerDestory)(
  76. usb_host_controller_handle controllerHandle); /*!< Destroy a controller instance function prototype*/
  77. usb_status_t (*controllerOpenPipe)(usb_host_controller_handle controllerHandle,
  78. usb_host_pipe_handle *pipeHandle,
  79. usb_host_pipe_init_t *pipeInit); /*!< Open a controller pipe function prototype*/
  80. usb_status_t (*controllerClosePipe)(
  81. usb_host_controller_handle controllerHandle,
  82. usb_host_pipe_handle pipeHandle); /*!< Close a controller pipe function prototype*/
  83. usb_status_t (*controllerWritePipe)(usb_host_controller_handle controllerHandle,
  84. usb_host_pipe_handle pipeHandle,
  85. usb_host_transfer_t *transfer); /*!< Write data to a pipe function prototype*/
  86. usb_status_t (*controllerReadPipe)(usb_host_controller_handle controllerHandle,
  87. usb_host_pipe_handle pipeHandle,
  88. usb_host_transfer_t *transfer); /*!< Read data from a pipe function prototype*/
  89. usb_status_t (*controllerIoctl)(usb_host_controller_handle controllerHandle,
  90. uint32_t ioctlEvent,
  91. void *ioctlParam); /*!< Control a controller function prototype*/
  92. } usb_host_controller_interface_t;
  93. /*! @}*/
  94. /*!
  95. * @addtogroup usb_host_drv
  96. * @{
  97. */
  98. /*! @brief USB host instance structure */
  99. typedef struct _usb_host_instance
  100. {
  101. void *controllerHandle; /*!< The low level controller handle*/
  102. host_callback_t deviceCallback; /*!< Device attach/detach callback*/
  103. usb_osa_mutex_handle hostMutex; /*!< Host layer mutex*/
  104. usb_host_transfer_t transferList[USB_HOST_CONFIG_MAX_TRANSFERS]; /*!< Transfer resource*/
  105. usb_host_transfer_t *transferHead; /*!< Idle transfer head*/
  106. const usb_host_controller_interface_t *controllerTable; /*!< KHCI/EHCI interface*/
  107. void *deviceList; /*!< Device list*/
  108. #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
  109. void *suspendedDevice; /*!< Suspended device handle*/
  110. volatile uint64_t hwTick; /*!< Current hw tick(ms)*/
  111. uint8_t sleepType; /*!< L1 LPM device handle*/
  112. #endif
  113. uint8_t addressBitMap[16]; /*!< Used for address allocation. The first bit is the address 1, second bit is the
  114. address 2*/
  115. uint8_t occupied; /*!< 0 - the instance is not occupied; 1 - the instance is occupied*/
  116. uint8_t controllerId; /*!< The controller ID*/
  117. } usb_host_instance_t;
  118. /*! @}*/
  119. #endif /* _USB_HOST_HCI_H_ */