Page 1 of 1

Knowing when a transfer is complete.

Posted: Wed Aug 12, 2009 10:51 pm
by maxi
Simple question really, is there anyway of knowing (device-side) when an endpoint0 transfer to the host has completed?

I would prefer to not use usbFunctionRead as my data is contained in a static RAM buffer that could be easily read by usbFunctionSetup alone.
I currently have something like this but I am not entirely sure that the driver is fully done even with that:

Code: Select all

uchar usbFunctionRead(uchar *data, uchar len)
{
    uchar i;
    if(len > bytesRemaining)
        len = bytesRemaining;
    bytesRemaining -= len;
    for(i = 0; i < len; i++)
        data[i] = getData(currentPosition);

    if(len < 8)
        tx_complete = 1;

    return len;
}

Any suggestions?

Re: Knowing when a transfer is complete.

Posted: Thu Aug 13, 2009 2:13 am
by Grendel
Try this (see usbPoll()):

Code: Select all

    extern volatile uchar usbTxLen ;

    tx_complete = (usbTxLen & 0x10) ;

Re: Knowing when a transfer is complete.

Posted: Thu Aug 13, 2009 2:54 am
by maxi
That is exactly what I was looking for

Thank you very much!

Re: Knowing when a transfer is complete.

Posted: Thu Aug 13, 2009 6:58 pm
by maxi
hmm, I think I may have marked this as solved prematurely :oops:

Something tells me this is not telling me that the tx has fully completed, only that the transmit system is idle.
From usbPoll()

Code: Select all

    if(usbTxLen & 0x10){    /* transmit system idle */
        if(usbMsgLen != USB_NO_MSG){    /* transmit data pending? */
            usbBuildTxBlock();
        }
    }


Perhaps I am misunderstanding?

Re: Knowing when a transfer is complete.

Posted: Sun Aug 16, 2009 5:54 pm
by maxi
Ok, from what I can make of the driver source what I actually need here is usbMsgLen, unfortunately this has been declared static in usbdrv.c.
By changing this to volatile I am able to include it externally but am not sure of the full implications of so doing.

The last thing I wanted to do was hack the API. If anyone has a better suggestion then please let me know.

Re: Knowing when a transfer is complete.

Posted: Mon Sep 21, 2009 9:51 pm
by christian
The clean method would be to use your own usbFunctionRead() and wait until bytesRemaining is zero. If you also want to wait until the host has read the last chunk, use Grendel's trick.

If you want to use the built-in usbFunctionRead for static memory blocks, have a look at usbMsgPtr. If it has advanced beyond your buffer, the last chunk is being transferred. Again, use Grendel's trick if you must make sure it has reached the host.