Dependencies:   mbed

Committer:
slowness
Date:
Fri Aug 26 12:19:16 2011 +0000
Revision:
0:4359b47b3d7c

        

Who changed what in which revision?

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