Page 1 of 1

need help for deeper understanding of USB with AVRs

Posted: Sat Jul 07, 2007 5:18 pm
by iphi
Hello,

I have successfully played with power switch and also did some software modifications. So far, I have learned how the host can send and receive some data with control messages.

Questions:
1.
Is it possible that the USB device sends some kind of notification to the Windows host, e.g. asking for new data without the host having to continuously poll?

How on the AVR side?
How on the windows side (callback function or windows message)?

2.
How can I find out how much RAM and which registers are free to use for my AVR application on top of the USB driver? What is the stack depth of the USB driver?

Thanks

Posted: Sat Jul 07, 2007 10:41 pm
by christian
In order to send notifications to the host, you need an Interrupt In endpoint. See our RemoteSensor example. I don't know how to handle these on Windows, though, if you need a callback called. Maybe you need a separate thread for that if you use libusb.

You could also implement a HID device and send the notification as I/O report. There are examples on the web how you can get a callback called for I/O reports on Windows, but I have never tried that.

The memory usage of any module is displayed by the "avr-size" command. The stack usage of the interrupt handler is 11 bytes. The C code needs a couple of bytes more -- but I have not checked what the compiler makes out o the code.

Posted: Sun Jul 08, 2007 10:36 am
by iphi
Hi Christian,

from your reply I learn that it is possible that an USB device initiates a data transfer/send a notification by itself to the host.
On the other hand I have just found this Maxim app note http://www.maxim-ic.com/appnotes.cfm/an_pk/3803 on the web stating:

"Host
USB is a "master-slave" bus with exactly one master and multiple slaves. The slaves are called peripherals or in USB nomenclature, functions. The master is called a host. ONLY THE HOST can initiate USB transfers; the peripherals always respond, never initiate. A PC is the most common host. ..."

Now I'm confused. Can you please clarify ?

Thank you very much!

Posted: Sun Jul 08, 2007 9:23 pm
by christian
The app note is correct: All transfers are initiated by the host.

However, from an application logic point of view, you don't care how initiates the transfer. For interrupt endpoints, all polling is done by the host controller hardware or the driver. The application on the host does not have to worry about that. Similarly, AVR-USB hides that fact from you.

You simply use usbSetInterrupt() to send the data and the driver waits until it's polled by the host. When you configure an interrupt endpoint, you also specify the poll frequency in milliseconds. This value is used by the host to do the polling.