EZ-USB CY7C68013A固件Slave FIFO初始化
//EP2 Auto OUT 2*1024bytes bulk
//EP6 Auto IN 2*1024bytes bulk,
void TD_Init( void ) // Called once at startup
{
CPUCS = 0x10; //48MHz operation
REVCTL=0x03; //Cypress推荐设置dyn_out=1, enh_pkt=1
SYNCDELAY;
//配置引脚FLAGA,FLAGB,FLAGC,FLAGD输出FIFO状态
PINFLAGSAB = 0x00; //根据FIFOADR[1:0]指向的端点,FLAGA定义为PF
//FLAGB定义为FULL
SYNCDELAY; //同步延时
PINFLAGSCD = 0x00; // FLAGC定义为EMPTY,FLAGD不使用
SYNCDELAY;
//配置端口A的复用引脚PORTA.7功能
PORTACFG = 0x00; //PA7/FLAGD作为端口引脚PA7,不作为FIFO的状态标志-FLAGD
SYNCDELAY;
//设置所有的FIFO接口引脚低电压/高电平有效
FIFOPINPOLAR = 0x00; //Slave FIFO接口引脚低电平有效
SYNCDELAY;
//配置接口的工作模式(端口、GPIF、Slave FIFO)
IFCONFIG = 0x43; //外部IFCLK外部时钟,48MHz,IFCLK不输出内部时钟
//不反相IFCLK引脚信号,同步传输,Slave FIFO工作模式
SYNCDELAY;
//不使用EP4和EP8
EP2CFG = 0xAA; //out 1024 bytes, 2x, bulk
SYNCDELAY;
EP6CFG = 0xAA; // in 1024 bytes, 2x, bulk
SYNCDELAY;
EP4CFG = 0x02; //clear valid bit
SYNCDELAY;
EP8CFG = 0x02; //clear valid bit
SYNCDELAY;
//复位FIFOS(EP2、EP6)到默认状态(FIFO flags、byte counts)
FIFORESET = 0x80; // activate NAK-ALL to avoid race conditions
SYNCDELAY;
FIFORESET = 0x02; // reset, FIFO 2
SYNCDELAY;
FIFORESET = 0x06; // reset, FIFO 6
SYNCDELAY;
FIFORESET = 0x00; // deactivate NAK-ALL,restore normal operation
SYNCDELAY;
//配置FIFO端点EP2和EP6
EP2FIFOCFG = 0x11; // AUTOOUT=1, WORDWIDE=1(16位数据传输)
SYNCDELAY;
EP6FIFOCFG = 0x09; //AUTOIN=1 , WORDWIDE=1(16位数据传输)
SYNCDELAY;
//设置AUTOIN时自动传输的包大小(注意,不能大于IN端点的缓冲区的大小)
EP6AUTOINLENH = 0x04; //Auto-commit 1024-byte packets
SYNCDELAY;
EP6AUTOINLENL = 0x00;
SYNCDELAY;
//清空EP2、EP6端点缓冲区(2个缓冲区要清空2次)
OUTPKTEND = 0x82; //Arm two OUT EP2 buffers to “prime the pump”
SYNCDELAY; //For OUT endpoints, you need to arm the buffers to let the SIE take
OUTPKTEND = 0x82; // control of them, and accept data from the host.
SYNCDELAY;
INPKTEND = 0x86; //“arming” the IN transfer
SYNCDELAY;
INPKTEND = 0x86;
SYNCDELAY;
}