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

📄 fat.h

📁 mp3播放器
💻 H
字号:
#ifndef __FAT_H__
#define __FAT_H__
//***********************************************
#include "config.h"
//***********************************************
#define BUFF1             0xE000
#define BUFF2             0xF000
//***********************************************
// FAT error codes
enum FATERR
{ 
  FATERR_NO_ERROR = 0, 
  FATERR_NO_DOSFORMAT, // not FAT formatted
  FATERR_NO_FILE 
};

//Flag for searching file or subdirectory
enum SCANFLAG
{ 
  FLAG_FILE = 0, 
  FLAG_DIR 
};

//For AB repeat mode
enum ABMODEFLAG
{
 ABMODE_STOP = 0,
 ABMODE_SET_A,
 ABMODE_SET_B,
 ABMODE_START
};


//By Stephanie ~20060206
typedef struct _PEntry
{
  U8	x86Boot;
  U8 	StartHead;
  U8 	StartSector;
  U8 	StartCylinder;
  U8 	PartitionType;
  U8 	EndHead;
  U8 	EndSector;
  U8 	EndCylinder;
  U32 	LogStartSector;
  U32 	NumSectors;
}PEntry;

typedef struct _MBR
{
  U8 		BootCode[446];
  PEntry 	P1;
  PEntry  	P2;
  PEntry 	P3;
  PEntry	P4;
  U16 Signature;
} MBR;

typedef struct _BS16
{
  U8	JmpCode[3];
  U8 	OEMName[8];
  //BPB
  U16 	BytesPerSector; 
  U8 	SectorsPerCluster; 
  U16 	ReservedSectors;
  U8 	NumFATs;
  U16 	RootDirEntries;
  U16 	TotalSectors;
  U8 	MediaByte;
  U16 	FATSz16;
  U16 	SectorsPerTrack;
  U16 	NumHeads;
  U32 	HiddenSectors;
  U32 	HugeSectors;
  //end BPB
  U8 	Dummy[3];
  U8 	VolumeID[4];
  U8 	VolumeLabel[11];
  U8 	FileSysType[8];
  U8 	BootCode[448];
  U16 	Signature;
}BS16;

typedef struct _BS32
{
  U8	JmpCode[3];
  U8 	OEMName[8];
  //BPB
  U16 	BytesPerSector; 
  U8 	SectorsPerCluster; 
  U16 	ReservedSectors;
  U8 	NumFATs;
  U16 	RootDirEntries;
  U16 	TotalSectors;
  U8 	MediaByte;
  U16 	NumFATSectors;
  U16 	SectorsPerTrack;
  U16 	NumHeads;
  U32 	HiddenSectors;
  U32	HugeSectors;
  //end BPB
  U32	FATSz32;
  U16 	ExtFlags;
  U16 	FSVer;
  U32	RootClus;
  U16 	FSInfo;
  U16 	BkBootSec;
  U8 	Reserved[12];
  U8 	DrvNum;
  U8 	Resverved1;
  U8 	BootSig;
  U8 	VolumeID[4];
  U8 	VolumeLabel[11];
  U8 	FileSysType[8];
  U8 	BootCode[420];
  U16 	Signature;
}BS32;


//For file description block(FDB)
typedef struct _DIR_
{
  S8	FileName[8];
  S8 	Extension[3];
  U8 	Attribute;
  U8 	Reserved[8];
  U16 	FSClusHI;
  U16 	Time;
  U16 	Date;
  U16 	FSClusLO;
  U32 	FileSize;
}_DIR;

typedef struct _LDIR_
{ 
  U8	Ord;
  U8	Name1[10];   
  U8	Attribute; 
  U8	Type;
  U8	Chksum;
  U8	Name2[12];
  U8	FSClusLO[2];
  U8	Name3[4]; 	 
}_LDIR;

//ID3v2 header 
typedef struct _HEADER
{
  U8	ID3v2ID[3];
  U8	ID3v2Version[2];
  U8	ID3v2Flag[1]; 
  U8	ID3V2Size[4];
}HEADER;

// for MBR, BPB 
typedef struct _CFatData_
{
  //U8	fRet;				//Return error.
  U8	fFAT32;				//Flag for file system is fat32.
  U16	wBytesPerSec;		//Number of bytes per sector.
  U8	bSectorsPerClu;		//Number of sectors per cluster.
  U32	dwRootStartlba;		//The root block start lba(Sector No.).
  U32	dwRootStartCluNo;	//The root block start cluster No. 
  U32	dwFatTabStartlba;	//The fat table block start lba(Sector No.).
  U32	dwClu2Startlba;		//The cluster 2 lba(Sector No.).
  U16	wSecNumInRoot;		//Number of sectors in root.->Using for fat16. 
  U32	dwSecNumInFat;		//Number of sectors in each fat table block. 
  U8	bFDBNumInSec;		//Number of FDB in one sector. 
  U32	dwMask;				//Masking bit31-bit24 for FAT 16,bit31-bit28 for fat32.
  //U8	LBA_shift;
  //U8	fFAT12;				//Flag for file system is fat12.       
}_CFatData;
 
//For cheching fat table  
typedef struct _FatTabData
{
  //U32	dwCurCluNo;		//The current cluster NO.
  U8	bShiftBits;		//Shifting bytes.(FAT16 = 1,FAT32 = 2)
  //U32	dwFATOffset;	//Number of bytes offsetting from the fat table block.  
  //U32	dwCluNoTmp;		//Saving cluster No for finding the previous cluster NO. 
  //U32	FAT12CluTmp;
}_FATTab;
 
typedef struct _FileData_
{
  //U32	dwDirEntryCluNo;			//The current directory entry.
  //U32	dwUpDirEntryCluNo;			//The parent directory entry.
  U32	dwFileStartCluNo;			//The start cluster NO. of file.
  U32	dwFileDataSize;				//The data size of file. 
  //U32	dwFileHeaderSz;				//The size of ID3 Header.
  //U32	dwAudioStartSeclba;			//The start lba (sector NO) of audio data. 
  U32	dwMovedDataToBuffSizeCNT;	//Recording data size moved from SD to DMA buffer(NO.5&NO.6) 
  U32	dwCurCluNo;					//The current cluster NO address.
  U32	dwCurSecLba;				//The current lba(sector NO.) address. 
  U16	wCurFDBNo;					//The address of FDB offsetting from the current sector NO. 
  //U32	dwDirEntryTmp;				//For saving current directory entry cluster no. 
  //U32	Temp;
  //U8	fMPEGErr;					//Flag for MPEG 2.5
  //U16	dwUserTemp;
  //U32	FrameHeader;				//For recording the frame header of audio data.
//***********************************************
  U32	RootDirNum;					//根目录项数(FAT16: 512; FAT32: 根目录簇数)
//***********************************************
}_FileData;

//For ab repeat mode
typedef struct _ABMode_
{
  unsigned char    fABMode;                       //Flag for AB repeat mode. 
  unsigned long    PASeclba;                     //For recording the lba(sector NO) address of start point a. 
  unsigned long    StartToADataSz;               //For recording the data size from audio data start lba to start point a. 	 
  unsigned long    ABTotalDataSz;                //For recording total data size of ab mode
  unsigned long    SaveFileSz;                   //For saving original file size	

  unsigned char    ClassD_DAC_Val;                   //For saving Class D DAC_CTL register value.
  unsigned char    MP3_CTL_Val; 	                //For saving MP3_CTL register value.
}_ABMode;
 
#define LITTLE_TO_BIG_2(word, tmpByte)			\
{												\
  (tmpByte) = ((U8 *)&(word))[0];				\
  ((U8 *)&(word))[0] = ((U8 *)&(word))[1];		\
  ((U8 *)&(word))[1] = (tmpByte);				\
}

#define LITTLE_TO_BIG_4(dword, tmpByte)			\
{										        \
  (tmpByte) = ((U8 *)&(dword))[0];				\
  ((U8 *)&(dword))[0] = ((U8 *)&(dword))[3];	\
  ((U8 *)&(dword))[3] = (tmpByte);				\
  (tmpByte) = ((U8 *)&(dword))[1];				\
  ((U8 *)&(dword))[1] = ((U8 *)&(dword))[2];	\
  ((U8 *)&(dword))[2] = (tmpByte);				\
}

#define BIG_TO_LITTLE_2(word, tmpByte)		LITTLE_TO_BIG_2(word, tmpByte)
#define BIG_TO_LITTLE_4(dword, tmpByte)		LITTLE_TO_BIG_4(dword, tmpByte)

#define ENDIAN_ASSIGN_2(pDst, pSrc)				\
{												\
  ((U8 *)(pDst))[0] = ((U8 *)(pSrc))[1];		\
  ((U8 *)(pDst))[1] = ((U8 *)(pSrc))[0];		\
}

#define ENDIAN_ASSIGN_4(pDst, pSrc)				\
{												\
  ((U8 *)(pDst))[0] = ((U8 *)(pSrc))[3];		\
  ((U8 *)(pDst))[1] = ((U8 *)(pSrc))[2];		\
  ((U8 *)(pDst))[2] = ((U8 *)(pSrc))[1];		\
  ((U8 *)(pDst))[3] = ((U8 *)(pSrc))[0];		\
}
	
// FAT structures and definitions
#define FAT_End								0xFFFFFFFF//Ending of file
#define FAT_Bug								0xFFFFFFF7//fat table breakdrown.
#define DIREntrySize						0x20//Size of FAT directory entry
#define FOUND								1 
 
//For checkng the first byte of FAT directory entry   
#define DIR_Unused							0x00//The directory entry is free.
#define DIR_Deleted							0xE5//The directory entry is free.

//For checkng the 11th byte of FAT directory entry 
#define ARCHIVE_FILE						0x00//Indicates that is file according bit4 = 0.
#define ARCHIVE_DIR							0x10//Indicates that is directroy according bit4 = 1.

#define ID3V2								0x0A //Indicates that size of header.

#define ID3V1Sz								0x80 //Size of ID3v1 header.

//For file system 
//***********************************************
/************************************************
* PURPOSE: 
* FAT cluster chain structure (each index is a fragment of the file)
************************************************/
typedef struct
{
  U32 cluster;//starting cluster of fragment
  U32 number;//number of subsequent clusters in fragment
} fat_st_clust_chain;
//***********************************************
#define MAX_FILE_FRAGMENT_NUMBER		((U8)150)//maximum number of authorized fragment for a file
//***********************************************
//***********************************************

#endif  

⌨️ 快捷键说明

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