User guide
CY3687 MoBL-USB FX2LP18 Development Kit User Guide, Doc. # 001-68582 Rev. *B 69
MoBL-USB Development Kit Firmware Examples
leaves them empty to receive a new packet from the host. It also clears any pending PING-NAK
interrupts and enables the PING-NAK interrupt for EP2 and EP4. The loopback is implemented in
the TD_Poll() function that is called repeatedly when the device is idle. Endpoints 2 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 reading the endpoint
2 empty bit in the endpoint status register (EP2468STAT). If endpoint 2 has data (that is sent from
the host), the capability of endpoint 6 to receive the data is checked. This is done by reading the end-
point 6 Full bit in the endpoint status register. If endpoint 6 is not full, then the data is transferred.
This decision is executed by the following statements:
if (!(EP2468STAT & bmEP2EMPTY))
{// check EP2 EMPTY (busy) bit in EP2468STAT (SFR), core set's this bit
when
// FIFO is empty
if (!(EP2468STAT & bmEP6FULL))
{// check EP6 FULL (busy) bit in EP2468STAT (SFR), core set's this bit
// when FIFO is full
The data pointers are initialized to the corresponding buffers. The first auto pointer is initialized to the
first byte of the endpoint 2 FIFO buffer. The second auto-pointer is initialized to the first byte of the
endpoint 6 FIFO buffer. The number of bytes to be transferred is read from the byte count registers
of Endpoint 2. The registers EP2BCL, EP2BCH contain the number of bytes written into the FIFO
buffer by the host. These two registers give the byte count of the data transferred to the FIFO in an
OUT transaction as long as the data is not committed to the peripheral side. This data pointer initial-
ization and loading of the count is done in the following statements:
APTR1H = MSB( &EP2FIFOBUF ); // Initializing the first data pointer
APTR1L = LSB( &EP2FIFOBUF );
AUTOPTRH2 = MSB( &EP6FIFOBUF ); // Initializing the second data pointer
AUTOPTRL2 = LSB( &EP6FIFOBUF );
count = (EP2BCH << 8) + EP2BCL; // The count value is loaded from the byte
// count registers
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;
}
Because auto pointers have been enabled, the pointers increment automatically, and the statement
EXTAUTODAT2 = EXTAUTODAT1;
transfers data from endpoint 2 to endpoint 6. Each time the above statement is executed the auto
pointer is incremented. The above statement is executed repeatedly to transfer each byte from end-
point 2 to 6. 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 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 same operation is carried out to implement a data loop with endpoints 4 and 8.