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

📄 fat.lst

📁 atmel at89c51snd1c mp3芯片方案源码
💻 LST
📖 第 1 页 / 共 5 页
字号:
 501   1        Hard_read_open(fat_dir_start_sect);
 502   1        
 503   1        do /* scan all entries */
 504   1        {
 505   2          if (dir_is_root == TRUE)
 506   2          { /* root dir is linear -> Hard_read_byte() */
 507   3            for (i = 0; i < DIR_SIZE; i++)
 508   3              gl_buffer[i] = Hard_read_byte();
 509   3          }
 510   2          else
 511   2          { /* subdir can be fragmented -> dgetc() */
 512   3            for (i = 0; i < DIR_SIZE; i++)
 513   3              gl_buffer[i] = fat_dgetc();
 514   3          }
 515   2          counter_entry++;                          /* increase the # entry         */
 516   2      
 517   2          if ((gl_buffer[0] != FILE_DELETED) && (gl_buffer[0] != FILE_NOT_EXIST))
 518   2          { /* Existing file ? */ 
 519   3            fat_dir_entry_list[index] = entry_pos;  /* save the relative position   */
 520   3      
 521   3            entry_pos_saved = entry_pos;
 522   3            entry_pos = 1;                          /* reset the relative position  */
 523   3            index++;                                /* increase the index           */
 524   3      
 525   3            while (gl_buffer[11] == ATTR_LFN_ENTRY) /* LFN entry ?                  */
 526   3            {                                       /* then read all the LFN entry  */
 527   4              if (dir_is_root == TRUE)
 528   4              { /* root dir is linear -> Hard_read_byte() */
 529   5                for (i = 0; i < DIR_SIZE; i++)
 530   5                  gl_buffer[i] = Hard_read_byte();
 531   5              }
 532   4              else
 533   4              { /* subdir can be fragmented -> dgetc() */
 534   5                for (i = 0; i < DIR_SIZE; i++)
 535   5                  gl_buffer[i] = fat_dgetc();
 536   5              }
 537   4      
 538   4              counter_entry++;                    /* increase the # entry */
 539   4              entry_pos++;                        /* increase the relative position */
 540   4                                                  /* for the next file */
 541   4            }
 542   3      
 543   3            /* filter on the file type */
 544   3            fat_cache.current.attributes = gl_buffer[11];
 545   3            ext[0] = gl_buffer[8];
 546   3            ext[1] = gl_buffer[9];
 547   3            ext[2] = gl_buffer[10];
 548   3            if ((fat_check_ext() & id) == FILE_XXX)
 549   3            {                                     /* Don't valid the entry */
 550   4              index--;                                              
C51 COMPILER V7.50   FAT                                                                   02/16/2009 09:59:55 PAGE 10  

 551   4              entry_pos += entry_pos_saved;
 552   4            }
 553   3          }
 554   2          else   /* Not an existing file */    
 555   2            entry_pos++;
 556   2      
 557   2          fat_dir_list_last = index;              /* update last file index */
 558   2          /* For sub-directory, there is no logical limit for the number of entries */
 559   2          /* In order to detect the last file, we check gl_buffer[0]                */
 560   2          /* We can put in the chain directory MAX_DIRECTORY_FILE selected file     */
 561   2          if (gl_buffer[0] == FILE_NOT_EXIST)
 562   2            index = MAX_DIRECTORY_FILE;
 563   2          /* Overflow of entry_pos */
 564   2          if (entry_pos > MAX_DIRECTORY_GAP_FILE)
 565   2            index = MAX_DIRECTORY_FILE;
 566   2          /* For Root directory, the maximum entries is 512!                        */
 567   2          if ((dir_is_root == TRUE) && (counter_entry == MAX_DIRECTORY_FILE))
 568   2            index = MAX_DIRECTORY_FILE;
 569   2      
 570   2          if (dir_is_root == FALSE)
 571   2          {
 572   3            /* check if we are at the end of the directory */
 573   3            if ((((Byte*)&fat_dclust_byte_count)[1] == 0x00) &&
 574   3            ((((Byte*)&fat_dclust_byte_count)[0] & fat_cluster_mask) == 0x00) && 
 575   3            (fat_last_dclust_index == fat_dchain_index))
 576   3              index = MAX_DIRECTORY_FILE;
 577   3          }
 578   2        }
 579   1        while (index < MAX_DIRECTORY_FILE);
 580   1      
 581   1        fat_dir_current_sect = fat_dir_start_sect;
 582   1        Hard_read_close();
 583   1      }
 584          
 585          
 586          /*F**************************************************************************
 587          * NAME: fat_get_root_directory
 588          *----------------------------------------------------------------------------
 589          * PARAMS:
 590          *   id: file extension to select
 591          *
 592          * return:
 593          *   - OK: file available
 594          *   - KO: no requested file found
 595          *   - KO: low_level memory error
 596          *----------------------------------------------------------------------------
 597          * PURPOSE:
 598          *   Select first available file/dir in root diretory
 599          *----------------------------------------------------------------------------
 600          * EXAMPLE:
 601          *----------------------------------------------------------------------------
 602          * NOTE:
 603          *   Fill all the cache information for the first time
 604          *----------------------------------------------------------------------------
 605          * REQUIREMENTS:
 606          *****************************************************************************/
 607          bit fat_get_root_directory (Byte id)
 608          {
 609   1        /* select first root dir entry */
 610   1        fat_dir_current_sect = fat_ptr_rdir;
 611   1        fat_dclust_byte_count = 0;
 612   1        dir_is_root = TRUE;
C51 COMPILER V7.50   FAT                                                                   02/16/2009 09:59:55 PAGE 11  

 613   1      
 614   1        fat_get_dir_file_list(id);                /* create list of entries */
 615   1      
 616   1        if (fat_dir_list_last == 0)
 617   1          return KO;                              /* no requested (id) entry */
 618   1      
 619   1        fat_dir_list_index = 0;                   /* point on first root entry */
 620   1      
 621   1        /* extract info from table */
 622   1        if (fat_dseek(fat_dir_entry_list[0] * DIR_SIZE) == OK)
 623   1        {
 624   2          fat_get_dir_entry(&fat_cache.current);  /* update current file info */
 625   2          /* parent dir is also root */
 626   2          fat_cache.parent.start_cluster = 0;   
 627   2          fat_cache.parent.attributes = ATTR_ROOT_DIR;  /* mark as root dir */
 628   2          return OK;
 629   2        }
 630   1        else
 631   1          return KO;                              /* low level error */
 632   1      }
 633          
 634          
 635          /*F**************************************************************************
 636          * NAME: fat_goto_next
 637          *----------------------------------------------------------------------------
 638          * PARAMS:
 639          *
 640          * return:
 641          *   - OK: next file available
 642          *   - KO: last file reached
 643          *   - KO: low_level memory error
 644          *----------------------------------------------------------------------------
 645          * PURPOSE:
 646          *   Fetch the next dir/file info in cache
 647          *----------------------------------------------------------------------------
 648          * EXAMPLE:
 649          *----------------------------------------------------------------------------
 650          * NOTE:
 651          *----------------------------------------------------------------------------
 652          * REQUIREMENTS:
 653          *****************************************************************************/ 
 654          bit fat_goto_next (void)
 655          {
 656   1        
 657   1        if (fat_dir_list_index < (fat_dir_list_last - 1))
 658   1        {
 659   2          fat_dir_list_index++;
 660   2       
 661   2          if (fat_dseek((Int16)(fat_dir_entry_list[fat_dir_list_index ] * DIR_SIZE))== OK)
 662   2          { 
 663   3            fat_get_dir_entry(&fat_cache.current);/* update current file info */
 664   3            return OK;
 665   3          }
 666   2          else
 667   2            return KO;                            /* low level error */
 668   2        }
 669   1        else
 670   1          return KO;                              /* already on last file */
 671   1      }
 672          
 673          
 674          /*F**************************************************************************
C51 COMPILER V7.50   FAT                                                                   02/16/2009 09:59:55 PAGE 12  

 675          * NAME: fat_goto_prev
 676          *----------------------------------------------------------------------------
 677          * PARAMS:
 678          *
 679          * return:
 680          *   - OK: previous file available
 681          *   - KO: first file reached
 682          *   - KO: low_level memory error
 683          *----------------------------------------------------------------------------
 684          * PURPOSE:
 685          *   Fetch the previous directory info in cache
 686          *----------------------------------------------------------------------------
 687          * EXAMPLE:
 688          *----------------------------------------------------------------------------
 689          * NOTE:
 690          *----------------------------------------------------------------------------
 691          * REQUIREMENTS:
 692          *****************************************************************************/ 
 693          bit fat_goto_prev (void)
 694          {
 695   1      Byte min;
 696   1        
 697   1        if (dir_is_root)
 698   1          min = 0;
 699   1        else
 700   1          min = 2;
 701   1      
 702   1        if (fat_dir_list_index != min)            /* first file of the directory? */
 703   1        {
 704   2          if (fat_dseek((Int16)(fat_dir_entry_list[fat_dir_list_index] * (-DIR_SIZE))) == OK)
 705   2          { /* go to previous file */
 706   3            fat_dir_list_index--;
 707   3            fat_get_dir_entry(&fat_cache.current);/* update current file info */
 708   3            return OK;
 709   3          }
 710   2          else
 711   2            return KO;                            /* low level error */
 712   2        }
 713   1        else
 714   1          return KO;                              /* already on first file */
 715   1      }
 716          
 717          /*F**************************************************************************
 718          * NAME: fat_seek_last
 719          *----------------------------------------------------------------------------
 720          * PARAMS:
 721          *
 722          * return:
 723          *   OK: last file available
 724          *   KO: low level error
 725          *----------------------------------------------------------------------------
 726          * PURPOSE:
 727          *   Fetch the last directory info in cache
 728          *----------------------------------------------------------------------------
 729          * EXAMPLE:
 730          *----------------------------------------------------------------------------
 731          * NOTE:
 732          *----------------------------------------------------------------------------
 733          * REQUIREMENTS:
 734          *****************************************************************************/ 
 735          bit fat_seek_last (void)
 736          {
C51 COMPILER V7.50   FAT                                                                   02/16/2009 09:59:55 PAGE 13  

 737   1      Uint16 gl_offset;
 738   1      Uint16 i;
 739   1        
 740   1        for (i = fat_dir_list_index + 1, gl_offset = 0; i < fat_dir_list_last; fat_dir_list_index++, i++)
 741   1          gl_offset += fat_dir_entry_list[i];
 742   1      
 743   1        if (fat_dseek(gl_offset * DIR_SIZE) == OK)
 744   1        {
 745   2          fat_get_dir_entry(&fat_cache.current);      
 746   2          return OK;
 747   2        }
 748   1        else
 749   1          return KO;                              /* low level error */
 750   1      }
 751          
 752          /*F**************************************************************************
 753          * NAME: fat_seek_entry_record
 754          *----------------------------------------------------------------------------
 755          * PARAMS:

⌨️ 快捷键说明

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