fat.lst

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

LST
1,534
字号
 163      =1  #define SPI_CPOL   0x2
 164      =1  #define SPI_CPHA   0x4
 165      =1  #define SPI_MST    0x8
 166      =1  #define SPI_TIE    0x10
 167      =1  #define SPI_RIE    0x20
 168      =1  #define SPI_EN     0x40
 169      =1  #define SPI_SSOEN  0x80
 170      =1  // SPI control 1
 171      =1  #define SPI_3M     0x0
 172      =1  #define SPI_1P5M   0x1
 173      =1  #define SPI_750K   0x2
 174      =1  #define SPI_375K   0x3
 175      =1  #define SPI_188K   0x4
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 6   

 176      =1  #define SPI_94K    0x5
 177      =1  #define SPI_47K    0x6
 178      =1  #define SPI_23K    0x7 
 179      =1  // SPI status
 180      =1  #define SPI_SPTEF  0x1
 181      =1  #define SPI_RRDY   0x2
 182      =1  #define SPI_WERR   0x4
 183      =1  #define SPI_RERR   0x8
 184      =1  // SD control
 185      =1  #define SD_64B     0x0
 186      =1  #define SD_128B    0x1
 187      =1  #define SD_256B    0x2
 188      =1  #define SD_512B    0x3
 189      =1  #define SD_WR      0x40
 190      =1  #define SD_EN      0x80
 191      =1  // SD status 0
 192      =1  
 193      =1  // SD status 1
 194      =1  #define SD_SDERR   0x1
 195      =1  #define SD_SDINT   0x2
 196      =1  #define SD_CMDEND  0x4
 197      =1  
 198      =1  #define SD_DETECT  0x4
 199      =1  
 200      =1  // Buffer Control
 201      =1  #ifdef OLD_CHIP
 202      =1          #define MCU2MP3    0x03
 203      =1          #define USB2MP3    0x13
 204      =1  #else
           =1         #define MCU2MP3    0x02
           =1     #define USB2MP3    0x12
           =1 #endif
 208      =1  #define USB2MCU    0x10
 209      =1  #define MCU2USB    0x01
 210      =1  #define USBFLSH    0x14
 211      =1  
 212      =1  // function prototypes
 213      =1  unsigned short WordSwap(unsigned short input);
 214      =1  void DelayMs(unsigned int nFactor);
 215      =1  void DelayUs(unsigned char nFactor);
 216      =1  unsigned long SwapINT32(unsigned long dData);
 217      =1  unsigned char SendUart(unsigned char *pUsrBuf, unsigned int num);
 218      =1  
 219      =1  
 220      =1  
   2          #include "fat.h"
   1      =1  unsigned long FirstSectorofCluster(unsigned int n);
   2      =1  unsigned int ThisFatEntOffset(unsigned int clusterNum);
   3      =1  unsigned int GetNextClusterNum(unsigned int clusterNum);
   4      =1  unsigned int ThisFatSecNum(unsigned int clusterNum);
   3          #include "tpbulk.h"
   1      =1  #include "rbccmd.h"
   1      =2  /*
   2      =2  // RBC commands
   3      =2  */
   4      =2  #define RBC_CMD_FORMAT                                          0x04
   5      =2  #define RBC_CMD_READ10                                          0x28
   6      =2  #define RBC_CMD_READCAPACITY                            0x25
   7      =2  #define RBC_CMD_STARTSTOPUNIT                           0x1B
   8      =2  #define RBC_CMD_SYNCCACHE                                       0x35
   9      =2  #define RBC_CMD_VERIFY10                                        0x2F
  10      =2  #define RBC_CMD_WRITE10                                         0x2A
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 7   

  11      =2  
  12      =2  /*
  13      =2  // SPC-2 commands
  14      =2  */
  15      =2  #define SPC_CMD_INQUIRY                                         0x12
  16      =2  #define SPC_CMD_MODESELECT6                                     0x15
  17      =2  #define SPC_CMD_MODESENSE6                                      0x1A
  18      =2  #define SPC_CMD_PERSISTANTRESERVIN                      0x5E
  19      =2  #define SPC_CMD_PERSISTANTRESERVOUT                     0x5F
  20      =2  #define SPC_CMD_PRVENTALLOWMEDIUMREMOVAL        0x1E
  21      =2  #define SPC_CMD_RELEASE6                                        0x17
  22      =2  #define SPC_CMD_REQUESTSENSE                            0x03
  23      =2  #define SPC_CMD_RESERVE6                                        0x16
  24      =2  #define SPC_CMD_TESTUNITREADY                           0x00
  25      =2  #define SPC_CMD_WRITEBUFFER                                     0x3B
  26      =2  #define SPC_CMD_READLONG                                        0x23
  27      =2  
  28      =2  
  29      =2  /*
  30      =2  // ATAPI Command Descriptor Block - 13 Bytes
  31      =2  */
  32      =2  
  33      =2  typedef struct _READ_10 {
  34      =2                  UINT8 OperationCode;
  35      =2                  UINT8 Reserved1;
  36      =2                  UINT8 LBA_3;
  37      =2                  UINT8 LBA_2;
  38      =2          UINT8 LBA_1;
  39      =2                  UINT8 LBA_0;
  40      =2                  UINT8 Reserved2;
  41      =2                  UINT8 XferLen_1;
  42      =2                  UINT8 XferLen_0;
  43      =2                  UINT8 Reserved3[3];
  44      =2  } READ_10, *pREAD_10;
  45      =2  
  46      =2  typedef struct _WRITE_10 {
  47      =2                  UINT8 OperationCode;
  48      =2                  UINT8 Reserved1;
  49      =2                  UINT8 LBA_3;
  50      =2                  UINT8 LBA_2;
  51      =2          UINT8 LBA_1;
  52      =2                  UINT8 LBA_0;
  53      =2                  UINT8 Reserved2;
  54      =2                  UINT8 XferLen_1;
  55      =2                  UINT8 XferLen_0;
  56      =2                  UINT8 Reserved3[3];
  57      =2  } WRITE_10, *pWRITE_10;
  58      =2  
  59      =2  typedef struct _MODE_SENSE_10 {
  60      =2                  UINT8 OperationCode;
  61      =2                  UINT8 Reserved1;
  62      =2                  UINT8 PageCode : 6;
  63      =2                  UINT8 Pc : 2;
  64      =2                  UINT8 Reserved2[4];
  65      =2                  UINT8 ParameterListLengthMsb;
  66      =2                  UINT8 ParameterListLengthLsb;
  67      =2                  UINT8 Reserved3[3];
  68      =2  } MODE_SENSE_10, *pMODE_SENSE_10;
  69      =2  
  70      =2  typedef struct _MODE_SELECT_10 {
  71      =2                  UINT8 OperationCode;
  72      =2                  UINT8 Reserved1 : 4;
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 8   

  73      =2                  UINT8 PFBit : 1;
  74      =2                  UINT8 Reserved2 : 3;
  75      =2                  UINT8 Reserved3[5];
  76      =2                  UINT8 ParameterListLengthMsb;
  77      =2                  UINT8 ParameterListLengthLsb;
  78      =2                  UINT8 Reserved4[3];
  79      =2  } MODE_SELECT_10, *pMODE_SELECT_10;
  80      =2  /*
  81      =2  ////////////////////////////////////////////////////////////////////////////////////
  82      =2  // Command Descriptor Block - max = 16 Bytes 
  83      =2  //      _RBC : Reduced Block Command               
  84      =2  //      _SPC : SPC-2 SCSI primary Command - 2
  85      =2  ////////////////////////////////////////////////////////////////////////////////////
  86      =2  */
  87      =2  
  88      =2  /*
  89      =2  // Generic
  90      =2  */
  91      =2  typedef struct _GENERIC_CDB {
  92      =2          UINT8 OperationCode;
  93      =2      UINT8 Reserved[15];
  94      =2  } GENERIC_CDB,*pGENERIC_CDB;
  95      =2  
  96      =2  typedef struct _GENERIC_RBC {
  97      =2          UINT8 OperationCode;
  98      =2      UINT8 Reserved[8];
  99      =2          UINT8 Control;
 100      =2  } GENERIC_RBC,*pGENERIC_RBC;
 101      =2  
 102      =2  /*
 103      =2  // format unit
 104      =2  */
 105      =2  typedef struct _FORMAT_RBC {
 106      =2          UINT8 OperationCode;    // 04H
 107      =2          UINT8 VendorSpecific;
 108      =2          UINT8 Increment : 1;
 109      =2          UINT8 PercentorTime : 1;
 110      =2          UINT8 Progress : 1;
 111      =2      UINT8 Immediate : 1;
 112      =2          UINT8 VendorSpecific1 : 4;
 113      =2          UINT8 Reserved2[2];
 114      =2          UINT8 Control;
 115      =2  } FORMAT_RBC, *pFORMAT_RBC;
 116      =2  
 117      =2  
 118      =2  /*
 119      =2  // Read Command
 120      =2  */
 121      =2  typedef struct _READ_RBC {
 122      =2          UINT8 OperationCode;    // 10H
 123      =2          UINT8 VendorSpecific;
 124      =2          union{
 125      =2                  struct
 126      =2                  {
 127      =2                  UINT8 LBA_3;
 128      =2                  UINT8 LBA_2;
 129      =2                  UINT8 LBA_1;
 130      =2                  UINT8 LBA_0;
 131      =2                  } LBA_W8 ;
 132      =2  
 133      =2                  UINT32 LBA_W32;
 134      =2                }LBA;
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 9   

 135      =2          UINT8 Reserved;
 136      =2          //UINT8 XferLength_1;
 137      =2          //UINT8 XferLength_0;
 138      =2          UINT16 XferLength;
 139      =2          UINT8 Control;
 140      =2          //UINT8 Reserved1[3];
 141      =2  } READ_RBC, *pREAD_RBC;
 142      =2  
 143      =2  
 144      =2  /*
 145      =2  // Read Capacity Data - returned in Big Endian format
 146      =2  */
 147      =2  typedef struct _READ_CAPACITY_DATA {
 148      =2  
 149      =2      UINT8 LBA_3;
 150      =2      UINT8 LBA_2;
 151      =2      UINT8 LBA_1;
 152      =2      UINT8 LBA_0;
 153      =2  
 154      =2      UINT8 BlockLen_3;
 155      =2      UINT8 BlockLen_2;
 156      =2      UINT8 BlockLen_1;
 157      =2      UINT8 BlockLen_0;
 158      =2  } READ_CAPACITY_DATA, *pREAD_CAPACITY_DATA;
 159      =2  //////////////////////////////////////////////////
 160      =2  typedef struct _READ_LONG_CMD{
 161      =2      UINT8 OperationCode;
 162      =2      UINT8 LogicalUnitNum        :3;
 163      =2      UINT8 RES_1         :5;
 164      =2      UINT8 RES_2;
 165      =2      UINT8 RES_3;
 166      =2      UINT8 RES_4;
 167      =2      UINT8 RES_5;
 168      =2      UINT8 RES_6;
 169      =2      UINT16 AllocationLen;
 170      =2      UINT8 RES_7;
 171      =2      UINT8 RES_8;
 172      =2      UINT8 RES_9;
 173      =2  }READ_LONG_CMD, *pREAD_LONG_CMD;
 174      =2  
 175      =2  typedef struct _READ_LONG {
 176      =2  
 177      =2      UINT8 RES_1;
 178      =2      UINT8 RES_2;
 179      =2      UINT8 RES_3;
 180      =2      UINT8 CAP_LIST_LEN;
 181      =2      
 182      =2      UINT8 LBA_3;
 183      =2      UINT8 LBA_2;
 184      =2      UINT8 LBA_1;
 185      =2      UINT8 LBA_0;
 186      =2  
 187      =2      UINT8 Descripter;
 188      =2      UINT8 BlockLen_2;
 189      =2      UINT8 BlockLen_1;
 190      =2      UINT8 BlockLen_0;
 191      =2  } READ_LONG, *pREAD_LONG;
 192      =2  /*
 193      =2  // Read Capacity command
 194      =2  */
 195      =2  typedef struct _READ_CAPACITY_RBC {
 196      =2          UINT8                OperationCode;     /* 10H */
C51 COMPILER V8.02   FAT                                                                   09/19/2006 15:01:23 PAGE 10  

 197      =2          union  {
 198      =2                          FLEXI_INT32                     l0[2];
 199      =2                  UINT32               l[2];
 200      =2                  READ_CAPACITY_DATA  CapData;       /* Reserved area, here is used as temp*/
 201      =2                  } tmpVar;
 202      =2  
 203      =2          UINT8                Control;
 204      =2  } READ_CAPACITY_RBC, *pREAD_CAPACITY_RBC;
 205      =2  
 206      =2  typedef struct _READ_CAPACITY_RSP {
 207      =2          UINT32 LastLBA;
 208      =2          UINT32 BlockSize;
 209      =2  
 210      =2  } READ_CAPACITY_RSP, *pREAD_CAPACITY_RSP;
 211      =2  /*
 212      =2  // START_STOP_UNIT
 213      =2  */
 214      =2  typedef struct _START_STOP_RBC {
 215      =2      UINT8 OperationCode;    /*1BH*/
 216      =2      UINT8 Immediate: 1;
 217      =2      UINT8 Reserved1 : 7;
 218      =2      UINT8 Reserved2[2];
 219      =2          union _START_STOP_FLAGS
 220      =2      {
 221      =2          struct
 222      =2          {
 223      =2              UINT8 Start          : 1;
 224      =2              UINT8 LoadEject      : 1;
 225      =2              UINT8 Reserved3      : 2;
 226      =2              UINT8 PowerConditions: 4;
 227      =2          } bits0;
 228      =2  
 229      =2          struct
 230      =2          {
 231      =2              UINT8 MediumState    : 2;
 232      =2              UINT8 Reserved3      : 2;

⌨️ 快捷键说明

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