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

📄 usb_std_req.lst

📁 针对TMS320C6000系列的DSP芯片的在线升级的源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.12  USB_STD_REQ                                                            06/09/2004 15:44:26 PAGE 1   


C51 COMPILER V6.12, COMPILATION OF MODULE USB_STD_REQ
OBJECT MODULE PLACED IN USB_STD_REQ.OBJ
COMPILER INVOKED BY: c:\Keil\C51\BIN\C51.EXE USB_STD_REQ.c DB OE

stmt level    source

   1          /*
   2          FILENAME: USB_STD_REQ.c
   3          
   4          author: DM
   5          
   6          11/22/02
   7          
   8          This source file contains the subroutines used to handle incoming setup packets.
   9          These are called by Handle_Setup in USB_ISR.c and used for  USB chapter 9
  10          compliance.
  11          
  12          */
  13          
  14          
  15          
  16          #include "c8051F320.h"
  17          #include "USB_REGISTER.h"
  18          #include "USB_MAIN.h"
  19          #include "USB_DESCRIPTOR.h"
  20          
  21          extern device_descriptor DeviceDesc;            // These are created in USB_DESCRIPTOR.h
  22          extern configuration_descriptor ConfigDesc;
  23          extern interface_descriptor InterfaceDesc;
  24          extern endpoint_descriptor Endpoint1Desc;
  25          extern endpoint_descriptor Endpoint2Desc;
  26          extern BYTE* StringDescTable[];
  27          
  28          extern setup_buffer Setup;                      // Buffer for current device request information
  29          extern unsigned int DataSize; 
  30          extern unsigned int DataSent;                         
  31          extern BYTE* DataPtr;
  32          
  33          extern BYTE Ep_Status[];                        // This array contains status bytes for EP 0-2
  34          
  35          code BYTE ONES_PACKET[2] = {0x01, 0x00};        // These are response packets used for
  36          code BYTE ZERO_PACKET[2] = {0x00, 0x00};        // communication with host
  37          
  38          extern BYTE USB_State;                          // Determines current usb device state
  39          
  40          
  41          void Get_Status(void)                           // This routine returns a two byte status packet
  42          {                                               // to the host
  43   1                                             
  44   1         if (Setup.wValue.c[MSB] || Setup.wValue.c[LSB] || 
  45   1                                                      // If non-zero return length or data length not
  46   1         Setup.wLength.c[MSB]    || (Setup.wLength.c[LSB] != 2))  
  47   1                                                      // equal to 2 then send a stall 
  48   1         {                                            // indicating invalid request
  49   2            Force_Stall();
  50   2         }
  51   1      
  52   1         switch(Setup.bmRequestType)                  // Determine if recipient was device, interface, or EP
  53   1         {
  54   2            case OUT_DEVICE:                          // If recipient was device
  55   2               if (Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB])
C51 COMPILER V6.12  USB_STD_REQ                                                            06/09/2004 15:44:26 PAGE 2   

  56   2               {
  57   3                  Force_Stall();                      // Send stall if request is invalid
  58   3               }
  59   2               else
  60   2               {
  61   3                  DataPtr = (BYTE*)&ZERO_PACKET;      // Otherwise send 0x00, indicating bus power and no
  62   3                  DataSize = 2;                       // remote wake-up supported
  63   3               }
  64   2               break;
  65   2            
  66   2            case OUT_INTERFACE:                       // See if recipient was interface
  67   2               if ((USB_State != DEV_CONFIGURED) ||  
  68   2               Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB]) 
  69   2                                                      // Only valid if device is configured and non-zero index 
  70   2               {
  71   3                  Force_Stall();                      // Otherwise send stall to host
  72   3               }
  73   2               else
  74   2               {
  75   3                  DataPtr = (BYTE*)&ZERO_PACKET;      // Status packet always returns 0x00
  76   3                  DataSize = 2;
  77   3               }
  78   2               break;
  79   2        
  80   2            case OUT_ENDPOINT:                        // See if recipient was an endpoint
  81   2               if ((USB_State != DEV_CONFIGURED) ||
  82   2               Setup.wIndex.c[MSB])                   // Make sure device is configured and index msb = 0x00
  83   2               {                                      // otherwise return stall to host
  84   3                  Force_Stall();                      
  85   3               }
  86   2               else
  87   2               {
  88   3                  if (Setup.wIndex.c[LSB] == IN_EP1)  // Handle case if request is directed to EP 1
  89   3                  {
  90   4                     if (Ep_Status[1] == EP_HALT)
  91   4                     {                                // If endpoint is halted, return 0x01,0x00
  92   5                        DataPtr = (BYTE*)&ONES_PACKET;
  93   5                        DataSize = 2;
  94   5                     }
  95   4                     else
  96   4                     {
  97   5                        DataPtr = (BYTE*)&ZERO_PACKET;// Otherwise return 0x00,0x00 to indicate endpoint active
  98   5                        DataSize = 2;
  99   5                     }
 100   4                  }
 101   3                  else
 102   3                  {
 103   4                     if (Setup.wIndex.c[LSB] == OUT_EP2)
 104   4                                                      // If request is directed to endpoint 2, send either
 105   4                     {                                // 0x01,0x00 if endpoint halted or 0x00,0x00 if 
 106   5                        if (Ep_Status[2] == EP_HALT)  // endpoint is active
 107   5                        {
 108   6                           DataPtr = (BYTE*)&ONES_PACKET;
 109   6                           DataSize = 2;
 110   6                        }
 111   5                        else
 112   5                        {
 113   6                           DataPtr = (BYTE*)&ZERO_PACKET;
 114   6                           DataSize = 2;
 115   6                        }
 116   5                     }
 117   4                     else
C51 COMPILER V6.12  USB_STD_REQ                                                            06/09/2004 15:44:26 PAGE 3   

 118   4                     {
 119   5                        Force_Stall();                // Send stall if unexpected data encountered
 120   5                     }
 121   4                  }
 122   3               }
 123   2               break;
 124   2      
 125   2            default:
 126   2               Force_Stall();
 127   2               break;
 128   2         }
 129   1         if (Ep_Status[0] != EP_STALL)
 130   1         {                            
 131   2            POLL_WRITE_BYTE(E0CSR, rbSOPRDY);         // Set serviced Setup Packet, Endpoint 0 in               
             -    
 132   2            Ep_Status[0] = EP_TX;                     // transmit mode, and reset DataSent counter
 133   2            DataSent = 0;
 134   2         }
 135   1      }
 136          
 137          void Clear_Feature()                            // This routine can clear Halt Endpoint features
 138          {                                               // on endpoint 1 and 2.  
 139   1      
 140   1         if ((USB_State != DEV_CONFIGURED)          ||// Send procedural stall if device isn't configured
 141   1         (Setup.bmRequestType == IN_DEVICE)         ||// or request is made to host(remote wakeup not supported)
 142   1         (Setup.bmRequestType == IN_INTERFACE)      ||// or request is made to interface
 143   1         Setup.wValue.c[MSB]  || Setup.wIndex.c[MSB]||// or msbs of value or index set to non-zero value
 144   1         Setup.wLength.c[MSB] || Setup.wLength.c[LSB])// or data length set to non-zero.
 145   1         {
 146   2            Force_Stall();
 147   2         }
 148   1      
 149   1         else
 150   1         {             
 151   2            if ((Setup.bmRequestType == IN_ENDPOINT)&&// Verify that packet was directed at an endpoint
 152   2            (Setup.wValue.c[LSB] == ENDPOINT_HALT)  &&// the feature selected was HALT_ENDPOINT
 153   2            ((Setup.wIndex.c[LSB] == IN_EP1) ||       // and that the request was directed at EP 1 in
 154   2            (Setup.wIndex.c[LSB] == OUT_EP2)))        // or EP 2 out
 155   2            {
 156   3               if (Setup.wIndex.c[LSB] == IN_EP1) 
 157   3               {
 158   4                  POLL_WRITE_BYTE (INDEX, 1);         // Clear feature endpoint 1 halt
 159   4                  POLL_WRITE_BYTE (EINCSR1, rbInCLRDT);       
 160   4                  Ep_Status[1] = EP_IDLE;             // Set endpoint 1 status back to idle                    
 161   4               }
 162   3               else
 163   3               {
 164   4                  POLL_WRITE_BYTE (INDEX, 2);         // Clear feature endpoint 2 halt
 165   4                  POLL_WRITE_BYTE (EOUTCSR1, rbOutCLRDT);         
 166   4                  Ep_Status[2] = EP_IDLE;             // Set endpoint 2 status back to idle
 167   4               }
 168   3            }
 169   2            else
 170   2            { 
 171   3               Force_Stall();                         // Send procedural stall
 172   3            }
 173   2         }
 174   1         POLL_WRITE_BYTE(INDEX, 0);                   // Reset Index to 0
 175   1         if (Ep_Status[0] != EP_STALL)
 176   1         {
 177   2            POLL_WRITE_BYTE(E0CSR, (rbSOPRDY | rbDATAEND));
 178   2      	                                            // Set Serviced Out packet ready and data end to 
C51 COMPILER V6.12  USB_STD_REQ                                                            06/09/2004 15:44:26 PAGE 4   

 179   2                                                      // indicate transaction is over
 180   2         }
 181   1      }
 182          
 183          
 184          void Set_Feature(void)                          // This routine will set the EP Halt feature for
 185          {                                               // endpoints 1 and 2
 186   1      
 187   1         if ((USB_State != DEV_CONFIGURED)          ||// Make sure device is configured, setup data
 188   1         (Setup.bmRequestType == IN_DEVICE)         ||// is all valid and that request is directed at
 189   1         (Setup.bmRequestType == IN_INTERFACE)      ||// an endpoint
 190   1         Setup.wValue.c[MSB]  || Setup.wIndex.c[MSB]|| 
 191   1         Setup.wLength.c[MSB] || Setup.wLength.c[LSB])
 192   1         {
 193   2            Force_Stall();                            // Otherwise send stall to host
 194   2         }
 195   1      
 196   1         else
 197   1         {             
 198   2            if ((Setup.bmRequestType == IN_ENDPOINT)&&// Make sure endpoint exists and that halt
 199   2            (Setup.wValue.c[LSB] == ENDPOINT_HALT)  &&// endpoint feature is selected
 200   2            ((Setup.wIndex.c[LSB] == IN_EP1)        || 
 201   2            (Setup.wIndex.c[LSB] == OUT_EP2)))
 202   2            {
 203   3               if (Setup.wIndex.c[LSB] == IN_EP1) 
 204   3               {
 205   4                  POLL_WRITE_BYTE (INDEX, 1);         // Set feature endpoint 1 halt
 206   4                  POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);       
 207   4                  Ep_Status[1] = EP_HALT;                                  
 208   4               }
 209   3               else
 210   3               {
 211   4                  POLL_WRITE_BYTE (INDEX, 2);         // Set feature Ep2 halt
 212   4                  POLL_WRITE_BYTE (EOUTCSR1, rbOutSDSTL);         
 213   4                  Ep_Status[2] = EP_HALT;  		    
 214   4               }
 215   3            }
 216   2            else
 217   2            { 
 218   3               Force_Stall();                         // Send procedural stall
 219   3            }
 220   2         }   
 221   1         POLL_WRITE_BYTE(INDEX, 0);
 222   1         if (Ep_Status[0] != EP_STALL)
 223   1         {

⌨️ 快捷键说明

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