Import Library

Committer:
carlos_nascimento08
Date:
Sun Jul 22 20:46:05 2012 +0000
Revision:
0:10643735c105
USBHostFile
;

Who changed what in which revision?

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