Read GPS MT3329

Dependencies:   FatFileSystem mbed

Committer:
belloula
Date:
Sun Mar 29 14:43:22 2015 +0000
Revision:
0:9611b40fec6f
Read from MT3329 GPS and print on Pc (usb serial pc)

Who changed what in which revision?

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