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