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

📄 f32x_usb_isr.lst

📁 C8051F320 SOURCE CODE 内容有: * USB Bulk Driver Example * USB Bulk Firmware Example * Host Ap
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE F32X_USB_ISR
OBJECT MODULE PLACED IN F32x_USB_ISR.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe F32x_USB_ISR.c DB OE

stmt level    source

   1          //-----------------------------------------------------------------------------
   2          // F32x_USB_USBISR.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2005 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          //
   9          // Source file for USB firmware. Includes the following routines:
  10          //
  11          // - USB_ISR(): Top-level USB interrupt handler. All USB handler
  12          //    routines are called from here.
  13          // - Endpoint0(): Endpoint0 interrupt handler.
  14          // - BulkOrInterruptOut(): Bulk or Interrupt OUT interrupt
  15          //    handler.
  16          // - BulkOrInterruptIn(): Places DataToWrite on the IN FIFO.
  17          // - USBReset (): USB Reset event handler.
  18          // - State_Machine(): USB state machine
  19          // - Receive_Setup(): Determine whether a read or write request
  20          //    been received and initializes variables accordingly.
  21          // - Receive_File(): Receives and saves data
  22          // - Page_Erase(): Erases a page of FLASH
  23          // - Page_Write(): Writes to a page of FLASH
  24          //
  25          //
  26          // How To Test:    See Readme.txt
  27          //
  28          //
  29          // FID:            32X000013
  30          // Target:         C8051F32x
  31          // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  32          //                 Silicon Laboratories IDE version 2.6
  33          // Command Line:   See Readme.txt
  34          // Project Name:   F32x_USB_Bulk
  35          //
  36          //
  37          // Release 1.3
  38          //    -All changes by GP
  39          //    -21 NOV 2005
  40          //    -Changed revision number to match project revision
  41          //     No content changes to this file
  42          //    -Modified file to fit new formatting guidelines
  43          //    -Changed file name from usb_isr.c
  44          //
  45          //
  46          // Release 1.2
  47          //    -Initial Revision (JS/CS/JM)
  48          //    -XX OCT 2003
  49          //
  50          
  51          //-----------------------------------------------------------------------------
  52          // Includes
  53          //-----------------------------------------------------------------------------
  54          
  55          #include "c8051F320.h"
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 2   

  56          #include "F32x_USB_Registers.h"
  57          #include "F32x_USB_Structs.h"
  58          #include "F32x_USB_Main.h"
  59          #include "F32x_USB_Descriptors.h"
  60          #include "F32x_USB_Config.h"
  61          #include "F32x_USB_Request.h"
  62          
  63          //-----------------------------------------------------------------------------
  64          // Extern Global Variables
  65          //-----------------------------------------------------------------------------
  66          
  67          extern DEVICE_STATUS  gDeviceStatus;
  68          extern EP0_COMMAND    gEp0Command;
  69          extern EP_STATUS      gEp0Status;
  70          extern EP_STATUS      gEp1InStatus;
  71          extern EP_STATUS      gEp2OutStatus;
  72          
  73          //-----------------------------------------------------------------------------
  74          // Global Constants
  75          //-----------------------------------------------------------------------------
  76          
  77          //  Constants Definitions
  78          #define NUM_STG_PAGES   20             // Total number of flash pages to
  79                                                 // be used for file storage
  80          #define MAX_BLOCK_SIZE  64             // Use the maximum block size of 64
  81          #define FLASH_PAGE_SIZE 512            // Size of each flash page
  82          #define BLOCKS_PR_PAGE  FLASH_PAGE_SIZE/MAX_BLOCK_SIZE
  83          #define MAX_NUM_BLOCKS  BLOCKS_PR_PAGE*NUM_STG_PAGES
  84          
  85          // UINT type definition
  86          #ifndef _UINT_DEF_
              #define _UINT_DEF_
              typedef unsigned int UINT;
              #endif                                 // _UINT_DEF_
  90          
  91          // BYTE type definition
  92          #ifndef _BYTE_DEF_
              #define _BYTE_DEF_
              typedef unsigned char BYTE;
              #endif                                 // _BYTE_DEF_ 
  96          
  97          //  Message Types
  98          #define READ_MSG    0x00    // Message types for communication with host
  99          #define WRITE_MSG   0x01
 100          #define SIZE_MSG    0x02
 101          
 102          //  Machine States
 103          #define ST_WAIT_DEV 0x01    // Wait for application to open a device instance
 104          #define ST_IDLE_DEV 0x02    // Device is open, wait for Setup Message from host
 105          #define ST_RX_SETUP 0x04    // Received Setup Message, decode and wait for data
 106          #define ST_RX_FILE  0x08    // Receive file data from host
 107          #define ST_TX_FILE  0x10    // Transmit file data to host
 108          #define ST_TX_ACK   0x20    // Transmit ACK 0xFF to host after every 8 packets
 109          #define ST_ERROR    0x80    // Error state
 110          
 111          
 112          typedef struct {            //  Structure definition of a block of data
 113              BYTE Piece[MAX_BLOCK_SIZE];
 114          }   BLOCK;
 115          
 116          typedef struct {            //  Structure definition of a flash memory page
 117              BYTE FlashPage[FLASH_PAGE_SIZE];
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 3   

 118          }   PAGE;
 119          
 120          xdata   BLOCK   TempStorage[BLOCKS_PR_PAGE];    // Temporary storage of between 
 121                                                          // flash writes
 122          
 123          code    BYTE    Pg0 _at_    0x1400;
 124          code    BYTE    Pg1 _at_    0x1600;
 125          code    BYTE    Pg2 _at_    0x1800;
 126          code    BYTE    Pg3 _at_    0x1A00;
 127          code    BYTE    Pg4 _at_    0x1C00;
 128          code    BYTE    Pg5 _at_    0x1E00;
 129          code    BYTE    Pg6 _at_    0x2000;
 130          code    BYTE    Pg7 _at_    0x2200;
 131          code    BYTE    Pg8 _at_    0x2400;
 132          code    BYTE    Pg9 _at_    0x2600;
 133          
 134          code    BYTE    Pg10    _at_    0x2800;
 135          code    BYTE    Pg11    _at_    0x2A00;
 136          code    BYTE    Pg12    _at_    0x2C00;
 137          code    BYTE    Pg13    _at_    0x2E00;
 138          code    BYTE    Pg14    _at_    0x3000;
 139          code    BYTE    Pg15    _at_    0x3200;
 140          code    BYTE    Pg16    _at_    0x3400;
 141          code    BYTE    Pg17    _at_    0x3600;
 142          code    BYTE    Pg18    _at_    0x3800;
 143          code    BYTE    Pg19    _at_    0x3A00;
 144          
 145          idata   BYTE*   PageIndices[20] =   {&Pg0,  &Pg1,   &Pg2,   &Pg3,   &Pg4,   
 146                                               &Pg5,  &Pg6,   &Pg7,   &Pg8,   &Pg9,
 147                                               &Pg10, &Pg11,  &Pg12,  &Pg13,  &Pg14,  
 148                                                                                   &Pg15,  &Pg16,  &Pg17,  &Pg18,  &Pg19};
 149          
 150          data    UINT    BytesToWrite;   //  Total number of bytes to write to the host
 151          data    UINT    BytesToRead;    //  Total number of bytes to read from host
 152          data    BYTE    Buffer[3];      //  Buffer for Setup messages
 153          data    BYTE    NumBlocks;      //  Number of Blocks for this transfer
 154          data    BYTE    M_State;        //  Current Machine State
 155          data    BYTE    BlockIndex;     //  Index of Current Block in Page
 156          data    BYTE    PageIndex;      //  Index of Current Page in File
 157          data    BYTE    BlocksRead;     //  Total Number of Blocks Read
 158          data    BYTE    BlocksWrote;    //  Total Number of Blocks Written
 159          data    BYTE*   ReadIndex;
 160          
 161          // code const   BYTE    Serial1[0x0A] = {0x0A,0x03,'A',0,'B',0,'C',0,'D',0};
 162          // Serial Number Defintion
 163          
 164          code    BYTE    LengthFile[3]   _at_    0x1200;
 165          //  {Length(Low Byte), Length(High Byte), Number of Blocks}
 166          
 167          sbit Led1 = P2^2; // LED='1' means ON
 168          sbit Led2 = P2^3; // These blink to indicate data transmission
 169          
 170          //-----------------------------------------------------------------------------
 171          // Function Prototypes
 172          //-----------------------------------------------------------------------------
 173          
 174          void    State_Machine(void);        
 175          void    Receive_Setup(void);        
 176          void    Receive_File(void);        
 177          
 178          //-----------------------------------------------------------------------------
 179          // Interrupt Service Routines
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 4   

 180          //-----------------------------------------------------------------------------
 181          
 182          //-----------------------------------------------------------------------------
 183          // USB_ISR
 184          //-----------------------------------------------------------------------------
 185          //
 186          //
 187          // This is the top level USB ISR. All endpoint interrupt/request
 188          // handlers are called from this function.
 189          //
 190          // Handler routines for any configured interrupts should be
 191          // added in the appropriate endpoint handler call slots.
 192          //
 193          //-----------------------------------------------------------------------------
 194          void USB_ISR () interrupt 8
 195          {
 196   1         BYTE bCommonInt, bInInt, bOutInt;
 197   1      
 198   1         // Read interrupt registers
 199   1         UREAD_BYTE(CMINT, bCommonInt);
 200   1         UREAD_BYTE(IN1INT, bInInt);
 201   1         UREAD_BYTE(OUT1INT, bOutInt);
 202   1      
 203   1         // Check for reset interrupt
 204   1         if (bCommonInt & rbRSTINT)
 205   1         {
 206   2            // Call reset handler
 207   2           USBReset();
 208   2            M_State = ST_WAIT_DEV;
 209   2         }
 210   1      
 211   1         // Check for Endpoint0 interrupt
 212   1         if (bInInt & rbEP0)
 213   1         {
 214   2            // Call Endpoint0 handler
 215   2            Endpoint0();
 216   2         }
 217   1      
 218   1         // Endpoint1 IN
 219   1         if (bInInt & rbIN1)
 220   1         {
 221   2               if (M_State == ST_RX_FILE)    // Ack Transmit complete, go to RX state
 222   2               {
 223   3                 M_State = (ST_TX_ACK);
 224   3               }
 225   2               if (M_State == ST_TX_FILE)    // File block transmit complete, 
 226   2                                                     // go to TX state
 227   2               {
 228   3                 // Go to Idle when done
 229   3                 M_State = (BlocksWrote == NumBlocks) ? ST_IDLE_DEV : ST_TX_FILE;      
 230   3               }
 231   2         }
 232   1      
 233   1         // Endpoint2 OUT
 234   1         if (bOutInt & rbOUT2)
 235   1         {
 236   2            // Call Endpoint2 OUT handler
 237   2            BulkOrInterruptOut(&gEp2OutStatus);
 238   2      
 239   2            M_State = (M_State == ST_IDLE_DEV) ? ST_RX_SETUP : ST_RX_FILE;
 240   2         }
 241   1      
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 5   

 242   1         State_Machine();
 243   1      }
 244          
 245          //-----------------------------------------------------------------------------
 246          // Support Subroutines
 247          //-----------------------------------------------------------------------------
 248          
 249          //-----------------------------------------------------------------------------
 250          // Endpoint0
 251          //-----------------------------------------------------------------------------
 252          //
 253          // Return Value : None
 254          // Parameters   : None
 255          //
 256          //-----------------------------------------------------------------------------
 257          void Endpoint0 ()
 258          {
 259   1         BYTE bTemp = 0;
 260   1         BYTE bCsr1, uTxBytes;
 261   1      
 262   1         UWRITE_BYTE(INDEX, 0);                 // Target ep0
 263   1         UREAD_BYTE(E0CSR, bCsr1);
 264   1      
 265   1         // Handle Setup End
 266   1         if (bCsr1 & rbSUEND)                   // Check for setup end
 267   1         {                                      // Indicate setup end serviced
 268   2            UWRITE_BYTE(E0CSR, rbSSUEND);
 269   2            gEp0Status.bEpState = EP_IDLE;      // ep0 state to idle
 270   2            M_State = ST_IDLE_DEV;              // ported from usb_file.c
 271   2         }
 272   1      
 273   1         // Handle sent stall
 274   1         if (bCsr1 & rbSTSTL)                   // If last state requested a stall
 275   1         {                                      // Clear Sent Stall bit (STSTL)
 276   2            UWRITE_BYTE(E0CSR, 0);
 277   2            gEp0Status.bEpState = EP_IDLE;      // ep0 state to idle
 278   2            M_State = ST_IDLE_DEV;              // ported from usb_file.c
 279   2         }
 280   1      

⌨️ 快捷键说明

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