I have errors with this program.

Dependencies:   mbed FATFileSystem

Committer:
carlos_nascimento08
Date:
Sun Jul 22 20:01:51 2012 +0000
Revision:
0:ebf86c956c58
Error debug

Who changed what in which revision?

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