Application Note
23 of 42
001-65209 Rev.*I
2021-03-19
Getting Started with FX2LP™
FX2LP Development Tools
In other words, EP2 has a packet, and EP6 has room for a packet. Doing the test this way handles any packet
size and takes the double-buffering into account.
5.3.2.3
Interrupt Service Routines
The
bulkloop.c
file contains ISR functions for every USB interrupt source. A few ISRs set flags for the
fw.c
code,
and others perform USB enumeration functions. You only need to fill in code for the ISRs that your application
uses.
The following ISR shows how to clear an FX2LP USB interrupt request:
// Setup Token Interrupt Handler
voidISR_Sutok(void) interrupt 0
{
EZUSB_IRQ_CLEAR();
USBIRQ = bmSUTOK;
// Clear SUTOK IRQ
}
The “0” after the interrupt keyword is the ID for all USB interrupt requests. Two interrupt request flags are
cleared in a particular order: first, the general USB interrupt flag and then the individual USB source flag; in this
example, the “Setup Token Arrived” flag. This ISR is an example of a code “hook”; you can take any action when
a SETUP packet arrives by inserting code into this ISR.
The
bulkloop
application requires four customized ISRs:
Set_Configuration ISR
The host sets the FX2LP configuration as the last step of its enumeration process. This is a good time to
initialize application hardware. The I
2
C unit that drives the 7-segment readout is initialized here.
EP2INOUT/EP6INOUT ISR
These IRQs fire when a packet is dispatched from EP6-IN or arrives at EP2-OUT. The ISR code turns on an LED on
the FX2LP Development Board, then sets an
inblink
(EP6-IN) or
outblink
(EP2-OUT) variable (in
bulkloop.c
) to
control how long the LED stays on.
SOF ISR
The SOF ISR serves as a convenient timer, firing every millisecond at Full Speed and every 125 microseconds at
Hi-Speed. The ISR code toggles an LED on the FX2LP Development Board every 500 times through the ISR,
which equates to once per second at Full Speed and 8 times per second at Hi-Speed. The ISR code also
decrements
inblink
and
outblink
variables that were set when IN and OUT packets arrived, turning off
indicator LEDs when the counters hit zero.
5.3.2.4
Handling USB Dual Speeds
When a USB 2.0 device comes out of reset it operates at Full Speed. The host then negotiates with the device
using low-level bus signaling to determine its operating speed. FX2LP provides an interrupt to indicate that it
has just switched to Hi-Speed operation as the result of the host-device speed negotiation.
A USB 2.0 device must operate at Full Speed and Hi-Speed. A Hi-Speed USB device provides two sets of
descriptors, one for each speed. Two ISRs take care of designating the proper descriptors depending on speed: