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

📄 fat.lst

📁 采用811芯片实现单片机读写U盘的源代码
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.00  FAT                                                                    09/22/2005 17:15:32 PAGE 1   


C51 COMPILER V7.00, COMPILATION OF MODULE FAT
OBJECT MODULE PLACED IN .\out\Fat.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Fat.c LARGE BROWSE DEBUG OBJECTEXTEND OBJECT(.\out\Fat.obj)

stmt level    source

   1          #define FAT_FILE
   2          #include "include.h"
   3          
   4          //磁盘分区信息
   5          //MBR_INFO partition_table[MBR_INFO_MAX];
   6          //分区基本信息
   7          //SYS_INFO_BLOCK deviceinfo;
   8          //FAT表基本信息
   9          //FAT_INFO fat_info;
  10          //当前文件目录项
  11          //FILE_DIR_ITEM cur_file_item;
  12          //文件指针信息
  13          //FILE_INFO file_point;
  14          //当前目录信息
  15          //DIR_INFO cur_dir_info;
  16          //当前FAT表扇区
  17          //FAT_TABLE FATBUF;
  18          //空闲FAT表扇区
  19          //FAT_TABLE free_fat_item;
  20          
  21          //extern unsigned char xdata DBUF[BUFFER_LENGTH];
  22          
  23          //extern XXGFLAGS bdata bXXGFlags;
  24          
  25          /**********************************************
  26          得到指定簇的第一个扇区号
  27          ***********************************************/
  28          ulong FirstSectorofCluster(ulong clusterNum)
  29          {
  30   1              unsigned long temp;
  31   1              temp=clusterNum-2;
  32   1              temp=temp<<(BitNum(deviceinfo.SecPerClus));
  33   1              temp=temp+deviceinfo.DataFirstSec;
  34   1              return temp;
  35   1      }
  36          
  37          /***********************************************
  38          得到指定簇的FAT扇区号
  39          ***********************************************/
  40          ulong ThisFatSecNum(ulong clusterNum)
  41          {
  42   1         ulong temp;
  43   1         if(deviceinfo.type)
  44   1              temp=clusterNum<<2;   //*4
  45   1         else         
  46   1              temp=clusterNum<<1;   //*2
  47   1      //   temp=temp/deviceinfo.BytePerSec;
  48   1              temp=temp>>9;
  49   1         temp=temp+deviceinfo.FATFirstSec;
  50   1         return temp;
  51   1      }
  52          
  53          /************************************************
  54          得到指定簇的FAT扇区偏移量(FAT表的下标)
  55          ************************************************/
C51 COMPILER V7.00  FAT                                                                    09/22/2005 17:15:32 PAGE 2   

  56          uint ThisFatEntOffset(ulong clusterNum)
  57          {
  58   1              uint temp2;
  59   1      
  60   1              if(deviceinfo.type)
  61   1                      temp2=(uint)(clusterNum&0x7f);
  62   1              else
  63   1                      temp2=(uint)(clusterNum&0x100); 
  64   1              return temp2;   
  65   1      }
  66          
  67          /************************************************
  68          从FAT表内的偏移量得到簇号
  69          入口参数:fatoffset 为FAT表结构的下标
  70          ************************************************/
  71          ulong GetClusterNum(uint fatoffset,ulong fatsec)
  72          {
  73   1              ulong temp;
  74   1              temp=(fatsec-deviceinfo.FATFirstSec)<<9;
  75   1              if(deviceinfo.type)
  76   1                      temp=(temp>>2)+fatoffset;
  77   1              else    
  78   1                      temp=(temp>>1)+fatoffset;
  79   1              return temp;
  80   1      }
  81                          
  82          /*************************************************
  83          得到指定簇的下一个簇号
  84          *************************************************/
  85          ulong GetNextClusterNum(ulong clusterNum)
  86          {
  87   1              uint xxgFatEntOffset;
  88   1              ulong xxgFatSecNum,new_cluster;
  89   1      //      uchar error;
  90   1              
  91   1              xxgFatSecNum=ThisFatSecNum(clusterNum);
  92   1              xxgFatEntOffset=ThisFatEntOffset(clusterNum);
  93   1              //ThisFile.FatSectorPointer=xxgFatSecNum;
  94   1              if(fat_info.cur_fat_sec!=xxgFatSecNum)
  95   1              {       
  96   2                      if(!updata_fat_cur()) return FALSE;
  97   2                      if(!RBC_Read(xxgFatSecNum,1,FATBUF.date))
  98   2                              return FALSE;
  99   2                      fat_info.cur_fat_sec=xxgFatSecNum;              
 100   2              }
 101   1              
 102   1              if(deviceinfo.type){
 103   2                      new_cluster=SwapINT32(FATBUF.fat32[xxgFatEntOffset]);
 104   2              }       
 105   1              else{
 106   2                      new_cluster=(ulong)(SwapINT16(FATBUF.fat16[xxgFatEntOffset]));  
 107   2                      if(new_cluster>0xffef) new_cluster|=0x0fff0000;
 108   2              }
 109   1              return new_cluster;
 110   1      }
 111          
 112          /*****************************************************************
 113          删除指定簇的簇链
 114          *****************************************************************/
 115          uchar DeleteClusterLink(ulong clusterNum)
 116          {
 117   1              ulong xxgFatSecNum;
C51 COMPILER V7.00  FAT                                                                    09/22/2005 17:15:32 PAGE 3   

 118   1              uint xxgFatEntOffset;
 119   1      //      uchar error;
 120   1      //      uint temp_sec=0;
 121   1      //      uchar error,write_flag=0;
 122   1              
 123   1              do{
 124   2                      xxgFatSecNum=ThisFatSecNum(clusterNum);
 125   2                      xxgFatEntOffset=ThisFatEntOffset(clusterNum);
 126   2                      
 127   2                      if(fat_info.cur_fat_sec!=xxgFatSecNum){
 128   3                              if(!updata_fat_cur()) return FALSE;
 129   3                              if(!RBC_Read(xxgFatSecNum,1,FATBUF.date))
 130   3                                      return FALSE;
 131   3                              fat_info.cur_fat_sec=xxgFatSecNum;      
 132   3                      }       
 133   2                      if(deviceinfo.type){
 134   3                              clusterNum=SwapINT32(FATBUF.fat32[xxgFatEntOffset]);
 135   3                              FATBUF.fat32[xxgFatEntOffset]=0;
 136   3                      }       
 137   2                      else{
 138   3                              clusterNum=(ulong)(SwapINT16(FATBUF.fat16[xxgFatEntOffset]));
 139   3                              if(clusterNum>0xffef) clusterNum|=0x0fff0000;
 140   3                              FATBUF.fat16[xxgFatEntOffset]=0;
 141   3                      }
 142   2                      fat_info.free_count++;
 143   2                      fat_info.cur_fat_updata=1;              
 144   2              }while((clusterNum>1)&&(clusterNum<0x0ffffff0));
 145   1              
 146   1              if(!updata_fat_cur()) return FALSE;
 147   1              
 148   1              return TRUE;
 149   1      }
 150          
 151          /******************************************************************
 152          改变文件偏移量
 153          说明:若大于文件长度则指向文件底
 154          ******************************************************************/
 155          uchar GoToPointer(ulong pointer)
 156          {
 157   1              //unsigned char temp;
 158   1              uint clusterSize;
 159   1              ulong po_temp,clue_temp;
 160   1              
 161   1              if(!file_point.file_size) return TRUE;
 162   1              if(pointer>file_point.file_size) pointer=file_point.file_size;
 163   1              
 164   1              po_temp=pointer;
 165   1              
 166   1              clusterSize=deviceinfo.BytePerSec<<(BitNum(deviceinfo.SecPerClus));
 167   1              file_point.current_clue=file_point.file_start_clue;
 168   1              while(pointer>=clusterSize)
 169   1              {
 170   2                      clue_temp=GetNextClusterNum(file_point.current_clue);
 171   2                      if(clue_temp>0x0fffffef)
 172   2                      {
 173   3                              break;
 174   3                      }
 175   2                      pointer-=clusterSize;
 176   2                      file_point.current_clue=clue_temp;
 177   2              }
 178   1      //      file_point.SectorofCluster=pointer/deviceinfo.BPB_BytesPerSec;
 179   1              file_point.offset_sec_clue=(uint)(pointer>>9);
C51 COMPILER V7.00  FAT                                                                    09/22/2005 17:15:32 PAGE 4   

 180   1              file_point.current_sec=FirstSectorofCluster(file_point.current_clue)+file_point.offset_sec_clue;
 181   1              file_point.offset_byte=pointer-((uint)file_point.offset_sec_clue)<<9;
 182   1              file_point.offset_fat_sec=fat_info.cur_fat_sec;
 183   1              if(po_temp>file_point.file_size)
 184   1                      file_point.offset_point=file_point.file_size;
 185   1              else
 186   1                      file_point.offset_point=po_temp;
 187   1                              
 188   1              return TRUE;
 189   1              
 190   1      }
 191          
 192          /*******************************************************************
 193          从FAT信息结构中得到下一个空簇
 194          说明:调用该函数前确认FAT表中有空簇
 195          *******************************************************************/
 196          uchar GetFreeCusterNum(void)
 197          {
 198   1      //      ulong clus_fat_sec;
 199   1              uint clus_fat_offset,end_offset;
 200   1              uchar find_flag=0,loop_time=0;
 201   1              
 202   1      //      clus_fat_sec=fat_info.free_fat_sec-1;
 203   1      //      if(clus_fat_sec<deviceinfo.FATFirstSec)
 204   1      //              clus_fat_sec=deviceinfo.FATFirstSec+deviceinfo.FATSz;
 205   1                      
 206   1              clus_fat_offset=ThisFatEntOffset(fat_info.next_free_clus);
 207   1      //      clus_fat_offset++;
 208   1              
 209   1              if(deviceinfo.type)

⌨️ 快捷键说明

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