SD

Dependents:   Andar_Linha_Reta_Robo_Claw_v1

Fork of MSCFileSystem by Chris Styles

Committer:
carlos_nascimento08
Date:
Sun Sep 16 15:00:33 2012 +0000
Revision:
5:59daf2b48180
Parent:
0:3e7d2baed4b4
USB;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
carlos_nascimento08 5:59daf2b48180 1 /*
carlos_nascimento08 5:59daf2b48180 2 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 3 * NXP USB Host Stack
carlos_nascimento08 5:59daf2b48180 4 *
carlos_nascimento08 5:59daf2b48180 5 * (c) Copyright 2008, NXP SemiConductors
carlos_nascimento08 5:59daf2b48180 6 * (c) Copyright 2008, OnChip Technologies LLC
carlos_nascimento08 5:59daf2b48180 7 * All Rights Reserved
carlos_nascimento08 5:59daf2b48180 8 *
carlos_nascimento08 5:59daf2b48180 9 * www.nxp.com
carlos_nascimento08 5:59daf2b48180 10 * www.onchiptech.com
carlos_nascimento08 5:59daf2b48180 11 *
carlos_nascimento08 5:59daf2b48180 12 * File : usbhost_lpc17xx.h
carlos_nascimento08 5:59daf2b48180 13 * Programmer(s) : Ravikanth.P
carlos_nascimento08 5:59daf2b48180 14 * Version :
carlos_nascimento08 5:59daf2b48180 15 *
carlos_nascimento08 5:59daf2b48180 16 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 17 */
carlos_nascimento08 5:59daf2b48180 18
carlos_nascimento08 5:59daf2b48180 19 #ifndef USBHOST_LPC17xx_H
carlos_nascimento08 5:59daf2b48180 20 #define USBHOST_LPC17xx_H
carlos_nascimento08 5:59daf2b48180 21
carlos_nascimento08 5:59daf2b48180 22 /*
carlos_nascimento08 5:59daf2b48180 23 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 24 * INCLUDE HEADER FILES
carlos_nascimento08 5:59daf2b48180 25 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 26 */
carlos_nascimento08 5:59daf2b48180 27
carlos_nascimento08 5:59daf2b48180 28 #include "usbhost_inc.h"
carlos_nascimento08 5:59daf2b48180 29
carlos_nascimento08 5:59daf2b48180 30 /*
carlos_nascimento08 5:59daf2b48180 31 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 32 * PRINT CONFIGURATION
carlos_nascimento08 5:59daf2b48180 33 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 34 */
carlos_nascimento08 5:59daf2b48180 35
carlos_nascimento08 5:59daf2b48180 36 #define PRINT_ENABLE 1
carlos_nascimento08 5:59daf2b48180 37
carlos_nascimento08 5:59daf2b48180 38 #if PRINT_ENABLE
carlos_nascimento08 5:59daf2b48180 39 #define PRINT_Log(...) printf(__VA_ARGS__)
carlos_nascimento08 5:59daf2b48180 40 #define PRINT_Err(rc) printf("ERROR: In %s at Line %u - rc = %d\n", __FUNCTION__, __LINE__, rc)
carlos_nascimento08 5:59daf2b48180 41
carlos_nascimento08 5:59daf2b48180 42 #else
carlos_nascimento08 5:59daf2b48180 43 #define PRINT_Log(...) do {} while(0)
carlos_nascimento08 5:59daf2b48180 44 #define PRINT_Err(rc) do {} while(0)
carlos_nascimento08 5:59daf2b48180 45
carlos_nascimento08 5:59daf2b48180 46 #endif
carlos_nascimento08 5:59daf2b48180 47
carlos_nascimento08 5:59daf2b48180 48 /*
carlos_nascimento08 5:59daf2b48180 49 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 50 * GENERAL DEFINITIONS
carlos_nascimento08 5:59daf2b48180 51 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 52 */
carlos_nascimento08 5:59daf2b48180 53
carlos_nascimento08 5:59daf2b48180 54 #define DESC_LENGTH(x) x[0]
carlos_nascimento08 5:59daf2b48180 55 #define DESC_TYPE(x) x[1]
carlos_nascimento08 5:59daf2b48180 56
carlos_nascimento08 5:59daf2b48180 57
carlos_nascimento08 5:59daf2b48180 58 #define HOST_GET_DESCRIPTOR(descType, descIndex, data, length) \
carlos_nascimento08 5:59daf2b48180 59 Host_CtrlRecv(USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR, \
carlos_nascimento08 5:59daf2b48180 60 (descType << 8)|(descIndex), 0, length, data)
carlos_nascimento08 5:59daf2b48180 61
carlos_nascimento08 5:59daf2b48180 62 #define HOST_SET_ADDRESS(new_addr) \
carlos_nascimento08 5:59daf2b48180 63 Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_ADDRESS, \
carlos_nascimento08 5:59daf2b48180 64 new_addr, 0, 0, NULL)
carlos_nascimento08 5:59daf2b48180 65
carlos_nascimento08 5:59daf2b48180 66 #define USBH_SET_CONFIGURATION(configNum) \
carlos_nascimento08 5:59daf2b48180 67 Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_CONFIGURATION, \
carlos_nascimento08 5:59daf2b48180 68 configNum, 0, 0, NULL)
carlos_nascimento08 5:59daf2b48180 69
carlos_nascimento08 5:59daf2b48180 70 #define USBH_SET_INTERFACE(ifNum, altNum) \
carlos_nascimento08 5:59daf2b48180 71 Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE, SET_INTERFACE, \
carlos_nascimento08 5:59daf2b48180 72 altNum, ifNum, 0, NULL)
carlos_nascimento08 5:59daf2b48180 73
carlos_nascimento08 5:59daf2b48180 74 /*
carlos_nascimento08 5:59daf2b48180 75 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 76 * OHCI OPERATIONAL REGISTER FIELD DEFINITIONS
carlos_nascimento08 5:59daf2b48180 77 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 78 */
carlos_nascimento08 5:59daf2b48180 79
carlos_nascimento08 5:59daf2b48180 80 /* ------------------ HcControl Register --------------------- */
carlos_nascimento08 5:59daf2b48180 81 #define OR_CONTROL_CLE 0x00000010
carlos_nascimento08 5:59daf2b48180 82 #define OR_CONTROL_BLE 0x00000020
carlos_nascimento08 5:59daf2b48180 83 #define OR_CONTROL_HCFS 0x000000C0
carlos_nascimento08 5:59daf2b48180 84 #define OR_CONTROL_HC_OPER 0x00000080
carlos_nascimento08 5:59daf2b48180 85 /* ----------------- HcCommandStatus Register ----------------- */
carlos_nascimento08 5:59daf2b48180 86 #define OR_CMD_STATUS_HCR 0x00000001
carlos_nascimento08 5:59daf2b48180 87 #define OR_CMD_STATUS_CLF 0x00000002
carlos_nascimento08 5:59daf2b48180 88 #define OR_CMD_STATUS_BLF 0x00000004
carlos_nascimento08 5:59daf2b48180 89 /* --------------- HcInterruptStatus Register ----------------- */
carlos_nascimento08 5:59daf2b48180 90 #define OR_INTR_STATUS_WDH 0x00000002
carlos_nascimento08 5:59daf2b48180 91 #define OR_INTR_STATUS_RHSC 0x00000040
carlos_nascimento08 5:59daf2b48180 92 /* --------------- HcInterruptEnable Register ----------------- */
carlos_nascimento08 5:59daf2b48180 93 #define OR_INTR_ENABLE_WDH 0x00000002
carlos_nascimento08 5:59daf2b48180 94 #define OR_INTR_ENABLE_RHSC 0x00000040
carlos_nascimento08 5:59daf2b48180 95 #define OR_INTR_ENABLE_MIE 0x80000000
carlos_nascimento08 5:59daf2b48180 96 /* ---------------- HcRhDescriptorA Register ------------------ */
carlos_nascimento08 5:59daf2b48180 97 #define OR_RH_STATUS_LPSC 0x00010000
carlos_nascimento08 5:59daf2b48180 98 #define OR_RH_STATUS_DRWE 0x00008000
carlos_nascimento08 5:59daf2b48180 99 /* -------------- HcRhPortStatus[1:NDP] Register -------------- */
carlos_nascimento08 5:59daf2b48180 100 #define OR_RH_PORT_CCS 0x00000001
carlos_nascimento08 5:59daf2b48180 101 #define OR_RH_PORT_PRS 0x00000010
carlos_nascimento08 5:59daf2b48180 102 #define OR_RH_PORT_CSC 0x00010000
carlos_nascimento08 5:59daf2b48180 103 #define OR_RH_PORT_PRSC 0x00100000
carlos_nascimento08 5:59daf2b48180 104
carlos_nascimento08 5:59daf2b48180 105
carlos_nascimento08 5:59daf2b48180 106 /*
carlos_nascimento08 5:59daf2b48180 107 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 108 * FRAME INTERVAL
carlos_nascimento08 5:59daf2b48180 109 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 110 */
carlos_nascimento08 5:59daf2b48180 111
carlos_nascimento08 5:59daf2b48180 112 #define FI 0x2EDF /* 12000 bits per frame (-1) */
carlos_nascimento08 5:59daf2b48180 113 #define DEFAULT_FMINTERVAL ((((6 * (FI - 210)) / 7) << 16) | FI)
carlos_nascimento08 5:59daf2b48180 114
carlos_nascimento08 5:59daf2b48180 115 /*
carlos_nascimento08 5:59daf2b48180 116 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 117 * TRANSFER DESCRIPTOR CONTROL FIELDS
carlos_nascimento08 5:59daf2b48180 118 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 119 */
carlos_nascimento08 5:59daf2b48180 120
carlos_nascimento08 5:59daf2b48180 121 #define TD_ROUNDING (USB_INT32U) (0x00040000) /* Buffer Rounding */
carlos_nascimento08 5:59daf2b48180 122 #define TD_SETUP (USB_INT32U)(0) /* Direction of Setup Packet */
carlos_nascimento08 5:59daf2b48180 123 #define TD_IN (USB_INT32U)(0x00100000) /* Direction In */
carlos_nascimento08 5:59daf2b48180 124 #define TD_OUT (USB_INT32U)(0x00080000) /* Direction Out */
carlos_nascimento08 5:59daf2b48180 125 #define TD_DELAY_INT(x) (USB_INT32U)((x) << 21) /* Delay Interrupt */
carlos_nascimento08 5:59daf2b48180 126 #define TD_TOGGLE_0 (USB_INT32U)(0x02000000) /* Toggle 0 */
carlos_nascimento08 5:59daf2b48180 127 #define TD_TOGGLE_1 (USB_INT32U)(0x03000000) /* Toggle 1 */
carlos_nascimento08 5:59daf2b48180 128 #define TD_CC (USB_INT32U)(0xF0000000) /* Completion Code */
carlos_nascimento08 5:59daf2b48180 129
carlos_nascimento08 5:59daf2b48180 130 /*
carlos_nascimento08 5:59daf2b48180 131 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 132 * USB STANDARD REQUEST DEFINITIONS
carlos_nascimento08 5:59daf2b48180 133 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 134 */
carlos_nascimento08 5:59daf2b48180 135
carlos_nascimento08 5:59daf2b48180 136 #define USB_DESCRIPTOR_TYPE_DEVICE 1
carlos_nascimento08 5:59daf2b48180 137 #define USB_DESCRIPTOR_TYPE_CONFIGURATION 2
carlos_nascimento08 5:59daf2b48180 138 #define USB_DESCRIPTOR_TYPE_INTERFACE 4
carlos_nascimento08 5:59daf2b48180 139 #define USB_DESCRIPTOR_TYPE_ENDPOINT 5
carlos_nascimento08 5:59daf2b48180 140 /* ----------- Control RequestType Fields ----------- */
carlos_nascimento08 5:59daf2b48180 141 #define USB_DEVICE_TO_HOST 0x80
carlos_nascimento08 5:59daf2b48180 142 #define USB_HOST_TO_DEVICE 0x00
carlos_nascimento08 5:59daf2b48180 143 #define USB_REQUEST_TYPE_CLASS 0x20
carlos_nascimento08 5:59daf2b48180 144 #define USB_RECIPIENT_DEVICE 0x00
carlos_nascimento08 5:59daf2b48180 145 #define USB_RECIPIENT_INTERFACE 0x01
carlos_nascimento08 5:59daf2b48180 146 /* -------------- USB Standard Requests -------------- */
carlos_nascimento08 5:59daf2b48180 147 #define SET_ADDRESS 5
carlos_nascimento08 5:59daf2b48180 148 #define GET_DESCRIPTOR 6
carlos_nascimento08 5:59daf2b48180 149 #define SET_CONFIGURATION 9
carlos_nascimento08 5:59daf2b48180 150 #define SET_INTERFACE 11
carlos_nascimento08 5:59daf2b48180 151
carlos_nascimento08 5:59daf2b48180 152 /*
carlos_nascimento08 5:59daf2b48180 153 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 154 * TYPE DEFINITIONS
carlos_nascimento08 5:59daf2b48180 155 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 156 */
carlos_nascimento08 5:59daf2b48180 157
carlos_nascimento08 5:59daf2b48180 158 typedef struct hcEd { /* ----------- HostController EndPoint Descriptor ------------- */
carlos_nascimento08 5:59daf2b48180 159 volatile USB_INT32U Control; /* Endpoint descriptor control */
carlos_nascimento08 5:59daf2b48180 160 volatile USB_INT32U TailTd; /* Physical address of tail in Transfer descriptor list */
carlos_nascimento08 5:59daf2b48180 161 volatile USB_INT32U HeadTd; /* Physcial address of head in Transfer descriptor list */
carlos_nascimento08 5:59daf2b48180 162 volatile USB_INT32U Next; /* Physical address of next Endpoint descriptor */
carlos_nascimento08 5:59daf2b48180 163 } HCED;
carlos_nascimento08 5:59daf2b48180 164
carlos_nascimento08 5:59daf2b48180 165 typedef struct hcTd { /* ------------ HostController Transfer Descriptor ------------ */
carlos_nascimento08 5:59daf2b48180 166 volatile USB_INT32U Control; /* Transfer descriptor control */
carlos_nascimento08 5:59daf2b48180 167 volatile USB_INT32U CurrBufPtr; /* Physical address of current buffer pointer */
carlos_nascimento08 5:59daf2b48180 168 volatile USB_INT32U Next; /* Physical pointer to next Transfer Descriptor */
carlos_nascimento08 5:59daf2b48180 169 volatile USB_INT32U BufEnd; /* Physical address of end of buffer */
carlos_nascimento08 5:59daf2b48180 170 } HCTD;
carlos_nascimento08 5:59daf2b48180 171
carlos_nascimento08 5:59daf2b48180 172 typedef struct hcca { /* ----------- Host Controller Communication Area ------------ */
carlos_nascimento08 5:59daf2b48180 173 volatile USB_INT32U IntTable[32]; /* Interrupt Table */
carlos_nascimento08 5:59daf2b48180 174 volatile USB_INT32U FrameNumber; /* Frame Number */
carlos_nascimento08 5:59daf2b48180 175 volatile USB_INT32U DoneHead; /* Done Head */
carlos_nascimento08 5:59daf2b48180 176 volatile USB_INT08U Reserved[116]; /* Reserved for future use */
carlos_nascimento08 5:59daf2b48180 177 volatile USB_INT08U Unknown[4]; /* Unused */
carlos_nascimento08 5:59daf2b48180 178 } HCCA;
carlos_nascimento08 5:59daf2b48180 179
carlos_nascimento08 5:59daf2b48180 180 /*
carlos_nascimento08 5:59daf2b48180 181 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 182 * EXTERN DECLARATIONS
carlos_nascimento08 5:59daf2b48180 183 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 184 */
carlos_nascimento08 5:59daf2b48180 185
carlos_nascimento08 5:59daf2b48180 186 extern volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */
carlos_nascimento08 5:59daf2b48180 187 extern volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */
carlos_nascimento08 5:59daf2b48180 188 extern volatile HCTD *TDHead; /* Head transfer descriptor structure */
carlos_nascimento08 5:59daf2b48180 189 extern volatile HCTD *TDTail; /* Tail transfer descriptor structure */
carlos_nascimento08 5:59daf2b48180 190 extern volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */
carlos_nascimento08 5:59daf2b48180 191
carlos_nascimento08 5:59daf2b48180 192 /*
carlos_nascimento08 5:59daf2b48180 193 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 194 * FUNCTION PROTOTYPES
carlos_nascimento08 5:59daf2b48180 195 **************************************************************************************************************
carlos_nascimento08 5:59daf2b48180 196 */
carlos_nascimento08 5:59daf2b48180 197
carlos_nascimento08 5:59daf2b48180 198 void Host_Init (void);
carlos_nascimento08 5:59daf2b48180 199
carlos_nascimento08 5:59daf2b48180 200 extern "C" void USB_IRQHandler(void) __irq;
carlos_nascimento08 5:59daf2b48180 201
carlos_nascimento08 5:59daf2b48180 202 USB_INT32S Host_EnumDev (void);
carlos_nascimento08 5:59daf2b48180 203
carlos_nascimento08 5:59daf2b48180 204 USB_INT32S Host_ProcessTD(volatile HCED *ed,
carlos_nascimento08 5:59daf2b48180 205 volatile USB_INT32U token,
carlos_nascimento08 5:59daf2b48180 206 volatile USB_INT08U *buffer,
carlos_nascimento08 5:59daf2b48180 207 USB_INT32U buffer_len);
carlos_nascimento08 5:59daf2b48180 208
carlos_nascimento08 5:59daf2b48180 209 void Host_DelayUS ( USB_INT32U delay);
carlos_nascimento08 5:59daf2b48180 210 void Host_DelayMS ( USB_INT32U delay);
carlos_nascimento08 5:59daf2b48180 211
carlos_nascimento08 5:59daf2b48180 212
carlos_nascimento08 5:59daf2b48180 213 void Host_TDInit (volatile HCTD *td);
carlos_nascimento08 5:59daf2b48180 214 void Host_EDInit (volatile HCED *ed);
carlos_nascimento08 5:59daf2b48180 215 void Host_HCCAInit (volatile HCCA *hcca);
carlos_nascimento08 5:59daf2b48180 216
carlos_nascimento08 5:59daf2b48180 217 USB_INT32S Host_CtrlRecv ( USB_INT08U bm_request_type,
carlos_nascimento08 5:59daf2b48180 218 USB_INT08U b_request,
carlos_nascimento08 5:59daf2b48180 219 USB_INT16U w_value,
carlos_nascimento08 5:59daf2b48180 220 USB_INT16U w_index,
carlos_nascimento08 5:59daf2b48180 221 USB_INT16U w_length,
carlos_nascimento08 5:59daf2b48180 222 volatile USB_INT08U *buffer);
carlos_nascimento08 5:59daf2b48180 223
carlos_nascimento08 5:59daf2b48180 224 USB_INT32S Host_CtrlSend ( USB_INT08U bm_request_type,
carlos_nascimento08 5:59daf2b48180 225 USB_INT08U b_request,
carlos_nascimento08 5:59daf2b48180 226 USB_INT16U w_value,
carlos_nascimento08 5:59daf2b48180 227 USB_INT16U w_index,
carlos_nascimento08 5:59daf2b48180 228 USB_INT16U w_length,
carlos_nascimento08 5:59daf2b48180 229 volatile USB_INT08U *buffer);
carlos_nascimento08 5:59daf2b48180 230
carlos_nascimento08 5:59daf2b48180 231 void Host_FillSetup( USB_INT08U bm_request_type,
carlos_nascimento08 5:59daf2b48180 232 USB_INT08U b_request,
carlos_nascimento08 5:59daf2b48180 233 USB_INT16U w_value,
carlos_nascimento08 5:59daf2b48180 234 USB_INT16U w_index,
carlos_nascimento08 5:59daf2b48180 235 USB_INT16U w_length);
carlos_nascimento08 5:59daf2b48180 236
carlos_nascimento08 5:59daf2b48180 237
carlos_nascimento08 5:59daf2b48180 238 void Host_WDHWait (void);
carlos_nascimento08 5:59daf2b48180 239
carlos_nascimento08 5:59daf2b48180 240
carlos_nascimento08 5:59daf2b48180 241 USB_INT32U ReadLE32U (volatile USB_INT08U *pmem);
carlos_nascimento08 5:59daf2b48180 242 void WriteLE32U (volatile USB_INT08U *pmem,
carlos_nascimento08 5:59daf2b48180 243 USB_INT32U val);
carlos_nascimento08 5:59daf2b48180 244 USB_INT16U ReadLE16U (volatile USB_INT08U *pmem);
carlos_nascimento08 5:59daf2b48180 245 void WriteLE16U (volatile USB_INT08U *pmem,
carlos_nascimento08 5:59daf2b48180 246 USB_INT16U val);
carlos_nascimento08 5:59daf2b48180 247 USB_INT32U ReadBE32U (volatile USB_INT08U *pmem);
carlos_nascimento08 5:59daf2b48180 248 void WriteBE32U (volatile USB_INT08U *pmem,
carlos_nascimento08 5:59daf2b48180 249 USB_INT32U val);
carlos_nascimento08 5:59daf2b48180 250 USB_INT16U ReadBE16U (volatile USB_INT08U *pmem);
carlos_nascimento08 5:59daf2b48180 251 void WriteBE16U (volatile USB_INT08U *pmem,
carlos_nascimento08 5:59daf2b48180 252 USB_INT16U val);
carlos_nascimento08 5:59daf2b48180 253
carlos_nascimento08 5:59daf2b48180 254 #endif