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

📄 periph.lst

📁 实现ez-usb fx2的 自定义请求功能
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.02b   PERIPH                                                               06/30/2004 15:13:17 PAGE 1   


C51 COMPILER V7.02b, COMPILATION OF MODULE PERIPH
OBJECT MODULE PLACED IN periph.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE periph.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #pragma NOIV               // Do not generate interrupt vectors
   2          //-----------------------------------------------------------------------------
   3          //   File:      periph.c
   4          //   Contents:   Hooks required to implement USB peripheral function.
   5          //
   6          //   Copyright (c) 1997 AnchorChips, Inc. All rights reserved
   7          //-----------------------------------------------------------------------------
   8          #include "fx2.h"
   9          #include "fx2regs.h"
  10          #include "io.h"
  11          #include "key.h"
  12          #include "led.h"
  13          #include "serial.h"
  14          #include "eeprom.h"
  15          #include "fx2sdly.h"     
  16          extern BOOL   GotSUD;         // Received setup data flag
  17          extern BOOL   Sleep;
  18          extern BOOL   Rwuen;
  19          extern BOOL   Selfpwr;
  20          
  21          BYTE   Configuration;      // Current configuration
  22          BYTE   AlternateSetting;   // Alternate settings
  23          
  24          //-----------------------------------------------------------------------------
  25          // Task Dispatcher hooks
  26          //   The following hooks are called by the task dispatcher.
  27          //-----------------------------------------------------------------------------
  28          
  29          void TD_Init(void)             // Called once at startup
  30          {
  31   1              REVCTL = 0x03; // MUST set REVCTL.0 and REVCTL.1 to 1
  32   1          SYNCDELAY;
  33   1          BREAKPT &= ~bmBPEN;      // to see BKPT LED go out TGE
  34   1          Rwuen = TRUE;            // Enable remote-wakeup*/
  35   1      }
  36          
  37          void TD_Poll(void)             // Called repeatedly while the device is idle
  38          {
  39   1      }
  40          
  41          BOOL TD_Suspend(void)          // Called before the device goes into suspend mode
  42          {
  43   1         return(TRUE);
  44   1      }
  45          
  46          BOOL TD_Resume(void)          // Called after the device resumes
  47          {
  48   1         return(TRUE);
  49   1      }
  50          
  51          //-----------------------------------------------------------------------------
  52          // Device Request hooks
  53          //   The following hooks are called by the end point 0 device request parser.
  54          //-----------------------------------------------------------------------------
  55          
C51 COMPILER V7.02b   PERIPH                                                               06/30/2004 15:13:17 PAGE 2   

  56          BOOL DR_GetDescriptor(void)
  57          {
  58   1         return(TRUE);
  59   1      }
  60          
  61          BOOL DR_SetConfiguration(void)   // Called when a Set Configuration command is received
  62          {
  63   1         Configuration = SETUPDAT[2];
  64   1         return(TRUE);            // Handled by user code
  65   1      }
  66          
  67          BOOL DR_GetConfiguration(void)   // Called when a Get Configuration command is received
  68          {
  69   1         EP0BUF[0] = Configuration;
  70   1         EP0BCH = 0;
  71   1         EP0BCL = 1;
  72   1         return(TRUE);            // Handled by user code
  73   1      }
  74          
  75          BOOL DR_SetInterface(void)       // Called when a Set Interface command is received
  76          {
  77   1         AlternateSetting = SETUPDAT[2];
  78   1         return(TRUE);            // Handled by user code
  79   1      }
  80          
  81          BOOL DR_GetInterface(void)       // Called when a Set Interface command is received
  82          {
  83   1         EP0BUF[0] = AlternateSetting;
  84   1         EP0BCH = 0;
  85   1         EP0BCL = 1;
  86   1         return(TRUE);            // Handled by user code
  87   1      }
  88          
  89          BOOL DR_GetStatus(void)
  90          {
  91   1         return(TRUE);
  92   1      }
  93          
  94          BOOL DR_ClearFeature(void)
  95          {
  96   1         return(TRUE);
  97   1      }
  98          
  99          BOOL DR_SetFeature(void)
 100          {
 101   1         return(TRUE);
 102   1      }
 103          
 104          
 105          #define VR_UPLOAD               0xc0
 106          #define VR_DOWNLOAD             0x40
 107          
 108          #define ZSUSB20DDB_VENDOR_REQUEST_LED_DISP                0xB0   //led显示
 109          #define ZSUSB20DDB_VENDOR_REQUEST_KEY_READ                0xB1   //键盘读取
 110          #define ZSUSB20DDB_VENDOR_REQUEST_EEPROM_ACCESS           0xB2   //EEPROM访问
 111          #define ZSUSB20DDB_VENDOR_REQUEST_SRAM_ACCESS             0xB3   //SRAM访问
 112          #define ZSUSB20DDB_VENDOR_REQUEST_SERIAL_ACCESS           0xB4   //串口访问
 113          
 114          BOOL DR_VendorCmnd(void)
 115          {
 116   1              WORD            addr, len, bc,length;
 117   1              WORD i;
C51 COMPILER V7.02b   PERIPH                                                               06/30/2004 15:13:17 PAGE 3   

 118   1              BYTE flag;
 119   1              BYTE xdata *point;
 120   1      
 121   1              len = SETUPDAT[6];
 122   1              len |= (SETUPDAT[7] << 8);
 123   1              switch(SETUPDAT[1])
 124   1              { 
 125   2                      case ZSUSB20DDB_VENDOR_REQUEST_LED_DISP:    //led显示
 126   2                      {
 127   3                              DispBuf[SETUPDAT[3]&3] = SETUPDAT[2];   //wValueH为第几位了led,wValueL为显示值
 128   3                              break;
 129   3                      }
 130   2                      case ZSUSB20DDB_VENDOR_REQUEST_KEY_READ:    //键盘读取
 131   2                      {
 132   3                              if(OKey_Value != 0xFF)
 133   3                              {
 134   4                                      EP0BUF[0] = OKey_Value;
 135   4                                      EP0BCH = 0;
 136   4                                      EP0BCL = 1;
 137   4                                      OKey_Value = 0xFF;
 138   4                              }
 139   3                              else
 140   3                              {
 141   4                                      EP0BCH = 0;
 142   4                                      EP0BCL = 0;
 143   4                              }
 144   3                              break;
 145   3                      }
 146   2                      case ZSUSB20DDB_VENDOR_REQUEST_EEPROM_ACCESS:
 147   2                      case ZSUSB20DDB_VENDOR_REQUEST_SRAM_ACCESS:
 148   2                      {
 149   3                              addr = SETUPDAT[2];             // Get address and length
 150   3                              addr |= SETUPDAT[3] << 8;
 151   3                              // Is this an upload command ?
 152   3                              if(SETUPDAT[0] == VR_UPLOAD)
 153   3                              {
 154   4                                      while(len)                                      // Move requested data through EP0IN 
 155   4                                      {                                                       // one packet at a time.
 156   5                                              if(len < 64)
 157   5                                                      bc = len;
 158   5                                              else
 159   5                                                      bc = 64;
 160   5                                              // Is this a RAM upload ?
 161   5                                              if(SETUPDAT[1] == ZSUSB20DDB_VENDOR_REQUEST_SRAM_ACCESS)
 162   5                                              {
 163   6                                                      for(i=0; i<bc; i++)
 164   6                                                              *(EP0BUF+i) = *((BYTE xdata *)addr+i);
 165   6                                              }
 166   5                                              else
 167   5                                              {
 168   6                                                      EEPROMRead(addr,bc,(WORD)EP0BUF);
 169   6                                              }
 170   5                                              EP0BCH = 0;
 171   5                                              EP0BCL = (BYTE)bc; // Arm endpoint
 172   5                                              addr += bc;
 173   5                                              len -= bc;
 174   5      
 175   5                                              while(EP0CS & bmEPBUSY);
 176   5                                      }
 177   4                              }
 178   3                              // Is this a download command ?
 179   3                              else if(SETUPDAT[0] == VR_DOWNLOAD)
C51 COMPILER V7.02b   PERIPH                                                               06/30/2004 15:13:17 PAGE 4   

 180   3                              {
 181   4                                      while(len)                                      // Move new data through EP0OUT 
 182   4                                      {                                                       // one packet at a time.
 183   5                                              // Arm endpoint - do it here to clear (after sud avail)
 184   5                                              EP0BCH = 0;
 185   5                                              EP0BCL = 0; // Clear bytecount to allow new data in; also stops NAKing
 186   5      
 187   5                                              while(EP0CS & bmEPBUSY);
 188   5      
 189   5                                              bc = EP0BCL; // Get the new bytecount
 190   5                                              // Is this a RAM download ?
 191   5                                              if(SETUPDAT[1] == ZSUSB20DDB_VENDOR_REQUEST_SRAM_ACCESS)
 192   5                                              {
 193   6                                                      for(i=0; i<bc; i++)
 194   6                                                               *((BYTE xdata *)addr+i) = *(EP0BUF+i);
 195   6                                              }
 196   5                                              else
 197   5                                                      EEPROMWrite(addr,bc,(WORD)EP0BUF);
 198   5                                              addr += bc;
 199   5                                              len -= bc;
 200   5                                      }
 201   4                              }
 202   3                              break;
 203   3                      }
 204   2                      case ZSUSB20DDB_VENDOR_REQUEST_SERIAL_ACCESS:
 205   2                      {
 206   3                              flag = SETUPDAT[2];
 207   3                              // Is this an upload command ?
 208   3                              if(SETUPDAT[0] == VR_UPLOAD)
 209   3                              {
 210   4                                      if(flag == 0) ES0 = 0;
 211   4                                      else ES1 = 0;
 212   4                                      length = ((flag == 0)?ReceiveCount0:ReceiveCount1);
 213   4                                      point =  ((flag == 0)?ReceiveBuf0:ReceiveBuf1);
 214   4                                      if(length > len)   //只能传输小于或等于请求长度的数据
 215   4                                              length = len; //limit to the requested length
 216   4                                      while(length)                                   // Move requested data through EP0IN 
 217   4                                      {               
 218   5                                      // one packet at a time.
 219   5                                              if(length < 64)
 220   5                                                      bc = length;

⌨️ 快捷键说明

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