Dependencies:   mbed

Committer:
slowness
Date:
Fri Aug 26 12:19:16 2011 +0000
Revision:
0:4359b47b3d7c

        

Who changed what in which revision?

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