Fat32.LST
上传用户:jcsy2001
上传日期:2013-11-29
资源大小:201k
文件大小:10k
开发平台:

C/C++

  1. C51 COMPILER V8.02   FAT32                                                                 04/29/2007 12:48:54 PAGE 1   
  2. C51 COMPILER V8.02, COMPILATION OF MODULE FAT32
  3. OBJECT MODULE PLACED IN Fat32.OBJ
  4. COMPILER INVOKED BY: D:KeilC51BINC51.EXE Fat32.c BROWSE DEBUG OBJECTEXTEND
  5. line level    source
  6.    1          #include "common.h"
  7.    2          #include "Fat.h"
  8.    3          #include "Fat32.h"
  9.    4          #include "DEVICE.H"
  10.    5          #include "HAL.H"
  11.    6          ////////////////////////////////////////
  12.    7          extern SYS_INFO_BLOCK xdata DeviceInfo;
  13.    8          extern FILE_INFO xdata ThisFile;
  14.    9          extern unsigned char xdata DBUF[BUFFER_LENGTH];
  15.   10          extern unsigned char xdata FATBUF[512];
  16.   11          ////////////////////////////////////////
  17.   12          
  18.   13          unsigned long FirstSectorofCluster32(unsigned long clusterNum)
  19.   14          {
  20.   15   1              unsigned long temp;
  21.   16   1              temp=clusterNum-2;
  22.   17   1              temp=temp*DeviceInfo.BPB_SecPerClus;
  23.   18   1              temp=temp+DeviceInfo.FirstDataSector;
  24.   19   1              return temp;
  25.   20   1      }
  26.   21          
  27.   22          unsigned long ThisFatSecNum32(unsigned long clusterNum)
  28.   23          {
  29.   24   1         unsigned long temp;
  30.   25   1         temp=clusterNum/(DeviceInfo.BPB_BytesPerSec/4);
  31.   26   1         temp=temp+DeviceInfo.FatStartSector;
  32.   27   1         return temp;
  33.   28   1      }
  34.   29          
  35.   30          unsigned long ThisFatEntOffset32(unsigned long clusterNum)
  36.   31          {
  37.   32   1              return (clusterNum%(DeviceInfo.BPB_BytesPerSec/4))*4;
  38.   33   1      }
  39.   34          
  40.   35          unsigned long GetNextClusterNum32(unsigned long clusterNum)
  41.   36          {
  42.   37   1              unsigned long FatSecNum,FatEntOffset;
  43.   38   1              
  44.   39   1              FatSecNum=ThisFatSecNum32(clusterNum);
  45.   40   1              FatEntOffset=ThisFatEntOffset32(clusterNum);
  46.   41   1              if(ThisFile.FatSectorPointer!=FatSecNum)
  47.   42   1              {       
  48.   43   2                      
  49.   44   2                      if(!SdReadSector(FatSecNum,1,FATBUF))
  50.   45   2                              return 0xFFFFFFFF;
  51.   46   2                      ThisFile.FatSectorPointer=FatSecNum;
  52.   47   2              }
  53.   48   1              
  54.   49   1              ///////////////////////////////////////////////////
  55.   50   1              clusterNum=LSwapINT32(FATBUF[FatEntOffset],FATBUF[FatEntOffset+1],FATBUF[FatEntOffset+2],FATBUF[FatEntOff
  56.              -set+3]);
  57.   51   1              return clusterNum;
  58.   52   1      }
  59.   53          
  60.   54          unsigned char GoToPointer32(unsigned long pointer)
  61. C51 COMPILER V8.02   FAT32                                                                 04/29/2007 12:48:54 PAGE 2   
  62.   55          {
  63.   56   1              
  64.   57   1              unsigned int clusterSize;
  65.   58   1              
  66.   59   1              clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
  67.   60   1              ThisFile.ClusterPointer=ThisFile.StartCluster;
  68.   61   1              while(pointer>clusterSize)
  69.   62   1              {
  70.   63   2                      pointer-=clusterSize;   
  71.   64   2                      ThisFile.ClusterPointer=GetNextClusterNum32(ThisFile.ClusterPointer);
  72.   65   2                      if(ThisFile.ClusterPointer==0xffffffff)
  73.   66   2                      {
  74.   67   3                      return FALSE;
  75.   68   3                      }
  76.   69   2              }
  77.   70   1              ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
  78.   71   1              ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
  79.   72   1              ThisFile.OffsetofSector=pointer%DeviceInfo.BPB_BytesPerSec;
  80.   73   1              ThisFile.FatSectorPointer=0;
  81.   74   1              return TRUE;
  82.   75   1              
  83.   76   1      }
  84.   77          
  85.   78          unsigned char DeleteClusterLink32(unsigned long clusterNum)
  86.   79          {
  87.   80   1              unsigned long FatSecNum,FatEntOffset;
  88.   81   1              unsigned char i;
  89.   82   1              while((clusterNum>1)&&(clusterNum<DeviceInfo.TotCluster))
  90.   83   1              {
  91.   84   2              FatSecNum=ThisFatSecNum32(clusterNum);
  92.   85   2              FatEntOffset=ThisFatEntOffset32(clusterNum);
  93.   86   2              if(SdReadSector(FatSecNum,1,DBUF))
  94.   87   2             {
  95.   88   3               if(clusterNum<DeviceInfo.LastFreeCluster) DeviceInfo.LastFreeCluster=clusterNum; 
  96.   89   3                       clusterNum=LSwapINT32(DBUF[FatEntOffset],DBUF[FatEntOffset+1],DBUF[FatEntOffset+2],DBUF[FatEntOffset+3]
  97.              -);
  98.   90   3             }
  99.   91   2              else
  100.   92   2                      return FALSE;
  101.   93   2              DBUF[FatEntOffset]=0x00;DBUF[FatEntOffset+1]=0x00;DBUF[FatEntOffset+2]=0x00;DBUF[FatEntOffset+3]=0x00;                  
  102.   94   2              for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
  103.   95   2                      {
  104.   96   3                      DelayMs(5);
  105.   97   3                      if(!SdWriteSector(FatSecNum+i*DeviceInfo.BPB_FATSz32,1,DBUF))
  106.   98   3                              return FALSE;
  107.   99   3                      }       
  108.  100   2              }
  109.  101   1              return TRUE;
  110.  102   1      }
  111.  103          
  112.  104          unsigned long GetFreeCusterNum32(void)
  113.  105          {
  114.  106   1              unsigned long xdata clusterNum,i;
  115.  107   1              unsigned long xdata sectorNum;
  116.  108   1              unsigned char xdata j;
  117.  109   1              sectorNum=ThisFatSecNum32(DeviceInfo.LastFreeCluster);
  118.  110   1          clusterNum=(sectorNum-DeviceInfo.FatStartSector)*(DeviceInfo.BPB_BytesPerSec/4);
  119.  111   1      
  120.  112   1              while(sectorNum<DeviceInfo.BPB_FATSz32+DeviceInfo.FatStartSector)
  121.  113   1              {               
  122.  114   2                      if(!SdReadSector(sectorNum,1,DBUF))
  123.  115   2                              return 0x0;
  124. C51 COMPILER V8.02   FAT32                                                                 04/29/2007 12:48:54 PAGE 3   
  125.  116   2                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+4)
  126.  117   2                              {
  127.  118   3                               if((DBUF[i]==0)&&(DBUF[i+1]==0)&&(DBUF[i+2]==0)&&(DBUF[i+3]==0))
  128.  119   3                                      {       
  129.  120   4                                      DBUF[i]=0xff;DBUF[i+1]=0xff;DBUF[i+2]=0xff;DBUF[i+3]=0xff;
  130.  121   4                                      for(j=0;j<DeviceInfo.BPB_NumFATs;j++)
  131.  122   4                                              {
  132.  123   5                                              DelayMs(5);
  133.  124   5                                              if(!SdWriteSector(sectorNum+j*DeviceInfo.BPB_FATSz32,1,DBUF))
  134.  125   5                                                      return FALSE;
  135.  126   5                                              }       
  136.  127   4                      clusterNum=clusterNum+i/4;
  137.  128   4                              if((clusterNum-2)<DeviceInfo.TotCluster) 
  138.  129   4                                        {
  139.  130   5                                         if(clusterNum>DeviceInfo.LastFreeCluster) DeviceInfo.LastFreeCluster=clusterNum;
  140.  131   5                                         return clusterNum;
  141.  132   5                                        }
  142.  133   4                                      else return     FALSE; 
  143.  134   4                                      }
  144.  135   3                              }       
  145.  136   2                      clusterNum+=DeviceInfo.BPB_BytesPerSec/4;               
  146.  137   2                      sectorNum++;
  147.  138   2                      DelayMs(1);
  148.  139   2              }       
  149.  140   1              return 0x0;
  150.  141   1      }
  151.  142          
  152.  143          unsigned long CreateClusterLink32(unsigned long currentCluster)
  153.  144          {
  154.  145   1              unsigned long xdata newCluster;
  155.  146   1              unsigned long xdata FatSecNum,FatEntOffset;
  156.  147   1              unsigned char xdata i;
  157.  148   1      
  158.  149   1              newCluster=GetFreeCusterNum32();
  159.  150   1                      
  160.  151   1              FatSecNum=ThisFatSecNum32(currentCluster);
  161.  152   1              FatEntOffset=ThisFatEntOffset32(currentCluster);
  162.  153   1              if(SdReadSector(FatSecNum,1,DBUF))
  163.  154   1                      {
  164.  155   2                      DBUF[FatEntOffset]=newCluster;
  165.  156   2                      DBUF[FatEntOffset+1]=newCluster>>8;
  166.  157   2                      DBUF[FatEntOffset+2]=newCluster>>16;
  167.  158   2                      DBUF[FatEntOffset+3]=newCluster>>24;
  168.  159   2                      for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
  169.  160   2                              {
  170.  161   3                              DelayMs(5);
  171.  162   3                              if(!SdWriteSector(FatSecNum+i*DeviceInfo.BPB_FATSz32,1,DBUF))
  172.  163   3                                      return FALSE;
  173.  164   3                              }               
  174.  165   2                      }
  175.  166   1              else
  176.  167   1                      return 0x00;
  177.  168   1              
  178.  169   1              return newCluster;
  179.  170   1      }
  180. MODULE INFORMATION:   STATIC OVERLAYABLE
  181.    CODE SIZE        =   2330    ----
  182.    CONSTANT SIZE    =   ----    ----
  183.    XDATA SIZE       =   ----      26
  184.    PDATA SIZE       =   ----    ----
  185. C51 COMPILER V8.02   FAT32                                                                 04/29/2007 12:48:54 PAGE 4   
  186.    DATA SIZE        =   ----      55
  187.    IDATA SIZE       =   ----    ----
  188.    BIT SIZE         =   ----    ----
  189. END OF MODULE INFORMATION.
  190. C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)