fat.lst

来自「51环境下的FAT及FAT32文件系统源码」· LST 代码 · 共 1,534 行 · 第 1/5 页

LST
1,534 行
字号
  45      =1      unsigned char *buffer;      
  46      =1      SetupPKG setup;
  47      =1      unsigned char epbulkin;
  48      =1      unsigned char epbulkout;
  49      =1   
  50      =1  } XXGPKG, *pXXGPKG;
  51      =1  
  52      =1  // Standard Device Descriptor
  53      =1  typedef struct             //14 fields and 18 bytes;
  54      =1  {   BYTE bLength;                  //Descriptor size in bytes  --descriptor
  55      =1      BYTE bDescriptorType;  //The constant DEVICE(01h)  --descriptor
  56      =1      WORD bcdUSB;                   //The USB specification number that the Device and the descriptor comply with;
  57      =1      BYTE bDeviceClass;     //device class
  58      =1      BYTE bDeviceSubClass;
  59      =1      BYTE bDeviceProtocol;
  60      =1      BYTE bMaxPacketSize0;  //maximum packet size for endpoint 0;
  61      =1      WORD idVendor;                 
  62      =1      WORD idProduct;
  63      =1      WORD bcdDevice;                //the device's release number;
  64      =1      BYTE iManufacturer;    //an index that points to a string describing the manufacture;
  65      =1      BYTE iProduct;                 //an index that points to a string describing the product;
  66      =1      BYTE iSerialNumber;     
  67      =1      BYTE bNumConfigurations;   //the number of configuration the device supports;
  68      =1  } sDevDesc, *pDevDesc;
  69      =1  // Standard Configuration Descriptor describes the device's feature and abilities;
  70      =1  typedef struct
  71      =1  {       
  72      =1      BYTE bLength;                // Size of descriptor in Byte
  73      =1          BYTE bType;                                      // the constant Configuration(02h)
  74      =1          WORD wLength;                // the number of data bytes that the device returns,
  75      =1          BYTE bNumIntf;                           // Number of interfaces the configuration supports;
  76      =1          BYTE bCV;                        // bConfigurationValue,identifies the configuration for Get_Configuration and Se
             -t_Configuration;
  77      =1          BYTE bIndex;                     // iConfiguration,index to a string that describes the configuration;
  78      =1          BYTE bAttr;                  // Self power/bus power and remote wakeup;
  79      =1          BYTE bMaxPower;                          // Power config
  80      =1  } sCfgDesc, *pCfgDesc;
  81      =1  
  82      =1  // Standard Interface Descriptor 9 bytes
  83      =1  typedef struct
  84      =1  {       BYTE bLength;       
  85      =1          BYTE bType;                  //the constant INTERFACE(04h);
  86      =1          BYTE iNum;                   //Number identifying this interface;
  87      =1          BYTE iAltString;         //Value used to select an alternate setting;
  88      =1          BYTE bEndPoints;         //Number of endpoints supported in addition to Endpoint0;
  89      =1          BYTE iClass;             //class code
  90      =1          BYTE iSub;                   //subclass code
  91      =1          BYTE iProto;             //protocol code
  92      =1          BYTE iIndex;             //index of string descriptor for interface;
  93      =1  } sIntfDesc, *pIntfDesc;
  94      =1  
  95      =1  // Standard EndPoint Descriptor 7 bytes
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 21  

  96      =1  typedef struct
  97      =1  {       BYTE bLength;
  98      =1          BYTE bType;                  //the constant endpoint(05h);
  99      =1          BYTE bEPAdd;             //includes the endpoint number(bits 0 through 3) and direction(bit 7);
 100      =1          BYTE bAttr;                  //bits 1 and 0 specify the type of transfer the endpoint supports.00=control,10=bulk...
             -;
 101      =1          WORD wPayLoad;       //maximum packet size supported; low-speed this must be 0x08
 102      =1          BYTE bInterval;      //for full-speed bulk and control transfers,the value is ignored.
 103      =1  } sEPDesc, *pEPDesc;
 104      =1  
 105      =1  /*-------------------------------------------------------------------------
 106      =1   * Standard Chapter 9 definition
 107      =1   *-------------------------------------------------------------------------
 108      =1   */
 109      =1  #define GET_STATUS      0x00                                                                                                                              
 110      =1  #define CLEAR_FEATURE   0x01
 111      =1  #define SET_FEATURE     0x03
 112      =1  #define SET_ADDRESS     0x05
 113      =1  #define GET_DESCRIPTOR  0x06
 114      =1  #define SET_DESCRIPTOR  0x07
 115      =1  #define GET_CONFIG      0x08
 116      =1  #define SET_CONFIG      0x09
 117      =1  #define GET_INTERFACE   0x0a
 118      =1  #define SET_INTERFACE   0x0b
 119      =1  #define SYNCH_FRAME     0x0c
 120      =1  
 121      =1  
 122      =1  #define DEVICE          0x01
 123      =1  #define CONFIGURATION   0x02
 124      =1  #define STRING          0x03
 125      =1  #define INTERFACE       0x04
 126      =1  #define ENDPOINT        0x05
 127      =1  
 128      =1  #define STDCLASS        0x00
 129      =1  /*-------------------------------------------------------------------------
 130      =1   * USB Host control command definitions
 131      =1   *-------------------------------------------------------------------------
 132      =1   */
 133      =1   //cmd                       
 134      =1  #define WRITE0      0x42
 135      =1  #define WRITE1      0xc2   
 136      =1  #define READ        0x04
 137      =1  
 138      =1  #define SETUP       0x41
 139      =1  #define SEND_ACK    0x20
 140      =1  //pid
 141      =1  #define PID_SETUP   0xD0 
 142      =1  #define PID_IN      0x90
 143      =1  #define PID_OUT     0x10
 144      =1  //flag
 145      =1  #define DEV_TGL     0x01
 146      =1  #define PKT_VLD     0x04
 147      =1  #define PKT_ERR         0x02
 148      =1  #define PKT_DATA    0x40
 149      =1  #define PKT_SENT    0x02
 150      =1  #define DEV_ACK     0x20
 151      =1  #define DEV_NAK     0x10
 152      =1  #define DEV_STALL   0x08
 153      =1  #define DEV_TO      0x80
 154      =1  
 155      =1  
 156      =1  // Alarms
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 22  

 157      =1  #define MP3_REQ         0x02
 158      =1  
 159      =1  void usbBufRead(unsigned char *s, unsigned char c);
 160      =1  void usbBufWrite(unsigned char *s, unsigned char c);
 161      =1  void usbReset(void);
 162      =1  unsigned char usbXfer(unsigned char endPoint);
 163      =1  unsigned char ep0Xfer(void);
 164      =1  unsigned char epBulkSend(unsigned char *pBuffer,unsigned int len);
 165      =1  unsigned char epBulkRcv(unsigned char *pBuffer,unsigned int len);
 166      =1  unsigned char setAddress(unsigned char addr);
 167      =1  unsigned char setConfiguration(void);
 168      =1  unsigned char setDesc(void);
 169      =1  unsigned char enumUsbDev(BYTE usbaddr);
 170      =1  void usbInit(void);
 171      =1  void checkKeyLED(void);
 172      =1  
   5          ////////////////////////////////////////
   6          extern SYS_INFO_BLOCK xdata DeviceInfo;
   7          extern FILE_INFO xdata ThisFile;
   8          unsigned int FatSectorPointer=-1;
   9          extern UINT8 xdata FATBUF[512];
  10          
  11          ////////////////////////////////////////
  12          unsigned int ThisFatSecNum(unsigned int clusterNum)
  13          {
  14   1         unsigned int temp;
  15   1         temp=clusterNum*2;
  16   1         temp=temp/DeviceInfo.BPB_BytesPerSec;
  17   1         temp=temp+DeviceInfo.FatStartSector;
  18   1         return temp;
  19   1      }
  20          
  21          unsigned long FirstSectorofCluster(unsigned int clusterNum)
  22          {
  23   1              unsigned long temp;
  24   1              temp=clusterNum-2;
  25   1              temp=temp*DeviceInfo.BPB_SecPerClus;
  26   1              temp=temp+DeviceInfo.FirstDataSector;
  27   1              return temp;
  28   1      }
  29          
  30          unsigned int ThisFatEntOffset(unsigned int clusterNum)
  31          {
  32   1              unsigned int temp1,temp2;
  33   1              temp1=2*clusterNum;
  34   1              temp2=temp1/DeviceInfo.BPB_BytesPerSec;
  35   1              temp1=temp1-temp2*DeviceInfo.BPB_BytesPerSec;
  36   1              return temp1;
  37   1      }
  38          
  39          unsigned int GetNextClusterNum(unsigned int clusterNum)
  40          {
  41   1              unsigned int xxgFatSecNum,xxgFatEntOffset;
  42   1              
  43   1              xxgFatSecNum=ThisFatSecNum(clusterNum);
  44   1              xxgFatEntOffset=ThisFatEntOffset(clusterNum);
  45   1      
  46   1              if(FatSectorPointer!=xxgFatSecNum)
  47   1              {       
  48   2                      
  49   2                      if(!RBC_ReadOneSec(xxgFatSecNum, FATBUF))
  50   2                              return 0xFFFF;
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 23  

  51   2                      FatSectorPointer=xxgFatSecNum;
  52   2              }
  53   1              
  54   1      
  55   1              ///////////////////////////////////////////////////
  56   1              clusterNum=FATBUF[xxgFatEntOffset+1];
  57   1              clusterNum=clusterNum<<8;
  58   1              clusterNum+=FATBUF[xxgFatEntOffset];    
  59   1              return clusterNum;
  60   1      }
  61          
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 24  

ASSEMBLY LISTING OF GENERATED OBJECT CODE


             ; FUNCTION _ThisFatSecNum (BEGIN)
                                           ; SOURCE LINE # 12
;---- Variable 'clusterNum' assigned to Register 'R6/R7' ----
                                           ; SOURCE LINE # 13
                                           ; SOURCE LINE # 15
0000 EF                MOV     A,R7
0001 25E0              ADD     A,ACC
0003 FF                MOV     R7,A
0004 EE                MOV     A,R6
0005 33                RLC     A
;---- Variable 'temp' assigned to Register 'R2/R3' ----
0006 CB                XCH     A,R3
0007 EF                MOV     A,R7
0008 CB                XCH     A,R3
0009 FA                MOV     R2,A
                                           ; SOURCE LINE # 16
000A 900000      E     MOV     DPTR,#DeviceInfo+08H
000D E0                MOVX    A,@DPTR
000E FC                MOV     R4,A
000F A3                INC     DPTR
0010 E0                MOVX    A,@DPTR
0011 FD                MOV     R5,A
0012 CE                XCH     A,R6
0013 EA                MOV     A,R2
0014 CE                XCH     A,R6
0015 120000      E     LCALL   ?C?UIDIV
0018 CA                XCH     A,R2
0019 EE                MOV     A,R6
001A CA                XCH     A,R2
001B CB                XCH     A,R3
001C EF                MOV     A,R7
001D CB                XCH     A,R3
                                           ; SOURCE LINE # 17
001E 900000      E     MOV     DPTR,#DeviceInfo+03CH
0021 A3                INC     DPTR
0022 A3                INC     DPTR
0023 E0                MOVX    A,@DPTR
0024 FE                MOV     R6,A
0025 A3                INC     DPTR
0026 E0                MOVX    A,@DPTR
0027 2B                ADD     A,R3
0028 FB                MOV     R3,A
0029 EE                MOV     A,R6
002A 3A                ADDC    A,R2
                                           ; SOURCE LINE # 18
002B FE                MOV     R6,A
002C CF                XCH     A,R7
002D EB                MOV     A,R3
002E CF                XCH     A,R7
                                           ; SOURCE LINE # 19
002F         ?C0001:
002F 22                RET     
             ; FUNCTION _ThisFatSecNum (END)

             ; FUNCTION _FirstSectorofCluster (BEGIN)
                                           ; SOURCE LINE # 21
;---- Variable 'clusterNum' assigned to Register 'R6/R7' ----
                                           ; SOURCE LINE # 22
                                           ; SOURCE LINE # 24
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 25  

0000 EF                MOV     A,R7
0001 24FE              ADD     A,#0FEH
0003 FF                MOV     R7,A
0004 EE                MOV     A,R6
0005 34FF              ADDC    A,#0FFH
0007 FE                MOV     R6,A
0008 E4                CLR     A
0009 FC                MOV     R4,A
000A FD                MOV     R5,A
000B 900000      R     MOV     DPTR,#temp
000E 120000      E     LCALL   ?C?LSTXDATA
                                           ; SOURCE LINE # 25
0011 900000      E     MOV     DPTR,#DeviceInfo+0AH
0014 E0                MOVX    A,@DPTR
0015 FF                MOV     R7,A
0016 E4                CLR     A
0017 FC                MOV     R4,A
0018 FD                MOV     R5,A
0019 FE                MOV     R6,A
001A 900000      R     MOV     DPTR,#temp
001D E0                MOVX    A,@DPTR
001E F8                MOV     R0,A
001F A3                INC     DPTR
0020 E0                MOVX    A,@DPTR
0021 F9                MOV     R1,A
0022 A3                INC     DPTR
0023 E0                MOVX    A,@DPTR
0024 FA                MOV     R2,A
0025 A3                INC     DPTR
0026 E0                MOVX    A,@DPTR
0027 FB                MOV     R3,A
0028 120000      E     LCALL   ?C?LMUL
002B 900000      R     MOV     DPTR,#temp
002E 120000      E     LCALL   ?C?LSTXDATA
                                           ; SOURCE LINE # 26
0031 900000      R     MOV     DPTR,#temp
0034 E0                MOVX    A,@DPTR
0035 FC                MOV     R4,A
0036 A3                INC     DPTR
0037 E0                MOVX    A,@DPTR
0038 FD                MOV     R5,A
0039 A3                INC     DPTR
003A E0                MOVX    A,@DPTR
003B FE                MOV     R6,A
003C A3                INC     DPTR
003D E0                MOVX    A,@DPTR
003E FF                MOV 

⌨️ 快捷键说明

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