Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Wed Dec 15 18:01:30 2010 +0000
Revision:
7:4e2468d7d5cb
Parent:
0:ac1725ba162c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
segundo 0:ac1725ba162c 1
segundo 0:ac1725ba162c 2 /*
segundo 0:ac1725ba162c 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
segundo 0:ac1725ba162c 4
segundo 0:ac1725ba162c 5 Permission is hereby granted, free of charge, to any person obtaining a copy
segundo 0:ac1725ba162c 6 of this software and associated documentation files (the "Software"), to deal
segundo 0:ac1725ba162c 7 in the Software without restriction, including without limitation the rights
segundo 0:ac1725ba162c 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
segundo 0:ac1725ba162c 9 copies of the Software, and to permit persons to whom the Software is
segundo 0:ac1725ba162c 10 furnished to do so, subject to the following conditions:
segundo 0:ac1725ba162c 11
segundo 0:ac1725ba162c 12 The above copyright notice and this permission notice shall be included in
segundo 0:ac1725ba162c 13 all copies or substantial portions of the Software.
segundo 0:ac1725ba162c 14
segundo 0:ac1725ba162c 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
segundo 0:ac1725ba162c 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
segundo 0:ac1725ba162c 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
segundo 0:ac1725ba162c 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
segundo 0:ac1725ba162c 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
segundo 0:ac1725ba162c 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
segundo 0:ac1725ba162c 21 THE SOFTWARE.
segundo 0:ac1725ba162c 22 */
segundo 0:ac1725ba162c 23
segundo 0:ac1725ba162c 24 #ifndef USB_INC_H
segundo 0:ac1725ba162c 25 #define USB_INC_H
segundo 0:ac1725ba162c 26
segundo 0:ac1725ba162c 27 #include "mbed.h"
segundo 0:ac1725ba162c 28
segundo 0:ac1725ba162c 29 #define MIN(a,b) ((a)<(b)?(a):(b))
segundo 0:ac1725ba162c 30 #define MAX(a,b) ((a)>(b)?(a):(b))
segundo 0:ac1725ba162c 31
segundo 0:ac1725ba162c 32 //typedef int32_t RC;
segundo 0:ac1725ba162c 33
segundo 0:ac1725ba162c 34 typedef uint8_t byte;
segundo 0:ac1725ba162c 35 typedef uint16_t word;
segundo 0:ac1725ba162c 36
segundo 0:ac1725ba162c 37 enum UsbErr
segundo 0:ac1725ba162c 38 {
segundo 0:ac1725ba162c 39 __USBERR_MIN = -0xFFFF,
segundo 0:ac1725ba162c 40 USBERR_DISCONNECTED,
segundo 0:ac1725ba162c 41 USBERR_NOTFOUND,
segundo 0:ac1725ba162c 42 USBERR_BADCONFIG,
segundo 0:ac1725ba162c 43 USBERR_PROCESSING,
segundo 0:ac1725ba162c 44 USBERR_HALTED, //Transfer on an ep is stalled
segundo 0:ac1725ba162c 45 USBERR_BUSY,
segundo 0:ac1725ba162c 46 USBERR_TDFAIL,
segundo 0:ac1725ba162c 47 USBERR_ERROR,
segundo 0:ac1725ba162c 48 USBERR_OK = 0
segundo 0:ac1725ba162c 49 };
segundo 0:ac1725ba162c 50
segundo 0:ac1725ba162c 51
segundo 0:ac1725ba162c 52 /* From NXP's USBHostLite stack's usbhost_lpc17xx.h */
segundo 0:ac1725ba162c 53 /* Only the types names have been changed to avoid unecessary typedefs */
segundo 0:ac1725ba162c 54
segundo 0:ac1725ba162c 55
segundo 0:ac1725ba162c 56 /*
segundo 0:ac1725ba162c 57 **************************************************************************************************************
segundo 0:ac1725ba162c 58 * NXP USB Host Stack
segundo 0:ac1725ba162c 59 *
segundo 0:ac1725ba162c 60 * (c) Copyright 2008, NXP SemiConductors
segundo 0:ac1725ba162c 61 * (c) Copyright 2008, OnChip Technologies LLC
segundo 0:ac1725ba162c 62 * All Rights Reserved
segundo 0:ac1725ba162c 63 *
segundo 0:ac1725ba162c 64 * www.nxp.com
segundo 0:ac1725ba162c 65 * www.onchiptech.com
segundo 0:ac1725ba162c 66 *
segundo 0:ac1725ba162c 67 * File : usbhost_lpc17xx.h
segundo 0:ac1725ba162c 68 * Programmer(s) : Ravikanth.P
segundo 0:ac1725ba162c 69 * Version :
segundo 0:ac1725ba162c 70 *
segundo 0:ac1725ba162c 71 **************************************************************************************************************
segundo 0:ac1725ba162c 72 */
segundo 0:ac1725ba162c 73
segundo 0:ac1725ba162c 74
segundo 0:ac1725ba162c 75
segundo 0:ac1725ba162c 76 /*
segundo 0:ac1725ba162c 77 **************************************************************************************************************
segundo 0:ac1725ba162c 78 * OHCI OPERATIONAL REGISTER FIELD DEFINITIONS
segundo 0:ac1725ba162c 79 **************************************************************************************************************
segundo 0:ac1725ba162c 80 */
segundo 0:ac1725ba162c 81
segundo 0:ac1725ba162c 82 /* ------------------ HcControl Register --------------------- */
segundo 0:ac1725ba162c 83 #define OR_CONTROL_CLE 0x00000010
segundo 0:ac1725ba162c 84 #define OR_CONTROL_BLE 0x00000020
segundo 0:ac1725ba162c 85 #define OR_CONTROL_HCFS 0x000000C0
segundo 0:ac1725ba162c 86 #define OR_CONTROL_HC_OPER 0x00000080
segundo 0:ac1725ba162c 87 /* ----------------- HcCommandStatus Register ----------------- */
segundo 0:ac1725ba162c 88 #define OR_CMD_STATUS_HCR 0x00000001
segundo 0:ac1725ba162c 89 #define OR_CMD_STATUS_CLF 0x00000002
segundo 0:ac1725ba162c 90 #define OR_CMD_STATUS_BLF 0x00000004
segundo 0:ac1725ba162c 91 /* --------------- HcInterruptStatus Register ----------------- */
segundo 0:ac1725ba162c 92 #define OR_INTR_STATUS_WDH 0x00000002
segundo 0:ac1725ba162c 93 #define OR_INTR_STATUS_RHSC 0x00000040
segundo 0:ac1725ba162c 94 #define OR_INTR_STATUS_UE 0x00000010
segundo 0:ac1725ba162c 95 /* --------------- HcInterruptEnable Register ----------------- */
segundo 0:ac1725ba162c 96 #define OR_INTR_ENABLE_WDH 0x00000002
segundo 0:ac1725ba162c 97 #define OR_INTR_ENABLE_RHSC 0x00000040
segundo 0:ac1725ba162c 98 #define OR_INTR_ENABLE_MIE 0x80000000
segundo 0:ac1725ba162c 99 /* ---------------- HcRhDescriptorA Register ------------------ */
segundo 0:ac1725ba162c 100 #define OR_RH_STATUS_LPSC 0x00010000
segundo 0:ac1725ba162c 101 #define OR_RH_STATUS_DRWE 0x00008000
segundo 0:ac1725ba162c 102 /* -------------- HcRhPortStatus[1:NDP] Register -------------- */
segundo 0:ac1725ba162c 103 #define OR_RH_PORT_CCS 0x00000001
segundo 0:ac1725ba162c 104 #define OR_RH_PORT_PRS 0x00000010
segundo 0:ac1725ba162c 105 #define OR_RH_PORT_CSC 0x00010000
segundo 0:ac1725ba162c 106 #define OR_RH_PORT_PRSC 0x00100000
segundo 0:ac1725ba162c 107
segundo 0:ac1725ba162c 108
segundo 0:ac1725ba162c 109 /*
segundo 0:ac1725ba162c 110 **************************************************************************************************************
segundo 0:ac1725ba162c 111 * FRAME INTERVAL
segundo 0:ac1725ba162c 112 **************************************************************************************************************
segundo 0:ac1725ba162c 113 */
segundo 0:ac1725ba162c 114
segundo 0:ac1725ba162c 115 #define FI 0x2EDF /* 12000 bits per frame (-1) */
segundo 0:ac1725ba162c 116 #define DEFAULT_FMINTERVAL ((((6 * (FI - 210)) / 7) << 16) | FI)
segundo 0:ac1725ba162c 117
segundo 0:ac1725ba162c 118 /*
segundo 0:ac1725ba162c 119 **************************************************************************************************************
segundo 0:ac1725ba162c 120 * ENDPOINT DESCRIPTOR CONTROL FIELDS
segundo 0:ac1725ba162c 121 **************************************************************************************************************
segundo 0:ac1725ba162c 122 */
segundo 0:ac1725ba162c 123
segundo 0:ac1725ba162c 124 #define ED_SKIP (uint32_t) (0x00001000) /* Skip this ep in queue */
segundo 0:ac1725ba162c 125
segundo 0:ac1725ba162c 126 /*
segundo 0:ac1725ba162c 127 **************************************************************************************************************
segundo 0:ac1725ba162c 128 * TRANSFER DESCRIPTOR CONTROL FIELDS
segundo 0:ac1725ba162c 129 **************************************************************************************************************
segundo 0:ac1725ba162c 130 */
segundo 0:ac1725ba162c 131
segundo 0:ac1725ba162c 132 #define TD_ROUNDING (uint32_t) (0x00040000) /* Buffer Rounding */
segundo 0:ac1725ba162c 133 #define TD_SETUP (uint32_t)(0) /* Direction of Setup Packet */
segundo 0:ac1725ba162c 134 #define TD_IN (uint32_t)(0x00100000) /* Direction In */
segundo 0:ac1725ba162c 135 #define TD_OUT (uint32_t)(0x00080000) /* Direction Out */
segundo 0:ac1725ba162c 136 #define TD_DELAY_INT(x) (uint32_t)((x) << 21) /* Delay Interrupt */
segundo 0:ac1725ba162c 137 #define TD_TOGGLE_0 (uint32_t)(0x02000000) /* Toggle 0 */
segundo 0:ac1725ba162c 138 #define TD_TOGGLE_1 (uint32_t)(0x03000000) /* Toggle 1 */
segundo 0:ac1725ba162c 139 #define TD_CC (uint32_t)(0xF0000000) /* Completion Code */
segundo 0:ac1725ba162c 140
segundo 0:ac1725ba162c 141 /*
segundo 0:ac1725ba162c 142 **************************************************************************************************************
segundo 0:ac1725ba162c 143 * USB STANDARD REQUEST DEFINITIONS
segundo 0:ac1725ba162c 144 **************************************************************************************************************
segundo 0:ac1725ba162c 145 */
segundo 0:ac1725ba162c 146
segundo 0:ac1725ba162c 147 #define USB_DESCRIPTOR_TYPE_DEVICE 1
segundo 0:ac1725ba162c 148 #define USB_DESCRIPTOR_TYPE_CONFIGURATION 2
segundo 0:ac1725ba162c 149 #define USB_DESCRIPTOR_TYPE_INTERFACE 4
segundo 0:ac1725ba162c 150 #define USB_DESCRIPTOR_TYPE_ENDPOINT 5
segundo 0:ac1725ba162c 151 /* ----------- Control RequestType Fields ----------- */
segundo 0:ac1725ba162c 152 #define USB_DEVICE_TO_HOST 0x80
segundo 0:ac1725ba162c 153 #define USB_HOST_TO_DEVICE 0x00
segundo 0:ac1725ba162c 154 #define USB_REQUEST_TYPE_CLASS 0x20
segundo 0:ac1725ba162c 155 #define USB_RECIPIENT_DEVICE 0x00
segundo 0:ac1725ba162c 156 #define USB_RECIPIENT_INTERFACE 0x01
segundo 0:ac1725ba162c 157 /* -------------- USB Standard Requests -------------- */
segundo 0:ac1725ba162c 158 #define SET_ADDRESS 5
segundo 0:ac1725ba162c 159 #define GET_DESCRIPTOR 6
segundo 0:ac1725ba162c 160 #define SET_CONFIGURATION 9
segundo 0:ac1725ba162c 161 #define SET_INTERFACE 11
segundo 0:ac1725ba162c 162
segundo 0:ac1725ba162c 163 /*
segundo 0:ac1725ba162c 164 **************************************************************************************************************
segundo 0:ac1725ba162c 165 * TYPE DEFINITIONS
segundo 0:ac1725ba162c 166 **************************************************************************************************************
segundo 0:ac1725ba162c 167 */
segundo 0:ac1725ba162c 168
segundo 0:ac1725ba162c 169 typedef struct hcEd { /* ----------- HostController EndPoint Descriptor ------------- */
segundo 0:ac1725ba162c 170 volatile uint32_t Control; /* Endpoint descriptor control */
segundo 0:ac1725ba162c 171 volatile uint32_t TailTd; /* Physical address of tail in Transfer descriptor list */
segundo 0:ac1725ba162c 172 volatile uint32_t HeadTd; /* Physcial address of head in Transfer descriptor list */
segundo 0:ac1725ba162c 173 volatile uint32_t Next; /* Physical address of next Endpoint descriptor */
segundo 0:ac1725ba162c 174 } HCED;
segundo 0:ac1725ba162c 175
segundo 0:ac1725ba162c 176 typedef struct hcTd { /* ------------ HostController Transfer Descriptor ------------ */
segundo 0:ac1725ba162c 177 volatile uint32_t Control; /* Transfer descriptor control */
segundo 0:ac1725ba162c 178 volatile uint32_t CurrBufPtr; /* Physical address of current buffer pointer */
segundo 0:ac1725ba162c 179 volatile uint32_t Next; /* Physical pointer to next Transfer Descriptor */
segundo 0:ac1725ba162c 180 volatile uint32_t BufEnd; /* Physical address of end of buffer */
segundo 0:ac1725ba162c 181 } HCTD;
segundo 0:ac1725ba162c 182
segundo 0:ac1725ba162c 183 typedef struct hcca { /* ----------- Host Controller Communication Area ------------ */
segundo 0:ac1725ba162c 184 volatile uint32_t IntTable[32]; /* Interrupt Table */
segundo 0:ac1725ba162c 185 volatile uint32_t FrameNumber; /* Frame Number */
segundo 0:ac1725ba162c 186 volatile uint32_t DoneHead; /* Done Head */
segundo 0:ac1725ba162c 187 volatile uint8_t Reserved[116]; /* Reserved for future use */
segundo 0:ac1725ba162c 188 volatile uint8_t Unknown[4]; /* Unused */
segundo 0:ac1725ba162c 189 } HCCA;
segundo 0:ac1725ba162c 190
segundo 0:ac1725ba162c 191
segundo 0:ac1725ba162c 192
segundo 0:ac1725ba162c 193 #endif