Application Note
22 of 42
001-65209 Rev.*I
2021-03-19
Getting Started with FX2LP™
FX2LP Development Tools
imply store the Set values sent by the host and echo them back when the host issues the Get requests. For more
complex configurations, you can use these DR calls (“hooks”) to change camera
resolutions or route requests
to two different interfaces.
Because
bulkloop.c
contains a complete template for any USB device, you can use it as the basis for your
custom implementation. The remainder of this section describes the three portions of this file that require user
code to implement the bulkloop application.
5.3.2.1
TD_Init
This function does the following:
•
Sets the 8051 clock to 48 MHz.
•
Turns off the development board’s four LEDs. LEDs are turned on and off by reading specific memory
locations. This method controls the LEDs without consuming any I/O pins.
•
Configures EP2 as a BULK-OUT endpoint and EP6 as a BULK-IN endpoint. Both are double-buffered and use
512 byte FIFOs (
Error! Reference source not found.
).
•
Enables (“arms”) EP2
-OUT to receive two packets. The OUT endpoint is armed by writing any value into its
byte count register whose MSB is set. Setting the MSB (called the “SKIP bit”) skips the pa
cket.
•
Enables the FX2LP dual auto pointers. These hardware pointers auto-increment for efficient memory-to-
memory byte transfers from the EP2-OUT buffer to the EP6-IN buffer.
•
Enables three interrupts: SOF, EP2, and EP6 endpoint interrupts.
5.3.2.2
TD_Poll
TD_Poll is called in an infinite loop residing in
fw.c
(
Error! Reference source not found.
). For the
bulkloop
application, only two tasks are required:
1.
Update the 7-segment readout with the number of packets waiting for transmission to the host. The FX2LP
register EP6CS (Endpoint 6 Control and Status) provides this number in bits 6-4.
Further Reading
For more information on registers, refer to Chapter 15 of the
FX2LP Technical Reference Manual
2.
Check the endpoint FIFO flags to determine when it is time to transfer an OUT packet to an IN buffer. When
it is time, move the packet data from the EP2-OUT buffer to the EP6-IN buffer using auto pointers.
To understand how the item 2 transfer decision is made, it is important to understand two points regarding the
FX2LP endpoint FIFO flags:
a)
When multiple buffering is used, the FULL and EMPTY flags (of EP2468STAT register) reflect all the buffers,
not just one. Therefore, in the double-buffered case for this example, if one OUT packet is received, the
FULL flag remains unasserted because the second buffer is still available for an OUT transfer. The FULL flag
asserts only when a second packet arrives. Similarly, an IN endpoint EMPTY flag asserts only when both
buffers are empty, ready for the 8051 to fill them with new data.
b)
FX2LP updates FIFO flags (of the EP2468STAT register) only after successful receipt or transmission of a
USB packet.
Therefore, a looping transfer occurs when the following two conditions are satisfied:
•
EP2-OUT is not empty, AND
•
EP6-IN is not full.