![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
USB Host Lite downloaded from NXP web site. Untested! Compiled, dropped on MBED, booted up, and get the console message that it is initializing the stack. I however do not have the ability to connect a USB Memory device to test it.
Host/usbhost_lpc17xx.c@0:0826fcc5d020, 2010-01-13 (annotated)
- Committer:
- mshoemaker
- Date:
- Wed Jan 13 01:29:30 2010 +0000
- Revision:
- 0:0826fcc5d020
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mshoemaker | 0:0826fcc5d020 | 1 | /* |
mshoemaker | 0:0826fcc5d020 | 2 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 3 | * NXP USB Host Stack |
mshoemaker | 0:0826fcc5d020 | 4 | * |
mshoemaker | 0:0826fcc5d020 | 5 | * (c) Copyright 2008, NXP SemiConductors |
mshoemaker | 0:0826fcc5d020 | 6 | * (c) Copyright 2008, OnChip Technologies LLC |
mshoemaker | 0:0826fcc5d020 | 7 | * All Rights Reserved |
mshoemaker | 0:0826fcc5d020 | 8 | * |
mshoemaker | 0:0826fcc5d020 | 9 | * www.nxp.com |
mshoemaker | 0:0826fcc5d020 | 10 | * www.onchiptech.com |
mshoemaker | 0:0826fcc5d020 | 11 | * |
mshoemaker | 0:0826fcc5d020 | 12 | * File : usbhost_lpc17xx.c |
mshoemaker | 0:0826fcc5d020 | 13 | * Programmer(s) : Ravikanth.P |
mshoemaker | 0:0826fcc5d020 | 14 | * Version : |
mshoemaker | 0:0826fcc5d020 | 15 | * |
mshoemaker | 0:0826fcc5d020 | 16 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 17 | */ |
mshoemaker | 0:0826fcc5d020 | 18 | |
mshoemaker | 0:0826fcc5d020 | 19 | /* |
mshoemaker | 0:0826fcc5d020 | 20 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 21 | * INCLUDE HEADER FILES |
mshoemaker | 0:0826fcc5d020 | 22 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 23 | */ |
mshoemaker | 0:0826fcc5d020 | 24 | |
mshoemaker | 0:0826fcc5d020 | 25 | #include "usbhost_lpc17xx.h" |
mshoemaker | 0:0826fcc5d020 | 26 | |
mshoemaker | 0:0826fcc5d020 | 27 | /* |
mshoemaker | 0:0826fcc5d020 | 28 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 29 | * GLOBAL VARIABLES |
mshoemaker | 0:0826fcc5d020 | 30 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 31 | */ |
mshoemaker | 0:0826fcc5d020 | 32 | int gUSBConnected; |
mshoemaker | 0:0826fcc5d020 | 33 | |
mshoemaker | 0:0826fcc5d020 | 34 | volatile USB_INT32U HOST_RhscIntr = 0; /* Root Hub Status Change interrupt */ |
mshoemaker | 0:0826fcc5d020 | 35 | volatile USB_INT32U HOST_WdhIntr = 0; /* Semaphore to wait until the TD is submitted */ |
mshoemaker | 0:0826fcc5d020 | 36 | volatile USB_INT08U HOST_TDControlStatus = 0; |
mshoemaker | 0:0826fcc5d020 | 37 | volatile HCED *EDCtrl; /* Control endpoint descriptor structure */ |
mshoemaker | 0:0826fcc5d020 | 38 | volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */ |
mshoemaker | 0:0826fcc5d020 | 39 | volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */ |
mshoemaker | 0:0826fcc5d020 | 40 | volatile HCTD *TDHead; /* Head transfer descriptor structure */ |
mshoemaker | 0:0826fcc5d020 | 41 | volatile HCTD *TDTail; /* Tail transfer descriptor structure */ |
mshoemaker | 0:0826fcc5d020 | 42 | volatile HCCA *Hcca; /* Host Controller Communications Area structure */ |
mshoemaker | 0:0826fcc5d020 | 43 | USB_INT16U *TDBufNonVol; /* Identical to TDBuffer just to reduce compiler warnings */ |
mshoemaker | 0:0826fcc5d020 | 44 | volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */ |
mshoemaker | 0:0826fcc5d020 | 45 | volatile USB_INT08U *FATBuffer; /* Buffer used by FAT file system */ |
mshoemaker | 0:0826fcc5d020 | 46 | volatile USB_INT08U *UserBuffer; /* Buffer used by application */ |
mshoemaker | 0:0826fcc5d020 | 47 | |
mshoemaker | 0:0826fcc5d020 | 48 | /* |
mshoemaker | 0:0826fcc5d020 | 49 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 50 | * DELAY IN MILLI SECONDS |
mshoemaker | 0:0826fcc5d020 | 51 | * |
mshoemaker | 0:0826fcc5d020 | 52 | * Description: This function provides a delay in milli seconds |
mshoemaker | 0:0826fcc5d020 | 53 | * |
mshoemaker | 0:0826fcc5d020 | 54 | * Arguments : delay The delay required |
mshoemaker | 0:0826fcc5d020 | 55 | * |
mshoemaker | 0:0826fcc5d020 | 56 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 57 | * |
mshoemaker | 0:0826fcc5d020 | 58 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 59 | */ |
mshoemaker | 0:0826fcc5d020 | 60 | |
mshoemaker | 0:0826fcc5d020 | 61 | void Host_DelayMS (USB_INT32U delay) |
mshoemaker | 0:0826fcc5d020 | 62 | { |
mshoemaker | 0:0826fcc5d020 | 63 | volatile USB_INT32U i; |
mshoemaker | 0:0826fcc5d020 | 64 | |
mshoemaker | 0:0826fcc5d020 | 65 | |
mshoemaker | 0:0826fcc5d020 | 66 | for (i = 0; i < delay; i++) { |
mshoemaker | 0:0826fcc5d020 | 67 | Host_DelayUS(1000); |
mshoemaker | 0:0826fcc5d020 | 68 | } |
mshoemaker | 0:0826fcc5d020 | 69 | } |
mshoemaker | 0:0826fcc5d020 | 70 | |
mshoemaker | 0:0826fcc5d020 | 71 | /* |
mshoemaker | 0:0826fcc5d020 | 72 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 73 | * DELAY IN MICRO SECONDS |
mshoemaker | 0:0826fcc5d020 | 74 | * |
mshoemaker | 0:0826fcc5d020 | 75 | * Description: This function provides a delay in micro seconds |
mshoemaker | 0:0826fcc5d020 | 76 | * |
mshoemaker | 0:0826fcc5d020 | 77 | * Arguments : delay The delay required |
mshoemaker | 0:0826fcc5d020 | 78 | * |
mshoemaker | 0:0826fcc5d020 | 79 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 80 | * |
mshoemaker | 0:0826fcc5d020 | 81 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 82 | */ |
mshoemaker | 0:0826fcc5d020 | 83 | |
mshoemaker | 0:0826fcc5d020 | 84 | void Host_DelayUS (USB_INT32U delay) |
mshoemaker | 0:0826fcc5d020 | 85 | { |
mshoemaker | 0:0826fcc5d020 | 86 | volatile USB_INT32U i; |
mshoemaker | 0:0826fcc5d020 | 87 | |
mshoemaker | 0:0826fcc5d020 | 88 | |
mshoemaker | 0:0826fcc5d020 | 89 | for (i = 0; i < (4 * delay); i++) { /* This logic was tested. It gives app. 1 micro sec delay */ |
mshoemaker | 0:0826fcc5d020 | 90 | ; |
mshoemaker | 0:0826fcc5d020 | 91 | } |
mshoemaker | 0:0826fcc5d020 | 92 | } |
mshoemaker | 0:0826fcc5d020 | 93 | |
mshoemaker | 0:0826fcc5d020 | 94 | /* |
mshoemaker | 0:0826fcc5d020 | 95 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 96 | * INITIALIZE THE HOST CONTROLLER |
mshoemaker | 0:0826fcc5d020 | 97 | * |
mshoemaker | 0:0826fcc5d020 | 98 | * Description: This function initializes lpc17xx host controller |
mshoemaker | 0:0826fcc5d020 | 99 | * |
mshoemaker | 0:0826fcc5d020 | 100 | * Arguments : None |
mshoemaker | 0:0826fcc5d020 | 101 | * |
mshoemaker | 0:0826fcc5d020 | 102 | * Returns : |
mshoemaker | 0:0826fcc5d020 | 103 | * |
mshoemaker | 0:0826fcc5d020 | 104 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 105 | */ |
mshoemaker | 0:0826fcc5d020 | 106 | void Host_Init (void) |
mshoemaker | 0:0826fcc5d020 | 107 | { |
mshoemaker | 0:0826fcc5d020 | 108 | USB_INT32U HostBaseAddr; |
mshoemaker | 0:0826fcc5d020 | 109 | |
mshoemaker | 0:0826fcc5d020 | 110 | LPC_SC->PCONP |= (1UL<<31); |
mshoemaker | 0:0826fcc5d020 | 111 | LPC_USB->OTGClkCtrl = 0x0000001F; |
mshoemaker | 0:0826fcc5d020 | 112 | while ((LPC_USB->OTGClkSt & 0x0000001F) == 0) { /* Host clock is available */ |
mshoemaker | 0:0826fcc5d020 | 113 | ; |
mshoemaker | 0:0826fcc5d020 | 114 | } |
mshoemaker | 0:0826fcc5d020 | 115 | |
mshoemaker | 0:0826fcc5d020 | 116 | LPC_USB->OTGStCtrl = 0x3; |
mshoemaker | 0:0826fcc5d020 | 117 | |
mshoemaker | 0:0826fcc5d020 | 118 | /* P1[18] = USB_UP_LED, 01 */ |
mshoemaker | 0:0826fcc5d020 | 119 | /* P1[19] = /USB_PPWR, 10 */ |
mshoemaker | 0:0826fcc5d020 | 120 | /* P1[22] = USB_PWRD, 10 */ |
mshoemaker | 0:0826fcc5d020 | 121 | /* P1[27] = /USB_OVRCR, 10 */ |
mshoemaker | 0:0826fcc5d020 | 122 | LPC_PINCON->PINSEL3 &= ~((3<<4) | (3<<6) | (3<<12) | (3<<22)); |
mshoemaker | 0:0826fcc5d020 | 123 | LPC_PINCON->PINSEL3 |= ((1<<4)|(2<<6) | (2<<12) | (2<<22)); // 0x00802080 |
mshoemaker | 0:0826fcc5d020 | 124 | |
mshoemaker | 0:0826fcc5d020 | 125 | /* P0[29] = USB_D+, 01 */ |
mshoemaker | 0:0826fcc5d020 | 126 | /* P0[30] = USB_D-, 01 */ |
mshoemaker | 0:0826fcc5d020 | 127 | LPC_PINCON->PINSEL1 &= ~((3<<26) | (3<<28)); |
mshoemaker | 0:0826fcc5d020 | 128 | LPC_PINCON->PINSEL1 |= ((1<<26)|(1<<28)); // 0x14000000 |
mshoemaker | 0:0826fcc5d020 | 129 | |
mshoemaker | 0:0826fcc5d020 | 130 | PRINT_Log("Initializing Host Stack\n"); |
mshoemaker | 0:0826fcc5d020 | 131 | |
mshoemaker | 0:0826fcc5d020 | 132 | // For chip revision V01 and later |
mshoemaker | 0:0826fcc5d020 | 133 | HostBaseAddr = 0x20080000; |
mshoemaker | 0:0826fcc5d020 | 134 | |
mshoemaker | 0:0826fcc5d020 | 135 | Hcca = (volatile HCCA *)(HostBaseAddr+0x000); |
mshoemaker | 0:0826fcc5d020 | 136 | TDHead = (volatile HCTD *)(HostBaseAddr+0x100); |
mshoemaker | 0:0826fcc5d020 | 137 | TDTail = (volatile HCTD *)(HostBaseAddr+0x110); |
mshoemaker | 0:0826fcc5d020 | 138 | EDCtrl = (volatile HCED *)(HostBaseAddr+0x120); |
mshoemaker | 0:0826fcc5d020 | 139 | EDBulkIn = (volatile HCED *)(HostBaseAddr+0x130); |
mshoemaker | 0:0826fcc5d020 | 140 | EDBulkOut = (volatile HCED *)(HostBaseAddr+0x140); |
mshoemaker | 0:0826fcc5d020 | 141 | TDBuffer = (volatile USB_INT08U *)(HostBaseAddr+0x150); |
mshoemaker | 0:0826fcc5d020 | 142 | FATBuffer = (volatile USB_INT08U *)(HostBaseAddr+0x1D0); |
mshoemaker | 0:0826fcc5d020 | 143 | UserBuffer = (volatile USB_INT08U *)(HostBaseAddr+0x1000); |
mshoemaker | 0:0826fcc5d020 | 144 | |
mshoemaker | 0:0826fcc5d020 | 145 | /* Initialize all the TDs, EDs and HCCA to 0 */ |
mshoemaker | 0:0826fcc5d020 | 146 | Host_EDInit(EDCtrl); |
mshoemaker | 0:0826fcc5d020 | 147 | Host_EDInit(EDBulkIn); |
mshoemaker | 0:0826fcc5d020 | 148 | Host_EDInit(EDBulkOut); |
mshoemaker | 0:0826fcc5d020 | 149 | Host_TDInit(TDHead); |
mshoemaker | 0:0826fcc5d020 | 150 | Host_TDInit(TDTail); |
mshoemaker | 0:0826fcc5d020 | 151 | Host_HCCAInit(Hcca); |
mshoemaker | 0:0826fcc5d020 | 152 | |
mshoemaker | 0:0826fcc5d020 | 153 | |
mshoemaker | 0:0826fcc5d020 | 154 | Host_DelayMS(50); /* Wait 50 ms before apply reset */ |
mshoemaker | 0:0826fcc5d020 | 155 | LPC_USB->HcControl = 0; /* HARDWARE RESET */ |
mshoemaker | 0:0826fcc5d020 | 156 | LPC_USB->HcControlHeadED = 0; /* Initialize Control list head to Zero */ |
mshoemaker | 0:0826fcc5d020 | 157 | LPC_USB->HcBulkHeadED = 0; /* Initialize Bulk list head to Zero */ |
mshoemaker | 0:0826fcc5d020 | 158 | |
mshoemaker | 0:0826fcc5d020 | 159 | /* SOFTWARE RESET */ |
mshoemaker | 0:0826fcc5d020 | 160 | LPC_USB->HcCommandStatus = OR_CMD_STATUS_HCR; |
mshoemaker | 0:0826fcc5d020 | 161 | LPC_USB->HcFmInterval = DEFAULT_FMINTERVAL; /* Write Fm Interval and Largest Data Packet Counter */ |
mshoemaker | 0:0826fcc5d020 | 162 | |
mshoemaker | 0:0826fcc5d020 | 163 | /* Put HC in operational state */ |
mshoemaker | 0:0826fcc5d020 | 164 | LPC_USB->HcControl = (LPC_USB->HcControl & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER; |
mshoemaker | 0:0826fcc5d020 | 165 | LPC_USB->HcRhStatus = OR_RH_STATUS_LPSC; /* Set Global Power */ |
mshoemaker | 0:0826fcc5d020 | 166 | |
mshoemaker | 0:0826fcc5d020 | 167 | LPC_USB->HcHCCA = (USB_INT32U)Hcca; |
mshoemaker | 0:0826fcc5d020 | 168 | LPC_USB->HcInterruptStatus |= LPC_USB->HcInterruptStatus; /* Clear Interrrupt Status */ |
mshoemaker | 0:0826fcc5d020 | 169 | |
mshoemaker | 0:0826fcc5d020 | 170 | |
mshoemaker | 0:0826fcc5d020 | 171 | LPC_USB->HcInterruptEnable = OR_INTR_ENABLE_MIE | |
mshoemaker | 0:0826fcc5d020 | 172 | OR_INTR_ENABLE_WDH | |
mshoemaker | 0:0826fcc5d020 | 173 | OR_INTR_ENABLE_RHSC; |
mshoemaker | 0:0826fcc5d020 | 174 | |
mshoemaker | 0:0826fcc5d020 | 175 | |
mshoemaker | 0:0826fcc5d020 | 176 | |
mshoemaker | 0:0826fcc5d020 | 177 | /* Enable the USB Interrupt */ |
mshoemaker | 0:0826fcc5d020 | 178 | NVIC_EnableIRQ(USB_IRQn); /* enable USB interrupt */ |
mshoemaker | 0:0826fcc5d020 | 179 | NVIC_SetPriority (USB_IRQn, 0); /* highest priority */ |
mshoemaker | 0:0826fcc5d020 | 180 | |
mshoemaker | 0:0826fcc5d020 | 181 | |
mshoemaker | 0:0826fcc5d020 | 182 | PRINT_Log("Host Initialized\n"); |
mshoemaker | 0:0826fcc5d020 | 183 | } |
mshoemaker | 0:0826fcc5d020 | 184 | |
mshoemaker | 0:0826fcc5d020 | 185 | /* |
mshoemaker | 0:0826fcc5d020 | 186 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 187 | * INTERRUPT SERVICE ROUTINE |
mshoemaker | 0:0826fcc5d020 | 188 | * |
mshoemaker | 0:0826fcc5d020 | 189 | * Description: This function services the interrupt caused by host controller |
mshoemaker | 0:0826fcc5d020 | 190 | * |
mshoemaker | 0:0826fcc5d020 | 191 | * Arguments : None |
mshoemaker | 0:0826fcc5d020 | 192 | * |
mshoemaker | 0:0826fcc5d020 | 193 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 194 | * |
mshoemaker | 0:0826fcc5d020 | 195 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 196 | */ |
mshoemaker | 0:0826fcc5d020 | 197 | |
mshoemaker | 0:0826fcc5d020 | 198 | void USB_IRQHandler (void) |
mshoemaker | 0:0826fcc5d020 | 199 | { |
mshoemaker | 0:0826fcc5d020 | 200 | USB_INT32U int_status; |
mshoemaker | 0:0826fcc5d020 | 201 | USB_INT32U ie_status; |
mshoemaker | 0:0826fcc5d020 | 202 | |
mshoemaker | 0:0826fcc5d020 | 203 | int_status = LPC_USB->HcInterruptStatus; /* Read Interrupt Status */ |
mshoemaker | 0:0826fcc5d020 | 204 | ie_status = LPC_USB->HcInterruptEnable; /* Read Interrupt enable status */ |
mshoemaker | 0:0826fcc5d020 | 205 | |
mshoemaker | 0:0826fcc5d020 | 206 | if (!(int_status & ie_status)) { |
mshoemaker | 0:0826fcc5d020 | 207 | return; |
mshoemaker | 0:0826fcc5d020 | 208 | } else { |
mshoemaker | 0:0826fcc5d020 | 209 | |
mshoemaker | 0:0826fcc5d020 | 210 | int_status = int_status & ie_status; |
mshoemaker | 0:0826fcc5d020 | 211 | if (int_status & OR_INTR_STATUS_RHSC) { /* Root hub status change interrupt */ |
mshoemaker | 0:0826fcc5d020 | 212 | if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CSC) { |
mshoemaker | 0:0826fcc5d020 | 213 | if (LPC_USB->HcRhStatus & OR_RH_STATUS_DRWE) { |
mshoemaker | 0:0826fcc5d020 | 214 | /* |
mshoemaker | 0:0826fcc5d020 | 215 | * When DRWE is on, Connect Status Change |
mshoemaker | 0:0826fcc5d020 | 216 | * means a remote wakeup event. |
mshoemaker | 0:0826fcc5d020 | 217 | */ |
mshoemaker | 0:0826fcc5d020 | 218 | HOST_RhscIntr = 1;// JUST SOMETHING FOR A BREAKPOINT |
mshoemaker | 0:0826fcc5d020 | 219 | } |
mshoemaker | 0:0826fcc5d020 | 220 | else { |
mshoemaker | 0:0826fcc5d020 | 221 | /* |
mshoemaker | 0:0826fcc5d020 | 222 | * When DRWE is off, Connect Status Change |
mshoemaker | 0:0826fcc5d020 | 223 | * is NOT a remote wakeup event |
mshoemaker | 0:0826fcc5d020 | 224 | */ |
mshoemaker | 0:0826fcc5d020 | 225 | if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) { |
mshoemaker | 0:0826fcc5d020 | 226 | if (!gUSBConnected) { |
mshoemaker | 0:0826fcc5d020 | 227 | HOST_TDControlStatus = 0; |
mshoemaker | 0:0826fcc5d020 | 228 | HOST_WdhIntr = 0; |
mshoemaker | 0:0826fcc5d020 | 229 | HOST_RhscIntr = 1; |
mshoemaker | 0:0826fcc5d020 | 230 | gUSBConnected = 1; |
mshoemaker | 0:0826fcc5d020 | 231 | } |
mshoemaker | 0:0826fcc5d020 | 232 | else |
mshoemaker | 0:0826fcc5d020 | 233 | PRINT_Log("Spurious status change (connected)?\n"); |
mshoemaker | 0:0826fcc5d020 | 234 | } else { |
mshoemaker | 0:0826fcc5d020 | 235 | if (gUSBConnected) { |
mshoemaker | 0:0826fcc5d020 | 236 | LPC_USB->HcInterruptEnable = 0; // why do we get multiple disc. rupts??? |
mshoemaker | 0:0826fcc5d020 | 237 | HOST_RhscIntr = 0; |
mshoemaker | 0:0826fcc5d020 | 238 | gUSBConnected = 0; |
mshoemaker | 0:0826fcc5d020 | 239 | } |
mshoemaker | 0:0826fcc5d020 | 240 | else |
mshoemaker | 0:0826fcc5d020 | 241 | PRINT_Log("Spurious status change (disconnected)?\n"); |
mshoemaker | 0:0826fcc5d020 | 242 | } |
mshoemaker | 0:0826fcc5d020 | 243 | } |
mshoemaker | 0:0826fcc5d020 | 244 | LPC_USB->HcRhPortStatus1 = OR_RH_PORT_CSC; |
mshoemaker | 0:0826fcc5d020 | 245 | } |
mshoemaker | 0:0826fcc5d020 | 246 | if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRSC) { |
mshoemaker | 0:0826fcc5d020 | 247 | LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; |
mshoemaker | 0:0826fcc5d020 | 248 | } |
mshoemaker | 0:0826fcc5d020 | 249 | } |
mshoemaker | 0:0826fcc5d020 | 250 | if (int_status & OR_INTR_STATUS_WDH) { /* Writeback Done Head interrupt */ |
mshoemaker | 0:0826fcc5d020 | 251 | HOST_WdhIntr = 1; |
mshoemaker | 0:0826fcc5d020 | 252 | HOST_TDControlStatus = (TDHead->Control >> 28) & 0xf; |
mshoemaker | 0:0826fcc5d020 | 253 | } |
mshoemaker | 0:0826fcc5d020 | 254 | LPC_USB->HcInterruptStatus = int_status; /* Clear interrupt status register */ |
mshoemaker | 0:0826fcc5d020 | 255 | } |
mshoemaker | 0:0826fcc5d020 | 256 | return; |
mshoemaker | 0:0826fcc5d020 | 257 | } |
mshoemaker | 0:0826fcc5d020 | 258 | |
mshoemaker | 0:0826fcc5d020 | 259 | /* |
mshoemaker | 0:0826fcc5d020 | 260 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 261 | * PROCESS TRANSFER DESCRIPTOR |
mshoemaker | 0:0826fcc5d020 | 262 | * |
mshoemaker | 0:0826fcc5d020 | 263 | * Description: This function processes the transfer descriptor |
mshoemaker | 0:0826fcc5d020 | 264 | * |
mshoemaker | 0:0826fcc5d020 | 265 | * Arguments : ed Endpoint descriptor that contains this transfer descriptor |
mshoemaker | 0:0826fcc5d020 | 266 | * token SETUP, IN, OUT |
mshoemaker | 0:0826fcc5d020 | 267 | * buffer Current Buffer Pointer of the transfer descriptor |
mshoemaker | 0:0826fcc5d020 | 268 | * buffer_len Length of the buffer |
mshoemaker | 0:0826fcc5d020 | 269 | * |
mshoemaker | 0:0826fcc5d020 | 270 | * Returns : OK if TD submission is successful |
mshoemaker | 0:0826fcc5d020 | 271 | * ERROR if TD submission fails |
mshoemaker | 0:0826fcc5d020 | 272 | * |
mshoemaker | 0:0826fcc5d020 | 273 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 274 | */ |
mshoemaker | 0:0826fcc5d020 | 275 | |
mshoemaker | 0:0826fcc5d020 | 276 | USB_INT32S Host_ProcessTD (volatile HCED *ed, |
mshoemaker | 0:0826fcc5d020 | 277 | volatile USB_INT32U token, |
mshoemaker | 0:0826fcc5d020 | 278 | volatile USB_INT08U *buffer, |
mshoemaker | 0:0826fcc5d020 | 279 | USB_INT32U buffer_len) |
mshoemaker | 0:0826fcc5d020 | 280 | { |
mshoemaker | 0:0826fcc5d020 | 281 | volatile USB_INT32U td_toggle; |
mshoemaker | 0:0826fcc5d020 | 282 | |
mshoemaker | 0:0826fcc5d020 | 283 | |
mshoemaker | 0:0826fcc5d020 | 284 | if (ed == EDCtrl) { |
mshoemaker | 0:0826fcc5d020 | 285 | if (token == TD_SETUP) { |
mshoemaker | 0:0826fcc5d020 | 286 | td_toggle = TD_TOGGLE_0; |
mshoemaker | 0:0826fcc5d020 | 287 | } else { |
mshoemaker | 0:0826fcc5d020 | 288 | td_toggle = TD_TOGGLE_1; |
mshoemaker | 0:0826fcc5d020 | 289 | } |
mshoemaker | 0:0826fcc5d020 | 290 | } else { |
mshoemaker | 0:0826fcc5d020 | 291 | td_toggle = 0; |
mshoemaker | 0:0826fcc5d020 | 292 | } |
mshoemaker | 0:0826fcc5d020 | 293 | TDHead->Control = (TD_ROUNDING | |
mshoemaker | 0:0826fcc5d020 | 294 | token | |
mshoemaker | 0:0826fcc5d020 | 295 | TD_DELAY_INT(0) | |
mshoemaker | 0:0826fcc5d020 | 296 | td_toggle | |
mshoemaker | 0:0826fcc5d020 | 297 | TD_CC); |
mshoemaker | 0:0826fcc5d020 | 298 | TDTail->Control = 0; |
mshoemaker | 0:0826fcc5d020 | 299 | TDHead->CurrBufPtr = (USB_INT32U) buffer; |
mshoemaker | 0:0826fcc5d020 | 300 | TDTail->CurrBufPtr = 0; |
mshoemaker | 0:0826fcc5d020 | 301 | TDHead->Next = (USB_INT32U) TDTail; |
mshoemaker | 0:0826fcc5d020 | 302 | TDTail->Next = 0; |
mshoemaker | 0:0826fcc5d020 | 303 | TDHead->BufEnd = (USB_INT32U)(buffer + (buffer_len - 1)); |
mshoemaker | 0:0826fcc5d020 | 304 | TDTail->BufEnd = 0; |
mshoemaker | 0:0826fcc5d020 | 305 | |
mshoemaker | 0:0826fcc5d020 | 306 | ed->HeadTd = (USB_INT32U)TDHead | ((ed->HeadTd) & 0x00000002); |
mshoemaker | 0:0826fcc5d020 | 307 | ed->TailTd = (USB_INT32U)TDTail; |
mshoemaker | 0:0826fcc5d020 | 308 | ed->Next = 0; |
mshoemaker | 0:0826fcc5d020 | 309 | |
mshoemaker | 0:0826fcc5d020 | 310 | if (ed == EDCtrl) { |
mshoemaker | 0:0826fcc5d020 | 311 | LPC_USB->HcControlHeadED = (USB_INT32U)ed; |
mshoemaker | 0:0826fcc5d020 | 312 | LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_CLF; |
mshoemaker | 0:0826fcc5d020 | 313 | LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_CLE; |
mshoemaker | 0:0826fcc5d020 | 314 | } else { |
mshoemaker | 0:0826fcc5d020 | 315 | LPC_USB->HcBulkHeadED = (USB_INT32U)ed; |
mshoemaker | 0:0826fcc5d020 | 316 | LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF; |
mshoemaker | 0:0826fcc5d020 | 317 | LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE; |
mshoemaker | 0:0826fcc5d020 | 318 | } |
mshoemaker | 0:0826fcc5d020 | 319 | |
mshoemaker | 0:0826fcc5d020 | 320 | Host_WDHWait(); |
mshoemaker | 0:0826fcc5d020 | 321 | |
mshoemaker | 0:0826fcc5d020 | 322 | // if (!(TDHead->Control & 0xF0000000)) { |
mshoemaker | 0:0826fcc5d020 | 323 | if (!HOST_TDControlStatus) { |
mshoemaker | 0:0826fcc5d020 | 324 | return (OK); |
mshoemaker | 0:0826fcc5d020 | 325 | } else { |
mshoemaker | 0:0826fcc5d020 | 326 | return (ERR_TD_FAIL); |
mshoemaker | 0:0826fcc5d020 | 327 | } |
mshoemaker | 0:0826fcc5d020 | 328 | } |
mshoemaker | 0:0826fcc5d020 | 329 | |
mshoemaker | 0:0826fcc5d020 | 330 | /* |
mshoemaker | 0:0826fcc5d020 | 331 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 332 | * ENUMERATE THE DEVICE |
mshoemaker | 0:0826fcc5d020 | 333 | * |
mshoemaker | 0:0826fcc5d020 | 334 | * Description: This function is used to enumerate the device connected |
mshoemaker | 0:0826fcc5d020 | 335 | * |
mshoemaker | 0:0826fcc5d020 | 336 | * Arguments : None |
mshoemaker | 0:0826fcc5d020 | 337 | * |
mshoemaker | 0:0826fcc5d020 | 338 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 339 | * |
mshoemaker | 0:0826fcc5d020 | 340 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 341 | */ |
mshoemaker | 0:0826fcc5d020 | 342 | |
mshoemaker | 0:0826fcc5d020 | 343 | USB_INT32S Host_EnumDev (void) |
mshoemaker | 0:0826fcc5d020 | 344 | { |
mshoemaker | 0:0826fcc5d020 | 345 | USB_INT32S rc; |
mshoemaker | 0:0826fcc5d020 | 346 | |
mshoemaker | 0:0826fcc5d020 | 347 | PRINT_Log("Connect a Mass Storage device\n"); |
mshoemaker | 0:0826fcc5d020 | 348 | while (!HOST_RhscIntr); |
mshoemaker | 0:0826fcc5d020 | 349 | Host_DelayMS(100); /* USB 2.0 spec says atleast 50ms delay beore port reset */ |
mshoemaker | 0:0826fcc5d020 | 350 | LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRS; // Initiate port reset |
mshoemaker | 0:0826fcc5d020 | 351 | while (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRS) |
mshoemaker | 0:0826fcc5d020 | 352 | ; // Wait for port reset to complete... |
mshoemaker | 0:0826fcc5d020 | 353 | LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; // ...and clear port reset signal |
mshoemaker | 0:0826fcc5d020 | 354 | Host_DelayMS(200); /* Wait for 100 MS after port reset */ |
mshoemaker | 0:0826fcc5d020 | 355 | |
mshoemaker | 0:0826fcc5d020 | 356 | EDCtrl->Control = 8 << 16; /* Put max pkt size = 8 */ |
mshoemaker | 0:0826fcc5d020 | 357 | /* Read first 8 bytes of device desc */ |
mshoemaker | 0:0826fcc5d020 | 358 | rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_DEVICE, 0, TDBuffer, 8); |
mshoemaker | 0:0826fcc5d020 | 359 | if (rc != OK) { |
mshoemaker | 0:0826fcc5d020 | 360 | PRINT_Err(rc); |
mshoemaker | 0:0826fcc5d020 | 361 | return (rc); |
mshoemaker | 0:0826fcc5d020 | 362 | } |
mshoemaker | 0:0826fcc5d020 | 363 | EDCtrl->Control = TDBuffer[7] << 16; /* Get max pkt size of endpoint 0 */ |
mshoemaker | 0:0826fcc5d020 | 364 | rc = HOST_SET_ADDRESS(1); /* Set the device address to 1 */ |
mshoemaker | 0:0826fcc5d020 | 365 | if (rc != OK) { |
mshoemaker | 0:0826fcc5d020 | 366 | PRINT_Err(rc); |
mshoemaker | 0:0826fcc5d020 | 367 | return (rc); |
mshoemaker | 0:0826fcc5d020 | 368 | } |
mshoemaker | 0:0826fcc5d020 | 369 | Host_DelayMS(2); |
mshoemaker | 0:0826fcc5d020 | 370 | EDCtrl->Control = (EDCtrl->Control) | 1; /* Modify control pipe with address 1 */ |
mshoemaker | 0:0826fcc5d020 | 371 | /* Get the configuration descriptor */ |
mshoemaker | 0:0826fcc5d020 | 372 | rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, 9); |
mshoemaker | 0:0826fcc5d020 | 373 | if (rc != OK) { |
mshoemaker | 0:0826fcc5d020 | 374 | PRINT_Err(rc); |
mshoemaker | 0:0826fcc5d020 | 375 | return (rc); |
mshoemaker | 0:0826fcc5d020 | 376 | } |
mshoemaker | 0:0826fcc5d020 | 377 | /* Get the first configuration data */ |
mshoemaker | 0:0826fcc5d020 | 378 | rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, ReadLE16U(&TDBuffer[2])); |
mshoemaker | 0:0826fcc5d020 | 379 | if (rc != OK) { |
mshoemaker | 0:0826fcc5d020 | 380 | PRINT_Err(rc); |
mshoemaker | 0:0826fcc5d020 | 381 | return (rc); |
mshoemaker | 0:0826fcc5d020 | 382 | } |
mshoemaker | 0:0826fcc5d020 | 383 | rc = MS_ParseConfiguration(); /* Parse the configuration */ |
mshoemaker | 0:0826fcc5d020 | 384 | if (rc != OK) { |
mshoemaker | 0:0826fcc5d020 | 385 | PRINT_Err(rc); |
mshoemaker | 0:0826fcc5d020 | 386 | return (rc); |
mshoemaker | 0:0826fcc5d020 | 387 | } |
mshoemaker | 0:0826fcc5d020 | 388 | rc = USBH_SET_CONFIGURATION(1); /* Select device configuration 1 */ |
mshoemaker | 0:0826fcc5d020 | 389 | if (rc != OK) { |
mshoemaker | 0:0826fcc5d020 | 390 | PRINT_Err(rc); |
mshoemaker | 0:0826fcc5d020 | 391 | } |
mshoemaker | 0:0826fcc5d020 | 392 | Host_DelayMS(100); /* Some devices may require this delay */ |
mshoemaker | 0:0826fcc5d020 | 393 | return (rc); |
mshoemaker | 0:0826fcc5d020 | 394 | } |
mshoemaker | 0:0826fcc5d020 | 395 | |
mshoemaker | 0:0826fcc5d020 | 396 | /* |
mshoemaker | 0:0826fcc5d020 | 397 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 398 | * RECEIVE THE CONTROL INFORMATION |
mshoemaker | 0:0826fcc5d020 | 399 | * |
mshoemaker | 0:0826fcc5d020 | 400 | * Description: This function is used to receive the control information |
mshoemaker | 0:0826fcc5d020 | 401 | * |
mshoemaker | 0:0826fcc5d020 | 402 | * Arguments : bm_request_type |
mshoemaker | 0:0826fcc5d020 | 403 | * b_request |
mshoemaker | 0:0826fcc5d020 | 404 | * w_value |
mshoemaker | 0:0826fcc5d020 | 405 | * w_index |
mshoemaker | 0:0826fcc5d020 | 406 | * w_length |
mshoemaker | 0:0826fcc5d020 | 407 | * buffer |
mshoemaker | 0:0826fcc5d020 | 408 | * |
mshoemaker | 0:0826fcc5d020 | 409 | * Returns : OK if Success |
mshoemaker | 0:0826fcc5d020 | 410 | * ERROR if Failed |
mshoemaker | 0:0826fcc5d020 | 411 | * |
mshoemaker | 0:0826fcc5d020 | 412 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 413 | */ |
mshoemaker | 0:0826fcc5d020 | 414 | |
mshoemaker | 0:0826fcc5d020 | 415 | USB_INT32S Host_CtrlRecv ( USB_INT08U bm_request_type, |
mshoemaker | 0:0826fcc5d020 | 416 | USB_INT08U b_request, |
mshoemaker | 0:0826fcc5d020 | 417 | USB_INT16U w_value, |
mshoemaker | 0:0826fcc5d020 | 418 | USB_INT16U w_index, |
mshoemaker | 0:0826fcc5d020 | 419 | USB_INT16U w_length, |
mshoemaker | 0:0826fcc5d020 | 420 | volatile USB_INT08U *buffer) |
mshoemaker | 0:0826fcc5d020 | 421 | { |
mshoemaker | 0:0826fcc5d020 | 422 | USB_INT32S rc; |
mshoemaker | 0:0826fcc5d020 | 423 | |
mshoemaker | 0:0826fcc5d020 | 424 | |
mshoemaker | 0:0826fcc5d020 | 425 | Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length); |
mshoemaker | 0:0826fcc5d020 | 426 | rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8); |
mshoemaker | 0:0826fcc5d020 | 427 | if (rc == OK) { |
mshoemaker | 0:0826fcc5d020 | 428 | if (w_length) { |
mshoemaker | 0:0826fcc5d020 | 429 | rc = Host_ProcessTD(EDCtrl, TD_IN, TDBuffer, w_length); |
mshoemaker | 0:0826fcc5d020 | 430 | } |
mshoemaker | 0:0826fcc5d020 | 431 | if (rc == OK) { |
mshoemaker | 0:0826fcc5d020 | 432 | rc = Host_ProcessTD(EDCtrl, TD_OUT, NULL, 0); |
mshoemaker | 0:0826fcc5d020 | 433 | } |
mshoemaker | 0:0826fcc5d020 | 434 | } |
mshoemaker | 0:0826fcc5d020 | 435 | return (rc); |
mshoemaker | 0:0826fcc5d020 | 436 | } |
mshoemaker | 0:0826fcc5d020 | 437 | |
mshoemaker | 0:0826fcc5d020 | 438 | /* |
mshoemaker | 0:0826fcc5d020 | 439 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 440 | * SEND THE CONTROL INFORMATION |
mshoemaker | 0:0826fcc5d020 | 441 | * |
mshoemaker | 0:0826fcc5d020 | 442 | * Description: This function is used to send the control information |
mshoemaker | 0:0826fcc5d020 | 443 | * |
mshoemaker | 0:0826fcc5d020 | 444 | * Arguments : None |
mshoemaker | 0:0826fcc5d020 | 445 | * |
mshoemaker | 0:0826fcc5d020 | 446 | * Returns : OK if Success |
mshoemaker | 0:0826fcc5d020 | 447 | * ERR_INVALID_BOOTSIG if Failed |
mshoemaker | 0:0826fcc5d020 | 448 | * |
mshoemaker | 0:0826fcc5d020 | 449 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 450 | */ |
mshoemaker | 0:0826fcc5d020 | 451 | |
mshoemaker | 0:0826fcc5d020 | 452 | USB_INT32S Host_CtrlSend ( USB_INT08U bm_request_type, |
mshoemaker | 0:0826fcc5d020 | 453 | USB_INT08U b_request, |
mshoemaker | 0:0826fcc5d020 | 454 | USB_INT16U w_value, |
mshoemaker | 0:0826fcc5d020 | 455 | USB_INT16U w_index, |
mshoemaker | 0:0826fcc5d020 | 456 | USB_INT16U w_length, |
mshoemaker | 0:0826fcc5d020 | 457 | volatile USB_INT08U *buffer) |
mshoemaker | 0:0826fcc5d020 | 458 | { |
mshoemaker | 0:0826fcc5d020 | 459 | USB_INT32S rc; |
mshoemaker | 0:0826fcc5d020 | 460 | |
mshoemaker | 0:0826fcc5d020 | 461 | |
mshoemaker | 0:0826fcc5d020 | 462 | Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length); |
mshoemaker | 0:0826fcc5d020 | 463 | |
mshoemaker | 0:0826fcc5d020 | 464 | rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8); |
mshoemaker | 0:0826fcc5d020 | 465 | if (rc == OK) { |
mshoemaker | 0:0826fcc5d020 | 466 | if (w_length) { |
mshoemaker | 0:0826fcc5d020 | 467 | rc = Host_ProcessTD(EDCtrl, TD_OUT, TDBuffer, w_length); |
mshoemaker | 0:0826fcc5d020 | 468 | } |
mshoemaker | 0:0826fcc5d020 | 469 | if (rc == OK) { |
mshoemaker | 0:0826fcc5d020 | 470 | rc = Host_ProcessTD(EDCtrl, TD_IN, NULL, 0); |
mshoemaker | 0:0826fcc5d020 | 471 | } |
mshoemaker | 0:0826fcc5d020 | 472 | } |
mshoemaker | 0:0826fcc5d020 | 473 | return (rc); |
mshoemaker | 0:0826fcc5d020 | 474 | } |
mshoemaker | 0:0826fcc5d020 | 475 | |
mshoemaker | 0:0826fcc5d020 | 476 | /* |
mshoemaker | 0:0826fcc5d020 | 477 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 478 | * FILL SETUP PACKET |
mshoemaker | 0:0826fcc5d020 | 479 | * |
mshoemaker | 0:0826fcc5d020 | 480 | * Description: This function is used to fill the setup packet |
mshoemaker | 0:0826fcc5d020 | 481 | * |
mshoemaker | 0:0826fcc5d020 | 482 | * Arguments : None |
mshoemaker | 0:0826fcc5d020 | 483 | * |
mshoemaker | 0:0826fcc5d020 | 484 | * Returns : OK if Success |
mshoemaker | 0:0826fcc5d020 | 485 | * ERR_INVALID_BOOTSIG if Failed |
mshoemaker | 0:0826fcc5d020 | 486 | * |
mshoemaker | 0:0826fcc5d020 | 487 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 488 | */ |
mshoemaker | 0:0826fcc5d020 | 489 | |
mshoemaker | 0:0826fcc5d020 | 490 | void Host_FillSetup (USB_INT08U bm_request_type, |
mshoemaker | 0:0826fcc5d020 | 491 | USB_INT08U b_request, |
mshoemaker | 0:0826fcc5d020 | 492 | USB_INT16U w_value, |
mshoemaker | 0:0826fcc5d020 | 493 | USB_INT16U w_index, |
mshoemaker | 0:0826fcc5d020 | 494 | USB_INT16U w_length) |
mshoemaker | 0:0826fcc5d020 | 495 | { |
mshoemaker | 0:0826fcc5d020 | 496 | int i; |
mshoemaker | 0:0826fcc5d020 | 497 | for (i=0;i<w_length;i++) |
mshoemaker | 0:0826fcc5d020 | 498 | TDBuffer[i] = 0; |
mshoemaker | 0:0826fcc5d020 | 499 | |
mshoemaker | 0:0826fcc5d020 | 500 | TDBuffer[0] = bm_request_type; |
mshoemaker | 0:0826fcc5d020 | 501 | TDBuffer[1] = b_request; |
mshoemaker | 0:0826fcc5d020 | 502 | WriteLE16U(&TDBuffer[2], w_value); |
mshoemaker | 0:0826fcc5d020 | 503 | WriteLE16U(&TDBuffer[4], w_index); |
mshoemaker | 0:0826fcc5d020 | 504 | WriteLE16U(&TDBuffer[6], w_length); |
mshoemaker | 0:0826fcc5d020 | 505 | } |
mshoemaker | 0:0826fcc5d020 | 506 | |
mshoemaker | 0:0826fcc5d020 | 507 | |
mshoemaker | 0:0826fcc5d020 | 508 | |
mshoemaker | 0:0826fcc5d020 | 509 | /* |
mshoemaker | 0:0826fcc5d020 | 510 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 511 | * INITIALIZE THE TRANSFER DESCRIPTOR |
mshoemaker | 0:0826fcc5d020 | 512 | * |
mshoemaker | 0:0826fcc5d020 | 513 | * Description: This function initializes transfer descriptor |
mshoemaker | 0:0826fcc5d020 | 514 | * |
mshoemaker | 0:0826fcc5d020 | 515 | * Arguments : Pointer to TD structure |
mshoemaker | 0:0826fcc5d020 | 516 | * |
mshoemaker | 0:0826fcc5d020 | 517 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 518 | * |
mshoemaker | 0:0826fcc5d020 | 519 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 520 | */ |
mshoemaker | 0:0826fcc5d020 | 521 | |
mshoemaker | 0:0826fcc5d020 | 522 | void Host_TDInit (volatile HCTD *td) |
mshoemaker | 0:0826fcc5d020 | 523 | { |
mshoemaker | 0:0826fcc5d020 | 524 | |
mshoemaker | 0:0826fcc5d020 | 525 | td->Control = 0; |
mshoemaker | 0:0826fcc5d020 | 526 | td->CurrBufPtr = 0; |
mshoemaker | 0:0826fcc5d020 | 527 | td->Next = 0; |
mshoemaker | 0:0826fcc5d020 | 528 | td->BufEnd = 0; |
mshoemaker | 0:0826fcc5d020 | 529 | } |
mshoemaker | 0:0826fcc5d020 | 530 | |
mshoemaker | 0:0826fcc5d020 | 531 | /* |
mshoemaker | 0:0826fcc5d020 | 532 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 533 | * INITIALIZE THE ENDPOINT DESCRIPTOR |
mshoemaker | 0:0826fcc5d020 | 534 | * |
mshoemaker | 0:0826fcc5d020 | 535 | * Description: This function initializes endpoint descriptor |
mshoemaker | 0:0826fcc5d020 | 536 | * |
mshoemaker | 0:0826fcc5d020 | 537 | * Arguments : Pointer to ED strcuture |
mshoemaker | 0:0826fcc5d020 | 538 | * |
mshoemaker | 0:0826fcc5d020 | 539 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 540 | * |
mshoemaker | 0:0826fcc5d020 | 541 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 542 | */ |
mshoemaker | 0:0826fcc5d020 | 543 | |
mshoemaker | 0:0826fcc5d020 | 544 | void Host_EDInit (volatile HCED *ed) |
mshoemaker | 0:0826fcc5d020 | 545 | { |
mshoemaker | 0:0826fcc5d020 | 546 | |
mshoemaker | 0:0826fcc5d020 | 547 | ed->Control = 0; |
mshoemaker | 0:0826fcc5d020 | 548 | ed->TailTd = 0; |
mshoemaker | 0:0826fcc5d020 | 549 | ed->HeadTd = 0; |
mshoemaker | 0:0826fcc5d020 | 550 | ed->Next = 0; |
mshoemaker | 0:0826fcc5d020 | 551 | } |
mshoemaker | 0:0826fcc5d020 | 552 | |
mshoemaker | 0:0826fcc5d020 | 553 | /* |
mshoemaker | 0:0826fcc5d020 | 554 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 555 | * INITIALIZE HOST CONTROLLER COMMUNICATIONS AREA |
mshoemaker | 0:0826fcc5d020 | 556 | * |
mshoemaker | 0:0826fcc5d020 | 557 | * Description: This function initializes host controller communications area |
mshoemaker | 0:0826fcc5d020 | 558 | * |
mshoemaker | 0:0826fcc5d020 | 559 | * Arguments : Pointer to HCCA |
mshoemaker | 0:0826fcc5d020 | 560 | * |
mshoemaker | 0:0826fcc5d020 | 561 | * Returns : |
mshoemaker | 0:0826fcc5d020 | 562 | * |
mshoemaker | 0:0826fcc5d020 | 563 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 564 | */ |
mshoemaker | 0:0826fcc5d020 | 565 | |
mshoemaker | 0:0826fcc5d020 | 566 | void Host_HCCAInit (volatile HCCA *hcca) |
mshoemaker | 0:0826fcc5d020 | 567 | { |
mshoemaker | 0:0826fcc5d020 | 568 | USB_INT32U i; |
mshoemaker | 0:0826fcc5d020 | 569 | |
mshoemaker | 0:0826fcc5d020 | 570 | |
mshoemaker | 0:0826fcc5d020 | 571 | for (i = 0; i < 32; i++) { |
mshoemaker | 0:0826fcc5d020 | 572 | |
mshoemaker | 0:0826fcc5d020 | 573 | hcca->IntTable[i] = 0; |
mshoemaker | 0:0826fcc5d020 | 574 | hcca->FrameNumber = 0; |
mshoemaker | 0:0826fcc5d020 | 575 | hcca->DoneHead = 0; |
mshoemaker | 0:0826fcc5d020 | 576 | } |
mshoemaker | 0:0826fcc5d020 | 577 | |
mshoemaker | 0:0826fcc5d020 | 578 | } |
mshoemaker | 0:0826fcc5d020 | 579 | |
mshoemaker | 0:0826fcc5d020 | 580 | /* |
mshoemaker | 0:0826fcc5d020 | 581 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 582 | * WAIT FOR WDH INTERRUPT |
mshoemaker | 0:0826fcc5d020 | 583 | * |
mshoemaker | 0:0826fcc5d020 | 584 | * Description: This function is infinite loop which breaks when ever a WDH interrupt rises |
mshoemaker | 0:0826fcc5d020 | 585 | * |
mshoemaker | 0:0826fcc5d020 | 586 | * Arguments : None |
mshoemaker | 0:0826fcc5d020 | 587 | * |
mshoemaker | 0:0826fcc5d020 | 588 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 589 | * |
mshoemaker | 0:0826fcc5d020 | 590 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 591 | */ |
mshoemaker | 0:0826fcc5d020 | 592 | |
mshoemaker | 0:0826fcc5d020 | 593 | void Host_WDHWait (void) |
mshoemaker | 0:0826fcc5d020 | 594 | { |
mshoemaker | 0:0826fcc5d020 | 595 | while (!HOST_WdhIntr) { |
mshoemaker | 0:0826fcc5d020 | 596 | ; |
mshoemaker | 0:0826fcc5d020 | 597 | } |
mshoemaker | 0:0826fcc5d020 | 598 | HOST_WdhIntr = 0; |
mshoemaker | 0:0826fcc5d020 | 599 | } |
mshoemaker | 0:0826fcc5d020 | 600 | |
mshoemaker | 0:0826fcc5d020 | 601 | /* |
mshoemaker | 0:0826fcc5d020 | 602 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 603 | * READ LE 32U |
mshoemaker | 0:0826fcc5d020 | 604 | * |
mshoemaker | 0:0826fcc5d020 | 605 | * Description: This function is used to read an unsigned integer from a charecter buffer in the platform |
mshoemaker | 0:0826fcc5d020 | 606 | * containing little endian processor |
mshoemaker | 0:0826fcc5d020 | 607 | * |
mshoemaker | 0:0826fcc5d020 | 608 | * Arguments : pmem Pointer to the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 609 | * |
mshoemaker | 0:0826fcc5d020 | 610 | * Returns : val Unsigned integer |
mshoemaker | 0:0826fcc5d020 | 611 | * |
mshoemaker | 0:0826fcc5d020 | 612 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 613 | */ |
mshoemaker | 0:0826fcc5d020 | 614 | |
mshoemaker | 0:0826fcc5d020 | 615 | USB_INT32U ReadLE32U (volatile USB_INT08U *pmem) |
mshoemaker | 0:0826fcc5d020 | 616 | { |
mshoemaker | 0:0826fcc5d020 | 617 | USB_INT32U val; |
mshoemaker | 0:0826fcc5d020 | 618 | |
mshoemaker | 0:0826fcc5d020 | 619 | ((USB_INT08U *)&val)[0] = pmem[0]; |
mshoemaker | 0:0826fcc5d020 | 620 | ((USB_INT08U *)&val)[1] = pmem[1]; |
mshoemaker | 0:0826fcc5d020 | 621 | ((USB_INT08U *)&val)[2] = pmem[2]; |
mshoemaker | 0:0826fcc5d020 | 622 | ((USB_INT08U *)&val)[3] = pmem[3]; |
mshoemaker | 0:0826fcc5d020 | 623 | |
mshoemaker | 0:0826fcc5d020 | 624 | return (val); |
mshoemaker | 0:0826fcc5d020 | 625 | } |
mshoemaker | 0:0826fcc5d020 | 626 | |
mshoemaker | 0:0826fcc5d020 | 627 | /* |
mshoemaker | 0:0826fcc5d020 | 628 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 629 | * WRITE LE 32U |
mshoemaker | 0:0826fcc5d020 | 630 | * |
mshoemaker | 0:0826fcc5d020 | 631 | * Description: This function is used to write an unsigned integer into a charecter buffer in the platform |
mshoemaker | 0:0826fcc5d020 | 632 | * containing little endian processor. |
mshoemaker | 0:0826fcc5d020 | 633 | * |
mshoemaker | 0:0826fcc5d020 | 634 | * Arguments : pmem Pointer to the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 635 | * val Integer value to be placed in the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 636 | * |
mshoemaker | 0:0826fcc5d020 | 637 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 638 | * |
mshoemaker | 0:0826fcc5d020 | 639 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 640 | */ |
mshoemaker | 0:0826fcc5d020 | 641 | |
mshoemaker | 0:0826fcc5d020 | 642 | void WriteLE32U (volatile USB_INT08U *pmem, |
mshoemaker | 0:0826fcc5d020 | 643 | USB_INT32U val) |
mshoemaker | 0:0826fcc5d020 | 644 | { |
mshoemaker | 0:0826fcc5d020 | 645 | pmem[0] = ((USB_INT08U *)&val)[0]; |
mshoemaker | 0:0826fcc5d020 | 646 | pmem[1] = ((USB_INT08U *)&val)[1]; |
mshoemaker | 0:0826fcc5d020 | 647 | pmem[2] = ((USB_INT08U *)&val)[2]; |
mshoemaker | 0:0826fcc5d020 | 648 | pmem[3] = ((USB_INT08U *)&val)[3]; |
mshoemaker | 0:0826fcc5d020 | 649 | } |
mshoemaker | 0:0826fcc5d020 | 650 | |
mshoemaker | 0:0826fcc5d020 | 651 | /* |
mshoemaker | 0:0826fcc5d020 | 652 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 653 | * READ LE 16U |
mshoemaker | 0:0826fcc5d020 | 654 | * |
mshoemaker | 0:0826fcc5d020 | 655 | * Description: This function is used to read an unsigned short integer from a charecter buffer in the platform |
mshoemaker | 0:0826fcc5d020 | 656 | * containing little endian processor |
mshoemaker | 0:0826fcc5d020 | 657 | * |
mshoemaker | 0:0826fcc5d020 | 658 | * Arguments : pmem Pointer to the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 659 | * |
mshoemaker | 0:0826fcc5d020 | 660 | * Returns : val Unsigned short integer |
mshoemaker | 0:0826fcc5d020 | 661 | * |
mshoemaker | 0:0826fcc5d020 | 662 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 663 | */ |
mshoemaker | 0:0826fcc5d020 | 664 | |
mshoemaker | 0:0826fcc5d020 | 665 | USB_INT16U ReadLE16U (volatile USB_INT08U *pmem) |
mshoemaker | 0:0826fcc5d020 | 666 | { |
mshoemaker | 0:0826fcc5d020 | 667 | USB_INT16U val; |
mshoemaker | 0:0826fcc5d020 | 668 | |
mshoemaker | 0:0826fcc5d020 | 669 | ((USB_INT08U *)&val)[0] = pmem[0]; |
mshoemaker | 0:0826fcc5d020 | 670 | ((USB_INT08U *)&val)[1] = pmem[1]; |
mshoemaker | 0:0826fcc5d020 | 671 | |
mshoemaker | 0:0826fcc5d020 | 672 | |
mshoemaker | 0:0826fcc5d020 | 673 | return (val); |
mshoemaker | 0:0826fcc5d020 | 674 | } |
mshoemaker | 0:0826fcc5d020 | 675 | |
mshoemaker | 0:0826fcc5d020 | 676 | /* |
mshoemaker | 0:0826fcc5d020 | 677 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 678 | * WRITE LE 16U |
mshoemaker | 0:0826fcc5d020 | 679 | * |
mshoemaker | 0:0826fcc5d020 | 680 | * Description: This function is used to write an unsigned short integer into a charecter buffer in the |
mshoemaker | 0:0826fcc5d020 | 681 | * platform containing little endian processor |
mshoemaker | 0:0826fcc5d020 | 682 | * |
mshoemaker | 0:0826fcc5d020 | 683 | * Arguments : pmem Pointer to the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 684 | * val Value to be placed in the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 685 | * |
mshoemaker | 0:0826fcc5d020 | 686 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 687 | * |
mshoemaker | 0:0826fcc5d020 | 688 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 689 | */ |
mshoemaker | 0:0826fcc5d020 | 690 | |
mshoemaker | 0:0826fcc5d020 | 691 | void WriteLE16U (volatile USB_INT08U *pmem, |
mshoemaker | 0:0826fcc5d020 | 692 | USB_INT16U val) |
mshoemaker | 0:0826fcc5d020 | 693 | { |
mshoemaker | 0:0826fcc5d020 | 694 | pmem[0] = ((USB_INT08U *)&val)[0]; |
mshoemaker | 0:0826fcc5d020 | 695 | pmem[1] = ((USB_INT08U *)&val)[1]; |
mshoemaker | 0:0826fcc5d020 | 696 | } |
mshoemaker | 0:0826fcc5d020 | 697 | |
mshoemaker | 0:0826fcc5d020 | 698 | /* |
mshoemaker | 0:0826fcc5d020 | 699 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 700 | * READ BE 32U |
mshoemaker | 0:0826fcc5d020 | 701 | * |
mshoemaker | 0:0826fcc5d020 | 702 | * Description: This function is used to read an unsigned integer from a charecter buffer in the platform |
mshoemaker | 0:0826fcc5d020 | 703 | * containing big endian processor |
mshoemaker | 0:0826fcc5d020 | 704 | * |
mshoemaker | 0:0826fcc5d020 | 705 | * Arguments : pmem Pointer to the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 706 | * |
mshoemaker | 0:0826fcc5d020 | 707 | * Returns : val Unsigned integer |
mshoemaker | 0:0826fcc5d020 | 708 | * |
mshoemaker | 0:0826fcc5d020 | 709 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 710 | */ |
mshoemaker | 0:0826fcc5d020 | 711 | |
mshoemaker | 0:0826fcc5d020 | 712 | USB_INT32U ReadBE32U (volatile USB_INT08U *pmem) |
mshoemaker | 0:0826fcc5d020 | 713 | { |
mshoemaker | 0:0826fcc5d020 | 714 | USB_INT32U val; |
mshoemaker | 0:0826fcc5d020 | 715 | |
mshoemaker | 0:0826fcc5d020 | 716 | ((USB_INT08U *)&val)[0] = pmem[3]; |
mshoemaker | 0:0826fcc5d020 | 717 | ((USB_INT08U *)&val)[1] = pmem[2]; |
mshoemaker | 0:0826fcc5d020 | 718 | ((USB_INT08U *)&val)[2] = pmem[1]; |
mshoemaker | 0:0826fcc5d020 | 719 | ((USB_INT08U *)&val)[3] = pmem[0]; |
mshoemaker | 0:0826fcc5d020 | 720 | |
mshoemaker | 0:0826fcc5d020 | 721 | return (val); |
mshoemaker | 0:0826fcc5d020 | 722 | } |
mshoemaker | 0:0826fcc5d020 | 723 | |
mshoemaker | 0:0826fcc5d020 | 724 | /* |
mshoemaker | 0:0826fcc5d020 | 725 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 726 | * WRITE BE 32U |
mshoemaker | 0:0826fcc5d020 | 727 | * |
mshoemaker | 0:0826fcc5d020 | 728 | * Description: This function is used to write an unsigned integer into a charecter buffer in the platform |
mshoemaker | 0:0826fcc5d020 | 729 | * containing big endian processor |
mshoemaker | 0:0826fcc5d020 | 730 | * |
mshoemaker | 0:0826fcc5d020 | 731 | * Arguments : pmem Pointer to the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 732 | * val Value to be placed in the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 733 | * |
mshoemaker | 0:0826fcc5d020 | 734 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 735 | * |
mshoemaker | 0:0826fcc5d020 | 736 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 737 | */ |
mshoemaker | 0:0826fcc5d020 | 738 | |
mshoemaker | 0:0826fcc5d020 | 739 | void WriteBE32U (volatile USB_INT08U *pmem, |
mshoemaker | 0:0826fcc5d020 | 740 | USB_INT32U val) |
mshoemaker | 0:0826fcc5d020 | 741 | { |
mshoemaker | 0:0826fcc5d020 | 742 | pmem[0] = ((USB_INT08U *)&val)[3]; |
mshoemaker | 0:0826fcc5d020 | 743 | pmem[1] = ((USB_INT08U *)&val)[2]; |
mshoemaker | 0:0826fcc5d020 | 744 | pmem[2] = ((USB_INT08U *)&val)[1]; |
mshoemaker | 0:0826fcc5d020 | 745 | pmem[3] = ((USB_INT08U *)&val)[0]; |
mshoemaker | 0:0826fcc5d020 | 746 | |
mshoemaker | 0:0826fcc5d020 | 747 | } |
mshoemaker | 0:0826fcc5d020 | 748 | |
mshoemaker | 0:0826fcc5d020 | 749 | /* |
mshoemaker | 0:0826fcc5d020 | 750 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 751 | * READ BE 16U |
mshoemaker | 0:0826fcc5d020 | 752 | * |
mshoemaker | 0:0826fcc5d020 | 753 | * Description: This function is used to read an unsigned short integer from a charecter buffer in the platform |
mshoemaker | 0:0826fcc5d020 | 754 | * containing big endian processor |
mshoemaker | 0:0826fcc5d020 | 755 | * |
mshoemaker | 0:0826fcc5d020 | 756 | * Arguments : pmem Pointer to the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 757 | * |
mshoemaker | 0:0826fcc5d020 | 758 | * Returns : val Unsigned short integer |
mshoemaker | 0:0826fcc5d020 | 759 | * |
mshoemaker | 0:0826fcc5d020 | 760 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 761 | */ |
mshoemaker | 0:0826fcc5d020 | 762 | |
mshoemaker | 0:0826fcc5d020 | 763 | USB_INT16U ReadBE16U (volatile USB_INT08U *pmem) |
mshoemaker | 0:0826fcc5d020 | 764 | { |
mshoemaker | 0:0826fcc5d020 | 765 | USB_INT16U val; |
mshoemaker | 0:0826fcc5d020 | 766 | |
mshoemaker | 0:0826fcc5d020 | 767 | |
mshoemaker | 0:0826fcc5d020 | 768 | ((USB_INT08U *)&val)[0] = pmem[1]; |
mshoemaker | 0:0826fcc5d020 | 769 | ((USB_INT08U *)&val)[1] = pmem[0]; |
mshoemaker | 0:0826fcc5d020 | 770 | |
mshoemaker | 0:0826fcc5d020 | 771 | return (val); |
mshoemaker | 0:0826fcc5d020 | 772 | } |
mshoemaker | 0:0826fcc5d020 | 773 | |
mshoemaker | 0:0826fcc5d020 | 774 | /* |
mshoemaker | 0:0826fcc5d020 | 775 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 776 | * WRITE BE 16U |
mshoemaker | 0:0826fcc5d020 | 777 | * |
mshoemaker | 0:0826fcc5d020 | 778 | * Description: This function is used to write an unsigned short integer into the charecter buffer in the |
mshoemaker | 0:0826fcc5d020 | 779 | * platform containing big endian processor |
mshoemaker | 0:0826fcc5d020 | 780 | * |
mshoemaker | 0:0826fcc5d020 | 781 | * Arguments : pmem Pointer to the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 782 | * val Value to be placed in the charecter buffer |
mshoemaker | 0:0826fcc5d020 | 783 | * |
mshoemaker | 0:0826fcc5d020 | 784 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 785 | * |
mshoemaker | 0:0826fcc5d020 | 786 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 787 | */ |
mshoemaker | 0:0826fcc5d020 | 788 | |
mshoemaker | 0:0826fcc5d020 | 789 | void WriteBE16U (volatile USB_INT08U *pmem, |
mshoemaker | 0:0826fcc5d020 | 790 | USB_INT16U val) |
mshoemaker | 0:0826fcc5d020 | 791 | { |
mshoemaker | 0:0826fcc5d020 | 792 | pmem[0] = ((USB_INT08U *)&val)[1]; |
mshoemaker | 0:0826fcc5d020 | 793 | pmem[1] = ((USB_INT08U *)&val)[0]; |
mshoemaker | 0:0826fcc5d020 | 794 | } |