usb_host_hci.h 5.6 KB

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