code

Dependencies:   C12832_lcd CMPS03 FatFileSystemCpp GPS MMA7660 mbed

Fork of CompleteMbed by Group 14

Committer:
styles22
Date:
Tue Mar 21 14:17:48 2017 +0000
Revision:
8:32bb67e3eb06
Parent:
0:2557081b4322
Changed File to output time from gps

Who changed what in which revision?

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