EasyManua.ls Logo

Cypress CY3684 - Page 72

Cypress CY3684
117 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
72 EZ-USB Development Kit User Guide, Doc. # 001-66390 Rev. *D
EZ-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 are enabled, the pointers increment automatically.
EXTAUTODAT2 = EXTAUTODAT1;
After this statement transfers the data, 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 EZ-USB 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 EZ-
USB 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 for each 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 EZ-USB firmware framework provides hooks for all the interrupts
that it implements. The example project uses the ISR_Ibn interrupt service routine to handle In-Bulk-
NAK(IBN) interrupt for EP6 and EP8.
void ISR_Ibn(void) interrupt 0
{
int i;

Table of Contents

Related product manuals