Compact Flash I/O test

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbhost_lpc17xx.c Source File

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 volatile 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 **************************************************************************************************************
00286 *                                     PROCESS TRANSFER DESCRIPTOR
00287 *
00288 * Description: This function processes the transfer descriptor
00289 *
00290 * Arguments  : ed            Endpoint descriptor that contains this transfer descriptor
00291 *              token         SETUP, IN, OUT
00292 *              buffer        Current Buffer Pointer of the transfer descriptor
00293 *              buffer_len    Length of the buffer
00294 *
00295 * Returns    : OK       if TD submission is successful
00296 *              ERROR    if TD submission fails
00297 *
00298 **************************************************************************************************************
00299 */
00300 
00301 USB_INT32S  Host_ProcessTD (volatile  HCED       *ed,
00302                             volatile  USB_INT32U  token,
00303                             volatile  USB_INT08U *buffer,
00304                                       USB_INT32U  buffer_len)
00305 {
00306     volatile  USB_INT32U   td_toggle;
00307 
00308 
00309     if (ed == EDCtrl) {
00310         if (token == TD_SETUP) {
00311             td_toggle = TD_TOGGLE_0;
00312         } else {
00313             td_toggle = TD_TOGGLE_1;
00314         }
00315     } else {
00316         td_toggle = 0;
00317     }
00318     TDHead->Control = (TD_ROUNDING    |
00319                       token           |
00320                       TD_DELAY_INT(0) |                           
00321                       td_toggle       |
00322                       TD_CC);
00323     TDTail->Control = 0;
00324     TDHead->CurrBufPtr   = (USB_INT32U) buffer;
00325     TDTail->CurrBufPtr   = 0;
00326     TDHead->Next         = (USB_INT32U) TDTail;
00327     TDTail->Next         = 0;
00328     TDHead->BufEnd       = (USB_INT32U)(buffer + (buffer_len - 1));
00329     TDTail->BufEnd       = 0;
00330 
00331     ed->HeadTd  = (USB_INT32U)TDHead | ((ed->HeadTd) & 0x00000002);
00332     ed->TailTd  = (USB_INT32U)TDTail;
00333     ed->Next    = 0;
00334 
00335     if (ed == EDCtrl) {
00336         LPC_USB->HcControlHeadED = (USB_INT32U)ed;
00337         LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_CLF;
00338         LPC_USB->HcControl       = LPC_USB->HcControl       | OR_CONTROL_CLE;
00339     } else {
00340         LPC_USB->HcBulkHeadED    = (USB_INT32U)ed;
00341         LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF;
00342         LPC_USB->HcControl       = LPC_USB->HcControl       | OR_CONTROL_BLE;
00343     }    
00344 
00345     Host_WDHWait();
00346 
00347 //    if (!(TDHead->Control & 0xF0000000)) {
00348     if (!HOST_TDControlStatus) {
00349         return (OK);
00350     } else {      
00351         return (ERR_TD_FAIL);
00352     }
00353 }
00354 
00355 /*
00356 **************************************************************************************************************
00357 *                                       ENUMERATE THE DEVICE
00358 *
00359 * Description: This function is used to enumerate the device connected
00360 *
00361 * Arguments  : None
00362 *
00363 * Returns    : None
00364 *
00365 **************************************************************************************************************
00366 */
00367 
00368 USB_INT32S  Host_EnumDev (void)
00369 {
00370     USB_INT32S  rc;
00371 
00372    // PRINT_Log("Connect a Mass Storage device\r\n");
00373     while (!HOST_RhscIntr)
00374         __WFI();
00375     Host_DelayMS(100);                             /* USB 2.0 spec says atleast 50ms delay beore port reset */
00376     LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRS; // Initiate port reset
00377     while (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRS)
00378         __WFI(); // Wait for port reset to complete...
00379     LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; // ...and clear port reset signal
00380     Host_DelayMS(200);                                                 /* Wait for 100 MS after port reset  */
00381 
00382     EDCtrl->Control = 8 << 16;                                         /* Put max pkt size = 8              */
00383                                                                        /* Read first 8 bytes of device desc */
00384     rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_DEVICE, 0, TDBuffer, 8);
00385     if (rc != OK) {
00386         PRINT_Err(rc);
00387         return (rc);
00388     }
00389     EDCtrl->Control = TDBuffer[7] << 16;                               /* Get max pkt size of endpoint 0    */
00390     rc = HOST_SET_ADDRESS(1);                                          /* Set the device address to 1       */
00391     if (rc != OK) {
00392         PRINT_Err(rc);
00393         return (rc);
00394     }
00395     Host_DelayMS(2);
00396     EDCtrl->Control = (EDCtrl->Control) | 1;                          /* Modify control pipe with address 1 */
00397                                                                       /* Get the configuration descriptor   */
00398     rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, 9);
00399     if (rc != OK) {
00400         PRINT_Err(rc);
00401         return (rc);
00402     }
00403                                                                        /* Get the first configuration data  */
00404     rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, ReadLE16U(&TDBuffer[2]));
00405     if (rc != OK) {
00406         PRINT_Err(rc);
00407         return (rc);
00408     }
00409     rc = MS_ParseConfiguration();                                      /* Parse the configuration           */
00410     if (rc != OK) {
00411         PRINT_Err(rc);
00412         return (rc);
00413     }
00414     rc = USBH_SET_CONFIGURATION(1);                                    /* Select device configuration 1     */
00415     if (rc != OK) {
00416         PRINT_Err(rc);
00417     }
00418     Host_DelayMS(100);                                               /* Some devices may require this delay */
00419     return (rc);
00420 }
00421 
00422 /*
00423 **************************************************************************************************************
00424 *                                        RECEIVE THE CONTROL INFORMATION
00425 *
00426 * Description: This function is used to receive the control information
00427 *
00428 * Arguments  : bm_request_type
00429 *              b_request
00430 *              w_value
00431 *              w_index
00432 *              w_length
00433 *              buffer
00434 *
00435 * Returns    : OK       if Success
00436 *              ERROR    if Failed
00437 *
00438 **************************************************************************************************************
00439 */
00440    
00441 USB_INT32S  Host_CtrlRecv (         USB_INT08U   bm_request_type,
00442                                     USB_INT08U   b_request,
00443                                     USB_INT16U   w_value,
00444                                     USB_INT16U   w_index,
00445                                     USB_INT16U   w_length,
00446                           volatile  USB_INT08U  *buffer)
00447 {
00448     USB_INT32S  rc;
00449 
00450 
00451     Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length);
00452     rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8);
00453     if (rc == OK) {
00454         if (w_length) {
00455             rc = Host_ProcessTD(EDCtrl, TD_IN, TDBuffer, w_length);
00456         }
00457         if (rc == OK) {
00458             rc = Host_ProcessTD(EDCtrl, TD_OUT, NULL, 0);
00459         }
00460     }
00461     return (rc);
00462 }
00463 
00464 /*
00465 **************************************************************************************************************
00466 *                                         SEND THE CONTROL INFORMATION
00467 *
00468 * Description: This function is used to send the control information
00469 *
00470 * Arguments  : None
00471 *
00472 * Returns    : OK                      if Success
00473 *              ERR_INVALID_BOOTSIG    if Failed
00474 *
00475 **************************************************************************************************************
00476 */
00477 
00478 USB_INT32S  Host_CtrlSend (          USB_INT08U   bm_request_type,
00479                                      USB_INT08U   b_request,
00480                                      USB_INT16U   w_value,
00481                                      USB_INT16U   w_index,
00482                                      USB_INT16U   w_length,
00483                            volatile  USB_INT08U  *buffer)
00484 {
00485     USB_INT32S  rc;
00486 
00487 
00488     Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length);
00489 
00490     rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8);
00491     if (rc == OK) {
00492         if (w_length) {
00493             rc = Host_ProcessTD(EDCtrl, TD_OUT, TDBuffer, w_length);
00494         }
00495         if (rc == OK) {
00496             rc = Host_ProcessTD(EDCtrl, TD_IN, NULL, 0);
00497         }
00498     }
00499     return (rc);
00500 }
00501 
00502 /*
00503 **************************************************************************************************************
00504 *                                          FILL SETUP PACKET
00505 *
00506 * Description: This function is used to fill the setup packet
00507 *
00508 * Arguments  : None
00509 *
00510 * Returns    : OK                      if Success
00511 *              ERR_INVALID_BOOTSIG    if Failed
00512 *
00513 **************************************************************************************************************
00514 */
00515 
00516 void  Host_FillSetup (USB_INT08U   bm_request_type,
00517                       USB_INT08U   b_request,
00518                       USB_INT16U   w_value,
00519                       USB_INT16U   w_index,
00520                       USB_INT16U   w_length)
00521 {
00522     int i;
00523     for (i=0;i<w_length;i++)
00524         TDBuffer[i] = 0;
00525     
00526     TDBuffer[0] = bm_request_type;
00527     TDBuffer[1] = b_request;
00528     WriteLE16U(&TDBuffer[2], w_value);
00529     WriteLE16U(&TDBuffer[4], w_index);
00530     WriteLE16U(&TDBuffer[6], w_length);
00531 }
00532 
00533 
00534 
00535 /*
00536 **************************************************************************************************************
00537 *                                         INITIALIZE THE TRANSFER DESCRIPTOR
00538 *
00539 * Description: This function initializes transfer descriptor
00540 *
00541 * Arguments  : Pointer to TD structure
00542 *
00543 * Returns    : None
00544 *
00545 **************************************************************************************************************
00546 */
00547 
00548 void  Host_TDInit (volatile  HCTD *td)
00549 {
00550 
00551     td->Control    = 0;
00552     td->CurrBufPtr = 0;
00553     td->Next       = 0;
00554     td->BufEnd     = 0;
00555 }
00556 
00557 /*
00558 **************************************************************************************************************
00559 *                                         INITIALIZE THE ENDPOINT DESCRIPTOR
00560 *
00561 * Description: This function initializes endpoint descriptor
00562 *
00563 * Arguments  : Pointer to ED strcuture
00564 *
00565 * Returns    : None
00566 *
00567 **************************************************************************************************************
00568 */
00569 
00570 void  Host_EDInit (volatile  HCED *ed)
00571 {
00572 
00573     ed->Control = 0;
00574     ed->TailTd  = 0;
00575     ed->HeadTd  = 0;
00576     ed->Next    = 0;
00577 }
00578 
00579 /*
00580 **************************************************************************************************************
00581 *                                 INITIALIZE HOST CONTROLLER COMMUNICATIONS AREA
00582 *
00583 * Description: This function initializes host controller communications area
00584 *
00585 * Arguments  : Pointer to HCCA
00586 *
00587 * Returns    : 
00588 *
00589 **************************************************************************************************************
00590 */
00591 
00592 void  Host_HCCAInit (volatile  HCCA  *hcca)
00593 {
00594     USB_INT32U  i;
00595 
00596 
00597     for (i = 0; i < 32; i++) {
00598 
00599         hcca->IntTable[i] = 0;
00600         hcca->FrameNumber = 0;
00601         hcca->DoneHead    = 0;
00602     }
00603 
00604 }
00605 
00606 /*
00607 **************************************************************************************************************
00608 *                                         WAIT FOR WDH INTERRUPT
00609 *
00610 * Description: This function is infinite loop which breaks when ever a WDH interrupt rises
00611 *
00612 * Arguments  : None
00613 *
00614 * Returns    : None
00615 *
00616 **************************************************************************************************************
00617 */
00618 
00619 void  Host_WDHWait (void)
00620 {
00621   while (!HOST_WdhIntr)
00622       __WFI();
00623 
00624   HOST_WdhIntr = 0;
00625 }
00626 
00627 /*
00628 **************************************************************************************************************
00629 *                                         READ LE 32U
00630 *
00631 * Description: This function is used to read an unsigned integer from a character buffer in the platform
00632 *              containing little endian processor
00633 *
00634 * Arguments  : pmem    Pointer to the character buffer
00635 *
00636 * Returns    : val     Unsigned integer
00637 *
00638 **************************************************************************************************************
00639 */
00640 
00641 USB_INT32U  ReadLE32U (volatile  USB_INT08U  *pmem)
00642 {
00643     USB_INT32U val = *(USB_INT32U*)pmem;
00644 #ifdef __BIG_ENDIAN
00645     return __REV(val);
00646 #else
00647     return val;
00648 #endif    
00649 }
00650 
00651 /*
00652 **************************************************************************************************************
00653 *                                        WRITE LE 32U
00654 *
00655 * Description: This function is used to write an unsigned integer into a charecter buffer in the platform 
00656 *              containing little endian processor.
00657 *
00658 * Arguments  : pmem    Pointer to the charecter buffer
00659 *              val     Integer value to be placed in the charecter buffer
00660 *
00661 * Returns    : None
00662 *
00663 **************************************************************************************************************
00664 */
00665 
00666 void  WriteLE32U (volatile  USB_INT08U  *pmem,
00667                             USB_INT32U   val)
00668 {
00669 #ifdef __BIG_ENDIAN
00670     *(USB_INT32U*)pmem = __REV(val);
00671 #else
00672     *(USB_INT32U*)pmem = val;
00673 #endif
00674 }
00675 
00676 /*
00677 **************************************************************************************************************
00678 *                                          READ LE 16U
00679 *
00680 * Description: This function is used to read an unsigned short integer from a charecter buffer in the platform
00681 *              containing little endian processor
00682 *
00683 * Arguments  : pmem    Pointer to the charecter buffer
00684 *
00685 * Returns    : val     Unsigned short integer
00686 *
00687 **************************************************************************************************************
00688 */
00689 
00690 USB_INT16U  ReadLE16U (volatile  USB_INT08U  *pmem)
00691 {
00692     USB_INT16U val = *(USB_INT16U*)pmem;
00693 #ifdef __BIG_ENDIAN
00694     return __REV16(val);
00695 #else
00696     return val;
00697 #endif    
00698 }
00699 
00700 /*
00701 **************************************************************************************************************
00702 *                                         WRITE LE 16U
00703 *
00704 * Description: This function is used to write an unsigned short integer into a charecter buffer in the
00705 *              platform containing little endian processor
00706 *
00707 * Arguments  : pmem    Pointer to the charecter buffer
00708 *              val     Value to be placed in the charecter buffer
00709 *
00710 * Returns    : None
00711 *
00712 **************************************************************************************************************
00713 */
00714 
00715 void  WriteLE16U (volatile  USB_INT08U  *pmem,
00716                             USB_INT16U   val)
00717 {
00718 #ifdef __BIG_ENDIAN
00719     *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF);
00720 #else
00721     *(USB_INT16U*)pmem = val;
00722 #endif
00723 }
00724 
00725 /*
00726 **************************************************************************************************************
00727 *                                         READ BE 32U
00728 *
00729 * Description: This function is used to read an unsigned integer from a charecter buffer in the platform
00730 *              containing big endian processor
00731 *
00732 * Arguments  : pmem    Pointer to the charecter buffer
00733 *
00734 * Returns    : val     Unsigned integer
00735 *
00736 **************************************************************************************************************
00737 */
00738 
00739 USB_INT32U  ReadBE32U (volatile  USB_INT08U  *pmem)
00740 {
00741     USB_INT32U val = *(USB_INT32U*)pmem;
00742 #ifdef __BIG_ENDIAN
00743     return val;
00744 #else
00745     return __REV(val);
00746 #endif
00747 }
00748 
00749 /*
00750 **************************************************************************************************************
00751 *                                         WRITE BE 32U
00752 *
00753 * Description: This function is used to write an unsigned integer into a charecter buffer in the platform
00754 *              containing big endian processor
00755 *
00756 * Arguments  : pmem    Pointer to the charecter buffer
00757 *              val     Value to be placed in the charecter buffer
00758 *
00759 * Returns    : None
00760 *
00761 **************************************************************************************************************
00762 */
00763 
00764 void  WriteBE32U (volatile  USB_INT08U  *pmem,
00765                             USB_INT32U   val)
00766 {
00767 #ifdef __BIG_ENDIAN
00768     *(USB_INT32U*)pmem = val;
00769 #else
00770     *(USB_INT32U*)pmem = __REV(val);
00771 #endif
00772 }
00773 
00774 /*
00775 **************************************************************************************************************
00776 *                                         READ BE 16U
00777 *
00778 * Description: This function is used to read an unsigned short integer from a charecter buffer in the platform
00779 *              containing big endian processor
00780 *
00781 * Arguments  : pmem    Pointer to the charecter buffer
00782 *
00783 * Returns    : val     Unsigned short integer
00784 *
00785 **************************************************************************************************************
00786 */
00787 
00788 USB_INT16U  ReadBE16U (volatile  USB_INT08U  *pmem)
00789 {
00790     USB_INT16U val = *(USB_INT16U*)pmem;
00791 #ifdef __BIG_ENDIAN
00792     return val;
00793 #else
00794     return __REV16(val);
00795 #endif    
00796 }
00797 
00798 /*
00799 **************************************************************************************************************
00800 *                                         WRITE BE 16U
00801 *
00802 * Description: This function is used to write an unsigned short integer into the charecter buffer in the
00803 *              platform containing big endian processor
00804 *
00805 * Arguments  : pmem    Pointer to the charecter buffer
00806 *              val     Value to be placed in the charecter buffer
00807 *
00808 * Returns    : None
00809 *
00810 **************************************************************************************************************
00811 */
00812 
00813 void  WriteBE16U (volatile  USB_INT08U  *pmem,
00814                             USB_INT16U   val)
00815 {
00816 #ifdef __BIG_ENDIAN
00817     *(USB_INT16U*)pmem = val;
00818 #else
00819     *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF);
00820 #endif
00821 }