Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Atmel's AT91SAM7X USB write sometimes takes long time

Status
Not open for further replies.

my_abousamra

Junior Member level 3
Joined
Nov 25, 2008
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,478
Hi,

I'm using Atmel's AT91SAM7X microcontroller and Atmel device drivers, when I try to write data to USB (CDC driver) sometimes it takes relatively long time (1~2 seconds) which affects CPU load of my application, I tried to check the exact step I found 2 steps that It sometimes waits for transmission to complete for a long time (TXCOMP), as shown in code

Code:
//*----------------------------------------------------------------------------
//* \fn    AT91F_CDC_Write
//* \brief Send through endpoint 2
//*----------------------------------------------------------------------------
static uint AT91F_UDP_Write( AT91PS_CDC pCdc, const char *pData, uint length )
{
    AT91PS_UDP pUdp = pCdc->pUdp;
    uint cpt = 0;

    // Send the first packet
    cpt = MIN( length, AT91C_EP_IN_SIZE );
    length -= cpt;
    while( cpt-- ) pUdp->UDP_FDR[AT91C_EP_IN] = *pData++;
    pUdp->UDP_CSR[AT91C_EP_IN] |= AT91C_UDP_TXPKTRDY;

    while( length )
    {
        // Fill the second bank
        cpt = MIN( length, AT91C_EP_IN_SIZE );
        length -= cpt;
        while( cpt-- ) pUdp->UDP_FDR[AT91C_EP_IN] = *pData++;
        // Wait for the the first bank to be sent

        while( !( pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP ) )      // ISSUE: sometimes, it takes a long time to complete transmission
           if( !AT91F_UDP_IsConfigured( pCdc ) ) return length;

        pUdp->UDP_CSR[AT91C_EP_IN] &= ~( AT91C_UDP_TXCOMP );

        while( pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP );

        pUdp->UDP_CSR[AT91C_EP_IN] |= AT91C_UDP_TXPKTRDY;
    }
    // Wait for the end of transfer

    while( !( pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP ) )      // ISSUE: sometimes, it takes a long time to complete transmission
       if( !AT91F_UDP_IsConfigured( pCdc ) ) return length;

    pUdp->UDP_CSR[AT91C_EP_IN] &= ~( AT91C_UDP_TXCOMP );

    while( pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP );

    return length;
}

I don't know why it takes such long time every now and then and how to overcome it.
Notes
- I'm not familiar with USB driver internals.
- I communicate with a windows 7 machine and libusb-win32 (v1.2.6.0) library

Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top