USB_Standard_Requests.LST
上传用户:gxz1972
上传日期:2019-09-13
资源大小:323k
文件大小:22k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. C51 COMPILER V7.02b   USB_STANDARD_REQUESTS                                                11/30/2007 14:07:13 PAGE 1   
  2. C51 COMPILER V7.02b, COMPILATION OF MODULE USB_STANDARD_REQUESTS
  3. OBJECT MODULE PLACED IN USB_Standard_Requests.OBJ
  4. COMPILER INVOKED BY: C:KeilC51BINc51.exe USB_Standard_Requests.c DB OE
  5. stmt level    source
  6.    1          //-----------------------------------------------------------------------------
  7.    2          // USB_Standard_Requests.c
  8.    3          //-----------------------------------------------------------------------------
  9.    4          // Copyright 2007 Vson Technology, Inc.
  10.    5          // http://www.usbmcu.com
  11.    6          //
  12.    7          // Program Description:
  13.    8          //
  14.    9          //
  15.   10          //
  16.   11          //
  17.   12          //
  18.   13          // MCU:            C8051F347
  19.   14          // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  20.   15          //                 Silicon Laboratories IDE version 2.6
  21.   16          // Command Line:   
  22.   17          // Project Name:   TR1000
  23.   18          //
  24.   19          //
  25.   20          // Release 1.0
  26.   21          //    -All changes by Brin Cai
  27.   22          //    -24 JUL 2007
  28.   23          //
  29.   24          //
  30.   25          
  31.   26          //-----------------------------------------------------------------------------
  32.   27          // Includes
  33.   28          //-----------------------------------------------------------------------------
  34.   29          
  35.   30          #include "Include_H.h"
  36.   31          
  37.   32          //-----------------------------------------------------------------------------
  38.   33          // USB_Standard_Requests.c Global Variables
  39.   34          //-----------------------------------------------------------------------------
  40.   35          
  41.   36          BYTE        bEpState;
  42.   37          UINT        uNumBytes;
  43.   38          PIF_STATUS  pIfStatus;
  44.   39          
  45.   40          
  46.   41          //------------------------------------------------------------------------
  47.   42          //  Standard Request Routines
  48.   43          //------------------------------------------------------------------------
  49.   44          //
  50.   45          // These functions should be called when an endpoint0 command has
  51.   46          // been received with a corresponding "bRequest" field.
  52.   47          //
  53.   48          // - Each routine performs all command field checking, and
  54.   49          //   modifies fields of the Ep0Status structure accordingly
  55.   50          //
  56.   51          // After a call to a standard request routine, the calling routine
  57.   52          // should check Ep0Status.bEpState to determine the required action
  58.   53          // (i.e., send a STALL for EP_ERROR, load the FIFO for EP_TX).
  59.   54          // For transmit status, the data pointer (Ep0Status.pData),
  60.   55          // and data length (Ep0Status.uNumBytes) are prepared before the
  61. C51 COMPILER V7.02b   USB_STANDARD_REQUESTS                                                11/30/2007 14:07:13 PAGE 2   
  62.   56          // standard request routine returns. The calling routine must write
  63.   57          // the data to the FIFO and handle all data transfer
  64.   58          
  65.   59          //-----------------------------------------------------------------------------
  66.   60          // SetAddressRequest
  67.   61          //-----------------------------------------------------------------------------
  68.   62          //
  69.   63          // Return Value : None
  70.   64          // Parameters   : None
  71.   65          //
  72.   66          //-----------------------------------------------------------------------------
  73.   67          void SetAddressRequest ()
  74.   68          {
  75.   69   1         // Index and Length fields must be zero
  76.   70   1         // Device state must be default or addressed
  77.   71   1         if ((gEp0Command.wIndex.i) || (gEp0Command.wLength.i) ||
  78.   72   1         (gDeviceStatus.bDevState == DEV_CONFIG))
  79.   73   1         {
  80.   74   2            bEpState = EP_ERROR;
  81.   75   2         }
  82.   76   1      
  83.   77   1         else
  84.   78   1         {
  85.   79   2            // Assign new function address
  86.   80   2            UWRITE_BYTE(FADDR, gEp0Command.wValue.c[1]);
  87.   81   2            if (gDeviceStatus.bDevState == DEV_DEFAULT &&
  88.   82   2            gEp0Command.wValue.c[1] != 0)
  89.   83   2            {
  90.   84   3               gDeviceStatus.bDevState = DEV_ADDRESS;
  91.   85   3            }
  92.   86   2            if (gDeviceStatus.bDevState == DEV_ADDRESS &&
  93.   87   2            gEp0Command.wValue.c[1] == 0)
  94.   88   2            {
  95.   89   3               gDeviceStatus.bDevState = DEV_ADDRESS;
  96.   90   3            }
  97.   91   2            bEpState = EP_IDLE;
  98.   92   2         }
  99.   93   1         gEp0Status.bEpState = bEpState;
  100.   94   1      }
  101.   95          
  102.   96          //-----------------------------------------------------------------------------
  103.   97          // SetFeatureRequest
  104.   98          //-----------------------------------------------------------------------------
  105.   99          //
  106.  100          // Return Value : None
  107.  101          // Parameters   : None
  108.  102          //
  109.  103          //-----------------------------------------------------------------------------
  110.  104          void SetFeatureRequest ()
  111.  105          {
  112.  106   1         // Length field must be zero
  113.  107   1         // Device state must be configured, or addressed with Command Index
  114.  108   1         // field == 0
  115.  109   1         if ((gEp0Command.wLength.i != 0) ||
  116.  110   1         (gDeviceStatus.bDevState == DEV_DEFAULT) ||
  117.  111   1         (gDeviceStatus.bDevState == DEV_ADDRESS && gEp0Command.wIndex.i != 0))
  118.  112   1         {
  119.  113   2            bEpState = EP_ERROR;
  120.  114   2         }
  121.  115   1      
  122.  116   1         // Handle based on recipient
  123.  117   1         switch(gEp0Command.bmRequestType & CMD_MASK_RECIP)
  124. C51 COMPILER V7.02b   USB_STANDARD_REQUESTS                                                11/30/2007 14:07:13 PAGE 3   
  125.  118   1         {
  126.  119   2            // Device Request - Return error as remote wakeup is not supported
  127.  120   2            case CMD_RECIP_DEV:
  128.  121   2               bEpState = EP_ERROR;
  129.  122   2               break;
  130.  123   2      
  131.  124   2            // Endpoint Request
  132.  125   2            case CMD_RECIP_EP:
  133.  126   2               if (gEp0Command.wValue.i == ENDPOINT_HALT)
  134.  127   2               {
  135.  128   3                  bEpState = HaltEndpoint(gEp0Command.wIndex.i);
  136.  129   3                  break;
  137.  130   3               }
  138.  131   2               else
  139.  132   2               {
  140.  133   3                  bEpState = EP_ERROR;
  141.  134   3                  break;
  142.  135   3               }
  143.  136   2            default:
  144.  137   2               bEpState = EP_ERROR;
  145.  138   2               break;
  146.  139   2         }
  147.  140   1         gEp0Status.bEpState = bEpState;
  148.  141   1      }
  149.  142          
  150.  143          //-----------------------------------------------------------------------------
  151.  144          // ClearFeatureRequest
  152.  145          //-----------------------------------------------------------------------------
  153.  146          //
  154.  147          // Return Value : None
  155.  148          // Parameters   : None
  156.  149          //
  157.  150          //-----------------------------------------------------------------------------
  158.  151          void ClearFeatureRequest ()
  159.  152          {
  160.  153   1         // Length field must be zero
  161.  154   1         // Device state must be configured, or addressed with Command Index
  162.  155   1         // field == 0
  163.  156   1         if ((gEp0Command.wLength.i != 0) || (gDeviceStatus.bDevState == DEV_DEFAULT) ||
  164.  157   1         (gDeviceStatus.bDevState == DEV_ADDRESS && gEp0Command.wIndex.i != 0))
  165.  158   1         {
  166.  159   2            bEpState = EP_ERROR;
  167.  160   2         }
  168.  161   1      
  169.  162   1         // Handle based on recipient
  170.  163   1         switch(gEp0Command.bmRequestType & CMD_MASK_RECIP)
  171.  164   1         {
  172.  165   2            // Device Request
  173.  166   2            case CMD_RECIP_DEV:
  174.  167   2               // Remote wakeup not supported
  175.  168   2               bEpState = EP_ERROR;
  176.  169   2               break;
  177.  170   2      
  178.  171   2            // Endpoint Request
  179.  172   2            case CMD_RECIP_EP:
  180.  173   2               if (gEp0Command.wValue.i == ENDPOINT_HALT)
  181.  174   2               {
  182.  175   3                  // Enable the selected endpoint.
  183.  176   3                  bEpState = EnableEndpoint(gEp0Command.wIndex.i);
  184.  177   3                  break;
  185.  178   3               }
  186.  179   2               else
  187. C51 COMPILER V7.02b   USB_STANDARD_REQUESTS                                                11/30/2007 14:07:13 PAGE 4   
  188.  180   2               {
  189.  181   3                 bEpState = EP_ERROR;
  190.  182   3                 break;
  191.  183   3               }
  192.  184   2            default:
  193.  185   2               bEpState = EP_ERROR;
  194.  186   2               break;
  195.  187   2         }
  196.  188   1         gEp0Status.bEpState = bEpState;
  197.  189   1      }
  198.  190          
  199.  191          //-----------------------------------------------------------------------------
  200.  192          // SetConfigurationRequest
  201.  193          //-----------------------------------------------------------------------------
  202.  194          //
  203.  195          // Return Value : None
  204.  196          // Parameters   : None
  205.  197          //
  206.  198          //-----------------------------------------------------------------------------
  207.  199          void SetConfigurationRequest ()
  208.  200          {
  209.  201   1         // Index and Length fields must be zero
  210.  202   1         // Device state must be addressed or configured
  211.  203   1         if ((gEp0Command.wIndex.i) || (gEp0Command.wLength.i) ||
  212.  204   1         (gDeviceStatus.bDevState == DEV_DEFAULT))
  213.  205   1         {
  214.  206   2            bEpState = EP_ERROR;
  215.  207   2         }
  216.  208   1      
  217.  209   1         else
  218.  210   1         {
  219.  211   2            // Make sure assigned configuration exists
  220.  212   2            if (gEp0Command.wValue.c[1] >
  221.  213   2            gDescriptorMap.bStdDevDsc[std_bNumConfigurations])
  222.  214   2            {
  223.  215   3               bEpState = EP_ERROR;
  224.  216   3            }
  225.  217   2      
  226.  218   2            // Handle zero configuration assignment
  227.  219   2            else if  (gEp0Command.wValue.c[1] == 0)
  228.  220   2               gDeviceStatus.bDevState = DEV_ADDRESS;
  229.  221   2      
  230.  222   2            // Select the assigned configuration
  231.  223   2            else
  232.  224   2               bEpState = SetConfiguration(gEp0Command.wValue.c[1]);
  233.  225   2         }
  234.  226   1         gEp0Status.bEpState = bEpState; 
  235.  227   1      }
  236.  228          
  237.  229          
  238.  230          //-----------------------------------------------------------------------------
  239.  231          // SetInterfaceRequest
  240.  232          //-----------------------------------------------------------------------------
  241.  233          //
  242.  234          // Return Value : None
  243.  235          // Parameters   : None
  244.  236          //
  245.  237          //-----------------------------------------------------------------------------
  246.  238          void SetInterfaceRequest()
  247.  239          {
  248.  240   1         /*
  249.  241   1         // Length field must be zero
  250. C51 COMPILER V7.02b   USB_STANDARD_REQUESTS                                                11/30/2007 14:07:13 PAGE 5   
  251.  242   1         if ((gEp0Command.wLength.i) || (gDeviceStatus.bDevState != DEV_CONFIG))
  252.  243   1            bEpState = EP_ERROR;
  253.  244   1      
  254.  245   1         else
  255.  246   1         {
  256.  247   1            // Check that target interface exists for this configuration
  257.  248   1            if(gEp0Command.wIndex.i > gDeviceStatus.bNumInterf - 1)
  258.  249   1               bEpState = EP_ERROR;
  259.  250   1      
  260.  251   1            else
  261.  252   1            {
  262.  253   1               // Get pointer to interface status structure
  263.  254   1               pIfStatus = (PIF_STATUS)&gDeviceStatus.IfStatus;
  264.  255   1      
  265.  256   1               // Check that alternate setting exists for the interface
  266.  257   1               if (gEp0Command.wValue.i > pIfStatus->bNumAlts)
  267.  258   1                  bEpState = EP_ERROR;
  268.  259   1      
  269.  260   1               // Assign alternate setting
  270.  261   1               else
  271.  262   1               {
  272.  263   1                  pIfStatus->bCurrentAlt = gEp0Command.wValue.i;
  273.  264   1                  bEpState = SetInterface(pIfStatus);
  274.  265   1               }
  275.  266   1            }
  276.  267   1         }
  277.  268   1         gEp0Status.bEpState = bEpState;
  278.  269   1         */
  279.  270   1      }
  280.  271          
  281.  272          //-----------------------------------------------------------------------------
  282.  273          // GetStatusRequest
  283.  274          //-----------------------------------------------------------------------------
  284.  275          //
  285.  276          // Return Value : None
  286.  277          // Parameters   : None
  287.  278          //
  288.  279          //-----------------------------------------------------------------------------
  289.  280          void GetStatusRequest ()
  290.  281          {
  291.  282   1         // Value field must be zero; Length field must be 2
  292.  283   1         if ((gEp0Command.wValue.i != 0) || (gEp0Command.wLength.i != 0x02) ||
  293.  284   1         (gDeviceStatus.bDevState == DEV_DEFAULT) ||
  294.  285   1         (gDeviceStatus.bDevState == DEV_ADDRESS && gEp0Command.wIndex.i != 0))
  295.  286   1         {
  296.  287   2            bEpState = EP_ERROR;
  297.  288   2         }
  298.  289   1      
  299.  290   1         else
  300.  291   1         {
  301.  292   2            // Check for desired status (device, interface, endpoint)
  302.  293   2            switch (gEp0Command.bmRequestType & CMD_MASK_RECIP)
  303.  294   2            {
  304.  295   3               // Device
  305.  296   3               case CMD_RECIP_DEV:
  306.  297   3                  // Index must be zero for a Device status request
  307.  298   3                  if (gEp0Command.wIndex.i != 0)
  308.  299   3                     bEpState = EP_ERROR;
  309.  300   3                  else
  310.  301   3                  {
  311.  302   4                     // Prepare data_out for transmission
  312.  303   4                     gEp0Status.wData.c[1] = 0;
  313. C51 COMPILER V7.02b   USB_STANDARD_REQUESTS                                                11/30/2007 14:07:13 PAGE 6   
  314.  304   4                     gEp0Status.wData.c[0] = gDeviceStatus.bRemoteWakeupStatus;
  315.  305   4                     gEp0Status.wData.c[0] |= gDeviceStatus.bSelfPoweredStatus;
  316.  306   4                  }
  317.  307   3                  break;
  318.  308   3      
  319.  309   3               // Interface
  320.  310   3               case CMD_RECIP_IF:
  321.  311   3                  // Prepare data_out for transmission
  322.  312   3                  gEp0Status.wData.i = 0;
  323.  313   3                  break;
  324.  314   3      
  325.  315   3               // Endpoint
  326.  316   3               case CMD_RECIP_EP:
  327.  317   3                  // Prepare data_out for transmission
  328.  318   3                  gEp0Status.wData.i = 0;
  329.  319   3                  if (GetEpStatus(gEp0Command.wIndex.i) == EP_HALTED)
  330.  320   3                     gEp0Status.wData.c[0] |= 0x01;
  331.  321   3                  break;
  332.  322   3      
  333.  323   3               // Other cases unsupported
  334.  324   3               default:
  335.  325   3                  bEpState = EP_ERROR;
  336.  326   3                  break;
  337.  327   3            }
  338.  328   2      
  339.  329   2            // Endpoint0 state assignment
  340.  330   2            bEpState = EP_TX;
  341.  331   2      
  342.  332   2            // Point ep0 data pointer to transmit data_out
  343.  333   2            gEp0Status.pData = (BYTE *)&gEp0Status.wData.i;
  344.  334   2            gEp0Status.uNumBytes = 2;
  345.  335   2         }
  346.  336   1         gEp0Status.bEpState = bEpState;
  347.  337   1      }
  348.  338          
  349.  339          //-----------------------------------------------------------------------------
  350.  340          // GetDescriptorRequest
  351.  341          //-----------------------------------------------------------------------------
  352.  342          //
  353.  343          // Return Value : None
  354.  344          // Parameters   : None
  355.  345          //
  356.  346          //-----------------------------------------------------------------------------
  357.  347          void GetDescriptorRequest ()
  358.  348          {
  359.  349   1         WORD wTempInt;
  360.  350   1      
  361.  351   1         // This request is valid in all device states
  362.  352   1         // Switch on requested descriptor (Value field)
  363.  353   1         switch (gEp0Command.wValue.c[0])
  364.  354   1         {
  365.  355   2            // Device Descriptor Request
  366.  356   2            case DSC_DEVICE:
  367.  357   2               // Get size of the requested descriptor
  368.  358   2               uNumBytes = STD_DSC_SIZE;
  369.  359   2               // Prep to send the requested length
  370.  360   2               if (uNumBytes > gEp0Command.wLength.i)
  371.  361   2               {
  372.  362   3                  uNumBytes = gEp0Command.wLength.i;
  373.  363   3               }
  374.  364   2               // Point data pointer to the requested descriptor
  375.  365   2               gEp0Status.pData = (void*)&gDescriptorMap.bStdDevDsc;
  376. C51 COMPILER V7.02b   USB_STANDARD_REQUESTS                                                11/30/2007 14:07:13 PAGE 7   
  377.  366   2               bEpState = EP_TX;
  378.  367   2               break;
  379.  368   2      
  380.  369   2            // Configuration Descriptor Request
  381.  370   2            case DSC_CONFIG:
  382.  371   2               // Make sure requested descriptor exists
  383.  372   2               if (gEp0Command.wValue.c[1] >
  384.  373   2               gDescriptorMap.bStdDevDsc[std_bNumConfigurations])
  385.  374   2               {
  386.  375   3                  bEpState = EP_ERROR;
  387.  376   3               }
  388.  377   2               else
  389.  378   2               {
  390.  379   3                  // Get total length of this configuration descriptor
  391.  380   3                  // (includes all associated interface and endpoints)
  392.  381   3                  wTempInt.c[1] = gDescriptorMap.bCfg1[cfg_wTotalLength_lsb];
  393.  382   3                  wTempInt.c[0] = gDescriptorMap.bCfg1[cfg_wTotalLength_msb];
  394.  383   3                  uNumBytes = wTempInt.i;
  395.  384   3      
  396.  385   3                  // Prep to transmit the requested length
  397.  386   3                  if (uNumBytes > gEp0Command.wLength.i)
  398.  387   3                  {
  399.  388   4                     uNumBytes = gEp0Command.wLength.i;
  400.  389   4                  }
  401.  390   3                  // Point data pointer to requested descriptor
  402.  391   3                  gEp0Status.pData = &gDescriptorMap.bCfg1;
  403.  392   3                  bEpState = EP_TX;
  404.  393   3               }
  405.  394   2               break;
  406.  395   2         }
  407.  396   1         gEp0Status.uNumBytes = uNumBytes;
  408.  397   1         gEp0Status.bEpState = bEpState;
  409.  398   1      }
  410.  399          
  411.  400          //-----------------------------------------------------------------------------
  412.  401          // GetConfigurationRequest
  413.  402          //-----------------------------------------------------------------------------
  414.  403          //
  415.  404          // Return Value : None
  416.  405          // Parameters   : None
  417.  406          //
  418.  407          //-----------------------------------------------------------------------------
  419.  408          void GetConfigurationRequest ()
  420.  409          {
  421.  410   1         // Length field must be 1; Index field must be 0;
  422.  411   1         // Value field must be 0
  423.  412   1         if ((gEp0Command.wLength.i != 1) || (gEp0Command.wIndex.i) ||
  424.  413   1         (gEp0Command.wValue.i) || (gDeviceStatus.bDevState == DEV_DEFAULT))
  425.  414   1         {
  426.  415   2            bEpState = EP_ERROR;
  427.  416   2         }
  428.  417   1      
  429.  418   1         else if (gDeviceStatus.bDevState == DEV_ADDRESS)
  430.  419   1         {
  431.  420   2            // Prepare data_out for transmission
  432.  421   2            gEp0Status.wData.i = 0;
  433.  422   2            // Point ep0 data pointer to transmit data_out
  434.  423   2            gEp0Status.pData = (BYTE *)&gEp0Status.wData.i;
  435.  424   2            // ep0 state assignment
  436.  425   2            bEpState = EP_TX;
  437.  426   2         }
  438.  427   1      
  439. C51 COMPILER V7.02b   USB_STANDARD_REQUESTS                                                11/30/2007 14:07:13 PAGE 8   
  440.  428   1         else
  441.  429   1         {
  442.  430   2            // Index to desired field
  443.  431   2            gEp0Status.pData = (void *)&gDescriptorMap.bCfg1[cfg_bConfigurationValue];
  444.  432   2      
  445.  433   2            // ep0 state assignment
  446.  434   2            bEpState = EP_TX;
  447.  435   2         }
  448.  436   1         gEp0Status.uNumBytes = 1;
  449.  437   1         gEp0Status.bEpState = bEpState;
  450.  438   1      }
  451.  439          
  452.  440          //-----------------------------------------------------------------------------
  453.  441          // GetInterfaceRequest
  454.  442          //-----------------------------------------------------------------------------
  455.  443          //
  456.  444          // Return Value : None
  457.  445          // Parameters   : None
  458.  446          //
  459.  447          //-----------------------------------------------------------------------------
  460.  448          void GetInterfaceRequest ()
  461.  449          {
  462.  450   1         // Value field must be 0; Length field must be 1
  463.  451   1         if ((gEp0Command.wValue.i) || (gEp0Command.wLength.i != 1) ||
  464.  452   1         (gDeviceStatus.bDevState != DEV_CONFIG))
  465.  453   1         {
  466.  454   2            bEpState = EP_ERROR;
  467.  455   2         }
  468.  456   1      
  469.  457   1         else
  470.  458   1         {
  471.  459   2            // Make sure requested interface exists
  472.  460   2            if (gEp0Command.wIndex.i > gDeviceStatus.bNumInterf - 1)
  473.  461   2               bEpState = EP_ERROR;
  474.  462   2            else
  475.  463   2            {
  476.  464   3               // Get current interface setting
  477.  465   3               gEp0Status.pData = (void *)&gDeviceStatus.IfStatus->bCurrentAlt;
  478.  466   3      
  479.  467   3               // Length must be 1
  480.  468   3               gEp0Status.uNumBytes = 1;
  481.  469   3               bEpState = EP_TX;
  482.  470   3            }
  483.  471   2         }
  484.  472   1         gEp0Status.bEpState = bEpState;
  485.  473   1      }
  486.  474          
  487.  475          //-----------------------------------------------------------------------------
  488.  476          // End Of File
  489.  477          //-----------------------------------------------------------------------------
  490. MODULE INFORMATION:   STATIC OVERLAYABLE
  491.    CODE SIZE        =    608    ----
  492.    CONSTANT SIZE    =   ----    ----
  493.    XDATA SIZE       =   ----    ----
  494.    PDATA SIZE       =   ----    ----
  495.    DATA SIZE        =      6       2
  496.    IDATA SIZE       =   ----    ----
  497.    BIT SIZE         =   ----    ----
  498. END OF MODULE INFORMATION.
  499. C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)