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