原创 CY7C68013A开发板编程之七(Bulkext)

2010-12-26 14:11 1212 7 7 分类: 通信
这是用CYPRESS提供的框架程序实现的一个例子,功能是实现块传输(Bulk),上位机程序用的是Cybulk.exe,运行后如下所示,

d4d68571-8c26-4c5c-b53d-e86ee22eab5a.jpg


  第一,先看一下固件程序。函数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
     }
  }
}


  第三,装载固件程序,打开上位机软件,启动块传输,如下,


dced86ab-f70d-4dba-8f90-bea7dd168302.jpg


  当然,这个上位机程序并不完美,只能显示成功传输的块的数量,而不能实时显示数据的传输速度。


 


良子.2010年


欢迎交流:liangziusb@163.com


QQ:392425239

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
7
关闭 站长推荐上一条 /3 下一条