fat16test.rar

  • 雪狐2008
    了解作者
  • Visual C++
    开发工具
  • 180KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 20
    下载次数
  • 2007-12-25 15:34
    上传日期
S3C44BO的nandflash的读写与文件系统
fat16test.rar
  • fat16test
  • fat16
  • fat16.c
    43.9KB
  • fat16.H
    12.9KB
  • fat16test_Data
  • Debug
  • CWSettingsWindows.stg
    3.3KB
  • flashtest
  • FLASH.H
    1008B
  • FLASH.C
    9.8KB
  • WrRdflash.s
    621B
  • Target
  • option.h
    789B
  • option.s
    924B
  • 44blib.h
    2.1KB
  • 44blib.c
    11.4KB
  • DEF.H
    1.6KB
  • memcfg.s
    2.5KB
  • 44binit.s
    17.5KB
  • 44b.h
    15.5KB
  • 44BLIB_A.S
    871B
  • fat16test.mcp
    100.3KB
  • MAIN.C
    2.7KB
  • www.pudn.com.txt
    218B
内容介绍
#include <string.h> #include "fat16.h" #include "..\Target\44blib.h" #include "..\Target\44b.h" #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 #define DISK_32M 32 #define DISK_16M 16 #define DISK_1M 1 #define DEBUG_FAT 1 #define FAT_SIZEOFWORD 8*256 //请注意每个扇区实际为528个字节,最后还有16个字节 BYTE SectorBuffer[512]; //SectorBuffer BYTE SectorSpare[16];//Nandflash的备用区,防止sectorbuffer与clusterbuffer冲突 BYTE ClusterBuffer[32][512];//ClusterBuffer WORD FatCache[FAT_SIZEOFWORD]; //unsigned char *SectorBuffer = (unsigned char *) SECTOR_BUFFER1_ADDR;//暂放sector的512字节空间 //unsigned char *LongNameBuffer = (unsigned char *) LONGNAME_BUFFER_ADDR;//暂放长文件名的字节空间 //unsigned char *DirNameBuffer = (unsigned char *) DIRNAME_BUFFER_ADDR;//暂放路径名的字节空间 extern unsigned char Erase_Cluster(unsigned int cluster); extern void ReadPage(unsigned int block,unsigned int page,unsigned char *pPage); extern int WritePage(unsigned int block,unsigned int page,U8 *pPage); //--------------该函数用于将磁盘格式化----------------------------// int fat_format(unsigned char Media,unsigned char Sizeofdisk_M,unsigned char FilesysType) { //PARTSECTOR *partsector; //PARTRECORD *partrecord; int i,j,fatsec,temp,blocknum; BOOTSECTOR50 *bootsector; BPB50 *bpb; EXTBOOT *ext; const CHAR *litai_str="-LiTai- "; const CHAR *armsys_str="ARMSYS44B0 "; const CHAR *fat16_str="FAT16 "; blocknum=((Sizeofdisk_M<<20)>>9)>>5; /* for(i=0;i<blocknum;i++){ if(!(Erase_Cluster(i))) { Uart_Printf("\nErase Nand-flash failed!%d block,it can be omitted.",i); //return 0; } for(j=0;j<255;j++); } Uart_Printf("\nErase Nand-flash successfully!");*/ for(i=0;i<512;i++) SectorBuffer[i]=0xff; if(Media==NAND_FLASH_Drv)//对Nand-flash进行格式化 { //第0个扇区为DBR bootsector = (BOOTSECTOR50 *)SectorBuffer; bpb = (BPB50 *)(bootsector->bsBPB); ext = (EXTBOOT *)(bootsector->bsExt); bootsector->bsJump[0] = 0xeb; bootsector->bsJump[1] = 0x03; bootsector->bsJump[2] = 0x90; for(i=0;i<7;i++) bootsector->bsOemName[i] = *litai_str++; bootsector->bsOemName[7]='\0'; bootsector->bsBootSectSig0 = BOOTSIG0; bootsector->bsBootSectSig1 = BOOTSIG1; bpb->bpbBytesPerSec = 512; bpb->bpbSecPerClust = 32; if(FilesysType==PART_TYPE_FAT12||FilesysType==PART_TYPE_DOSFAT16 ||FilesysType==PART_TYPE_FAT16||FilesysType==PART_TYPE_FAT16LBA) bpb->bpbResSectors = 1; else if(FilesysType==PART_TYPE_FAT32||FilesysType==PART_TYPE_FAT32LBA) bpb->bpbResSectors = 32; bpb->bpbFATs = 2; bpb->bpbRootDirEnts = ((bpb->bpbSecPerClust)-1-(Sizeofdisk_M >> 1)) << 4; bpb->bpbSectors = Sizeofdisk_M << 11; bpb->bpbMedia = 0xf0;//必须与FAT[0]一致。 fatsec = bpb->bpbFATsecs = Sizeofdisk_M >> 2; bpb->bpbSecPerTrack = 0; bpb->bpbHeads = 0; bpb->bpbHiddenSecs = 0; bpb->bpbHugeSectors = Sizeofdisk_M << 11; ext->exDriveNumber = 0x80; ext->exReserved1 = 0; ext->exBootSignature = EXBOOTSIG; ext->exVolumeID = 0x88331446; for(i=0;i<10;i++) ext->exVolumeLabel[i] = *armsys_str++; ext->exVolumeLabel[10]='\0'; for(i=0;i<7;i++) ext->exFileSysType[i] = *fat16_str++; ext->exFileSysType[8]='\0'; memcpy(ClusterBuffer[0],SectorBuffer,512); //第1个扇区开始是FAT及FAT备份区 for(i=0;i<512;i++) SectorBuffer[i]=0x00; for(i=1;i<(fatsec*2+1);i++) memcpy(ClusterBuffer[i],SectorBuffer,512); ClusterBuffer[1][0]=0xf0;//0xf8? ClusterBuffer[1][1]=0xff; ClusterBuffer[1][2]=0xff; ClusterBuffer[1][3]=0xff; ClusterBuffer[fatsec+1][0]=0xf0;//0xf8? ClusterBuffer[fatsec+1][1]=0xff; ClusterBuffer[fatsec+1][2]=0xff; ClusterBuffer[fatsec+1][3]=0xff; //从第fatsec*2+1个扇区开始,是根目录区,到簇的最后,应该清零 for(i=fatsec*2+1;i<32;i++) memcpy(ClusterBuffer[i],SectorBuffer,512); for(i=0;i<32;i++)//一扇区接一扇区写入 { for(j=0;j<255;j++);//延时 temp=WritePage(0,i,ClusterBuffer[i]); if(temp==0) { Uart_Printf("\nFormat Nand-flash failed!"); return 0; } } Uart_Printf("\nFormat Nand-flash Successfully!\n"); return 1; } return 0; } //PARTRECORD PartInfo; unsigned char Fat32Enabled; unsigned int FirstDataSector; unsigned int BytesPerSector; unsigned int FATsectors; unsigned int SectorsPerCluster; unsigned int FirstFATSector; unsigned int FirstDirSector; unsigned int FileSize; unsigned int FatInCache = 0; DWORD RootDirSectors; // Numbers of sectors occupied by Root Directory. DWORD RootDirCount; //--------------该函数主要用于从已有的存储介质中获得文件系统信息------------------// unsigned char fatInit(void) { BOOTSECTOR50 *bootsector; BPB50 *bpb; EXTBOOT *ext; int i,j; for(j=0;j<255;j++); ReadPage(0,0,SectorBuffer); bootsector = (BOOTSECTOR50 *)SectorBuffer; bpb = (BPB50 *)(bootsector->bsBPB); ext = (EXTBOOT *)(bootsector->bsExt); // setup global disk constants FirstDataSector = 0;//PartInfo.prStartLBA; if(bpb->bpbFATsecs) { // bpbFATsecs is non-zero and is therefore valid FirstDirSector = bpb->bpbResSectors + bpb->bpbFATs * bpb->bpbFATsecs; //FAT12,16 =1 =2(2份FAT,其中1份为备份)×每一份FAT所占用的sector数 } SectorsPerCluster = bpb->bpbSecPerClust;//每cluster的sector数目 BytesPerSector = bpb->bpbBytesPerSec;//每sector的字节数 FirstFATSector = bpb->bpbResSectors + 0;//PartInfo.prStartLBA;//FAT区的起始地址 FATsectors = bpb->bpbFATsecs; FirstDataSector = FirstDirSector+((bpb->bpbRootDirEnts)>>4); RootDirCount = bpb->bpbRootDirEnts; RootDirSectors = (RootDirCount*32)>>9; #ifdef DEBUG_FAT Uart_Printf("\nOEM name : %s",(char *)(bootsector->bsOemName)); //Uart_Printf("\nFirst sector : %4x",PartInfo.prStartLBA); //Uart_Printf("\nSize : %4x",PartInfo.prSize); Uart_Printf("\nbytes per sector : %4d",bpb->bpbBytesPerSec); Uart_Printf("\nsectors per cluster : %4d",bpb->bpbSecPerClust); Uart_Printf("\nreserved sectors: %4d",bpb->bpbResSectors); Uart_Printf("\nRootDir Entrys : %4d",bpb->bpbRootDirEnts); Uart_Printf("\nTolSectors : %4d",bpb->bpbSectors); Uart_Printf("\nFatSectors : %4d",bpb->bpbFATsecs); //Uart_Printf("\nBigFatSectors : %4x",bpb->bpbBigFATsecs); Uart_Printf("\nNumber of Fats : %4d",bpb->bpbFATs); Uart_Printf("\nFirst Fat Sector: %4d",FirstFATSector); Uart_Printf("\nFirst Dir sector: %4d",FirstDirSector); Uart_Printf("\nFirst Data Sect : %4d",FirstDataSector); //Uart_Printf("\nVolNumber : %x",(unsigned int)(ext->exVolumeID)); Uart_Printf("\nVolumeLabel : %s\n",(char *)(ext->exVolumeLabel)); #endif for(i=0;i<FATsectors;i++) { ReadPage(0,i+1,SectorBuffer); for(j=0;j<256;j++) { FatCache[i*256+j] = SectorBuffer[j*2] + (SectorBuffer[j*2+1] << 8); } } return 0; } //一个测试程序 void fat16_Nandflash_test(void) { int x,result,i; char buff[]="fangajfdklsafjasfa;lfs;l"; char buff1[]="hzlitai elec. CO.,Ltd."; if(fat_format(NAND_FLASH_Drv,DISK_16M,PART_TYPE_FAT16)) { fatInit(); result=fat_mkdir("\\abcde"); x = fat_creat("\\abcde\\fang123.txt", 0x27);//0x27:txt file? //Uart_Printf("\nfat_creat's file handle=%d",x); fat_write(x, buff, 20);//将buff中10个字节内容写入文件x fat_write(x, buff1, 10); fat_lseek(x, 0, SEEK_SET); memset(buff, 0, sizeof(buff)); Uar
评论
    相关推荐
    • flash播放器
      flash播放器(flash7,8,9)
    • Flash广告
      Flash广告,有需要的朋友可以下载
    • flashbanner
      flash的banner图片变换效果,js和flash文件都在里面 ,直接看test页面中的代码就会用
    • flashbanner
      这里有10款FLASH BANNER条,对FLASH初学者,有一定的帮助。
    • 小青蛙FLash
      flash小青蛙找妈妈的素材,同时有池塘背景,可以用来作为课件使用
    • Flash 制作
      Flash实现多啦机器猫案例,简单易学。适用于初学Flash的同学参考 里面有完整的制作步骤
    • flash播放器
      flash播放器,支持拖放文件播放,支持换肤,是你播放flash文件的最佳选择!
    • flash
      教你怎么用flash画画
    • FLASH
      Flash反编译器(Flash Decompiler).rar
    • flash
      flash与图片结合