CODE

Dependencies:   C12832_lcd CMPS03 FatFileSystemCpp GPS MMA7660 mbed

Fork of CompleteMbed by Group 14

Committer:
Alex4475
Date:
Wed May 07 09:49:54 2014 +0000
Revision:
0:2557081b4322
Code to take GPS, Accelerometer and Compass data and print to a USB for data analysis

Who changed what in which revision?

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