This program is an example of of using the MSCUSBHost code with a raw build of ELM Chan Fat Fs. This was done to add both Long File Name Support along with proper time/date stamps (assuming you have a battery hooked up to keep time). This code exposes the Chan API (see main.cpp) and is NOT a c++ class: http://elm-chan.org/fsw/ff/00index_e.html The diskio.c file has the mapping needed to link the filesystem to the MSC stuff

Dependencies:   mbed

Committer:
emh203
Date:
Sun Jan 23 18:35:43 2011 +0000
Revision:
0:2dbbafe1b1fb
1st test version.   Test with raw mbed and Samtec USB-RA type A connector wired directly to pins.

Who changed what in which revision?

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