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

C/C++

  1. C51 COMPILER V8.02   FAT                                                                   04/29/2007 12:48:52 PAGE 1   
  2. C51 COMPILER V8.02, COMPILATION OF MODULE FAT
  3. OBJECT MODULE PLACED IN Fat.OBJ
  4. COMPILER INVOKED BY: D:KeilC51BINC51.EXE Fat.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          unsigned char xdata FATBUF[512];
  16.   11          ////////////////////////////////////////
  17.   12          
  18.   13          unsigned long FirstSectorofCluster(unsigned int 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 int ThisFatSecNum(unsigned int clusterNum)
  28.   23          {
  29.   24   1      
  30.   25   1         unsigned int temp;
  31.   26   1         temp=clusterNum/(DeviceInfo.BPB_BytesPerSec/2);
  32.   27   1         temp=temp+DeviceInfo.FatStartSector;
  33.   28   1         return temp;
  34.   29   1      
  35.   30   1      }
  36.   31          
  37.   32          unsigned int ThisFatEntOffset(unsigned int clusterNum)
  38.   33          {    
  39.   34   1              return (clusterNum%(DeviceInfo.BPB_BytesPerSec/2))*2;
  40.   35   1      }
  41.   36          
  42.   37          unsigned int GetNextClusterNum(unsigned int clusterNum)
  43.   38          {
  44.   39   1              unsigned int FatSecNum,FatEntOffset;
  45.   40   1              
  46.   41   1              FatSecNum=ThisFatSecNum(clusterNum);
  47.   42   1              FatEntOffset=ThisFatEntOffset(clusterNum);
  48.   43   1              if(ThisFile.FatSectorPointer!=FatSecNum)
  49.   44   1              {       
  50.   45   2                      
  51.   46   2                      if(!SdReadSector(FatSecNum,1,FATBUF))
  52.   47   2                              return 0xFFFF;
  53.   48   2                      ThisFile.FatSectorPointer=FatSecNum;
  54.   49   2              }
  55.   50   1              
  56.   51   1              ///////////////////////////////////////////////////
  57.   52   1              clusterNum=FATBUF[FatEntOffset+1];
  58.   53   1              clusterNum=clusterNum<<8;
  59.   54   1              clusterNum+=FATBUF[FatEntOffset];       
  60.   55   1              return clusterNum;
  61. C51 COMPILER V8.02   FAT                                                                   04/29/2007 12:48:52 PAGE 2   
  62.   56   1      }
  63.   57          
  64.   58          unsigned char GoToPointer(unsigned long pointer)
  65.   59          {
  66.   60   1              
  67.   61   1              unsigned int clusterSize;
  68.   62   1              
  69.   63   1              clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
  70.   64   1              ThisFile.ClusterPointer=ThisFile.StartCluster;
  71.   65   1              while(pointer>clusterSize)
  72.   66   1              {
  73.   67   2                      pointer-=clusterSize;   
  74.   68   2                      ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
  75.   69   2                      if(ThisFile.ClusterPointer==0xffff)
  76.   70   2                      {
  77.   71   3                      return FALSE;
  78.   72   3                      }
  79.   73   2              }
  80.   74   1              ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
  81.   75   1              ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
  82.   76   1              ThisFile.OffsetofSector=pointer%DeviceInfo.BPB_BytesPerSec;
  83.   77   1              ThisFile.FatSectorPointer=0;
  84.   78   1              return TRUE;
  85.   79   1              
  86.   80   1      }
  87.   81          
  88.   82          unsigned char DeleteClusterLink(unsigned int clusterNum)
  89.   83          {
  90.   84   1              unsigned int FatSecNum,FatEntOffset;
  91.   85   1              unsigned char i;
  92.   86   1              while((clusterNum>1)&&(clusterNum<0xfff0))
  93.   87   1              {
  94.   88   2              FatSecNum=ThisFatSecNum(clusterNum);
  95.   89   2              FatEntOffset=ThisFatEntOffset(clusterNum);
  96.   90   2              if(SdReadSector(FatSecNum,1,DBUF))
  97.   91   2                      {
  98.   92   3                       if(clusterNum<DeviceInfo.LastFreeCluster) DeviceInfo.LastFreeCluster=clusterNum; 
  99.   93   3                       clusterNum=DBUF[FatEntOffset+1];
  100.   94   3                       clusterNum=clusterNum<<8;
  101.   95   3                       clusterNum+=DBUF[FatEntOffset];                 
  102.   96   3                      }
  103.   97   2              else
  104.   98   2                      return FALSE;
  105.   99   2              DBUF[FatEntOffset]=0x00;
  106.  100   2              DBUF[FatEntOffset+1]=0x00;      
  107.  101   2              for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
  108.  102   2                      {
  109.  103   3                      DelayMs(5);
  110.  104   3                      if(!SdWriteSector(FatSecNum+i*DeviceInfo.BPB_FATSz16,1,DBUF))
  111.  105   3                              return FALSE;
  112.  106   3                      }       
  113.  107   2              }
  114.  108   1              return TRUE;
  115.  109   1      }
  116.  110          
  117.  111          unsigned int GetFreeCusterNum(void)
  118.  112          {
  119.  113   1              unsigned int clusterNum,i;
  120.  114   1              unsigned long sectorNum;
  121.  115   1              unsigned char j;
  122.  116   1              clusterNum=0;
  123.  117   1      //      sectorNum=DeviceInfo.FatStartSector;
  124. C51 COMPILER V8.02   FAT                                                                   04/29/2007 12:48:52 PAGE 3   
  125.  118   1      
  126.  119   1          sectorNum=ThisFatSecNum(DeviceInfo.LastFreeCluster);
  127.  120   1          clusterNum=(sectorNum-DeviceInfo.FatStartSector)*(DeviceInfo.BPB_BytesPerSec/2);
  128.  121   1      
  129.  122   1              while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
  130.  123   1              {
  131.  124   2                      
  132.  125   2                      if(!SdReadSector(sectorNum,1,DBUF))
  133.  126   2                              return 0x0;
  134.  127   2                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
  135.  128   2                              {
  136.  129   3                               if((DBUF[i]==0)&&(DBUF[i+1]==0))
  137.  130   3                                      {       
  138.  131   4                                      DBUF[i]=0xff;
  139.  132   4                                      DBUF[i+1]=0xff;
  140.  133   4                                      for(j=0;j<DeviceInfo.BPB_NumFATs;j++)
  141.  134   4                                              {
  142.  135   5                                              DelayMs(5);
  143.  136   5                                              if(!SdWriteSector(sectorNum+j*DeviceInfo.BPB_FATSz16,1,DBUF))
  144.  137   5                                                      return FALSE;
  145.  138   5                                              }
  146.  139   4                      clusterNum=clusterNum+i/2;
  147.  140   4                              if((clusterNum-2)<DeviceInfo.TotCluster) 
  148.  141   4                                        {
  149.  142   5                                         if(clusterNum>DeviceInfo.LastFreeCluster) DeviceInfo.LastFreeCluster=clusterNum;
  150.  143   5                                         return clusterNum;
  151.  144   5                                        }
  152.  145   4                                      else return     FALSE; 
  153.  146   4                                      }
  154.  147   3                               
  155.  148   3                              }       
  156.  149   2                      clusterNum+=DeviceInfo.BPB_BytesPerSec/2;               
  157.  150   2                      sectorNum++;
  158.  151   2                      DelayMs(1);
  159.  152   2              }
  160.  153   1              
  161.  154   1              return 0x0;
  162.  155   1      }
  163.  156          
  164.  157          unsigned int CreateClusterLink(unsigned int currentCluster)
  165.  158          {
  166.  159   1              unsigned int newCluster;
  167.  160   1              unsigned int FatSecNum,FatEntOffset;
  168.  161   1              unsigned char i;
  169.  162   1      
  170.  163   1              newCluster=GetFreeCusterNum();
  171.  164   1      
  172.  165   1              if(newCluster==0)
  173.  166   1                      return 0x00;
  174.  167   1                              
  175.  168   1              FatSecNum=ThisFatSecNum(currentCluster);
  176.  169   1              FatEntOffset=ThisFatEntOffset(currentCluster);
  177.  170   1              if(SdReadSector(FatSecNum,1,DBUF))
  178.  171   1                      {
  179.  172   2                      DBUF[FatEntOffset]=newCluster;
  180.  173   2                      DBUF[FatEntOffset+1]=newCluster>>8;
  181.  174   2                      for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
  182.  175   2                              {
  183.  176   3                              DelayMs(5);
  184.  177   3                              if(!SdWriteSector(FatSecNum+i*DeviceInfo.BPB_FATSz16,1,DBUF))
  185.  178   3                                      return FALSE;
  186.  179   3                              }               
  187. C51 COMPILER V8.02   FAT                                                                   04/29/2007 12:48:52 PAGE 4   
  188.  180   2                      }
  189.  181   1              else
  190.  182   1                      return 0x00;
  191.  183   1              
  192.  184   1              return newCluster;
  193.  185   1      }
  194. MODULE INFORMATION:   STATIC OVERLAYABLE
  195.    CODE SIZE        =   1499    ----
  196.    CONSTANT SIZE    =   ----    ----
  197.    XDATA SIZE       =    512    ----
  198.    PDATA SIZE       =   ----    ----
  199.    DATA SIZE        =   ----      41
  200.    IDATA SIZE       =   ----    ----
  201.    BIT SIZE         =   ----    ----
  202. END OF MODULE INFORMATION.
  203. C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)