NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UsbInc.h Source File

UsbInc.h

00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 #ifndef USB_INC_H
00025 #define USB_INC_H
00026 
00027 #include "mbed.h"
00028 
00029 #define MIN(a,b) ((a)<(b)?(a):(b))
00030 #define MAX(a,b) ((a)>(b)?(a):(b))
00031 
00032 //typedef int32_t RC;
00033 
00034 typedef uint8_t byte;
00035 typedef uint16_t word;
00036 
00037 enum UsbErr
00038 {
00039   __USBERR_MIN = -0xFFFF,
00040   USBERR_DISCONNECTED,
00041   USBERR_NOTFOUND,
00042   USBERR_BADCONFIG,
00043   USBERR_PROCESSING,
00044   USBERR_HALTED, //Transfer on an ep is stalled
00045   USBERR_BUSY,
00046   USBERR_TDFAIL,
00047   USBERR_ERROR,
00048   USBERR_OK = 0
00049 };
00050 
00051 
00052 /* From NXP's USBHostLite stack's usbhost_lpc17xx.h */
00053 /* Only the types names have been changed to avoid unecessary typedefs */
00054 
00055 
00056 /*
00057 **************************************************************************************************************
00058 *                                                 NXP USB Host Stack
00059 *
00060 *                                     (c) Copyright 2008, NXP SemiConductors
00061 *                                     (c) Copyright 2008, OnChip  Technologies LLC
00062 *                                                 All Rights Reserved
00063 *
00064 *                                                  www.nxp.com
00065 *                                               www.onchiptech.com
00066 *
00067 * File           : usbhost_lpc17xx.h
00068 * Programmer(s)  : Ravikanth.P
00069 * Version        :
00070 *
00071 **************************************************************************************************************
00072 */
00073 
00074 
00075 
00076 /*
00077 **************************************************************************************************************
00078 *                                  OHCI OPERATIONAL REGISTER FIELD DEFINITIONS
00079 **************************************************************************************************************
00080 */
00081 
00082                                             /* ------------------ HcControl Register ---------------------  */
00083 #define  OR_CONTROL_CLE                 0x00000010
00084 #define  OR_CONTROL_BLE                 0x00000020
00085 #define  OR_CONTROL_HCFS                0x000000C0
00086 #define  OR_CONTROL_HC_OPER             0x00000080
00087                                             /* ----------------- HcCommandStatus Register ----------------- */
00088 #define  OR_CMD_STATUS_HCR              0x00000001
00089 #define  OR_CMD_STATUS_CLF              0x00000002
00090 #define  OR_CMD_STATUS_BLF              0x00000004
00091                                             /* --------------- HcInterruptStatus Register ----------------- */
00092 #define  OR_INTR_STATUS_WDH             0x00000002
00093 #define  OR_INTR_STATUS_RHSC            0x00000040
00094 #define  OR_INTR_STATUS_UE              0x00000010
00095                                             /* --------------- HcInterruptEnable Register ----------------- */
00096 #define  OR_INTR_ENABLE_WDH             0x00000002
00097 #define  OR_INTR_ENABLE_RHSC            0x00000040
00098 #define  OR_INTR_ENABLE_MIE             0x80000000
00099                                             /* ---------------- HcRhDescriptorA Register ------------------ */
00100 #define  OR_RH_STATUS_LPSC              0x00010000
00101 #define  OR_RH_STATUS_DRWE              0x00008000
00102                                             /* -------------- HcRhPortStatus[1:NDP] Register -------------- */
00103 #define  OR_RH_PORT_CCS                 0x00000001
00104 #define  OR_RH_PORT_PRS                 0x00000010
00105 #define  OR_RH_PORT_CSC                 0x00010000
00106 #define  OR_RH_PORT_PRSC                0x00100000
00107 
00108 
00109 /*
00110 **************************************************************************************************************
00111 *                                               FRAME INTERVAL
00112 **************************************************************************************************************
00113 */
00114 
00115 #define  FI                     0x2EDF           /* 12000 bits per frame (-1)                               */
00116 #define  DEFAULT_FMINTERVAL     ((((6 * (FI - 210)) / 7) << 16) | FI)
00117 
00118 /*
00119 **************************************************************************************************************
00120 *                                       ENDPOINT DESCRIPTOR CONTROL FIELDS
00121 **************************************************************************************************************
00122 */
00123 
00124 #define  ED_SKIP            (uint32_t) (0x00001000)        /* Skip this ep in queue                       */
00125 
00126 /*
00127 **************************************************************************************************************
00128 *                                       TRANSFER DESCRIPTOR CONTROL FIELDS
00129 **************************************************************************************************************
00130 */
00131 
00132 #define  TD_ROUNDING        (uint32_t) (0x00040000)        /* Buffer Rounding                             */
00133 #define  TD_SETUP           (uint32_t)(0)                  /* Direction of Setup Packet                   */
00134 #define  TD_IN              (uint32_t)(0x00100000)         /* Direction In                                */
00135 #define  TD_OUT             (uint32_t)(0x00080000)         /* Direction Out                               */
00136 #define  TD_DELAY_INT(x)    (uint32_t)((x) << 21)          /* Delay Interrupt                             */
00137 #define  TD_TOGGLE_0        (uint32_t)(0x02000000)         /* Toggle 0                                    */
00138 #define  TD_TOGGLE_1        (uint32_t)(0x03000000)         /* Toggle 1                                    */
00139 #define  TD_CC              (uint32_t)(0xF0000000)         /* Completion Code                             */
00140 
00141 /*
00142 **************************************************************************************************************
00143 *                                       USB STANDARD REQUEST DEFINITIONS
00144 **************************************************************************************************************
00145 */
00146 
00147 #define  USB_DESCRIPTOR_TYPE_DEVICE                     1
00148 #define  USB_DESCRIPTOR_TYPE_CONFIGURATION              2
00149 #define  USB_DESCRIPTOR_TYPE_INTERFACE                  4
00150 #define  USB_DESCRIPTOR_TYPE_ENDPOINT                   5
00151                                                     /*  ----------- Control RequestType Fields  ----------- */
00152 #define  USB_DEVICE_TO_HOST         0x80
00153 #define  USB_HOST_TO_DEVICE         0x00
00154 #define  USB_REQUEST_TYPE_CLASS     0x20
00155 #define  USB_RECIPIENT_DEVICE       0x00
00156 #define  USB_RECIPIENT_INTERFACE    0x01
00157                                                     /* -------------- USB Standard Requests  -------------- */
00158 #define  SET_ADDRESS                 5
00159 #define  GET_DESCRIPTOR              6
00160 #define  SET_CONFIGURATION           9
00161 #define  SET_INTERFACE              11
00162 
00163 /*
00164 **************************************************************************************************************
00165 *                                       TYPE DEFINITIONS
00166 **************************************************************************************************************
00167 */
00168 
00169 typedef struct hcEd {                       /* ----------- HostController EndPoint Descriptor ------------- */
00170     volatile  uint32_t  Control;              /* Endpoint descriptor control                              */
00171     volatile  uint32_t  TailTd;               /* Physical address of tail in Transfer descriptor list     */
00172     volatile  uint32_t  HeadTd;               /* Physcial address of head in Transfer descriptor list     */
00173     volatile  uint32_t  Next;                 /* Physical address of next Endpoint descriptor             */
00174 } HCED;
00175 
00176 typedef struct hcTd {                       /* ------------ HostController Transfer Descriptor ------------ */
00177     volatile  uint32_t  Control;              /* Transfer descriptor control                              */
00178     volatile  uint32_t  CurrBufPtr;           /* Physical address of current buffer pointer               */
00179     volatile  uint32_t  Next;                 /* Physical pointer to next Transfer Descriptor             */
00180     volatile  uint32_t  BufEnd;               /* Physical address of end of buffer                        */
00181 } HCTD;
00182 
00183 typedef struct hcca {                       /* ----------- Host Controller Communication Area ------------  */
00184     volatile  uint32_t  IntTable[32];         /* Interrupt Table                                          */
00185     volatile  uint32_t  FrameNumber;          /* Frame Number                                             */
00186     volatile  uint32_t  DoneHead;             /* Done Head                                                */
00187     volatile  uint8_t  Reserved[116];        /* Reserved for future use                                  */
00188     volatile  uint8_t  Unknown[4];           /* Unused                                                   */
00189 } HCCA;
00190 
00191 
00192 
00193 #endif