?? 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 + -