V

Dependencies:   mbed FatFileSystemCpp TextLCD

Committer:
bertonieto
Date:
Mon Aug 12 21:54:14 2019 +0000
Revision:
2:73cbcff90232
Export new

Who changed what in which revision?

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