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

📄 fat.lst

📁 这是atmel公司的89C51SND1C的mp3源程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V6.20c  FAT                                                                   07/10/2002 15:17:46 PAGE 1   


C51 COMPILER V6.20c, COMPILATION OF MODULE FAT
OBJECT MODULE PLACED IN ..\obj\fat.obj
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE ..\src\file\fat.c BROWSE INCDIR(..\src\system;..\..\..\lib) DEFINE(KEIL) DE
                    -BUG OBJECTEXTEND PRINT(.\fat.lst) OBJECT(..\obj\fat.obj) 

stmt level    source

   1          /*C**************************************************************************
   2          * $RCSfile: fat.c,v $
   3          *----------------------------------------------------------------------------
   4          * Copyright (c) 2002 Atmel.
   5          *----------------------------------------------------------------------------
   6          * RELEASE:      $Name: DEMO_FAT_1_2_5 $      
   7          * REVISION:     $Revision: 1.12 $     
   8          * FILE_CVSID:   $Id: fat.c,v 1.12 2002/06/10 14:14:53 dturpin Exp $       
   9          *----------------------------------------------------------------------------
  10          * PURPOSE:
  11          * FAT16/FAT12 file-system basics functions
  12          * 
  13          * NOTES:
  14          * Supports only the first partition
  15          * Supports only 512 bytes sector size
  16          * Supports only file fragmentation < MAX_FILE_FRAGMENT_NUMBER
  17          * Supports only one file openned at a time
  18          *
  19          * Global Variables:
  20          *   - gl_buffer: array of bytes in pdata space
  21          *   - gl_wav_header:  wave structure in code
  22          *
  23          * CHANGES:
  24          * - TD 2002/02/28
  25          *   Add new variables for mass storage purpose:
  26          *     fat_nb_sector
  27          *     fat_sector_per_track
  28          *     fat_end_head
  29          *     fat_end_cylinder
  30          * - FF 2002/03/06
  31          *   Add fat_format function
  32          *****************************************************************************/
  33          
  34          /*_____ I N C L U D E S ____________________________________________________*/
  35          
  36          #include "config.h"                         /* system configuration */
  37          #include "..\mem\hard.h"                    /* low level function definition */
  38          #include "file.h"                           /* file function definition */
  39          #include "fat.h"                            /* fat file-system definition */
  40          #include "wav.h"                            /* wav file definition */
  41          
  42          
  43          /*_____ M A C R O S ________________________________________________________*/
  44          
  45          
  46          /*_____ D E F I N I T I O N ________________________________________________*/
  47          
  48          extern  pdata   Byte    gl_buffer[];
  49          extern  code    wav_struct  gl_wav_header;
  50          
  51          
  52          /* For exploration matters */
  53          xdata Uint16  fat_directory_chain[MAX_DIRECTORY_FILE]; /* array of relative entries position */
  54          xdata Uint16  fat_directory_pos;            /* global entries offset */
C51 COMPILER V6.20c  FAT                                                                   07/10/2002 15:17:46 PAGE 2   

  55          xdata Uint16  fat_last_file;                /* number of file stored (MP3, VOC, DIR) */
  56          xdata Uint32  fat_directory_base;           /* starting sector for directory */
  57          idata Uint16  fat_file_ptr;                 /* entry number pointer */
  58          xdata Uint32  fat_current_sector;           /* current sector where the current */
  59                                                      /* file/dir info (cache.info) is situated */
  60          xdata Uint16  fat_current_byte_counter;     /* the byte counter offset in the current */
  61                                                      /* sector where is the current file/dir entry */
  62          
  63          /* For file management matters */              
  64          /* the global byte counter, mainly use for the eof check */
  65          static data   Uint32   fat_file_byte_counter;  
  66          
  67          xdata fat_Cache   fat_cache;                /* The cache structure, see the .h for more info */
  68          char  pdata   *lfn_name = &(gl_buffer[32]); /* long filename limited to MAX_FILENAME_LEN chars */
  69          xdata char    ext[3];                       /* file extension (limited to 3 characters) */
  70          
  71          /* file chain management */
  72          static  data  Byte    fat_chain_index;      /* the number of the fragment of the file, in fact */
  73                                                      /* the index of the table in the cluster chain */
  74                        
  75          static  data  Byte    fat_chain_cluster;    /* the offset of the cluster from the first cluster */ 
  76                                                      /* of the fragment */
  77          
  78          static  xdata fat_cluster_chain clusters;       /* cluster chain for the current file */
  79          static  xdata fat_cluster_chain dir_clusters;   /* cluster chain for the current directory */
  80          
  81          static  bdata bit     dir_is_root;          /* TRUE: point the root directory  */
  82          static  data  Uint32  fat_ptr_fats;         /* address of the first byte of FAT */
  83          static  data  Uint32  fat_ptr_rdir;         /* address of the first byte of root dir */
  84          static  data  Uint32  fat_ptr_data;         /* address of the first byte of data */
  85          static  data  Byte    fat_cluster_size;     /* cluster size (sector count) */
  86          static  data  Byte    fat_cluster_mask;     /* mask for end of cluster test */
  87          
  88          static  idata Byte    fat_current_dir_fragment;
  89          static  idata Uint16  fat_current_dir_cluster;
  90          static  idata Byte    fat_current_sector_cluster;
  91          
  92          static  bdata bit     fat_is_fat16;         /* TRUE: FAT16 - FALSE: FAT12 */
  93          static  bdata bit     fat_open_mode;        /* READ or WRITE */
  94          
  95          /*_____ D E C L A R A T I O N ______________________________________________*/
  96          
  97          static  bit     fat_get_clusters (fat_cluster_chain *);
  98          static  bit     fat_dopen (void);
  99          static  bit     fat_dseek (Int16);
 100          static  Byte    fat_dgetc (void);
 101          
 102          
 103          /*F**************************************************************************
 104          * NAME: fat_install
 105          *----------------------------------------------------------------------------
 106          * PARAMS:
 107          *
 108          * return:
 109          *   - OK: intallation succeeded
 110          *   - KO: - partition 1 not active
 111          *         - FAT type is not FAT16
 112          *         - sector size is not 512 bytes
 113          *         - MBR or PBR signatures are not correct
 114          *         - low level read open failure
 115          *----------------------------------------------------------------------------
 116          * PURPOSE:
C51 COMPILER V6.20c  FAT                                                                   07/10/2002 15:17:46 PAGE 3   

 117          *   Install the fat system, read mbr, bootrecords...
 118          *----------------------------------------------------------------------------
 119          * EXAMPLE:
 120          *----------------------------------------------------------------------------
 121          * NOTE:
 122          *   sector size is fixed to 512 bytes to simplify low level drivers
 123          *   fat_ptr_fats = partition offset + nb_reserved_sector
 124          *   fat_ptr_rdir = fat_ptr_fat + fat_size * nb_fat
 125          *   fat_ptr_data = fat_ptr_rdir + nb_root_entries * 32 / 512
 126          *----------------------------------------------------------------------------
 127          * REQUIREMENTS:
 128          *****************************************************************************/
 129          bit fat_install (void)
 130          {
 131   1      Byte i;
 132   1      Uint16 fat_fat_size;
 133   1      Uint32 count_of_clusters;
 134   1      Uint32 Tot_sect;
 135   1      Uint32 fat_nb_sector;
 136   1      
 137   1        /* read and check usefull MBR info */
 138   1        /* go to the first partition field */
 139   1        if (Hard_read_open(MBR_ADDRESS) == OK) 
 140   1        {
 141   2          for (i= 446/2; i != 0; i--)
 142   2          {
 143   3            Hard_read_byte();                     /* go to first partition entry */
 144   3            Hard_read_byte();
 145   3          }
 146   2          /* check first partition state */
 147   2          if (Hard_read_byte() != PARTITION_ACTIVE)
 148   2          {
 149   3            Hard_read_close();                    /* close physical read */
 150   3            return KO;
 151   3          }
 152   2          Hard_read_byte();                       /* dummy reads */
 153   2          Hard_read_byte();
 154   2          Hard_read_byte();
 155   2          Hard_read_byte();
 156   2          Hard_read_byte();                       /* dummy reads */
 157   2          Hard_read_byte();
 158   2          Hard_read_byte();
 159   2          
 160   2      
 161   2          /* read partition offset (in sectors) at offset 8 */
 162   2          ((Byte*)&fat_ptr_fats)[3] = Hard_read_byte();
 163   2          ((Byte*)&fat_ptr_fats)[2] = Hard_read_byte();
 164   2          ((Byte*)&fat_ptr_fats)[1] = Hard_read_byte();
 165   2          ((Byte*)&fat_ptr_fats)[0] = Hard_read_byte();
 166   2          /* go to the MBR signature field */
 167   2          for (i= 52; i != 0; i--)
 168   2          {
 169   3            Hard_read_byte();                     /* dummy reads */
 170   3          }
 171   2          /* check MBR signature */
 172   2          if ((Hard_read_byte() != LOW(BR_SIGNATURE)) &&
 173   2              (Hard_read_byte() != HIGH(BR_SIGNATURE)))
 174   2          {
 175   3            Hard_read_close();                    /* close physical read */
 176   3            return KO;
 177   3          }
 178   2          Hard_read_close();                      /* close physical read */
C51 COMPILER V6.20c  FAT                                                                   07/10/2002 15:17:46 PAGE 4   

 179   2        }
 180   1        else
 181   1        { /* low level error */
 182   2          return KO;
 183   2        }
 184   1      
 185   1        /* read and check usefull PBR info */
 186   1        if (Hard_read_open(fat_ptr_fats) == OK) 
 187   1        {
 188   2          /* go to sector size field */
 189   2          for (i= 11; i != 0; i--)
 190   2          {
 191   3            Hard_read_byte();                     /* dummy reads */
 192   3          }
 193   2          /* read sector size (in bytes) */
 194   2          if (Hard_read_byte() != LOW(SECTOR_SIZE) ||
 195   2              Hard_read_byte() != HIGH(SECTOR_SIZE))
 196   2          {
 197   3            Hard_read_close();                    /* close physical read */
 198   3            return KO;
 199   3          }
 200   2          /* read cluster size (in sector) */
 201   2          fat_cluster_size = Hard_read_byte();
 202   2          fat_cluster_mask = HIGH((Uint16)fat_cluster_size * SECTOR_SIZE) - 1;
 203   2          /* compute FATs sector address: add reserved sector number */
 204   2          fat_ptr_fats += Hard_read_byte();
 205   2          fat_ptr_fats += (Uint16)Hard_read_byte() << 8;
 206   2          /* read number of FATs */
 207   2          i = Hard_read_byte();
 208   2          /* read number of dir entries  and compute rdir offset */
 209   2          ((Byte*)&fat_ptr_data)[3] = Hard_read_byte();
 210   2          ((Byte*)&fat_ptr_data)[2] = Hard_read_byte();
 211   2          ((Byte*)&fat_ptr_data)[1] = 0;
 212   2          ((Byte*)&fat_ptr_data)[0] = 0;
 213   2          fat_ptr_data = (fat_ptr_data * DIR_SIZE) / SECTOR_SIZE;
 214   2          /* read number of sector in partition (<32Mb) */
 215   2          ((Byte*)&fat_nb_sector)[3] = Hard_read_byte();
 216   2          ((Byte*)&fat_nb_sector)[2] = Hard_read_byte();
 217   2          ((Byte*)&fat_nb_sector)[1] = 0x00;
 218   2          ((Byte*)&fat_nb_sector)[0] = 0x00;
 219   2          Hard_read_byte();
 220   2          /* compute root directory sector address */
 221   2          ((Byte*)&fat_fat_size)[1] = Hard_read_byte();
 222   2          ((Byte*)&fat_fat_size)[0] = Hard_read_byte();
 223   2          
 224   2          fat_ptr_rdir = i * fat_fat_size;
 225   2          fat_ptr_rdir += fat_ptr_fats;
 226   2      
 227   2          Hard_read_byte();
 228   2          Hard_read_byte();
 229   2          Hard_read_byte();
 230   2          Hard_read_byte();
 231   2          Hard_read_byte();
 232   2          Hard_read_byte();
 233   2          Hard_read_byte();
 234   2          Hard_read_byte();
 235   2      
 236   2          /* read number of sector in partition (>32Mb) */
 237   2          ((Byte*)&fat_nb_sector)[3] += Hard_read_byte();
 238   2          ((Byte*)&fat_nb_sector)[2] += Hard_read_byte();
 239   2          ((Byte*)&fat_nb_sector)[1] += Hard_read_byte();
 240   2          ((Byte*)&fat_nb_sector)[0] += Hard_read_byte();
C51 COMPILER V6.20c  FAT                                                                   07/10/2002 15:17:46 PAGE 5   

 241   2      
 242   2          Tot_sect = fat_nb_sector - ( 1 + (i * fat_fat_size) + fat_ptr_data);
 243   2          count_of_clusters = Tot_sect / fat_cluster_size;
 244   2          if (count_of_clusters <= MAX_CLUSTERS12)
 245   2            fat_is_fat16 = FALSE;

⌨️ 快捷键说明

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