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

📄 fat.lst

📁 串口小程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 503          void fat_get_dir_file_list (Byte id)
 504          {
 505   1      Uint16 index;                               /* chain index */
 506   1      Uint16 counter_entry;                       /* entry counter: 0..MAX_DIRECTORY_FILE */
 507   1      Uint16 entry_pos;                           /* relative entry position */
 508   1      Uint16 entry_pos_saved;                     /* used when the file is not the id etension */
 509   1      Byte   i;
 510   1      
 511   1        index = 0;
 512   1        fat_dir_list_last = 0;
 513   1        counter_entry = 0;
 514   1        entry_pos = 0;   
 515   1        fat_dir_start_sect = fat_dir_current_sect;
 516   1        fat_dir_current_offs = 0;
 517   1        
 518   1        Hard_read_open(fat_dir_start_sect);
 519   1        
 520   1        do /* scan all entries */
 521   1        {
 522   2          if (dir_is_root == TRUE)
 523   2          { /* root dir is linear -> Hard_read_byte() */
 524   3            for (i = 0; i < DIR_SIZE; i++)
 525   3              gl_buffer[i] = Hard_read_byte();
 526   3          }
 527   2          else
 528   2          { /* subdir can be fragmented -> dgetc() */
 529   3            for (i = 0; i < DIR_SIZE; i++)
 530   3              gl_buffer[i] = fat_dgetc();
 531   3          }
 532   2          counter_entry++;                          /* increase the # entry         */
 533   2      
 534   2          if ((gl_buffer[0] != FILE_DELETED) && (gl_buffer[0] != FILE_NOT_EXIST))
 535   2          { /* Existing file ? */ 
 536   3            fat_dir_entry_list[index] = entry_pos;  /* save the relative position   */
 537   3            entry_pos_saved = entry_pos;
 538   3            entry_pos = 1;                          /* reset the relative position  */
 539   3            index++;                                /* increase the index           */
 540   3      
 541   3            while (gl_buffer[11] == ATTR_LFN_ENTRY) /* LFN entry ?                  */
 542   3            {                                       /* then read all the LFN entry  */
 543   4              if (dir_is_root == TRUE)
 544   4              { /* root dir is linear -> Hard_read_byte() */
 545   5                for (i = 0; i < DIR_SIZE; i++)
 546   5                  gl_buffer[i] = Hard_read_byte();
 547   5              }
 548   4              else
 549   4              { /* subdir can be fragmented -> dgetc() */
 550   5                for (i = 0; i < DIR_SIZE; i++)
C51 COMPILER V7.02a   FAT                                                                  09/13/2007 11:53:07 PAGE 10  

 551   5                  gl_buffer[i] = fat_dgetc();
 552   5              }
 553   4      
 554   4              counter_entry++;                    /* increase the # entry */
 555   4              entry_pos++;                        /* increase the relative position */
 556   4                                                  /* for the next file */
 557   4            }
 558   3      
 559   3            /* filter on the file type *////////////////////////////////////////////////////////////////////////
             -//////////////////////
 560   3            fat_cache.current.attributes = gl_buffer[11];
 561   3            ext[0] = gl_buffer[8];
 562   3            ext[1] = gl_buffer[9];
 563   3            ext[2] = gl_buffer[10];
 564   3            ext[3] = gl_buffer[4];
 565   3            ext[4] = gl_buffer[5];
 566   3            ext[5] = gl_buffer[6];
 567   3            ext[6] = gl_buffer[7];
 568   3      
 569   3            if ((fat_check_ext() & id) == FILE_XXX)
 570   3            {                                     /* Don't valid the entry */
 571   4              index--;                                              
 572   4              entry_pos += entry_pos_saved;
 573   4            }
 574   3          }
 575   2          else   /* Not an existing file */
 576   2            entry_pos++;
 577   2      
 578   2          fat_dir_list_last = index;              /* update last file index */
 579   2          /* For sub-directory, there is no logical limit for the number of entries */
 580   2          /* In order to detect the last file, we check gl_buffer[0]                */
 581   2          /* We can put in the chain directory MAX_DIRECTORY_FILE selected file     */
 582   2          if (gl_buffer[0] == FILE_NOT_EXIST)
 583   2            index = MAX_DIRECTORY_FILE;
 584   2          /* Overflow of entry_pos */
 585   2          if (entry_pos > MAX_DIRECTORY_GAP_FILE)
 586   2            index = MAX_DIRECTORY_FILE;
 587   2          /* For Root directory, the maximum entries is 512!                        */
 588   2          if ((dir_is_root == TRUE) && (counter_entry == MAX_DIRECTORY_FILE))
 589   2            index = MAX_DIRECTORY_FILE;
 590   2          if (dir_is_root == FALSE)
 591   2          {
 592   3            /* check if we are at the end of the directory */
 593   3            if ((((Byte*)&fat_dclust_byte_count)[1] == 0x00) &&
 594   3            ((((Byte*)&fat_dclust_byte_count)[0] & fat_cluster_mask) == 0x00) && 
 595   3            (fat_last_dclust_index == fat_dchain_index))
 596   3              index = MAX_DIRECTORY_FILE;
 597   3          }
 598   2        }
 599   1        while (index < MAX_DIRECTORY_FILE);
 600   1      
 601   1        fat_dir_current_sect = fat_dir_start_sect;
 602   1        Hard_read_close();
 603   1      }
 604          
 605          
 606          /*F**************************************************************************
 607          * NAME: fat_get_root_directory
 608          *----------------------------------------------------------------------------
 609          * PARAMS:
 610          *   id: file extension to select
 611          *
C51 COMPILER V7.02a   FAT                                                                  09/13/2007 11:53:07 PAGE 11  

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

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

 735          /*F**************************************************************************
 736          * NAME: fat_seek_last
 737          *----------------------------------------------------------------------------
 738          * PARAMS:
 739          *
 740          * return:
 741          *   OK: last file available
 742          *   KO: low level error
 743          *----------------------------------------------------------------------------
 744          * PURPOSE:
 745          *   Fetch the last directory info in cache
 746          *----------------------------------------------------------------------------
 747          * EXAMPLE:
 748          *----------------------------------------------------------------------------
 749          * NOTE:
 750          *----------------------------------------------------------------------------
 751          * REQUIREMENTS:
 752          *****************************************************************************/ 
 753          bit fat_seek_last (void)
 754          {
 755   1      Uint16 gl_offset;
 756   1      Uint16 i;

⌨️ 快捷键说明

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