第一,先看一下固件程序。函数TD_Init()先是对端点进行初始化,4个大端点,2和4为OUT端点,6和8为IN端点,具体配置如下,
EP2CFG = 0xA2;
SYNCDELAY;
EP4CFG = 0xA0;
SYNCDELAY;
EP6CFG = 0xE2;
SYNCDELAY;
EP8CFG = 0xE0;
接下来对两个OUT端点进行Arm,随时可以接受上位机发过来的数据,程序如下,
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;
第二,函数TD_Poll()实现块传输。具体实现可以看程序,注释很详细,
void TD_Poll(void) // Called repeatedly while the device is idle
{
WORD i;
WORD count;
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
// Source is EP2OUT
APTR1H = MSB( &EP2FIFOBUF );
APTR1L = LSB( &EP2FIFOBUF );
// Destination is external RAM (at 0x2800)
AUTOPTRH2 = 0x28;
AUTOPTRL2 = 0x00;
count = (EP2BCH << 8) + EP2BCL;
for( i = 0x0000; i < count; i++ )
{
EXTAUTODAT2 = EXTAUTODAT1;
}
// Source is external RAM
APTR1H = 0x28;
APTR1L = 0x00;
// Destination is EP6IN
AUTOPTRH2 = MSB( &EP6FIFOBUF );
AUTOPTRL2 = LSB( &EP6FIFOBUF );
count = (EP2BCH << 8) + EP2BCL;
for( i = 0x0000; i < count; i++ )
{
EXTAUTODAT2 = EXTAUTODAT1;
}
EP6BCH = EP2BCH;
SYNCDELAY;
EP6BCL = EP2BCL; // arm EP6IN
SYNCDELAY;
EP2BCL = 0x80; // re(arm) EP2OUT
}
}
if(!(EP2468STAT & bmEP4EMPTY))
{ // check EP4 EMPTY(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is empty
if(!(EP2468STAT & bmEP8FULL))
{ // check EP8 FULL(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is full
// setup AUTOPOINTER(s) in SFR space
// source is EP4OUT
APTR1H = MSB( &EP4FIFOBUF );
APTR1L = LSB( &EP4FIFOBUF );
// Destination is external RAM (at 0x2A00)
AUTOPTRH2 = 0x2A;
AUTOPTRL2 = 0x00;
count = (EP4BCH << 8) + EP4BCL;
for( i = 0x0000; i < count; i++ )
{
EXTAUTODAT2 = EXTAUTODAT1;
}
// Source is external RAM
APTR1H = 0x2A;
APTR1L = 0x00;
// Destination is EP8IN
AUTOPTRH2 = MSB( &EP8FIFOBUF );;
AUTOPTRL2 = LSB( &EP8FIFOBUF );;
count = (EP4BCH << 8) + EP4BCL;
// loop EP2OUT buffer data to EP6IN
for( i = 0x0000; i < count; i++ )
{
// setup to transfer EP2OUT buffer to EP6IN buffer using AUTOPOINTER(s)
EXTAUTODAT2 = EXTAUTODAT1;
}
EP8BCH = EP4BCH;
SYNCDELAY;
EP8BCL = EP4BCL; // arm EP8IN
SYNCDELAY;
EP4BCL = 0x80; // re(arm) EP4OUT
}
}
}
第三,装载固件程序,打开上位机软件,启动块传输,如下,
当然,这个上位机程序并不完美,只能显示成功传输的块的数量,而不能实时显示数据的传输速度。
良子.2010年
欢迎交流:liangziusb@163.com
QQ:392425239
文章评论(0条评论)
登录后参与讨论