资源简介
#include
#include "FAT16.h"
#include "sd.h"
//------------------------------------------------------------------------
#define SEC_Size 512
#define MBR_Sector 0 //绝对地址
#define FAT_Sector 0 //逻辑地址
//-------------------------------------------------------------------------
uint8_t BUFFER[SEC_Size];
uint8_t PB_RelativeSector;
uint16_t BPB_BytesPerSec;
uint8_t BPB_SecPerClus;
uint16_t BPB_RsvdSecCnt;
uint8_t BPB_NumFATs;
uint16_t BPB_RootEntCnt;
uint16_t BPB_TotSec16;
代码片段和文件信息
//-------------------------------------------------------------------------
/*FAT16.C - LINO TECH
Designed by Carter
2008-03-19
*/
#include
#include “FAT16.h“
#include “sd.h“
//------------------------------------------------------------------------
#define SEC_Size 512
#define MBR_Sector 0 //绝对地址
#define FAT_Sector 0 //逻辑地址
//-------------------------------------------------------------------------
uint8_t BUFFER[SEC_Size];
uint8_t PB_RelativeSector;
uint16_t BPB_BytesPerSec;
uint8_t BPB_SecPerClus;
uint16_t BPB_RsvdSecCnt;
uint8_t BPB_NumFATs;
uint16_t BPB_RootEntCnt;
uint16_t BPB_TotSec16;
uint16_t BPB_FATSz16; //FAT占用的sectors
uint32_t BPB_HiddSec;
//-------------------------------------------------------------------------
uint8_t ReadSector(uint32_t sector uint8_t* buffer )
{
int8 stat;
hwInterface sdNow;
sdNow.sectorCount = 1;
stat = sd_readSector(&sdNowsectorbuffer512);
if(stat==0)
{
return SD_SUCC;
}
else
{
return SD_FAIL;
};
}
uint8_t WriteSector(uint32_t sector uint8_t* buffer)
{
hwInterface sdNow;
sdNow.sectorCount = 1;
sd_writeSector(&sdNowsectorbuffer);
return 0;
}
uint8_t ReadBlock(uint32_t LBA){ //绝对地址读一个扇区
if(ReadSector(LBABUFFER)!=0)return SD_FAIL;
return SD_SUCC;
}
//-------------------------------------------------------------------------
uint8_t WriteBlock(uint32_t LBA){ //绝对地址写一个扇区
if(WriteSector(LBABUFFER)!=0)return SD_FAIL;
return SD_SUCC;
}
//-------------------------------------------------------------------------
uint8_t ReadFatBlock(uint32_t Add){ //逻辑地址读一个扇区
// return ReadBlock(Add+PB_RelativeSector); //for HardDisk
return ReadBlock(Add+BPB_HiddSec);
}
//-------------------------------------------------------------------------
uint8_t WriteFatBlock(uint32_t Add){ //逻辑地址写一个扇区
// return WriteBlock(Add+PB_RelativeSector); //for HardDisk
return WriteBlock(Add+BPB_HiddSec);
}
//-------------------------------------------------------------------------
void CopyBytes(uint8_t *psuint8_t *pduint16_t size){ //内存拷贝
for(;size;size--)*pd++=*ps++;
}
//-------------------------------------------------------------------------
uint8_t IsEqual(uint8_t *pauint8_t *pbuint8_t size){ //内存比较
for(;size;size--)if(*pa++!=*pb++)return 0;
return 1;
}
//-------------------------------------------------------------------------
void EmptyBytes(uint8_t *pduint16_t size){ //内存清空
for(;size;size--)*pd++ =0;
}
//-------------------------------------------------------------------------
uint8_t ReadMBR(void){ //读取MBR数据结构
uint8_t ok;
FAT_MBR * MBR=(FAT_MBR*)BUFFER;
ok=ReadBlock(MBR_Sector);
if(ok==SD_FAIL)return SD_FAIL;
if(MBR->MBR_Signature!=0xAA55)return SD_FAIL; //读有效标志
//获取参数
PB_RelativeSector=MBR->MBR_pb[0].PB_RelativeSector;//读逻辑地址与绝对地址的偏移
return SD_SUCC;
}
- 上一篇:传智播客云计算高手班第三期
- 下一篇:一种新颖的三相SPWM技术
评论
共有 条评论