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

📄 f32x_usb_standard_requests.lst

📁 USB演示程序,包含了pc端的demo,cygnal 8051f321 chip
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.50   F32X_USB_STANDARD_REQUESTS                                            08/23/2006 15:13:09 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE F32X_USB_STANDARD_REQUESTS
OBJECT MODULE PLACED IN F32x_USB_Standard_Requests.OBJ
COMPILER INVOKED BY: D:\keil\C51\BIN\c51.exe F32x_USB_Standard_Requests.c DB OE

line level    source

   1          //-----------------------------------------------------------------------------
   2          // F32x_USB_Standard_Requests.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2005 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          //
   9          // This source file contains the subroutines used to handle incoming 
  10          // setup packets. These are called by Handle_Setup in USB_ISR.c and used for 
  11          // USB chapter 9 compliance.
  12          //
  13          
  14          // How To Test:    See Readme.txt
  15          //
  16          //
  17          // FID:            32X000027
  18          // Target:         C8051F32x
  19          // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  20          //                 Silicon Laboratories IDE version 2.6
  21          // Command Line:   See Readme.txt
  22          // Project Name:   F32x_USB_Interrupt
  23          //
  24          //
  25          // Release 1.3
  26          //    -All changes by GP
  27          //    -22 NOV 2005
  28          //    -Changed revision number to match project revision
  29          //     No content changes to this file
  30          //    -Modified file to fit new formatting guidelines
  31          //    -Changed file name from USB_STD_REQ.c
  32          //
  33          // Release 1.0
  34          //    -Initial Revision (JS)
  35          //    -22 NOV 2002
  36          //
  37          
  38          //-----------------------------------------------------------------------------
  39          // Includes
  40          //-----------------------------------------------------------------------------
  41          
  42          #include "c8051F320.h"
  43          #include "F32x_USB_Register.h"
  44          #include "F32x_USB_Main.h"
  45          #include "F32x_USB_Descriptor.h"
  46          
  47          //-----------------------------------------------------------------------------
  48          // Externs
  49          //-----------------------------------------------------------------------------
  50          
  51          // These are created in USB_DESCRIPTOR.h
  52          
  53          extern device_descriptor DeviceDesc;            
  54          extern configuration_descriptor ConfigDesc;
  55          extern interface_descriptor InterfaceDesc;
C51 COMPILER V7.50   F32X_USB_STANDARD_REQUESTS                                            08/23/2006 15:13:09 PAGE 2   

  56          extern endpoint_descriptor Endpoint1Desc;
  57          extern endpoint_descriptor Endpoint2Desc;
  58          extern BYTE* StringDescTable[];
  59          
  60          extern setup_buffer Setup;             // Buffer for current device request
  61          extern unsigned int DataSize;
  62          extern unsigned int DataSent;
  63          extern BYTE* DataPtr;
  64          
  65          extern BYTE Ep_Status[];               // Contains status bytes for EP 0-2
  66          
  67          extern BYTE USB_State;                 // Determines current usb device state
  68          
  69          //-----------------------------------------------------------------------------
  70          // Global Variables
  71          //-----------------------------------------------------------------------------
  72          
  73          // These are response packets used for communication with host
  74          code BYTE ONES_PACKET[2] = {0x01, 0x00};        
  75          code BYTE ZERO_PACKET[2] = {0x00, 0x00};        
  76          
  77          //-----------------------------------------------------------------------------
  78          // Support Subroutines
  79          //-----------------------------------------------------------------------------
  80          
  81          //-----------------------------------------------------------------------------
  82          // Get_Status
  83          //-----------------------------------------------------------------------------
  84          //
  85          // Return Value : None
  86          // Parameters   : None
  87          //
  88          // This routine returns a two byte status packet to the host
  89          //
  90          //-----------------------------------------------------------------------------
  91          
  92          void Get_Status(void)                  
  93          {                                      
  94   1      
  95   1         if (Setup.wValue.c[MSB] || Setup.wValue.c[LSB] ||
  96   1                                                      
  97   1         // If non-zero return length or data length not  equal to 2 then send a stall
  98   1         // indicating invalid request
  99   1         Setup.wLength.c[MSB]    || (Setup.wLength.c[LSB] != 2))                                               
 100   1         {                                            
 101   2            Force_Stall();
 102   2         }
 103   1      
 104   1         // Determine if recipient was device, interface, or EP
 105   1         switch(Setup.bmRequestType)                  
 106   1         {
 107   2            // If recipient was device
 108   2            case OUT_DEVICE:                          
 109   2               if (Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB])
 110   2               {
 111   3                          // Send stall if request is invalid
 112   3                  Force_Stall();             
 113   3               }
 114   2               else
 115   2               {
 116   3                          // Otherwise send 0x00, indicating bus power and no
 117   3                              // remote wake-up supported
C51 COMPILER V7.50   F32X_USB_STANDARD_REQUESTS                                            08/23/2006 15:13:09 PAGE 3   

 118   3                  DataPtr = (BYTE*)&ZERO_PACKET;      
 119   3                  DataSize = 2;                       
 120   3               }
 121   2               break;
 122   2      
 123   2            // See if recipient was interface
 124   2            case OUT_INTERFACE:                       
 125   2                   // Only valid if device is configured and non-zero index
 126   2               if ((USB_State != DEV_CONFIGURED) ||
 127   2                    Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB])                                                
 128   2               {
 129   3                          // Otherwise send stall to host
 130   3                  Force_Stall();                      
 131   3               }
 132   2               else
 133   2               {
 134   3                          // Status packet always returns 0x00
 135   3                  DataPtr = (BYTE*)&ZERO_PACKET;      
 136   3                  DataSize = 2;
 137   3               }
 138   2               break;
 139   2      
 140   2            // See if recipient was an endpoint
 141   2            case OUT_ENDPOINT:                        
 142   2                   // Make sure device is configured and index msb = 0x00
 143   2               if ((USB_State != DEV_CONFIGURED) || Setup.wIndex.c[MSB])                   
 144   2               {                                     
 145   3                  Force_Stall();              // otherwise return stall to host
 146   3               }
 147   2               else
 148   2               {
 149   3                  // Handle case if request is directed to EP 1
 150   3                  if (Setup.wIndex.c[LSB] == IN_EP1)  
 151   3                  {
 152   4                     if (Ep_Status[1] == EP_HALT)
 153   4                     {                                
 154   5                                    // If endpoint is halted, return 0x01,0x00
 155   5                        DataPtr = (BYTE*)&ONES_PACKET;
 156   5                        DataSize = 2;
 157   5                     }
 158   4                     else
 159   4                     {
 160   5                                    // Otherwise return 0x00,0x00 to indicate endpoint active
 161   5                        DataPtr = (BYTE*)&ZERO_PACKET;
 162   5                        DataSize = 2;
 163   5                     }
 164   4                  }
 165   3                  else
 166   3                  {
 167   4                                 // If request is directed to endpoint 2, send either
 168   4                                 // 0x01,0x00 if endpoint halted or 0x00,0x00 if endpoint is active
 169   4                     if (Setup.wIndex.c[LSB] == OUT_EP2)
 170   4                                                      
 171   4                     {                                
 172   5                        if (Ep_Status[2] == EP_HALT)
 173   5                        {
 174   6                           DataPtr = (BYTE*)&ONES_PACKET;
 175   6                           DataSize = 2;
 176   6                        }
 177   5                        else
 178   5                        {
 179   6                           DataPtr = (BYTE*)&ZERO_PACKET;
C51 COMPILER V7.50   F32X_USB_STANDARD_REQUESTS                                            08/23/2006 15:13:09 PAGE 4   

 180   6                           DataSize = 2;
 181   6                        }
 182   5                     }
 183   4                     else
 184   4                     {
 185   5                        Force_Stall();       // Send stall if unexpected data
 186   5                     }
 187   4                  }
 188   3               }
 189   2               break;
 190   2      
 191   2            default:
 192   2               Force_Stall();
 193   2               break;
 194   2         }
 195   1         if (Ep_Status[0] != EP_STALL)
 196   1         {
 197   2            // Set serviced Setup Packet, Endpoint 0 intransmit mode, 
 198   2                // and reset DataSent counter
 199   2            POLL_WRITE_BYTE(E0CSR, rbSOPRDY);        
 200   2            Ep_Status[0] = EP_TX;                     
 201   2            DataSent = 0;

⌨️ 快捷键说明

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