⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bulkloop.lst

📁 用于进行Cypress USB FX2控制
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.05a   BULKLOOP                                                             04/30/2008 16:42:26 PAGE 1   


C51 COMPILER V8.05a, COMPILATION OF MODULE BULKLOOP
OBJECT MODULE PLACED IN bulkloop.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE bulkloop.c DEBUG OBJECTEXTEND

line level    source

   1          //-----------------------------------------------------------------------------
   2          //   File:      bulkloop.c
   3          //   Contents:  Hooks required to implement USB peripheral function.
   4          //
   5          // $Archive: /USB/Examples/FX2LP/bulkloop/bulkloop.c $
   6          // $Date: 3/23/05 2:55p $
   7          // $Revision: 4 $
   8          //
   9          //
  10          //-----------------------------------------------------------------------------
  11          // Copyright 2003, Cypress Semiconductor Corporation
  12          //-----------------------------------------------------------------------------
  13          #pragma NOIV               // Do not generate interrupt vectors
  14          
  15          #include "fx2.h"
  16          #include "fx2regs.h"
  17          #include "syncdly.h"            // SYNCDELAY macro
  18          #include "stdio.h"
  19          extern BOOL GotSUD;             // Received setup data flag
  20          extern BOOL Sleep;
  21          extern BOOL Rwuen;
  22          extern BOOL Selfpwr;
  23          
  24          BYTE Configuration;             // Current configuration
  25          BYTE AlternateSetting;          // Alternate settings
  26          
  27          #define VR_NAKALL_ON    0xD0
  28          #define VR_NAKALL_OFF   0xD1
  29          
  30          //-----------------------------------------------------------------------------
  31          // Task Dispatcher hooks
  32          //   The following hooks are called by the task dispatcher.
  33          //-----------------------------------------------------------------------------
  34          
  35          void TD_Init(void)             // Called once at startup
  36          {
  37   1         // set the CPU clock to 48MHz
  38   1         CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1) ;
  39   1      
  40   1         // set the slave FIFO interface to 48MHz
  41   1         IFCONFIG |= 0x40;
  42   1      
  43   1        // Registers which require a synchronization delay, see section 15.14
  44   1        // FIFORESET        FIFOPINPOLAR
  45   1        // INPKTEND         OUTPKTEND
  46   1        // EPxBCH:L         REVCTL
  47   1        // GPIFTCB3         GPIFTCB2
  48   1        // GPIFTCB1         GPIFTCB0
  49   1        // EPxFIFOPFH:L     EPxAUTOINLENH:L
  50   1        // EPxFIFOCFG       EPxGPIFFLGSEL
  51   1        // PINFLAGSxx       EPxFIFOIRQ
  52   1        // EPxFIFOIE        GPIFIRQ
  53   1        // GPIFIE           GPIFADRH:L
  54   1        // UDMACRCH:L       EPxGPIFTRIG
  55   1        // GPIFTRIG
C51 COMPILER V8.05a   BULKLOOP                                                             04/30/2008 16:42:26 PAGE 2   

  56   1        
  57   1        // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well...
  58   1        //      ...these have been replaced by GPIFTC[B3:B0] registers
  59   1      
  60   1        // default: all endpoints have their VALID bit set
  61   1        // default: TYPE1 = 1 and TYPE0 = 0 --> BULK  
  62   1        // default: EP2 and EP4 DIR bits are 0 (OUT direction)
  63   1        // default: EP6 and EP8 DIR bits are 1 (IN direction)
  64   1        // default: EP2, EP4, EP6, and EP8 are double buffered
  65   1      
  66   1        // we are just using the default values, yes this is not necessary...
  67   1        EP1OUTCFG = 0xA0;     // A=1010       Valid=1,激活; Type=10,bulk
  68   1        EP1INCFG = 0xA0;
  69   1        SYNCDELAY;                    // see TRM section 15.14
  70   1        EP2CFG = 0xA2;        // A2=1010 0010 Valid=1;Dir=0,out;Type=10,bulk;Size=512B;Buf=512*2B
  71   1        SYNCDELAY;                    
  72   1        EP4CFG = 0xA0;        // out
  73   1        SYNCDELAY;                    
  74   1        EP6CFG = 0xE2;        // Dir=1,in;
  75   1        SYNCDELAY;                    
  76   1        EP8CFG = 0xE0;        // in
  77   1      
  78   1        // out endpoints do not come up armed
  79   1        
  80   1        // since the defaults are double buffered we must write dummy byte counts twice
  81   1        SYNCDELAY;                    
  82   1        EP2BCL = 0x80;                // arm EP2OUT by writing byte count w/skip.
  83   1        SYNCDELAY;                    
  84   1        EP2BCL = 0x80;
  85   1        SYNCDELAY;                    
  86   1        EP4BCL = 0x80;                // arm EP4OUT by writing byte count w/skip.
  87   1        SYNCDELAY;                    
  88   1        EP4BCL = 0x80;    
  89   1      
  90   1        // enable dual autopointer feature
  91   1        AUTOPTRSETUP |= 0x01;
  92   1      
  93   1      }
  94          
  95          
  96          void TD_Poll(void)              // Called repeatedly while the device is idle
  97          {
  98   1        WORD i;
  99   1        WORD count;
 100   1        //char *str;
 101   1        //----------------------------if-------------------------//
 102   1        if(!(EP2468STAT & bmEP2EMPTY))
 103   1        { // check EP2 EMPTY(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is empty
 104   2          // 检查EP2的忙位,8051核心将会设置这个位,当FIFO是空的时候。
 105   2           if(!(EP2468STAT & bmEP6FULL))
 106   2           {  // check EP6 FULL(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is full
 107   3                  // 检查EP6的忙位,8051核心将会设置这个位,当FIFO是满的时候。
 108   3              APTR1H = MSB( &EP2FIFOBUF );
 109   3              APTR1L = LSB( &EP2FIFOBUF );
 110   3                      //见Ezusb.h
 111   3                      //#define MSB(word) (BYTE)(((WORD)word>>8)&0xff)
 112   3                      //#define LSB(word) (BYTE)((WORD)word&0xff)
 113   3      
 114   3              AUTOPTRH2 = MSB( &EP6FIFOBUF );
 115   3              AUTOPTRL2 = LSB( &EP6FIFOBUF );
 116   3      
 117   3              count = (EP2BCH << 8) + EP2BCL;
C51 COMPILER V8.05a   BULKLOOP                                                             04/30/2008 16:42:26 PAGE 3   

 118   3      
 119   3              // loop EP2OUT buffer data to EP6IN
 120   3              for( i = 0x0000; i < count; i++ )
 121   3              {
 122   4                         EP6FIFOBUF[i]=EP2FIFOBUF[i];
 123   4                 // setup to transfer EP2OUT buffer to EP6IN buffer using AUTOPOINTER(s)
 124   4                 //EXTAUTODAT2 = EXTAUTODAT1;
 125   4                         //putchar(a[i]);
 126   4                         printf("%d",EP6FIFOBUF[i]);
 127   4              }
 128   3              EP6BCH = EP2BCH;  
 129   3              SYNCDELAY;  
 130   3              EP6BCL = EP2BCL;        // arm EP6IN
 131   3              SYNCDELAY;                    
 132   3              EP2BCL = 0x80;          // re(arm) EP2OUT
 133   3                      //printf("2");
 134   3           }
 135   2        }
 136   1      
 137   1        if(!(EP2468STAT & bmEP4EMPTY))
 138   1        { // check EP4 EMPTY(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is empty
 139   2           if(!(EP2468STAT & bmEP8FULL))
 140   2           {  // check EP8 FULL(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is full
 141   3              APTR1H = MSB( &EP4FIFOBUF );
 142   3              APTR1L = LSB( &EP4FIFOBUF );
 143   3      
 144   3              AUTOPTRH2 = MSB( &EP8FIFOBUF );
 145   3              AUTOPTRL2 = LSB( &EP8FIFOBUF );
 146   3      
 147   3              count = (EP4BCH << 8) + EP4BCL;
 148   3                      
 149   3                      PORTACFG = 0x00; // [7:0] as port I/O
 150   3                      OEA = 0xff; // Enable E1/E2output
 151   3                      //IOA = 0x00;   
 152   3      
 153   3                      for (i=0;i<count;i++)
 154   3                      {
 155   4                              putchar(EP4FIFOBUF[i]);
 156   4                              if ( 0x30 == EP4FIFOBUF[i] )
 157   4                              {
 158   5                                      printf("30 received.i=%d.\n",i);
 159   5                                      //IOA = 0xFF;
 160   5                                      IOA = 0x00;
 161   5                              }
 162   4                              else if ( 0x31 == EP4FIFOBUF[i] )
 163   4                              {
 164   5                                      printf("31 received.i=%d.\n",i);
 165   5                                      //IOA = 0xFF;
 166   5                                      IOA = 0xff;
 167   5                              }
 168   4                              else if ( 0x32 == EP4FIFOBUF[i] )
 169   4                              {
 170   5                                      printf("32 received.i=%d.\n",i);
 171   5                                      //IOA = 0xFF;
 172   5                                      IOA = ~IOA;
 173   5                              }
 174   4                      }    
 175   3      
 176   3              // loop EP4OUT buffer data to EP8IN
 177   3              ///*
 178   3                      for( i = 0x0000; i < count; i++ )
 179   3              {
C51 COMPILER V8.05a   BULKLOOP                                                             04/30/2008 16:42:26 PAGE 4   

 180   4               
 181   4                 // setup to transfer EP4OUT buffer to EP8IN buffer using AUTOPOINTER(s)
 182   4                 EXTAUTODAT2 = EXTAUTODAT1;
 183   4                         printf("EXTAUTODAT2 = EXTAUTODAT1,the %dth time.\n",i+1);
 184   4              }
 185   3                      //*/
 186   3      
 187   3              EP8BCH = EP4BCH;  
 188   3              SYNCDELAY;  
 189   3              EP8BCL = EP4BCL;        // arm EP8IN
 190   3              SYNCDELAY;                    
 191   3              EP4BCL = 0x80;          // re(arm) EP4OUT
 192   3      
 193   3                      //for(i=0;i<count;i++)
 194   3                      //{
 195   3                      //      putchar(EP8FIFOBUF[i]);
 196   3              //}
 197   3          
 198   3           }
 199   2        }
 200   1      
 201   1                 
 202   1      
 203   1      }
 204          
 205          BOOL TD_Suspend(void)          // Called before the device goes into suspend mode
 206          {
 207   1         return(TRUE);
 208   1      }
 209          
 210          BOOL TD_Resume(void)          // Called after the device resumes
 211          {
 212   1         return(TRUE);
 213   1      }
 214          
 215          //-----------------------------------------------------------------------------
 216          // Device Request hooks
 217          //   The following hooks are called by the end point 0 device request parser.
 218          //-----------------------------------------------------------------------------
 219          
 220          BOOL DR_GetDescriptor(void)
 221          {
 222   1         return(TRUE);
 223   1      }
 224          
 225          BOOL DR_SetConfiguration(void)   // Called when a Set Configuration command is received
 226          {
 227   1         Configuration = SETUPDAT[2];
 228   1         return(TRUE);            // Handled by user code
 229   1      }
 230          
 231          BOOL DR_GetConfiguration(void)   // Called when a Get Configuration command is received
 232          {
 233   1         EP0BUF[0] = Configuration;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -