Interrupt Service Routine (ISR) Flowcharts
13-86
13.6 Interrupt Service Routine (ISR) Flowcharts
The flowcharts in this section give general operational guidelines for USB ISR
processing. System-architecture-specific details are left to the engineers who
write the local host and USB host code. One USB-specific interrupt register is
provided (IRQ_SRC) to keep track of the interrupts to handle. These interrupts
can be of the following types:
-
General USB interrupts (including endpoint 0, DMA, and device states
interrupts)
-
Non-isochronous endpoint-specific interrupt
-
Start of frame (SOF) interrupt for isochronous transactions
The general USB interrupt ISR must handle non-autodecoded control trans-
fers on endpoint 0 and some special interrupts generated due to USB device
state modifications or DMA transfers. The ISR for the endpoint-specific inter-
rupt must handle interrupts from the USB module that are generated due to
USB activity for non-isochronous endpoints. The SOF ISR is responsible for
handling isochronous endpoints and, if needed by the application, tracking the
USB frame number. Many flowcharts are presented below to give a guideline
for how to handle the interrupts related to the USB function module. The flow-
charts in this section assume that the Nak_En bit is cleared.
A key assumption behind the flowcharts presented here is that the application
provides separate buffers for each direction of endpoint, except for endpoint
0. The flowcharts show reads from these application buffers for IN transactions
on TX endpoints, and they show writes to these application buffers for OUT
transactions on RX endpoints.
13.6.1 Important Note on USB Interrupts
When an endpoint interrupt is asserted, the local host sets the EP_Sel bit to
1. The local host must finish the interrupt handling before clearing EP_Sel bit,
because clearing this bit clears the corresponding status bit in the status flag
register (ACK, NAK, STALL). When an interrupt is pending on an endpoint, the
local host must not select then deselect the endpoint without handling the inter-
rupt, because this clears the pending transaction status flags. The local host
does not need to set EP_Sel to 1 when setting the Set_FIFO_En, the Set_Halt
and the Clr_Halt bits.
The endpoint status (STAT_FLG register) is updated at the end of each USB
transaction if the previous transaction has been handled. If a pending interrupt
has not been handled when a new non-transparent transaction occurs, status
flags are not updated (and NAK is returned, even if FIFO was enabled, or
STALLed, if endpoint halt feature was set), so that the local host never misses