complete

Dependencies:   FatFileSystem mbed

Fork of SnakeSnakeGame by Tho Jian Xiang

Committer:
superlova
Date:
Sat Aug 08 09:32:56 2015 +0000
Revision:
1:4222a8f9ca88
for rexry

Who changed what in which revision?

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