User guide
66 CY3687 MoBL-USB FX2LP18 Development Kit User Guide, Doc. # 001-68582 Rev. *B
MoBL-USB Development Kit Firmware Examples
and 4 are armed to accept data from the host. This data is transferred to endpoint 6 and endpoint 8
respectively. To implement this, endpoint 2 is first checked to see if it has data. This is done by read-
ing the endpoint 2 empty bit in the endpoint status register (EP2468STAT). If endpoint 2 has data
(that is sent from the host), then check if the host has requested data on EP6. This is done by read-
ing the EP6 In-Bulk-Flag bit in the IbnFlag variable. If the host has requested for data on EP6, then
the data is transferred.
This decision is executed by the following statement:
if (!(EP2468STAT & bmEP2EMPTY) && (IbnFlag & bmEP6IBN) )
// if there is new data in EP2FIFOBUF and the IBN flag for EP6 has been
set, //then copy the data from EP2 to EP6
The data transfer is carried out by the execution of the following loop:
for( i = 0x0000; i < count; i++ )
{
// setup to transfer EP2OUT buffer to EP6IN buffer using AUTOPOINTER(s)
EXTAUTODAT2 = EXTAUTODAT1;
}
As auto pointers have been enabled the pointers increment automatically, and the statement
EXTAUTODAT2 = EXTAUTODAT1;
After the data is transferred, endpoint 2 has to be "rearmed" to accept a new packet from the host.
Endpoint 6 has to be “committed”, that is, make the FIFO buffers available to the host for reading
data from the Endpoint 6.
This is accomplished by the following statements:
EP6BCH = EP2BCH;
SYNCDELAY;
EP6BCL = EP2BCL; // commit EP6IN by specifying the number of bytes the
host can read //from EP6
SYNCDELAY;
EP2BCL = 0x80; // re (arm) EP2OUT
The EP6 In-Bulk-NAK Flag bit in the IbnFlag variable is cleared. The EP6 In-Bulk-NAK interrupt
request is cleared by setting the corresponding bit in the IBNIRQ register. Finally, the EP6 In-Bulk-
NAK interrupt is enabled by setting the corresponding bit in the IBNIE register.
IbnFlag &= ~bmEP6IBN; // clear the IBN flag
IBNIRQ = bmEP6IBN; // clear the IBN IRQ
IBNIE |= bmEP6IBN; // enable the IBN IRQ
The same operation is carried out to implement a data loop with endpoints 4 and 8.
When the host requests an IN packet from an MoBL-USB FX2LP BULK endpoint, the endpoint
NAKs (returns the NAK PID) until the endpoint buffer is filled with data and armed for transfer, at
which point the MoBL-USB FX2LP18 device answers the IN request with data. Until the endpoint is
armed, a flood of IN-NAKs can tie up bus bandwidth. Therefore, if the IN endpoints are not always
kept full and armed, it may be useful to know when the host is "knocking at the door”, requesting IN
data. The IN-BULK-NAK (IBN) interrupt provides this notification. The IBN interrupt fires whenever a
Bulk endpoint NAKs an IN request. The IBNIE/IBNIRQ registers contain individual enable and
request bits per endpoint, and the NAKIE/NAKIRQ registers each contain a single-bit, IBN, that is the
ORd combination of the individual bits in IBNIE/IBNIRQ, respectively. The MoBL-USB FX2LP18
device firmware framework provides hooks for all the interrupts that it implements. The example proj-
ect uses ISR_Ibn interrupt service routine to handle In-Bulk-NAK(IBN) interrupt for EP6 and EP8.
void ISR_Ibn(void) interrupt 0
{
int i;