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_H__ 32 #define __USB_H__ 33 34 #include <stdint.h> 35 #include <stdio.h> 36 #include <fsl_common.h> 37 #include <fsl_os_abstraction.h> 38 #include "usb_misc.h" 39 #include "usb_spec.h" 40 41 /*! 42 * @addtogroup usb_drv 43 * @{ 44 */ 45 46 /******************************************************************************* 47 * Definitions 48 ******************************************************************************/ 49 /*! @brief Defines USB stack major version */ 50 #define USB_STACK_VERSION_MAJOR (1U) 51 /*! @brief Defines USB stack minor version */ 52 #define USB_STACK_VERSION_MINOR (6U) 53 /*! @brief Defines USB stack bugfix version */ 54 #define USB_STACK_VERSION_BUGFIX (3U) 55 56 /*! @brief USB stack version definition */ 57 #define USB_MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix)) 58 59 /*! @brief USB stack component version definition, changed with component in yaml together */ 60 #define USB_STACK_COMPONENT_VERSION \ 61 MAKE_VERSION(USB_STACK_VERSION_MAJOR, USB_STACK_VERSION_MINOR, USB_STACK_VERSION_BUGFIX) 62 63 /* 64 * Component ID used by tools 65 * 66 * FSL_COMPONENT_ID "middleware.usb.stack_common" 67 */ 68 69 /*! @brief USB error code */ 70 typedef enum _usb_status 71 { 72 kStatus_USB_Success = 0x00U, /*!< Success */ 73 kStatus_USB_Error, /*!< Failed */ 74 75 kStatus_USB_Busy, /*!< Busy */ 76 kStatus_USB_InvalidHandle, /*!< Invalid handle */ 77 kStatus_USB_InvalidParameter, /*!< Invalid parameter */ 78 kStatus_USB_InvalidRequest, /*!< Invalid request */ 79 kStatus_USB_ControllerNotFound, /*!< Controller cannot be found */ 80 kStatus_USB_InvalidControllerInterface, /*!< Invalid controller interface */ 81 82 kStatus_USB_NotSupported, /*!< Configuration is not supported */ 83 kStatus_USB_Retry, /*!< Enumeration get configuration retry */ 84 kStatus_USB_TransferStall, /*!< Transfer stalled */ 85 kStatus_USB_TransferFailed, /*!< Transfer failed */ 86 kStatus_USB_AllocFail, /*!< Allocation failed */ 87 kStatus_USB_LackSwapBuffer, /*!< Insufficient swap buffer for KHCI */ 88 kStatus_USB_TransferCancel, /*!< The transfer cancelled */ 89 kStatus_USB_BandwidthFail, /*!< Allocate bandwidth failed */ 90 kStatus_USB_MSDStatusFail, /*!< For MSD, the CSW status means fail */ 91 kStatus_USB_EHCIAttached, 92 kStatus_USB_EHCIDetached, 93 kStatus_USB_DataOverRun, /*!< The amount of data returned by the endpoint exceeded 94 either the size of the maximum data packet allowed 95 from the endpoint or the remaining buffer size. */ 96 } usb_status_t; 97 98 /*! @brief USB host handle type define */ 99 typedef void *usb_host_handle; 100 101 /*! @brief USB device handle type define. For device stack it is the whole device handle; for host stack it is the 102 * attached device instance handle*/ 103 typedef void *usb_device_handle; 104 105 /*! @brief USB OTG handle type define */ 106 typedef void *usb_otg_handle; 107 108 /*! @brief USB controller ID */ 109 typedef enum _usb_controller_index 110 { 111 kUSB_ControllerKhci0 = 0U, /*!< KHCI 0U */ 112 kUSB_ControllerKhci1 = 1U, /*!< KHCI 1U, Currently, there are no platforms which have two KHCI IPs, this is reserved 113 to be used in the future. */ 114 kUSB_ControllerEhci0 = 2U, /*!< EHCI 0U */ 115 kUSB_ControllerEhci1 = 3U, /*!< EHCI 1U, Currently, there are no platforms which have two EHCI IPs, this is reserved 116 to be used in the future. */ 117 118 kUSB_ControllerLpcIp3511Fs0 = 4U, /*!< LPC USB IP3511 FS controller 0 */ 119 kUSB_ControllerLpcIp3511Fs1 = 5U, /*!< LPC USB IP3511 FS controller 1, there are no platforms which have two IP3511 120 IPs, this is reserved to be used in the future. */ 121 122 kUSB_ControllerLpcIp3511Hs0 = 6U, /*!< LPC USB IP3511 HS controller 0 */ 123 kUSB_ControllerLpcIp3511Hs1 = 7U, /*!< LPC USB IP3511 HS controller 1, there are no platforms which have two IP3511 124 IPs, this is reserved to be used in the future. */ 125 126 kUSB_ControllerOhci0 = 8U, /*!< OHCI 0U */ 127 kUSB_ControllerOhci1 = 9U, /*!< OHCI 1U, Currently, there are no platforms which have two OHCI IPs, this is reserved 128 to be used in the future. */ 129 130 kUSB_ControllerIp3516Hs0 = 10U, /*!< IP3516HS 0U */ 131 kUSB_ControllerIp3516Hs1 = 11U, /*!< IP3516HS 1U, Currently, there are no platforms which have two IP3516HS IPs, 132 this is reserved to be used in the future. */ 133 kUSB_ControllerDwc30 = 12U, /*!< DWC3 0U */ 134 kUSB_ControllerDwc31 = 13U, /*!< DWC3 1U Currently, there are no platforms which have two Dwc IPs, this is reserved 135 to be used in the future.*/ 136 } usb_controller_index_t; 137 138 /** 139 * @brief USB stack version fields 140 */ 141 typedef struct _usb_version 142 { 143 uint8_t major; /*!< Major */ 144 uint8_t minor; /*!< Minor */ 145 uint8_t bugfix; /*!< Bug fix */ 146 } usb_version_t; 147 148 /******************************************************************************* 149 * API 150 ******************************************************************************/ 151 152 /*! @} */ 153 154 #endif /* __USB_H__ */ 155