Dependents:   sample_collection_for_starboard_orange starboard_orange_samples

Committer:
chris
Date:
Wed Jun 13 10:52:22 2012 +0000
Revision:
1:29e541664957
Parent:
0:f4e330489777
I was asked to commit this, but i dont know why

Who changed what in which revision?

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