|
FOR AN EMBEDDED PROCESSOR
by Stuart Allman
Start ý Typical
USB Solutions ý Required Components
ý An Easier Solution ý Following
the Rules ý Firmware ý Vendor-Specific
Requests ý Host Transfer Mechanisms
ý USB Transfers ý How
Does It Work? ý The Grand Conclusion
ý Sources and PDF
VENDOR-SPECIFIC REQUESTS
GET_IO gets the values on port1[2:0].
These bits are hi-z inputs and should be pulled high or low if the
device is bus-powered. If the inputs are left floating while the device
is suspended, then the inputs may consume too much current to meet
the 500-ýA USB suspend current specification.
SET_IO is written to port3[1:0].
These pins have an internal pull-up resistor and CMOS pull down, so
you can use these pins as a host-controlled reset, button pull-up
resistor, or any other output function.
The IN endpoint communication channel
has a buffer size of 32 bytes. SET_TIMEOUT is used to set a transmission
timeout value on this buffer. If the timeout value is set to 0 ms
(by default, but you can change the default in embedinf.h),
then the microcontroller will wait for the device to fill up the endpoint
buffer before sending data to the USB host. If this value is between
1 and 255 ms and the embedded processor has not written enough bytes
to fill up the buffer in that time interval, the microcontroller will
time out and send all the bytes in the IN endpoint data buffer. This
is meant to handle the situation when the embedded processor may only
have 5 bytes to send. If the timeout period is nonzero, then the data
will make it to the host after the timeout period, otherwise the data
will remain in the IN endpoint buffer until a full 32 bytes are written
into the HAPI by the embedded processor.
And finally, SEND_IMMEDIATE causes
the microcontroller to send whatever data it has in the endpoint 1
buffer to the USB host immediately.
One thing you have to keep in mind when
thinking about USB transfers is that everything is defined to be host-centric.
Each device is assigned an address during the enumeration process.
After enumeration, the host communicates with the peripheral using
logical communication channels that exist at that address. These logical
communication channels are called endpoints. Each endpoint is assigned
a size, direction, and type of transfer mechanism allowed. A peripheralýs
OUT endpoint accepts data from the USB host. A peripheralýs IN endpoint
sends data to the USB host.
The host application allows you to send
up to 32 bytes at a time to the embedded processor (OUT endpoint)
buffer in the microcontroller. These bytes are then transferred from
the OUT endpoint buffer to the central microprocessor via the HAPI.
Data transfers from the host to central microprocessor cannot occur
again until the central microprocessor reads all of the bytes from
the previous transfer.
The host application continuously monitors
the IN endpoint while the device is attached to the host. Whenever
a packet is sent from the peripheral to the host, the data is displayed
in the window at the bottom of the application.
PREVIOUS
NEXT
Circuit Cellar provides up-to-date information for engineers. Visit
www.circuitcellar.com for
more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe online.
ýCircuit Cellar, the Magazine for Computer Applications. Posted with
permission. |