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