This package contains a simple test of tests for various elements of the SmartBoard hardware, which is a simple baseboard designed for easy embedding. It is able to run both a semi-automatic test suite as well as allow interactive testing.
Dependencies: EthernetNetIf NTPClient_NetServices mbed
usbhost_lpc17xx.c
00001 /* 00002 ************************************************************************************************************** 00003 * NXP USB Host Stack 00004 * 00005 * (c) Copyright 2008, NXP SemiConductors 00006 * (c) Copyright 2008, OnChip Technologies LLC 00007 * All Rights Reserved 00008 * 00009 * www.nxp.com 00010 * www.onchiptech.com 00011 * 00012 * File : usbhost_lpc17xx.c 00013 * Programmer(s) : Ravikanth.P 00014 * Version : 00015 * 00016 ************************************************************************************************************** 00017 */ 00018 00019 /* 00020 ************************************************************************************************************** 00021 * INCLUDE HEADER FILES 00022 ************************************************************************************************************** 00023 */ 00024 00025 #include "usbhost_lpc17xx.h" 00026 00027 // Added DEBUG_X to eliminate annoying print statements 00028 // Copyright (c) 2011, David Smart 00029 00030 // define for additional details 00031 //#define DEBUG_X 00032 00033 /* 00034 ************************************************************************************************************** 00035 * GLOBAL VARIABLES 00036 ************************************************************************************************************** 00037 */ 00038 int gUSBConnected; 00039 00040 volatile USB_INT32U HOST_RhscIntr = 0; /* Root Hub Status Change interrupt */ 00041 volatile USB_INT32U HOST_WdhIntr = 0; /* Semaphore to wait until the TD is submitted */ 00042 volatile USB_INT08U HOST_TDControlStatus = 0; 00043 volatile HCED *EDCtrl; /* Control endpoint descriptor structure */ 00044 volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */ 00045 volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */ 00046 volatile HCTD *TDHead; /* Head transfer descriptor structure */ 00047 volatile HCTD *TDTail; /* Tail transfer descriptor structure */ 00048 volatile HCCA *Hcca; /* Host Controller Communications Area structure */ 00049 USB_INT16U *TDBufNonVol; /* Identical to TDBuffer just to reduce compiler warnings */ 00050 volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */ 00051 00052 // USB host structures 00053 // AHB SRAM block 1 00054 #define HOSTBASEADDR 0x2007C000 00055 // reserve memory for the linker 00056 static USB_INT08U HostBuf[0x200] __attribute__((at(HOSTBASEADDR))); 00057 /* 00058 ************************************************************************************************************** 00059 * DELAY IN MILLI SECONDS 00060 * 00061 * Description: This function provides a delay in milli seconds 00062 * 00063 * Arguments : delay The delay required 00064 * 00065 * Returns : None 00066 * 00067 ************************************************************************************************************** 00068 */ 00069 00070 void Host_DelayMS (USB_INT32U delay) 00071 { 00072 volatile USB_INT32U i; 00073 00074 00075 for (i = 0; i < delay; i++) { 00076 Host_DelayUS(1000); 00077 } 00078 } 00079 00080 /* 00081 ************************************************************************************************************** 00082 * DELAY IN MICRO SECONDS 00083 * 00084 * Description: This function provides a delay in micro seconds 00085 * 00086 * Arguments : delay The delay required 00087 * 00088 * Returns : None 00089 * 00090 ************************************************************************************************************** 00091 */ 00092 00093 void Host_DelayUS (USB_INT32U delay) 00094 { 00095 volatile USB_INT32U i; 00096 00097 00098 for (i = 0; i < (4 * delay); i++) { /* This logic was tested. It gives app. 1 micro sec delay */ 00099 ; 00100 } 00101 } 00102 00103 // bits of the USB/OTG clock control register 00104 #define HOST_CLK_EN (1<<0) 00105 #define DEV_CLK_EN (1<<1) 00106 #define PORTSEL_CLK_EN (1<<3) 00107 #define AHB_CLK_EN (1<<4) 00108 00109 // bits of the USB/OTG clock status register 00110 #define HOST_CLK_ON (1<<0) 00111 #define DEV_CLK_ON (1<<1) 00112 #define PORTSEL_CLK_ON (1<<3) 00113 #define AHB_CLK_ON (1<<4) 00114 00115 // we need host clock, OTG/portsel clock and AHB clock 00116 #define CLOCK_MASK (HOST_CLK_EN | PORTSEL_CLK_EN | AHB_CLK_EN) 00117 00118 /* 00119 ************************************************************************************************************** 00120 * INITIALIZE THE HOST CONTROLLER 00121 * 00122 * Description: This function initializes lpc17xx host controller 00123 * 00124 * Arguments : None 00125 * 00126 * Returns : 00127 * 00128 ************************************************************************************************************** 00129 */ 00130 void Host_Init (void) 00131 { 00132 #ifdef DEBUG_X 00133 PRINT_Log("In Host_Init\n"); 00134 #endif 00135 NVIC_DisableIRQ(USB_IRQn); /* Disable the USB interrupt source */ 00136 00137 // turn on power for USB 00138 LPC_SC->PCONP |= (1UL<<31); 00139 // Enable USB host clock, port selection and AHB clock 00140 LPC_USB->USBClkCtrl |= CLOCK_MASK; 00141 // Wait for clocks to become available 00142 while ((LPC_USB->USBClkSt & CLOCK_MASK) != CLOCK_MASK) 00143 ; 00144 00145 // it seems the bits[0:1] mean the following 00146 // 0: U1=device, U2=host 00147 // 1: U1=host, U2=host 00148 // 2: reserved 00149 // 3: U1=host, U2=device 00150 // NB: this register is only available if OTG clock (aka "port select") is enabled!! 00151 // since we don't care about port 2, set just bit 0 to 1 (U1=host) 00152 LPC_USB->OTGStCtrl |= 1; 00153 00154 // now that we've configured the ports, we can turn off the portsel clock 00155 LPC_USB->USBClkCtrl &= ~PORTSEL_CLK_EN; 00156 00157 // power pins are not connected on mbed, so we can skip them 00158 /* P1[18] = USB_UP_LED, 01 */ 00159 /* P1[19] = /USB_PPWR, 10 */ 00160 /* P1[22] = USB_PWRD, 10 */ 00161 /* P1[27] = /USB_OVRCR, 10 */ 00162 /*LPC_PINCON->PINSEL3 &= ~((3<<4) | (3<<6) | (3<<12) | (3<<22)); 00163 LPC_PINCON->PINSEL3 |= ((1<<4)|(2<<6) | (2<<12) | (2<<22)); // 0x00802080 00164 */ 00165 00166 // configure USB D+/D- pins 00167 /* P0[29] = USB_D+, 01 */ 00168 /* P0[30] = USB_D-, 01 */ 00169 LPC_PINCON->PINSEL1 &= ~((3<<26) | (3<<28)); 00170 LPC_PINCON->PINSEL1 |= ((1<<26)|(1<<28)); // 0x14000000 00171 00172 #ifdef DEBUG_X 00173 PRINT_Log("Initializing Host Stack\n"); 00174 #endif 00175 00176 Hcca = (volatile HCCA *)(HostBuf+0x000); 00177 TDHead = (volatile HCTD *)(HostBuf+0x100); 00178 TDTail = (volatile HCTD *)(HostBuf+0x110); 00179 EDCtrl = (volatile HCED *)(HostBuf+0x120); 00180 EDBulkIn = (volatile HCED *)(HostBuf+0x130); 00181 EDBulkOut = (volatile HCED *)(HostBuf+0x140); 00182 TDBuffer = (volatile USB_INT08U *)(HostBuf+0x150); 00183 00184 /* Initialize all the TDs, EDs and HCCA to 0 */ 00185 Host_EDInit(EDCtrl); 00186 Host_EDInit(EDBulkIn); 00187 Host_EDInit(EDBulkOut); 00188 Host_TDInit(TDHead); 00189 Host_TDInit(TDTail); 00190 Host_HCCAInit(Hcca); 00191 00192 Host_DelayMS(50); /* Wait 50 ms before apply reset */ 00193 LPC_USB->HcControl = 0; /* HARDWARE RESET */ 00194 LPC_USB->HcControlHeadED = 0; /* Initialize Control list head to Zero */ 00195 LPC_USB->HcBulkHeadED = 0; /* Initialize Bulk list head to Zero */ 00196 00197 /* SOFTWARE RESET */ 00198 LPC_USB->HcCommandStatus = OR_CMD_STATUS_HCR; 00199 LPC_USB->HcFmInterval = DEFAULT_FMINTERVAL; /* Write Fm Interval and Largest Data Packet Counter */ 00200 00201 /* Put HC in operational state */ 00202 LPC_USB->HcControl = (LPC_USB->HcControl & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER; 00203 LPC_USB->HcRhStatus = OR_RH_STATUS_LPSC; /* Set Global Power */ 00204 00205 LPC_USB->HcHCCA = (USB_INT32U)Hcca; 00206 LPC_USB->HcInterruptStatus |= LPC_USB->HcInterruptStatus; /* Clear Interrrupt Status */ 00207 00208 00209 LPC_USB->HcInterruptEnable = OR_INTR_ENABLE_MIE | 00210 OR_INTR_ENABLE_WDH | 00211 OR_INTR_ENABLE_RHSC; 00212 00213 NVIC_SetPriority(USB_IRQn, 0); /* highest priority */ 00214 /* Enable the USB Interrupt */ 00215 NVIC_EnableIRQ(USB_IRQn); 00216 #ifdef DEBUG_X 00217 PRINT_Log("Host Initialized\n"); 00218 #endif 00219 } 00220 00221 /* 00222 ************************************************************************************************************** 00223 * INTERRUPT SERVICE ROUTINE 00224 * 00225 * Description: This function services the interrupt caused by host controller 00226 * 00227 * Arguments : None 00228 * 00229 * Returns : None 00230 * 00231 ************************************************************************************************************** 00232 */ 00233 00234 void USB_IRQHandler (void) __irq 00235 { 00236 USB_INT32U int_status; 00237 USB_INT32U ie_status; 00238 00239 int_status = LPC_USB->HcInterruptStatus; /* Read Interrupt Status */ 00240 ie_status = LPC_USB->HcInterruptEnable; /* Read Interrupt enable status */ 00241 00242 if (!(int_status & ie_status)) { 00243 return; 00244 } else { 00245 00246 int_status = int_status & ie_status; 00247 if (int_status & OR_INTR_STATUS_RHSC) { /* Root hub status change interrupt */ 00248 if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CSC) { 00249 if (LPC_USB->HcRhStatus & OR_RH_STATUS_DRWE) { 00250 /* 00251 * When DRWE is on, Connect Status Change 00252 * means a remote wakeup event. 00253 */ 00254 HOST_RhscIntr = 1;// JUST SOMETHING FOR A BREAKPOINT 00255 } 00256 else { 00257 /* 00258 * When DRWE is off, Connect Status Change 00259 * is NOT a remote wakeup event 00260 */ 00261 if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) { 00262 if (!gUSBConnected) { 00263 HOST_TDControlStatus = 0; 00264 HOST_WdhIntr = 0; 00265 HOST_RhscIntr = 1; 00266 gUSBConnected = 1; 00267 } 00268 else { 00269 #ifdef DEBUG_X 00270 PRINT_Log("Spurious status change (connected)?\n"); 00271 #endif 00272 } 00273 } else { 00274 if (gUSBConnected) { 00275 LPC_USB->HcInterruptEnable = 0; // why do we get multiple disc. rupts??? 00276 HOST_RhscIntr = 0; 00277 gUSBConnected = 0; 00278 } 00279 else { 00280 #ifdef DEBUG_X 00281 PRINT_Log("Spurious status change (disconnected)?\n"); 00282 #endif 00283 } 00284 } 00285 } 00286 LPC_USB->HcRhPortStatus1 = OR_RH_PORT_CSC; 00287 } 00288 if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRSC) { 00289 LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; 00290 } 00291 } 00292 if (int_status & OR_INTR_STATUS_WDH) { /* Writeback Done Head interrupt */ 00293 HOST_WdhIntr = 1; 00294 HOST_TDControlStatus = (TDHead->Control >> 28) & 0xf; 00295 } 00296 LPC_USB->HcInterruptStatus = int_status; /* Clear interrupt status register */ 00297 } 00298 return; 00299 } 00300 00301 /* 00302 ************************************************************************************************************** 00303 * PROCESS TRANSFER DESCRIPTOR 00304 * 00305 * Description: This function processes the transfer descriptor 00306 * 00307 * Arguments : ed Endpoint descriptor that contains this transfer descriptor 00308 * token SETUP, IN, OUT 00309 * buffer Current Buffer Pointer of the transfer descriptor 00310 * buffer_len Length of the buffer 00311 * 00312 * Returns : OK if TD submission is successful 00313 * ERROR if TD submission fails 00314 * 00315 ************************************************************************************************************** 00316 */ 00317 00318 USB_INT32S Host_ProcessTD (volatile HCED *ed, 00319 volatile USB_INT32U token, 00320 volatile USB_INT08U *buffer, 00321 USB_INT32U buffer_len) 00322 { 00323 volatile USB_INT32U td_toggle; 00324 00325 00326 if (ed == EDCtrl) { 00327 if (token == TD_SETUP) { 00328 td_toggle = TD_TOGGLE_0; 00329 } else { 00330 td_toggle = TD_TOGGLE_1; 00331 } 00332 } else { 00333 td_toggle = 0; 00334 } 00335 TDHead->Control = (TD_ROUNDING | 00336 token | 00337 TD_DELAY_INT(0) | 00338 td_toggle | 00339 TD_CC); 00340 TDTail->Control = 0; 00341 TDHead->CurrBufPtr = (USB_INT32U) buffer; 00342 TDTail->CurrBufPtr = 0; 00343 TDHead->Next = (USB_INT32U) TDTail; 00344 TDTail->Next = 0; 00345 TDHead->BufEnd = (USB_INT32U)(buffer + (buffer_len - 1)); 00346 TDTail->BufEnd = 0; 00347 00348 ed->HeadTd = (USB_INT32U)TDHead | ((ed->HeadTd) & 0x00000002); 00349 ed->TailTd = (USB_INT32U)TDTail; 00350 ed->Next = 0; 00351 00352 if (ed == EDCtrl) { 00353 LPC_USB->HcControlHeadED = (USB_INT32U)ed; 00354 LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_CLF; 00355 LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_CLE; 00356 } else { 00357 LPC_USB->HcBulkHeadED = (USB_INT32U)ed; 00358 LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF; 00359 LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE; 00360 } 00361 00362 Host_WDHWait(); 00363 00364 // if (!(TDHead->Control & 0xF0000000)) { 00365 if (!HOST_TDControlStatus) { 00366 return (OK); 00367 } else { 00368 return (ERR_TD_FAIL); 00369 } 00370 } 00371 00372 /* 00373 ************************************************************************************************************** 00374 * ENUMERATE THE DEVICE 00375 * 00376 * Description: This function is used to enumerate the device connected 00377 * 00378 * Arguments : None 00379 * 00380 * Returns : None 00381 * 00382 ************************************************************************************************************** 00383 */ 00384 00385 USB_INT32S Host_EnumDev (void) 00386 { 00387 USB_INT32S rc; 00388 00389 #ifdef DEBUG_X 00390 PRINT_Log("Connect a Mass Storage device\n"); 00391 #endif 00392 while (!HOST_RhscIntr) 00393 __WFI(); 00394 Host_DelayMS(100); /* USB 2.0 spec says atleast 50ms delay beore port reset */ 00395 LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRS; // Initiate port reset 00396 while (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRS) 00397 __WFI(); // Wait for port reset to complete... 00398 LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; // ...and clear port reset signal 00399 Host_DelayMS(200); /* Wait for 100 MS after port reset */ 00400 00401 EDCtrl->Control = 8 << 16; /* Put max pkt size = 8 */ 00402 /* Read first 8 bytes of device desc */ 00403 rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_DEVICE, 0, TDBuffer, 8); 00404 if (rc != OK) { 00405 PRINT_Err(rc); 00406 return (rc); 00407 } 00408 EDCtrl->Control = TDBuffer[7] << 16; /* Get max pkt size of endpoint 0 */ 00409 rc = HOST_SET_ADDRESS(1); /* Set the device address to 1 */ 00410 if (rc != OK) { 00411 PRINT_Err(rc); 00412 return (rc); 00413 } 00414 Host_DelayMS(2); 00415 EDCtrl->Control = (EDCtrl->Control) | 1; /* Modify control pipe with address 1 */ 00416 /* Get the configuration descriptor */ 00417 rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, 9); 00418 if (rc != OK) { 00419 PRINT_Err(rc); 00420 return (rc); 00421 } 00422 /* Get the first configuration data */ 00423 rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, ReadLE16U(&TDBuffer[2])); 00424 if (rc != OK) { 00425 PRINT_Err(rc); 00426 return (rc); 00427 } 00428 rc = MS_ParseConfiguration(); /* Parse the configuration */ 00429 if (rc != OK) { 00430 PRINT_Err(rc); 00431 return (rc); 00432 } 00433 rc = USBH_SET_CONFIGURATION(1); /* Select device configuration 1 */ 00434 if (rc != OK) { 00435 PRINT_Err(rc); 00436 } 00437 Host_DelayMS(100); /* Some devices may require this delay */ 00438 return (rc); 00439 } 00440 00441 /* 00442 ************************************************************************************************************** 00443 * RECEIVE THE CONTROL INFORMATION 00444 * 00445 * Description: This function is used to receive the control information 00446 * 00447 * Arguments : bm_request_type 00448 * b_request 00449 * w_value 00450 * w_index 00451 * w_length 00452 * buffer 00453 * 00454 * Returns : OK if Success 00455 * ERROR if Failed 00456 * 00457 ************************************************************************************************************** 00458 */ 00459 00460 USB_INT32S Host_CtrlRecv ( USB_INT08U bm_request_type, 00461 USB_INT08U b_request, 00462 USB_INT16U w_value, 00463 USB_INT16U w_index, 00464 USB_INT16U w_length, 00465 volatile USB_INT08U *buffer) 00466 { 00467 USB_INT32S rc; 00468 00469 00470 Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length); 00471 rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8); 00472 if (rc == OK) { 00473 if (w_length) { 00474 rc = Host_ProcessTD(EDCtrl, TD_IN, TDBuffer, w_length); 00475 } 00476 if (rc == OK) { 00477 rc = Host_ProcessTD(EDCtrl, TD_OUT, NULL, 0); 00478 } 00479 } 00480 return (rc); 00481 } 00482 00483 /* 00484 ************************************************************************************************************** 00485 * SEND THE CONTROL INFORMATION 00486 * 00487 * Description: This function is used to send the control information 00488 * 00489 * Arguments : None 00490 * 00491 * Returns : OK if Success 00492 * ERR_INVALID_BOOTSIG if Failed 00493 * 00494 ************************************************************************************************************** 00495 */ 00496 00497 USB_INT32S Host_CtrlSend ( USB_INT08U bm_request_type, 00498 USB_INT08U b_request, 00499 USB_INT16U w_value, 00500 USB_INT16U w_index, 00501 USB_INT16U w_length, 00502 volatile USB_INT08U *buffer) 00503 { 00504 USB_INT32S rc; 00505 00506 00507 Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length); 00508 00509 rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8); 00510 if (rc == OK) { 00511 if (w_length) { 00512 rc = Host_ProcessTD(EDCtrl, TD_OUT, TDBuffer, w_length); 00513 } 00514 if (rc == OK) { 00515 rc = Host_ProcessTD(EDCtrl, TD_IN, NULL, 0); 00516 } 00517 } 00518 return (rc); 00519 } 00520 00521 /* 00522 ************************************************************************************************************** 00523 * FILL SETUP PACKET 00524 * 00525 * Description: This function is used to fill the setup packet 00526 * 00527 * Arguments : None 00528 * 00529 * Returns : OK if Success 00530 * ERR_INVALID_BOOTSIG if Failed 00531 * 00532 ************************************************************************************************************** 00533 */ 00534 00535 void Host_FillSetup (USB_INT08U bm_request_type, 00536 USB_INT08U b_request, 00537 USB_INT16U w_value, 00538 USB_INT16U w_index, 00539 USB_INT16U w_length) 00540 { 00541 int i; 00542 for (i=0;i<w_length;i++) 00543 TDBuffer[i] = 0; 00544 00545 TDBuffer[0] = bm_request_type; 00546 TDBuffer[1] = b_request; 00547 WriteLE16U(&TDBuffer[2], w_value); 00548 WriteLE16U(&TDBuffer[4], w_index); 00549 WriteLE16U(&TDBuffer[6], w_length); 00550 } 00551 00552 00553 00554 /* 00555 ************************************************************************************************************** 00556 * INITIALIZE THE TRANSFER DESCRIPTOR 00557 * 00558 * Description: This function initializes transfer descriptor 00559 * 00560 * Arguments : Pointer to TD structure 00561 * 00562 * Returns : None 00563 * 00564 ************************************************************************************************************** 00565 */ 00566 00567 void Host_TDInit (volatile HCTD *td) 00568 { 00569 00570 td->Control = 0; 00571 td->CurrBufPtr = 0; 00572 td->Next = 0; 00573 td->BufEnd = 0; 00574 } 00575 00576 /* 00577 ************************************************************************************************************** 00578 * INITIALIZE THE ENDPOINT DESCRIPTOR 00579 * 00580 * Description: This function initializes endpoint descriptor 00581 * 00582 * Arguments : Pointer to ED strcuture 00583 * 00584 * Returns : None 00585 * 00586 ************************************************************************************************************** 00587 */ 00588 00589 void Host_EDInit (volatile HCED *ed) 00590 { 00591 00592 ed->Control = 0; 00593 ed->TailTd = 0; 00594 ed->HeadTd = 0; 00595 ed->Next = 0; 00596 } 00597 00598 /* 00599 ************************************************************************************************************** 00600 * INITIALIZE HOST CONTROLLER COMMUNICATIONS AREA 00601 * 00602 * Description: This function initializes host controller communications area 00603 * 00604 * Arguments : Pointer to HCCA 00605 * 00606 * Returns : 00607 * 00608 ************************************************************************************************************** 00609 */ 00610 00611 void Host_HCCAInit (volatile HCCA *hcca) 00612 { 00613 USB_INT32U i; 00614 00615 00616 for (i = 0; i < 32; i++) { 00617 00618 hcca->IntTable[i] = 0; 00619 hcca->FrameNumber = 0; 00620 hcca->DoneHead = 0; 00621 } 00622 00623 } 00624 00625 /* 00626 ************************************************************************************************************** 00627 * WAIT FOR WDH INTERRUPT 00628 * 00629 * Description: This function is infinite loop which breaks when ever a WDH interrupt rises 00630 * 00631 * Arguments : None 00632 * 00633 * Returns : None 00634 * 00635 ************************************************************************************************************** 00636 */ 00637 00638 void Host_WDHWait (void) 00639 { 00640 while (!HOST_WdhIntr) 00641 __WFI(); 00642 00643 HOST_WdhIntr = 0; 00644 } 00645 00646 /* 00647 ************************************************************************************************************** 00648 * READ LE 32U 00649 * 00650 * Description: This function is used to read an unsigned integer from a character buffer in the platform 00651 * containing little endian processor 00652 * 00653 * Arguments : pmem Pointer to the character buffer 00654 * 00655 * Returns : val Unsigned integer 00656 * 00657 ************************************************************************************************************** 00658 */ 00659 00660 USB_INT32U ReadLE32U (volatile USB_INT08U *pmem) 00661 { 00662 USB_INT32U val = *(USB_INT32U*)pmem; 00663 #ifdef __BIG_ENDIAN 00664 return __REV(val); 00665 #else 00666 return val; 00667 #endif 00668 } 00669 00670 /* 00671 ************************************************************************************************************** 00672 * WRITE LE 32U 00673 * 00674 * Description: This function is used to write an unsigned integer into a charecter buffer in the platform 00675 * containing little endian processor. 00676 * 00677 * Arguments : pmem Pointer to the charecter buffer 00678 * val Integer value to be placed in the charecter buffer 00679 * 00680 * Returns : None 00681 * 00682 ************************************************************************************************************** 00683 */ 00684 00685 void WriteLE32U (volatile USB_INT08U *pmem, 00686 USB_INT32U val) 00687 { 00688 #ifdef __BIG_ENDIAN 00689 *(USB_INT32U*)pmem = __REV(val); 00690 #else 00691 *(USB_INT32U*)pmem = val; 00692 #endif 00693 } 00694 00695 /* 00696 ************************************************************************************************************** 00697 * READ LE 16U 00698 * 00699 * Description: This function is used to read an unsigned short integer from a charecter buffer in the platform 00700 * containing little endian processor 00701 * 00702 * Arguments : pmem Pointer to the charecter buffer 00703 * 00704 * Returns : val Unsigned short integer 00705 * 00706 ************************************************************************************************************** 00707 */ 00708 00709 USB_INT16U ReadLE16U (volatile USB_INT08U *pmem) 00710 { 00711 USB_INT16U val = *(USB_INT16U*)pmem; 00712 #ifdef __BIG_ENDIAN 00713 return __REV16(val); 00714 #else 00715 return val; 00716 #endif 00717 } 00718 00719 /* 00720 ************************************************************************************************************** 00721 * WRITE LE 16U 00722 * 00723 * Description: This function is used to write an unsigned short integer into a charecter buffer in the 00724 * platform containing little endian processor 00725 * 00726 * Arguments : pmem Pointer to the charecter buffer 00727 * val Value to be placed in the charecter buffer 00728 * 00729 * Returns : None 00730 * 00731 ************************************************************************************************************** 00732 */ 00733 00734 void WriteLE16U (volatile USB_INT08U *pmem, 00735 USB_INT16U val) 00736 { 00737 #ifdef __BIG_ENDIAN 00738 *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF); 00739 #else 00740 *(USB_INT16U*)pmem = val; 00741 #endif 00742 } 00743 00744 /* 00745 ************************************************************************************************************** 00746 * READ BE 32U 00747 * 00748 * Description: This function is used to read an unsigned integer from a charecter buffer in the platform 00749 * containing big endian processor 00750 * 00751 * Arguments : pmem Pointer to the charecter buffer 00752 * 00753 * Returns : val Unsigned integer 00754 * 00755 ************************************************************************************************************** 00756 */ 00757 00758 USB_INT32U ReadBE32U (volatile USB_INT08U *pmem) 00759 { 00760 USB_INT32U val = *(USB_INT32U*)pmem; 00761 #ifdef __BIG_ENDIAN 00762 return val; 00763 #else 00764 return __REV(val); 00765 #endif 00766 } 00767 00768 /* 00769 ************************************************************************************************************** 00770 * WRITE BE 32U 00771 * 00772 * Description: This function is used to write an unsigned integer into a charecter buffer in the platform 00773 * containing big endian processor 00774 * 00775 * Arguments : pmem Pointer to the charecter buffer 00776 * val Value to be placed in the charecter buffer 00777 * 00778 * Returns : None 00779 * 00780 ************************************************************************************************************** 00781 */ 00782 00783 void WriteBE32U (volatile USB_INT08U *pmem, 00784 USB_INT32U val) 00785 { 00786 #ifdef __BIG_ENDIAN 00787 *(USB_INT32U*)pmem = val; 00788 #else 00789 *(USB_INT32U*)pmem = __REV(val); 00790 #endif 00791 } 00792 00793 /* 00794 ************************************************************************************************************** 00795 * READ BE 16U 00796 * 00797 * Description: This function is used to read an unsigned short integer from a charecter buffer in the platform 00798 * containing big endian processor 00799 * 00800 * Arguments : pmem Pointer to the charecter buffer 00801 * 00802 * Returns : val Unsigned short integer 00803 * 00804 ************************************************************************************************************** 00805 */ 00806 00807 USB_INT16U ReadBE16U (volatile USB_INT08U *pmem) 00808 { 00809 USB_INT16U val = *(USB_INT16U*)pmem; 00810 #ifdef __BIG_ENDIAN 00811 return val; 00812 #else 00813 return __REV16(val); 00814 #endif 00815 } 00816 00817 /* 00818 ************************************************************************************************************** 00819 * WRITE BE 16U 00820 * 00821 * Description: This function is used to write an unsigned short integer into the charecter buffer in the 00822 * platform containing big endian processor 00823 * 00824 * Arguments : pmem Pointer to the charecter buffer 00825 * val Value to be placed in the charecter buffer 00826 * 00827 * Returns : None 00828 * 00829 ************************************************************************************************************** 00830 */ 00831 00832 void WriteBE16U (volatile USB_INT08U *pmem, 00833 USB_INT16U val) 00834 { 00835 #ifdef __BIG_ENDIAN 00836 *(USB_INT16U*)pmem = val; 00837 #else 00838 *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF); 00839 #endif 00840 }
Generated on Thu Jul 21 2022 00:25:24 by 1.7.2