General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
-
maxi
- Rank 3
- Posts: 122
- Joined: Fri Jul 24, 2009 6:13 pm
Post
by maxi » Wed Aug 12, 2009 10:51 pm
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?
Last edited by
maxi on Thu Aug 13, 2009 6:58 pm, edited 2 times in total.
-
Grendel
- Rank 4
- Posts: 167
- Joined: Sat Dec 16, 2006 9:53 pm
- Location: Oregon, USA
-
Contact:
Post
by Grendel » Thu Aug 13, 2009 2:13 am
Try this (see usbPoll()):
Code: Select all
extern volatile uchar usbTxLen ;
tx_complete = (usbTxLen & 0x10) ;
-
maxi
- Rank 3
- Posts: 122
- Joined: Fri Jul 24, 2009 6:13 pm
Post
by maxi » Thu Aug 13, 2009 2:54 am
That is exactly what I was looking for
Thank you very much!
Last edited by
maxi on Wed Aug 26, 2009 2:45 am, edited 1 time in total.
-
maxi
- Rank 3
- Posts: 122
- Joined: Fri Jul 24, 2009 6:13 pm
Post
by maxi » Thu Aug 13, 2009 6:58 pm
hmm, I think I may have marked this as solved prematurely
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?
Last edited by
maxi on Wed Aug 26, 2009 2:45 am, edited 1 time in total.
-
maxi
- Rank 3
- Posts: 122
- Joined: Fri Jul 24, 2009 6:13 pm
Post
by maxi » Sun Aug 16, 2009 5:54 pm
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.
-
christian
- Objective Development
- Posts: 1443
- Joined: Thu Nov 09, 2006 11:46 am
Post
by christian » Mon Sep 21, 2009 9:51 pm
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.