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