亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fat.c

?? 用ATmega8 做的MP3播放器
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
 * Copyright (c) 2003-2004 K. John '2B|!2B' Crispin
 * Copyright (c) 2005      Stephan Dobretsberger
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
 *
 * Feedback, Bugs, ... mail stephan.dobretsberger@gmx.at
 *
 */


#include "types.h"
#include "mmc.h"
#include "vs1001.h"
#include "spi.h"
#include "fat.h"

#include "test.h"

u08 fat_buf[FAT_RD_BUF_SIZE+1];

// starts by scanning the BPB
// sector needs to be equal to the first sector of the first partition
// use fat_get_part_start to get this value
//
// the first fat32 sector is set up as follows -->
//  u08   jmpboot[3]    0xEB 0x?? 0x90    -- instructions to jump to the boot loader
//  u08   OEMName[8]      -- identifies system that formatted the card
//  u08   BPB[42]         -- BIOS Parameter Block -- see below
//  .
//  .
//  .
//  u08   0xAA            -- signature
//  u08   0x55            -- signature
//
// fat32 BPB -->
//  u08 bytes_per_sec[2]  -- the size of a sector. for MMC this is always 512
//  u08 sec_per_clus      -- the number of sectrs per cluster. for MMC normally 1
//  u08 rsvd_sec[2]       -- reserved sectors for additional boot code. fat32 normally has 32 sectors
//  u08 num_fats          -- number of fat-chains on the disk ? leave at 2 to be sure
//  u08 root_dir_ent[2]   -- 0 for fat32. used by fat16
//  u08 tot_sec_16[2]     -- 0 for fat32. used by fat16
//  u08 media_type        -- used by OS to determine removeable, fixed ... used by msdos 1.x
//  u08 sec_per_fat[2]    -- 0 for fat32. used by fat16
//  u08 sec_per_track[2]  -- something for geometry ?
//  u08 num_heads[2]      -- number of heads.
//  u08 hidden_secs[4]    -- something for HW int 0x13
//  u08 tot_sec_32[4]     -- the number of sectors on this partition
//  u08 sec_per_fat_32[4] -- sectors per fat
//  u08 ext_flags[2]      -- extended partition ?
//  u08 fs_ver[2]         -- ?? something for fs
//  u08 root_clus[4]      -- offset to the sector that contains the root directory
//  u08 fs_inf[2]         -- ?? something for fs
//  u08 bpb_bak[2]        -- backup of bpb in reserved area of media



// defines for the offsets of the values in the bpb that we are interested in

#define FAT_OEM_START          3
#define FAT_OEM_STOP          10

#define FAT_BYTES_PER_SECTOR  11
#define FAT_SEC_PER_CLUS      13
#define FAT_RSVD_SEC_CNT      14
#define FAT_NUM_FATS          16
#define FAT_ROOT_ENT_CNT      17
#define FAT_TOTSEC            32
#define FAT_SIZE              36
#define FAT_ROOT_CLUS         44

// file attribs
#define FAT_READ_ONLY       0x01
#define FAT_HIDDEN          0x02
#define FAT_SYS             0x04
#define FAT_VOL_ID          0x08
#define FAT_DIRECTORY       0x10
#define FAT_ARCHIVE         0x20
#define FAT_LONG_NAME       0x0F

static u16 bytes_per_sec  = 0;
static u08 sec_per_clus   = 0;
static u16 rsvd_sec_cnt   = 0;
static u08 num_fats       = 0;
static u16 tot_sech       = 0;
static u16 tot_secl       = 0;
static u16 root_clush     = 0;
static u16 root_clusl     = 0;
static u16 fat_sizeh      = 0;
static u16 fat_sizel      = 0;

// our offsets
static u16 first_part_sector  = 0;
static u16 first_fat_sector   = 0;
static u16 first_data_sectorl = 0;

// name of our volume
static u08 volume_id[8];

// the directiory that gets used if no other is specified
static DIR directory;

#ifdef LFN_SUPPORT
static u08 lfn_tmp[(LFN_MAX_BLOCK*13)+1];
#endif

/* is build in
void strcpy(u08 *to, u08 *from)
{ while(*from)
  { *to = *from;
    to++;
    from++;
  }
};
*/



/*------------------ FAT LAYER --------------*/

// reads the mbr
// check for fat32 identifier
// finds the start of the first partition
u08 FAT_read_mbr(void)
{ // the number of bytes read
  u16 length = 0;
  u08 tmp;

  // start reading the mbr
  MMC_get_sec_start(0x00,0x00);
  // get the data
  while(length < 512)
  { length++;
    // get next byte
    tmp = MMC_get_sec_next();

    // partition type
    if(length == 451 && tmp != 0x0b)
      while(1); // stop if no FAT32

    // get the start sector of the first partition
    if(length == 455) first_part_sector = tmp;
    if(length == 456) first_part_sector += ((u16)tmp) << 8;
  };
  // stop reading from the mmc
  MMC_get_sec_stop();
  // FAB
  return FAT_OK;
};

// scans the BPB in the first(0x00) sector of the first partition
void FAT_read_first_part_sector(void)
{ // the number of bytes read
  u16 length = 0;

  // start reading from the mmc
  MMC_get_sec_start(0x00, first_part_sector);
  while(length < 512)
  { // get the next byte
    u08 tmp = MMC_get_sec_next();
    // read fat data
    switch(length)
    { case FAT_BYTES_PER_SECTOR:
        // get upper byte;
        bytes_per_sec = MMC_get_sec_next();
        length++;
        // assemble word
        bytes_per_sec = (bytes_per_sec << 8) + tmp;
        break;
      case FAT_SEC_PER_CLUS:
        sec_per_clus = tmp;
        break;
      case FAT_RSVD_SEC_CNT:
        // get upper byte;
        rsvd_sec_cnt = MMC_get_sec_next();
        length++;
        // assemble word
        rsvd_sec_cnt = (rsvd_sec_cnt << 8) + tmp;
        break;
      case FAT_NUM_FATS:
        num_fats = tmp;
        break;
      case FAT_TOTSEC:
        // get second byte;
        tot_secl = MMC_get_sec_next();
        length++;
        // assemble word
        tot_secl = (tot_secl << 8) + tmp;

        // get byte 3 and 4
        tmp = MMC_get_sec_next();
        length++;
        // get second byte;
        tot_sech = MMC_get_sec_next();
        length++;
        // assemble word
        tot_sech = (tot_sech << 8) + tmp;
        break;
      case FAT_SIZE:
        // get second byte;
        fat_sizel = MMC_get_sec_next();
        length++;
        // assemble word
        fat_sizel = (fat_sizel << 8) + tmp;

        // get byte 3 and 4
        tmp = MMC_get_sec_next();
        length++;
        // get second byte;
        fat_sizeh = MMC_get_sec_next();
        length++;
        // assemble word
        fat_sizeh = (fat_sizeh << 8) + tmp;
        break;
      case FAT_ROOT_CLUS:
        // get second byte;
        root_clusl = MMC_get_sec_next();
        length++;
        // assemble word
        root_clusl = (root_clusl << 8) + tmp;

        // get byte 3 and 4
        tmp = MMC_get_sec_next();
        length++;
        // get second byte;
        root_clush = MMC_get_sec_next();
        length++;
        // assemble word
        root_clush = (root_clush << 8) + tmp;
        break;
    };
    length++;
  };
  MMC_get_sec_stop();
};

// calc cluster to sectors
// by multiplying them with sec_per_clus
void cluster_to_sector(u16 *hiword, u16 *loword)
{ switch(sec_per_clus)
  { case 2:
      *hiword = ((*hiword)<<1) + ((*loword)>>15);
      *loword = ((*loword)<<1);
      return;
    case 4:
      *hiword = ((*hiword)<<2) + ((*loword)>>14);
      *loword = ((*loword)<<2);
      return;
    case 8:
      *hiword = ((*hiword)<<3) + ((*loword)>>13);
      *loword = ((*loword)<<3);
      return;
    case 16:
      *hiword = ((*hiword)<<4) + ((*loword)>>12);
      *loword = ((*loword)<<4);
      return;
    case 32:
      *hiword = ((*hiword)<<5) + ((*loword)>>11);
      *loword = ((*loword)<<5);
      return;
    case 64:
      *hiword = ((*hiword)<<6) + ((*loword)>>10);
      *loword = ((*loword)<<6);
      return;
    case 128:
      *hiword = ((*hiword)<<7) + ((*loword)>>9);
      *loword = ((*loword)<<7);
      return;
  }
}

// this function gets the addr in the data region for the next cluster of a file
void FAT_get_next_clus_addr(u16* clusterh, u16* clusterl)
{ // determine the sector that we need to read and which dword defines our  next cluster address
  u16 myh = *clusterh;
  u16 myl = *clusterl;
  u16 myoffset = *clusterl;

  // turn clusters into byte address
  myoffset = myoffset & 0x7f;
  myl = (myl >> 7) + ((myh & 0x7f) << 9);
  myh = myh >> 7;

  myl += first_fat_sector;
  if(myl < first_fat_sector) myh++;

  // get the data
  MMC_get_part_sec_start(myh, myl, myoffset << 2 ,4);
  *clusterl = MMC_get_sec_next();
  *clusterl += (MMC_get_sec_next() << 8);
  *clusterh = MMC_get_sec_next();
  *clusterh += (MMC_get_sec_next() << 8);

  // fine
  MMC_get_sec_stop();
};




void fat_init(void);

//
// 1.) reads the MBR
//     gets start sector of first partition
// 2.) verifies start sector
// 3.) get BPB
// 4.) find fat start
// 5.) start reading fat


void FAT_startup(void)
{ u08 i;

  // 1.) read MBR
  if(FAT_read_mbr() != FAT_OK)
  { // some error occured
    return;
  }

  // 2.) read BPB
  FAT_read_first_part_sector();

  // 3.) find fat start
  first_fat_sector = first_part_sector + rsvd_sec_cnt;
  first_data_sectorl = first_fat_sector + (num_fats * fat_sizel) - root_clusl*sec_per_clus;


  for(i=0; i<8; i++)
  { volume_id[i] = 'X';
  };

#ifdef LFN_SUPPORT
  for(i=0; i < (LFN_MAX_BLOCK*12)+1; i++)
  { lfn_tmp[i]=0x00;
  };
#endif

  fat_init();
  return;
};



/*------------------ FAT LAYER --------------*/



// compares a 11 byte block from the fat table with a 8 byte name and 3 byte extension.
// '*' is supported as a wildcard
bool fat_cmp_names(u08 *from_fat, u08 *name, u08 *extension)
{ u08 count = 0;
  for(;count < 8; count++)
  { if(name[count] == '*')
    { count = 100;
    }
    else
    { if(name[count] != from_fat[count])
        return false;
    };
  };

  if(extension)
  { for(count=0; count < 3; count++)
    { if(extension[count] =='*')
      { count = 100;
      }
      else
      { if(extension[count] != from_fat[8+count])
          return false;
      };
    };
  };
  return true;
};

// setup all the data needed by file i/o. gets called by FAT_startup
void fat_init(void)
{ directory.dir_currenth = root_clush;
  directory.dir_currentl = root_clusl;
};

// takes a 32 byte long fat entry and opens the file contained within
void fat_load_file_ptr(u08 *fat_entry, FILE *stream)
{ u08 i;
  stream->file_first_clusterl = (((u16)fat_entry[27])<<8) + (u16)fat_entry[26];
  stream->file_first_clusterh = (((u16)fat_entry[21])<<8) + (u16)fat_entry[20];

  stream->file_current_clusterl = stream->file_first_clusterl;
  stream->file_current_clusterh = stream->file_first_clusterh;
  stream->file_current_sector   = 0;

  stream->file_full_sizel = stream->file_sizel = (((u16)fat_entry[29])<<8) + fat_entry[28];
  stream->file_full_sizeh = stream->file_sizeh = (((u16)fat_entry[31])<<8) + fat_entry[30];

  stream->file_offset = 0x00;
  for(i=0; i<11; i++)
  { stream->name[i] = fat_entry[i];
  };

#ifdef LFN_SUPPORT
  stream->lfn_name[0] = 0x00;
  strcpy(stream->lfn_name, lfn_tmp);
#endif

};

// takes a 32 byte long fat entry and opens the dir contained within
void fat_load_dir_ptr(u08 *fat_entry, DIR *stream)
{ // get the dirposition
  stream->dir_currentl = (((u16)fat_entry[27])<<8) + fat_entry[26];
  stream->dir_currenth = (((u16)fat_entry[21])<<8) + fat_entry[20];

};


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久国产精品韩国三级视频| 成人午夜视频网站| 亚洲精品视频在线观看网站| 国产亚洲欧美一级| 国产亚洲成av人在线观看导航| 精品免费视频.| 欧美va亚洲va国产综合| 日韩一级高清毛片| 久久久久久电影| 国产精品久久毛片a| 亚洲成av人片观看| 麻豆国产91在线播放| 国产成人精品一区二区三区四区| 国产69精品久久777的优势| 91视视频在线直接观看在线看网页在线看 | 久久久久久久久99精品| 中文字幕免费一区| 国产一区二区导航在线播放| 91小视频免费看| 国产一区二区三区美女| 在线观看视频一区| 久久久99精品久久| 亚洲电影在线播放| eeuss鲁一区二区三区| 日韩欧美一区电影| 亚洲另类在线视频| 国产一区二区在线影院| 国产一二精品视频| 欧美一区二区三区在线| 国产精品国产三级国产普通话三级| 午夜久久久影院| 色国产综合视频| 国产精品成人免费在线| 久久99热99| 欧美精品一区二区三区四区 | 久久99精品久久久久久国产越南 | 五月激情六月综合| 色综合久久88色综合天天免费| 久久新电视剧免费观看| 麻豆成人久久精品二区三区小说| 欧美日韩精品电影| 亚洲尤物视频在线| 欧美日韩日本视频| 日韩经典一区二区| 日韩欧美国产三级| 国产精品亚洲专一区二区三区 | 免费观看在线色综合| 欧美日韩不卡在线| 激情都市一区二区| 久久久久久久精| 99这里只有久久精品视频| 亚洲色欲色欲www在线观看| 色综合色综合色综合色综合色综合| 亚洲欧美视频一区| 91精品国产美女浴室洗澡无遮挡| 秋霞av亚洲一区二区三| 国产人久久人人人人爽| 99精品国产99久久久久久白柏| 亚洲一区二区三区三| 日韩三级视频在线看| av电影天堂一区二区在线观看| 一区二区三区蜜桃| 久久精品在这里| 欧美午夜电影网| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 7777精品伊人久久久大香线蕉 | 日韩丝袜情趣美女图片| 国产白丝精品91爽爽久久| 亚洲黄色在线视频| 中国av一区二区三区| 欧美精品v日韩精品v韩国精品v| 国产麻豆精品一区二区| 日韩电影在线一区二区| 一区二区三区美女| 中文在线免费一区三区高中清不卡| 欧美日韩亚洲高清一区二区| 大尺度一区二区| 国产成人在线免费| 精品一区二区三区免费观看| 日本在线观看不卡视频| 亚洲自拍偷拍欧美| 一级精品视频在线观看宜春院| 日本一二三不卡| 国产精品天天看| 精品国产不卡一区二区三区| 精品精品国产高清a毛片牛牛| 欧美高清性hdvideosex| 欧美视频精品在线| 欧美一区二区三区色| 日韩午夜av一区| 久久亚洲一区二区三区四区| 91精品国产高清一区二区三区蜜臀| 欧美视频精品在线观看| 欧美精品黑人性xxxx| 欧美精品粉嫩高潮一区二区| 欧美一级免费大片| 精品国产sm最大网站免费看| 国产人久久人人人人爽| 综合久久综合久久| 亚洲va中文字幕| 国产精品一线二线三线| 成人免费毛片高清视频| 欧美视频一二三区| 精品国产a毛片| 一区二区三区国产精品| 天天色天天爱天天射综合| 国产精品一二三区在线| 欧洲一区在线观看| 久久精品男人天堂av| 亚洲国产视频直播| 成人一区在线观看| 欧美成人精品二区三区99精品| 国产肉丝袜一区二区| 日本欧美大码aⅴ在线播放| 成人激情校园春色| 精品乱码亚洲一区二区不卡| 亚洲精品视频在线观看免费| 久久精品国内一区二区三区| 欧洲亚洲国产日韩| 亚洲视频电影在线| 成人蜜臀av电影| 欧美激情在线免费观看| 精品一区二区三区蜜桃| 91精品国产综合久久国产大片| 国产精品久久久久久久裸模| 国产成人综合亚洲91猫咪| 精品理论电影在线观看| 精品一区二区精品| 欧美tk丨vk视频| 日本v片在线高清不卡在线观看| 欧美在线综合视频| 亚洲一二三四区不卡| 色综合一区二区| 一区二区三区四区av| 日本韩国欧美在线| 亚洲一区二区欧美| 91精品国产免费久久综合| 久热成人在线视频| 国产欧美精品一区| 99免费精品在线观看| 亚洲欧美日韩人成在线播放| 91香蕉视频黄| 日本亚洲免费观看| 国产午夜精品一区二区三区视频| 成熟亚洲日本毛茸茸凸凹| 亚洲人成网站在线| 欧美一区二区三区日韩视频| 国产另类ts人妖一区二区| 国产精品欧美久久久久一区二区| 色悠久久久久综合欧美99| 天天综合天天综合色| 中文字幕av一区二区三区免费看| 在线观看国产一区二区| 国产成人午夜精品影院观看视频| 一区二区三区在线不卡| 欧美精品一区二区三区高清aⅴ| 成人精品一区二区三区中文字幕| 午夜天堂影视香蕉久久| 一区二区三区四区不卡在线 | 日产国产欧美视频一区精品| 国产色产综合产在线视频| 色网站国产精品| 成人av午夜电影| 蜜桃久久久久久久| 亚洲国产aⅴ天堂久久| 欧美激情综合网| 久久精品欧美日韩| 亚洲精品一线二线三线无人区| 欧美午夜电影网| 欧美优质美女网站| 色综合天天综合网国产成人综合天| 加勒比av一区二区| 久久国产精品一区二区| 婷婷成人激情在线网| 亚洲一区二区美女| 亚洲永久免费av| 一区二区高清免费观看影视大全| 亚洲欧美区自拍先锋| 轻轻草成人在线| 男人的天堂亚洲一区| 欧美国产日韩在线观看| 欧美日韩大陆在线| 成人妖精视频yjsp地址| 麻豆91免费看| 亚洲日本韩国一区| 亚洲一区二区三区在线看| 亚洲午夜在线视频| 精品美女被调教视频大全网站| 91浏览器入口在线观看| 色哟哟一区二区| 777欧美精品| 日韩精品中文字幕一区二区三区| 欧美tk—视频vk| 国产精品美女久久福利网站| 亚洲欧美偷拍另类a∨色屁股| 洋洋成人永久网站入口| 九九精品视频在线看| 成人午夜看片网址| 欧美人妖巨大在线| 欧美丰满嫩嫩电影|