⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat16.h

📁 在s3c44b0下利用SD卡进行WAV文件(FAT16格式)播放的源程序
💻 H
📖 第 1 页 / 共 2 页
字号:
         WORD    bpbResSectors;  // 保留区域中的保留扇区数  // number of reserved sectors
         BYTE    bpbFATs;        // FAT表的份数  // number of FATs
         WORD    bpbRootDirEnts; // 根目录项数   // number of root directory entries
         WORD    bpbSectors;     // 此域为存储卷上的扇区总数  // total number of sectors
         BYTE    bpbMedia;       // 固定存储介质描述  // media descriptor
         WORD    bpbFATsecs;     // FAT表所占的扇区数  // number of sectors per FAT
         WORD    bpbSecPerTrack; // 每道扇区数  // sectors per track
         WORD    bpbHeads;       // 磁头数  // number of heads
         DWORD   bpbHiddenSecs;  // 隐藏扇区数  // # of hidden sectors
 // 3.3 compat ends here
         DWORD   bpbHugeSectors; // 总扇区数  // # of sectors if bpbSectors == 0
 // 5.0 compat ends here
         DWORD     bpbBigFATsecs;// 每个FAT区所占扇区数  // like bpbFATsecs for FAT32
         WORD      bpbExtFlags;  // 扩展标志  // extended flags:
 #define FATNUM    0xf           // mask for numbering active FAT
 #define FATMIRROR 0x80          // FAT is mirrored (like it always was)
         WORD      bpbFSVers;    // 文件系统版本  // filesystem version
 #define FSVERS    0             // currently only 0 is understood
         DWORD     bpbRootClust; // 根目录簇号  // start cluster for root directory
         WORD      bpbFSInfo;    // 文件系统信息扇区号  // filesystem info structure sector
         WORD      bpbBackup;    // 备份引导扇区  // backup boot sector
         // There is a 12 byte filler here, but we ignore it
 }BPB710;
 


// 目录或文件入口地址结构
// Structure of a dos directory entry.
typedef __packed struct
{
         BYTE        deName[8];      // 文件名  // filename, blank filled
 #define SLOT_EMPTY      0x00        // 目录项为空    // slot has never been used
 #define SLOT_E5         0x05                         // the real value is 0xe5
 #define SLOT_DELETED    0xe5        // 文件已被删除    // file in this slot deleted
 #define IS_DIR          0x2e            // this is directory
         char        deExtension[3]; // 扩展名  // extension, blank filled
         BYTE        deAttributes;   // 文件属性  // file attributes
 #define ATTR_NORMAL     0x00        // 读写    // normal file
 #define ATTR_READONLY   0x01        // 只读    // file is readonly
 #define ATTR_HIDDEN     0x02        // 隐藏    // file is hidden
 #define ATTR_SYSTEM     0x04        // 系统文件    // file is a system file
 #define ATTR_VOLUME     0x08        // 卷标文件    // entry is a volume label
 #define ATTR_LONG_FILENAME  0x0f    // 长文件名文件    // this is a long filename entry                
 #define ATTR_DIRECTORY  0x10        // 子目录文件    // entry is a directory name
 #define ATTR_ARCHIVE    0x20        // 归档文件    // file is new or modified
         BYTE        deLowerCase;   // 系统保留    // NT VFAT lower case flags
 #define LCASE_BASE      0x08            // filename base in lower case
 #define LCASE_EXT       0x10            // filename extension in lower case
         BYTE        CrtTimeTenth;   // 文件创建时间的10MS  // hundredth of seconds in CTime
         WORD        CrtTime;        // 文件创建时间  // create time
         WORD        CrtDate;        // 文件创建日期  // create date
         WORD        LstAccDate;     // 文件最近访问日期  // access date
         WORD        FstClusHI;      // 文件起始簇号的高16位  // high bytes of cluster number
         WORD        WrtTime;        // 文件最近修改时间  // last update time
         WORD        WrtDate;        // 文件最近修改日期  // last update date
         WORD        deStartCluster; // 文件起始簇号的低16位  // starting cluster of file
         DWORD       deFileSize;     // 文件长度  // size of file in bytes
}DIRENTRY;



// 长文件名入口地址结构
// Structure of a Win95 long name directory entry
 typedef __packed struct  //没用到
 {
         BYTE        weCnt;
 #define WIN_LAST        0x40
 #define WIN_CNT         0x3f
         BYTE        wePart1[10];
         BYTE        weAttributes;
 #define ATTR_WIN95      0x0f
         BYTE        weReserved1;
         BYTE        weChksum;
         BYTE        wePart2[12];
         WORD        weReserved2;
         BYTE        wePart3[4];
 }WINENTRY;	
 
 // This is the format of the contents of the deTime field in the direntry
 // structure.
 // We don't use bitfields because we don't know how compilers for
 // arbitrary machines will lay them out.
 // 目录或文件入口地址结构中的时间结构
 #define DT_2SECONDS_MASK        0x1F    // 秒  // seconds divided by 2
 #define DT_2SECONDS_SHIFT       0
 #define DT_MINUTES_MASK         0x7E0   // 分  // minutes
 #define DT_MINUTES_SHIFT        5
 #define DT_HOURS_MASK           0xF800  // 时  // hours
 #define DT_HOURS_SHIFT          11
 
 // This is the format of the contents of the deDate field in the direntry
 // structure.
 // 目录或文件入口地址结构中的日期结构
 #define DD_DAY_MASK             0x1F    // 日  // day of month
 #define DD_DAY_SHIFT            0
 #define DD_MONTH_MASK           0x1E0   // 月  // month
 #define DD_MONTH_SHIFT          5
 #define DD_YEAR_MASK            0xFE00  // 年 - 1980  // year - 1980
 #define DD_YEAR_SHIFT           9
 
typedef __packed struct 
{
	WORD Date;
	WORD Time;
	BYTE TimeTenth;
}FatDateTime;
//
//FAT16 Apis
//

typedef __packed struct 
{
	BYTE Attr;
	BYTE CrtTimeTenth;
	WORD CrtTime;
	WORD CrtDate;
	WORD LstAccDate;
	WORD WrtTime;
	WORD WrtDate;
	DWORD FileSize;
}_STAT;

typedef __packed struct 
{
	int valid; // 1 可用, 0 空闲.表示该数据结构(文件句柄)是否可用/空闲

	DWORD DirSectorNum;//文件目录信息扇区数
	int DirIndex;//目录索引

	DWORD StartSectorNum;//文件数据起始扇区数
	DWORD CurrentSectorNum;//当前扇区数
	DWORD SectorOffset; //SectorOffset一般在数据最后才有意义,因为要读取的数据不一定都是扇区的整数倍
						//SectorOffset就是最后的零头
	DIRENTRY dir;

	unsigned long offset;
}_FILE;

typedef __packed struct 
{
	DWORD DirSectorNum;
	int DirIndex;
	int IsRootDir;
	char filename[13];
}FatGet;
 
 // Prototypes
 int fat_format(unsigned char Media,unsigned char Sizeofdisk_M,unsigned char FilesysType);
 
 unsigned char fatInit(void);
 
  
void fat16_Nandflash_test(void);
 

 

int FlieList(const char *File_Extension);
int fat_mkdir( const char *dirname );
int fat_rmdir( const char *dirname );
int fat_getfirst(const char *path, char* filename);
int fat_getnext(char* filename);

int fat_close(int handle);
int fat_creat(const char* filename, BYTE attribute);
long fat_lseek(int handle, long offset, int origin);
int fat_open(const char* filename);
unsigned int fat_read(int handle, void* buffer, unsigned int bytes);
unsigned int fat_read1(int handle, void* buffer);
unsigned int fat_read2(int handle);
unsigned int fat_write(int handle, const char* buffer, unsigned int bytes);

int fat_remove( const char *filename);
int fat_get_stat( const char *filename,  _STAT *stat);
int fat_set_stat( const char *filename,  _STAT *stat);
int fat_rename( const char *oldname, const char *newname );                                 
 
 #endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -