Dependencies:   mbed

Committer:
joe
Date:
Fri Aug 20 15:38:52 2010 +0000
Revision:
2:a079de4fd5b9
Parent:
0:960b355eaa84

        

Who changed what in which revision?

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