📄 fat16.c
字号:
#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 DEBUG_FAT 1
//#define FAT_SIZEOFWORD 8*256
#define FAT_SIZEOFWORD 478*256
//请注意每个扇区实际为528个字节,最后还有16个字节
/*
BYTE SectorBuffer[512]=
{
0xeb,0x3c,0x90,0x4d,0x53,0x44,0x4f,0x53,0x35,0x2e,0x30,0x0,0x2,0x8,0x2,0x0,
0x2,0x0,0x2,0x0,0x0,0xf8,0xef,0x0,0x3f,0x0,0xff,0x0,0x0,0x0,0x0,0x0,
0x0,0x78,0x7,0x0,0x0,0x0,0x29,0xb2,0x9d,0x40,0xa8,0x4e,0x4f,0x20,0x4e,0x41,
0x4d,0x45,0x20,0x20,0x20,0x20,0x46,0x41,0x54,0x31,0x36,0x20,0x20,0x20,0x33,0xc9,
0x8e,0xd1,0xbc,0xf0,0x7b,0x8e,0xd9,0xb8,0x0,0x20,0x8e,0xc0,0xfc,0xbd,0x0,0x7c,
0x38,0x4e,0x24,0x7d,0x24,0x8b,0xc1,0x99,0xe8,0x3c,0x1,0x72,0x1c,0x83,0xeb,0x3a,
0x66,0xa1,0x1c,0x7c,0x26,0x66,0x3b,0x7,0x26,0x8a,0x57,0xfc,0x75,0x6,0x80,0xca,
0x2,0x88,0x56,0x2,0x80,0xc3,0x10,0x73,0xeb,0x33,0xc9,0x8a,0x46,0x10,0x98,0xf7,
0x66,0x16,0x3,0x46,0x1c,0x13,0x56,0x1e,0x3,0x46,0xe,0x13,0xd1,0x8b,0x76,0x11,
0x60,0x89,0x46,0xfc,0x89,0x56,0xfe,0xb8,0x20,0x0,0xf7,0xe6,0x8b,0x5e,0xb,0x3,
0xc3,0x48,0xf7,0xf3,0x1,0x46,0xfc,0x11,0x4e,0xfe,0x61,0xbf,0x0,0x0,0xe8,0xe6,
0x0,0x72,0x39,0x26,0x38,0x2d,0x74,0x17,0x60,0xb1,0xb,0xbe,0xa1,0x7d,0xf3,0xa6,
0x61,0x74,0x32,0x4e,0x74,0x9,0x83,0xc7,0x20,0x3b,0xfb,0x72,0xe6,0xeb,0xdc,0xa0,
0xfb,0x7d,0xb4,0x7d,0x8b,0xf0,0xac,0x98,0x40,0x74,0xc,0x48,0x74,0x13,0xb4,0xe,
0xbb,0x7,0x0,0xcd,0x10,0xeb,0xef,0xa0,0xfd,0x7d,0xeb,0xe6,0xa0,0xfc,0x7d,0xeb,
0xe1,0xcd,0x16,0xcd,0x19,0x26,0x8b,0x55,0x1a,0x52,0xb0,0x1,0xbb,0x0,0x0,0xe8,
0x3b,0x0,0x72,0xe8,0x5b,0x8a,0x56,0x24,0xbe,0xb,0x7c,0x8b,0xfc,0xc7,0x46,0xf0,
0x3d,0x7d,0xc7,0x46,0xf4,0x29,0x7d,0x8c,0xd9,0x89,0x4e,0xf2,0x89,0x4e,0xf6,0xc6,
0x6,0x96,0x7d,0xcb,0xea,0x3,0x0,0x0,0x20,0xf,0xb6,0xc8,0x66,0x8b,0x46,0xf8,
0x66,0x3,0x46,0x1c,0x66,0x8b,0xd0,0x66,0xc1,0xea,0x10,0xeb,0x5e,0xf,0xb6,0xc8,
0x4a,0x4a,0x8a,0x46,0xd,0x32,0xe4,0xf7,0xe2,0x3,0x46,0xfc,0x13,0x56,0xfe,0xeb,
0x4a,0x52,0x50,0x6,0x53,0x6a,0x1,0x6a,0x10,0x91,0x8b,0x46,0x18,0x96,0x92,0x33,
0xd2,0xf7,0xf6,0x91,0xf7,0xf6,0x42,0x87,0xca,0xf7,0x76,0x1a,0x8a,0xf2,0x8a,0xe8,
0xc0,0xcc,0x2,0xa,0xcc,0xb8,0x1,0x2,0x80,0x7e,0x2,0xe,0x75,0x4,0xb4,0x42,
0x8b,0xf4,0x8a,0x56,0x24,0xcd,0x13,0x61,0x61,0x72,0xb,0x40,0x75,0x1,0x42,0x3,
0x5e,0xb,0x49,0x75,0x6,0xf8,0xc3,0x41,0xbb,0x0,0x0,0x60,0x66,0x6a,0x0,0xeb,
0xb0,0x4e,0x54,0x4c,0x44,0x52,0x20,0x20,0x20,0x20,0x20,0x20,0xd,0xa,0x52,0x65,
0x6d,0x6f,0x76,0x65,0x20,0x64,0x69,0x73,0x6b,0x73,0x20,0x6f,0x72,0x20,0x6f,0x74,
0x68,0x65,0x72,0x20,0x6d,0x65,0x64,0x69,0x61,0x2e,0xff,0xd,0xa,0x44,0x69,0x73,
0x6b,0x20,0x65,0x72,0x72,0x6f,0x72,0xff,0xd,0xa,0x50,0x72,0x65,0x73,0x73,0x20,
0x61,0x6e,0x79,0x20,0x6b,0x65,0x79,0x20,0x74,0x6f,0x20,0x72,0x65,0x73,0x74,0x61,
0x72,0x74,0xd,0xa,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xac,0xcb,0xd8,0x55,0xaa
}; //SectorBuffer
*/
BYTE SectorBuffer[512]; //SectorBuffer
//BYTE SectorSpare[16];//Nandflash的备用区,防止sectorbuffer与clusterbuffer冲突
BYTE ClusterBuffer[512][512];//ClusterBuffer
WORD FatCache[FAT_SIZEOFWORD];//FAT区的内容备份区,FAT_SIZEOFWORD为FAT空间大小
BYTE Read_Cluster_Buffer[8][512]; //文件读取时的簇缓存
unsigned char ReadBuffer1[2500][512];//读缓存1 大小1600k 1.56M
unsigned char ReadBuffer2[8][512];//读缓存2 大小500k
unsigned char FileName_All[100][11];
unsigned char FileName_Select[12]={'\\'};
int m,n,init_done=0;
int buffer_add;
//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);
extern BYTE SD_ReadBlock(unsigned int blockaddr, char *recbuf);
//--------------该函数用于将磁盘格式化----------------------------//
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)))
if(!(SD_EraseBlock_00(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->bpbHugeSectors = 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]);
temp=SD_WriteBlock1(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);
SD_ReadBlock1(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;//每个FAT占用扇区数
FirstDataSector = FirstDirSector+((bpb->bpbRootDirEnts)>>4);//第一个数据扇区
RootDirCount = bpb->bpbRootDirEnts;
RootDirSectors = (RootDirCount*32)>>9;
#ifdef DEBUG_FAT
Uart_Printf("\n厂商标志和OS版本号 : %s",(char *)(bootsector->bsOemName));
//Uart_Printf("\nFirst sector : %4x",PartInfo.prStartLBA);
//Uart_Printf("\nSize : %4x",PartInfo.prSize);
Uart_Printf("\n每扇区字节数 : %4d",bpb->bpbBytesPerSec);
Uart_Printf("\n每族扇区数 : %4d",bpb->bpbSecPerClust);
Uart_Printf("\n保留扇区数 : %4d",bpb->bpbResSectors);
Uart_Printf("\n根目录项数 : %4d",bpb->bpbRootDirEnts);
//Uart_Printf("\n存储卷上的扇区总数 : %4d",bpb->bpbSectors);
Uart_Printf("\n存储卷上的扇区总数 : %4d",bpb->bpbHugeSectors);
Uart_Printf("\n每个FAT的扇区数 : %4d",bpb->bpbFATsecs);
//Uart_Printf("\nBigFatSectors : %4x",bpb->bpbBigFATsecs);
Uart_Printf("\nFAT表的份数 : %4d",bpb->bpbFATs);
Uart_Printf("\nFAT区的起始扇区数 : %4d",FirstFATSector);
Uart_Printf("\n根目录表起始扇区数 : %4d",FirstDirSector);
Uart_Printf("\n数据起始扇区数 : %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++) //作FAT区的内容拷贝
{
//ReadPage(0,i+1,SectorBuffer);
SD_ReadBlock1(0,i+2,SectorBuffer);//这里+2为+保留扇区
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;
int Select_music;
char buff[]="fangajfdklsafjasfa;lfs;l";
char buff1[]="hzlitai elec. CO.,Ltd.";
if(1) //fat_format(NAND_FLASH_Drv,DISK_16M,PART_TYPE_FAT16))
{
if(!init_done) //只执行一次fatInit
{
fatInit();
init_done=1;
}
//result=fat_mkdir("\\ABCDE");
//x = fat_creat("\\ABCDE\\CZM1933.TXT", 0x20);//0x20:txt file?
//Uart_Printf("\nfat_creat's file handle=%d",x);
//fat_write(x, buff, 24);//将buff中10个字节内容写入文件x
//fat_write(x, buff1, 22);
//fat_lseek(x, 0, SEEK_SET);
//memset(buff, 0, sizeof(buff));
//Uart_Printf("\nfat_read buff=");
Uart_Printf("\nPlease select the num of music to play!\n");
FlieList("ALL");
Select_music = Uart_GetIntNum();
memcpy(FileName_Select+1, FileName_All[Select_music], 11);
Uart_Printf("Reading music to RAM now!\n");
x=fat_open( (char*) &FileName_Select );//返回的值,即x表示文件的句柄号,既handles数组中的第几个句柄
fat_read2(x);
Uart_Printf("Read OK and Playing...\n");
for(i=0;i<1000;i++);
//while(1);
/*
fat_read(x, buff, 30);
for(i=0;i<30;i++)
Uart_Printf("%c",buff[i]);
fat_close(x);
x=fat_open("\\ABCDE\\CZM1933.txt");
Uart_Printf("\nfat_open's result=%d",x);
Uart_Printf("\nfat_read buff=");
fat_read(x, buff, 15);
for(i=0;i<15;i++)
Uart_Printf("%c",buff[i]);
fat_close(x);
result=fat_rename("\\ABCDE\\CZM1933.txt", "CZM1933.txt");
Uart_Printf("\nfat_rename's result=%d",x);
x=fat_open("\\ABCDE\\CZM1933.txt");
Uart_Printf("\nfat_open's result=%d",result);
Uart_Printf("\nfat_read buff=",result);
fat_read(x, buff, 20);
for(i=0;i<20;i++)
Uart_Printf("%c",buff[i]);
result=fat_remove("\\ABCDE\\CZM1933.txt");
Uart_Printf("\nfat_remove's result=%d",result);
x=fat_open("\\ABCDE\\CZM1933.txt");
Uart_Printf("\nfat_open's result=%d",x);
//result=fat_rename("\\abcde\\", "abcd12");
//Uart_Printf("\nfat_rename's result=%d",result);
result=fat_rmdir("\\abcde");
Uart_Printf("\nfat_rmdir's result=%d\n",result);
*/
}
}
void FlushFAT()//更新重写FAT1和FAT2的内容
{
int i,j;
//ReadPage(0,0,SectorBuffer);
SD_ReadBlock1(0,0,SectorBuffer);//读扇区0+备份,写时连扇区0一起写
memcpy(ClusterBuffer[0], SectorBuffer, BytesPerSector); //backup Sector0
for(i=FirstDirSector;i<SectorsPerCluster;i++)//暂不知啥意思
{
//ReadPage(0,i,SectorBuffer);
SD_ReadBlock1(0,i,SectorBuffer);
memcpy(ClusterBuffer[i],SectorBuffer,BytesPerSector);
}
for(i=0;i<FATsectors;i++)//备份FAT1,把已经更新过的整个FAT表,备份到ClusterBuffer
{ //FatCache已被更新过,0--FAT表所占扇区数 间循环 (0-239)
for(j=0;j<256;j++)
{
SectorBuffer[j*2]=(FatCache[i*256+j])%256;
SectorBuffer[j*2+1]=(FatCache[i*256+j])>>8;
}
memcpy(ClusterBuffer[i+FirstFATSector],SectorBuffer,BytesPerSector);
}
for(i=0;i<FATsectors;i++)//备份FAT2,backup FAT field
{
for(j=0;j<256;j++)
{
SectorBuffer[j*2]=(FatCache[i*256+j])%256;
SectorBuffer[j*2+1]=(FatCache[i*256+j])>>8;
}
memcpy(ClusterBuffer[i+FirstFATSector+FATsectors],SectorBuffer,BytesPerSector);
}
//Erase_Cluster(0);
SD_EraseBlock_00(0);//写入之前,擦除当前簇;现在只擦除0簇,后面的暂时没擦除
for(i=0;i<SectorsPerCluster;i++)//一扇区接一扇区写入,现在只写0簇,后面的暂时没写
{
for(j=0;j<255;j++);//延时
//WritePage(0,i,ClusterBuffer[i]);
SD_WriteBlock1(0,i,ClusterBuffer[i]);
}
}
//The sector number of the first sector of that cluster.
//FirstSectorofCluster = ((N – 2) * BPB_SecPerClus) + FirstDataSector;
//Because No MBR,so: clust-1!
unsigned long FirstSectorofCluster(unsigned long clust)//数据存放的cluster转为sector
{
return ((clust-1) * SectorsPerCluster + FirstDataSector);
}
// alloc a free cluster. policy is searching from prev cluster number, if no free cluster till end of fat, then search from head of fat.
// return a cluster number. 0xffff indicate faild, disk overflow.
// argument 0 : no prev cluster.
WORD AllocCluster(WORD PrevClusterNum)//查找空簇,找到后填写0xFFFF,后重写FAT表
{ //返回没用到的空簇
static WORD LastAllocClusterNum=0;
WORD i;
if(LastAllocClusterNum == 0)
LastAllocClusterNum = PrevClusterNum;
for(i = LastAllocClusterNum; i < BytesPerSector * FATsectors / sizeof(WORD); i++)
{
if(FatCache[i] == 0)//如果此簇为空簇,FatCache为FAT区的内容备份区,在fatInit时被写入信息
{
FatCache[i] = 0xffff; //填写0xFFFF,占用此簇,并且说明这是最后一簇 flag with 0xffff, this is the last cluster.
LastAllocClusterNum = i;
//chain this cluster to prev one.
if(PrevClusterNum != 0)
FatCache[PrevClusterNum] = LastAllocClusterNum;
FlushFAT();//更新FAT表
return LastAllocClusterNum;//返回簇号
}
}
// we have to search from head of fat //这里暂时没运行,待以后分析
for(i = 2; i < BytesPerSector * FATsectors / sizeof(WORD); i++)
{
if(FatCache[i] == 0)
{
FatCache[i] = 0xffff; // flag with 0xffff, this is the last cluster.
LastAllocClusterNum = i;
//chain this cluster to prev one.
if(PrevClusterNum != 0)
FatCache[PrevClusterNum] = LastAllocClusterNum;
//FlushFAT();//更新FAT表
return LastAllocClusterNum;
}
}
return 0xffff;
}
//return next cluster num,
//0xffff indicate no next cluster.
//Note! : this function will dirty cache!
WORD GetNextClusterNum(WORD ClusterNum)
{
return FatCache[ClusterNum];
}
// free cluster chain.此函数应当是用于依次释放fat链时
// argument 0 : no prev cluster.
void FreeCluster(WORD StartClusterNum)//何时更新disk中的FAT表?
{
WORD Cluster;
WORD NextCluster;
Cluster = StartClusterNum;
while(Cluster != 0xffff)
{
NextCluster = FatCache[Cluster];
FatCache[Cluster] = 0x0000;
Cluster = NextCluster;
}
//FlushFAT();//更新FAT表
}
DWORD CurrentCacheSector;
//Read a special sector into disk cache.
//NULL indicate failed.
BYTE* GetSectorData(DWORD StartSector)//LBA取得一个扇区的数据
{ //数据放在SectorBuffer数组中
unsigned int block;
unsigned int page;
//if((CurrentCacheSector == StartSector) && (StartSector != 0))
// return SectorBuffer;
block=StartSector/0x08;
page=StartSector%0x08;
//ReadPage(block,page,SectorBuffer);
SD_ReadBlock1(block,page,SectorBuffer);
CurrentCacheSector = StartSector;
return SectorBuffer;
}
void Flush() //烧写,内容在SectorBuffer中
{
//memcpy(&((BYTE*)MemDisk)[CurrentCacheSector * Bpb.BytsPerSec], SectorCache, 512);
int i,j;
unsigned int block;
unsigned int page;
block=CurrentCacheSector/0x08;//由上一次调用GetSectorData时的参数StartSector计算簇数
page =CurrentCacheSector%0x08;//计算扇区数
memcpy(ClusterBuffer[page],SectorBuffer, BytesPerSector);
if(page==0)
{
for(i=1;i<SectorsPerCluster;i++)//循环一簇,读取每扇区数据,保存到缓存
{
//ReadPage(block,i,SectorBuffer);
SD_ReadBlock1(block,i,SectorBuffer);
memcpy(ClusterBuffer[i], SectorBuffer, BytesPerSector);
}
}
else
{
for(i=0;i<page-1;i++)
{
//ReadPage(block,i,SectorBuffer);
SD_ReadBlock1(block,i,SectorBuffer);
memcpy(ClusterBuffer[i], SectorBuffer, BytesPerSector);
}
for(i=page+1;i< SectorsPerCluster;i++)
{
//ReadPage(block,i,SectorBuffer);
SD_ReadBlock1(block,i,SectorBuffer);
memcpy(ClusterBuffer[i], SectorBuffer, BytesPerSector);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -