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