User guide

CY3687 MoBL-USB FX2LP18 Development Kit User Guide, Doc. # 001-68582 Rev. *B 65
MoBL-USB Development Kit Firmware Examples
8.3 IBN Firmware Example
8.3.1 Description
This example illustrates the configuration of MoBL-USB FX2LP18 to accept bulk data from the host
and loop it back to the host using an IN-BULK-NAK interrupt. Click on ibn.Uv2 project file at
<Installed_directory>\<Version>\Firmware\ibn. In TD_init() function of ibn.c file four endpoints are
configured to handle bulk transfer: two OUT endpoints and two IN endpoints. The four endpoints
defined in the descriptor file have to be configured in this function. This is done by the following
statements:
EP2CFG = 0xA2;
SYNCDELAY;
EP4CFG = 0xA0;
SYNCDELAY;
EP6CFG = 0xE2;
SYNCDELAY;
EP8CFG = 0xE0
The key characteristics of each endpoint are as follows:
Endpoint 2 - OUT, Bulk, double buffered
Endpoint 4 - OUT, Bulk, double buffered
Endpoint 6 - IN, Bulk, double buffered
Endpoint 8 - IN, Bulk, double buffered
Writing to these registers typically takes more than two clock cycles needed for a MOVX instruction.
Therefore, the SYNCDELAY, already defined, is added. The TRM provides the list of registers that
need this delay function when writing to them. The OUT endpoints, after they are configured, need to
be ARMed to accept packets from the host. Because the endpoints are double-buffered, you must
arm the endpoint twice. Arming is essentially freeing up the buffers and making them available to the
host to receive packets.
By writing a 1 to bit7 of the byte count register the endpoint is ARMed.
EP2BCL = 0x80; // arm EP2OUT by writing byte count w/skip.
SYNCDELAY;
EP2BCL = 0x80;
SYNCDELAY;
EP4BCL = 0x80; // arm EP4OUT by writing byte count w/skip.
SYNCDELAY;
EP4BCL = 0x80;
The lines above arm the two OUT endpoints by skipping two packets of data making the buffers
available to receive OUT data:
NAKIRQ = bmBIT0; // clear the global IBN IRQ
NAKIE |= bmBIT0; // enable the global IBN IRQ
IbnFlag = 0x00; // clear our IBN flag
IBNIRQ = 0xFF; // clear any pending IBN IRQ
IBNIE |= bmEP6IBN | bmEP8IBN; // enable the IBN interrupt
for EP6 and EP8
The firmware clears the In-Bulk-NAK flags of all endpoints and any pending In-Bulk-NAK interrupts
and enables the In-Bulk-NAK interrupt for EP6 and EP8.
AUTOPTRSETUP |= 0x01;
This enables the AUTO pointer used for data transfer in the TD_Poll() function. The loopback is
implemented in the TD_Poll function which is called repeatedly when the device is idle. Endpoints 2