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