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

📄 fat32.lst

📁 atmel at89c51snd1c mp3芯片方案源码
💻 LST
📖 第 1 页 / 共 5 页
字号:
 983   1        temp = fat_dir_list_index - 1;
 984   1        fat_seek_first();
 985   1        for (; temp != 0; temp--)
 986   1          result = fat_goto_next();
 987   1        return result;
 988   1      }
 989          
 990          /*F**************************************************************************
 991          * NAME: fat_seek_first
 992          *----------------------------------------------------------------------------
 993          * PARAMS:
 994          *
 995          * return:
 996          *   - OK: first file found
 997          *   - KO: low level error
 998          *----------------------------------------------------------------------------
 999          * PURPOSE:
1000          *   Fetch the first directory info in cache
1001          *----------------------------------------------------------------------------
1002          * EXAMPLE:
1003          *----------------------------------------------------------------------------
1004          * NOTE:
1005          *----------------------------------------------------------------------------
1006          * REQUIREMENTS:
1007          *****************************************************************************/ 
1008          bit fat32_seek_first (void)
1009          {
1010   1        fat32_clear_dir_info(); 
1011   1        fat_dir_current_sect = fat_dir_start_sect;
1012   1        fat_current_start_entry_position = 0;
1013   1        fat_current_end_entry_position = 0;
1014   1      
1015   1        if (dir_is_root)
1016   1        { /* root diretory */
1017   2          fat_dir_list_index = 1;                         
1018   2          fat32_fetch_file_info(&fat_cache.current, FETCH_NEXT);  /* fetch first root entry */
1019   2          return OK;
1020   2        }
1021   1        else
1022   1        { /* not root dir */
1023   2          fat32_fetch_file_info(&fat_cache.parent, FETCH_NEXT);   /* dot entry          */
1024   2          fat32_fetch_file_info(&fat_cache.parent, FETCH_NEXT);   /* dotdot entry       */
1025   2          fat_dir_list_index = 2;                               /* update entry index */
1026   2          return fat32_goto_next();                               /* update first file info */
1027   2        }
1028   1      }
1029          
1030          
1031          /*F**************************************************************************
1032          * NAME: fat_goto_subdir
1033          *----------------------------------------------------------------------------
1034          * PARAMS:
1035          *   id: file extension to select
1036          *
1037          * return:
1038          *   - OK: subdir selected
C51 COMPILER V7.50   FAT32                                                                 11/27/2007 20:46:00 PAGE 18  

1039          *   - KO: current entry not a directory
1040          *   - KO: low level error
1041          *----------------------------------------------------------------------------
1042          * PURPOSE:
1043          *   Go to the subdir if current is a directory
1044          *----------------------------------------------------------------------------
1045          * EXAMPLE:
1046          *----------------------------------------------------------------------------
1047          * NOTE:
1048          *   Also called by goto_parentdir() with current info from parent info
1049          *----------------------------------------------------------------------------
1050          * REQUIREMENTS:
1051          *****************************************************************************/ 
1052          bit fat32_goto_subdir (Byte id)
1053          {                        
1054   1        /* check if current file is a directory */
1055   1        if ((fat_cache.current.attributes & ATTR_DIRECTORY) == ATTR_DIRECTORY)
1056   1        {
1057   2          /* computes the sector address (RELATIVE) */
1058   2          if (fat_cache.current.start_cluster == fat_rootclus_fat32)
1059   2          {
1060   3            return fat32_get_root_directory(id);                    /* go to root dir */
1061   3          }
1062   2      
1063   2          /* go to not root dir */ 
1064   2          fat32_get_clusters(&dclusters, MAX_DIR_FRAGMENT_NUMBER);  /* get directory allocation table */        
             -                                 
1065   2          fat_last_dclust_index = fat_last_clust_index;           /* save last index position for chain cluster 
             -*/
1066   2          fat_dir_current_sect = (((Uint32)(dclusters[0].cluster)) * fat_cluster_size)    /* computes sector add
             -ress from allocation table */
1067   2                                 + fat_ptr_data;
1068   2      
1069   2          fat32_get_dir_file_list(id);                              /* create list of entries */
1070   2          fat_dir_list_index = 1;                                 /* point on first root entry */
1071   2          fat_current_start_entry_position = 0;
1072   2          fat_current_end_entry_position = 0;    
1073   2          
1074   2          fat32_fetch_file_info(&fat_cache.current, FETCH_NEXT);    /* dot entry    */   
1075   2          fat32_fetch_file_info(&fat_cache.parent, FETCH_NEXT);     /* dotdot entry */
1076   2          fat_dir_list_index = 2;                                 /* update index position entry */
1077   2          if(fat_cache.parent.start_cluster == 0x00)              /* if parent dir is root */
1078   2          {
1079   3            fat_cache.parent.start_cluster = fat_rootclus_fat32;  /* then update start cluster value */
1080   3          }
1081   2          dir_is_root = FALSE;
1082   2          return fat32_goto_next();
1083   2        }
1084   1        else
1085   1          return KO;                                /* current entry is not a dir */
1086   1      }
1087            
1088          
1089          /*F**************************************************************************
1090          * NAME: fat_goto_parentdir
1091          *----------------------------------------------------------------------------
1092          * PARAMS: 
1093          *   id: file extension to select
1094          *
1095          * return:
1096          *----------------------------------------------------------------------------
1097          * PURPOSE:
C51 COMPILER V7.50   FAT32                                                                 11/27/2007 20:46:00 PAGE 19  

1098          *   Go to the parent directory
1099          *----------------------------------------------------------------------------
1100          * EXAMPLE:
1101          *----------------------------------------------------------------------------
1102          * NOTE:
1103          *----------------------------------------------------------------------------
1104          * REQUIREMENTS:
1105          *****************************************************************************/ 
1106          bit fat32_goto_parentdir (Byte id)
1107          { 
1108   1      Uint32 temp_cluster;
1109   1        temp_cluster = dclusters[0].cluster + 2;        /* save cluster info */
1110   1        if (temp_cluster != fat_rootclus_fat32)
1111   1        {
1112   2          fat_cache.current = fat_cache.parent;         /* goto the parent directory */
1113   2        
1114   2          /* issue the equivalent to a cd .. DOS command */
1115   2          if (fat32_goto_subdir(id))
1116   2          {
1117   3            while (temp_cluster != fat_cache.current.start_cluster)
1118   3            {
1119   4              if (fat32_goto_next() == KO)
1120   4                break;
1121   4            }
1122   3            if (temp_cluster == fat_cache.current.start_cluster)
1123   3              return OK;
1124   3            else
1125   3              return KO;
1126   3        
1127   3          }
1128   2          else
1129   2          {
1130   3            return KO;
1131   3          }
1132   2        }
1133   1        else
1134   1        {
1135   2          return OK; /* Nothing to do because we are in the root directory */
1136   2        }
1137   1      }
1138          
1139          
1140          
1141          /*F**************************************************************************
1142          * NAME: fat_update_fat_sector
1143          *----------------------------------------------------------------------------
1144          * PARAMS: 
1145          *   sector_number : fat sector position
1146          *
1147          * return:
1148          *----------------------------------------------------------------------------
1149          * PURPOSE:
1150          *   update a sector of fat
1151          *----------------------------------------------------------------------------
1152          * EXAMPLE:
1153          *----------------------------------------------------------------------------
1154          * NOTE:
1155          *   This function check if there is 2 fats to be updated
1156          *----------------------------------------------------------------------------
1157          * REQUIREMENTS:
1158          *****************************************************************************/  
1159          void fat32_update_fat_sector (Uint16 sector_number)
C51 COMPILER V7.50   FAT32                                                                 11/27/2007 20:46:00 PAGE 20  

1160          {
1161   1        fat32_up_down_load_sector(fat_ptr_fats + sector_number, DOWNLOAD);                   /* FAT 1 update */
1162   1        if (fat_2_is_present == TRUE)
1163   1        {
1164   2          fat32_up_down_load_sector(fat_ptr_fats + sector_number + fat_fat_size, DOWNLOAD);  /* FAT 2 update */
1165   2        }      
1166   1      }
1167          
1168          
1169          /*F**************************************************************************
1170          * NAME: fat_update_entry_fat
1171          *----------------------------------------------------------------------------
1172          * PARAMS:
1173          *
1174          * return:
1175          *----------------------------------------------------------------------------
1176          * PURPOSE:
1177          *   Update root entry and FAT after a writing file session (create or re-write)
1178          *----------------------------------------------------------------------------
1179          * EXAMPLE:
1180          *----------------------------------------------------------------------------
1181          * NOTE:
1182          *----------------------------------------------------------------------------
1183          * REQUIREMENTS:
1184          *   
1185          *****************************************************************************/
1186          void fat32_update_entry_fat (void)
1187          {
1188   1      Byte index;
1189   1      Uint16 chain_index;
1190   1      Uint16 sector_number;
1191   1      Byte id;
1192   1      Uint16 i;
1193   1      Uint16 j;
1194   1      Uint32 cluster;
1195   1      Uint16 temp;
1196   1      Uint32 nb_cluster;
1197   1      
1198   1      /*********************/
1199   1      /* Update directory entry */
1200   1      /*********************/
1201   1        fat32_clear_dir_info();
1202   1        fat_dir_current_offs = (fat_current_end_entry_position - 1) * 32;
1203   1        fat32_calc_cluster();
1204   1        fat32_up_down_load_sector(fat_dir_current_sect, UPLOAD);
1205   1        j = ((fat_current_end_entry_position - 1) % 16) * 32 ;                /* Position of entry in the sector
             - */
1206   1      
1207   1        /* Update file size */
1208   1        if (fat_cache.current.size.l <= fat_file_size.l)
1209   1          fat_cache.current.size.l = fat_file_size.l;
1210   1        fat_buf_sector[j + 28] = fat_cache.current.size.b[3];
1211   1        fat_buf_sector[j + 29] = fat_cache.current.size.b[2];
1212   1        fat_buf_sector[j + 30] = fat_cache.current.size.b[1];
1213   1        fat_buf_sector[j + 31] = fat_cache.current.size.b[0];
1214   1      
1215   1        ext[0] = fat_buf_sector[j + 8];
1216   1        ext[1] = fat_buf_sector[j + 9];
1217   1        ext[2] = fat_buf_sector[j + 10];
1218   1        id = fat32_check_ext();
1219   1      
1220   1        fat32_up_down_load_sector(fat_dir_current_sect, DOWNLOAD);
C51 COMPILER V7.50   FAT32                                                                 11/27/2007 20:46:00 PAGE 21  

1221   1      
1222   1      /********************/
1223   1      /* Update fat 1 & 2 */
1224   1      /********************/
1225   1        /* Calculate file size cluster */
1226   1        nb_cluster = (fat_cache.current.size.l / SECTOR_SIZE) / fat_cluster_si

⌨️ 快捷键说明

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