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