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

📄 fat.h

📁 该软件为在sunplus的61单片机上实现的mp3播放器.里面有完整的源代码.
💻 H
字号:
#ifndef	__FAT_h__
#define	__FAT_h__
/*H**************************************************************************
* 文件名:       filename.h         
*----------------------------------------------------------------------------
* 版权          (c) 2004 TGE.
*----------------------------------------------------------------------------
* 释放:         Spce061A      
* 版本:         1.13     
*----------------------------------------------------------------------------
* 目的:
* 
*****************************************************************************/

/*_____    包括     ________________________________________________________*/

/*_____    宏       ________________________________________________________*/
/*_____ I N C L U D E S ____________________________________________________*/


/*_____ M A C R O S ________________________________________________________*/

/*----- FAT Configuration -----*/
#define FAT_PARTITIONNED  TRUE              /* TRUE: format with 1 partition, 
                                               FALSE: without partition */

#define READ              0
#define WRITE             1

#define FREE_CLUSTER      (0x0000)  /* free cluster value in FAT */
#define LAST_CLUSTER12    (0x0FFF)  /* last file cluster in FAT 12 */
#define BAD_CLUSTER12     (0x0FF7)  /* bad cluster value in FAT 12 */
#define LAST_CLUSTER16    (0xFFFF)  /* last file cluster in FAT 16 */
#define BAD_CLUSTER16     (0xFFF7)  /* bad cluster value in FAT 16  */

#define MBR_ADDRESS       (0)       /* Master Boot Record address */
#define ATTR_FILE         (0x00)      /* Normal File Attribute */
#define ATTR_READ_ONLY    (0x01)      /* Read Only File Attribute */
#define ATTR_HIDDEN       (0x02)      /* Hidden File Attribute */
#define ATTR_SYSTEM       (0x04)      /* System File Attribute */
#define ATTR_DIRECTORY    (0x10)      /* Directory Attribute */
#define ATTR_ARCHIVE      (0x20)      /* Archive Attribute */
#define ATTR_LFN_ENTRY    (0x0F)      /* LFN entry attribute */
#define ATTR_ROOT_DIR     (0x90)      /* internal use only */

#define PARTITION_ACTIVE  (0x80)      /* the active partition state */

#define FILE_NOT_EXIST    (0x00)      /* current file does not exist */
#define FILE_DELETED      (0xE5)      /* current file is deleted */

#define LFN_SEQ_MASK      (0x3F)      /* LFN sequence number mask */

#define ODD_EVEN_MASK     (0x01)      /* the odd / even test mask */

#define FAT12             (0x01)      /* FAT12 type */
#define FAT16_INF32M      (0x04)      /* FAT16 type < 32 Mbytes */
#define FAT16_SUP32M      (0x06)      /* FAT16 type > 32 Mbytes */
#define FAT32             (0x0B)      /* FAT32 type not supported */
#define MAX_CLUSTERS12    (4084)    /* FAT12 if < FAT16 else */
#define MAX_CLUSTERS16    (65524)   /* FAT16 if < FAT32 else */

/* Format Info */
#define SECTOR_SIZE       (512)     /* supported sector size */
#define DIR_SIZE          (32)        /* directory entry size */
#define NB_ROOT_ENTRY     (unsigned int) (512)
#define NB_RESERVED       (1)         /* number of reserved sectors */
#define NB_FATS           (2)
#define HARD_DISK         (0xF8)      /* hard disk device */
#define FAT_DRIVE_NUMBER  (0x81)
#define FAT_EXT_SIGN      (0x29)
#define BR_SIGNATURE      (0xAA55)  /* boot record signature */
#define MBR_ADDRESS       (0)       /* master boot record address */


#define FORMAT_NB_CYLINDER            500	//(*tab).nb_cylinder
#define FORMAT_NB_HEAD                8		//(*tab).nb_head
#define FORMAT_NB_SECTOR              16	//(*tab).nb_sector
#define FORMAT_NB_HIDDEN_SECTOR       (unsigned long int) 51//	47//(*tab).nb_hidden_sector
#define FORMAT_NB_SECTOR_PER_CLUSTER  32	//(*tab).nb_sector_per_cluster

// Address Define
#define MBR_ADDR		0x0000
#define HIDDEN_ADDR		(MBR_ADDR + SECTOR_SIZE)
#define DBR_ADDR		(MBR_ADDR + SECTOR_SIZE * FORMAT_NB_HIDDEN_SECTOR)
#define FAT1_ADDR		(DBR_ADDR + SECTOR_SIZE)
#define FAT2_ADDR		(FAT1_ADDR+ nb_sector_fat * SECTOR_SIZE)
#define ROOT_DIR_ADDR	(0x8000)
#define DATA_ADDR		(0xC000)

/* FAT definition */
/* For LFN name, the name will be build with MAX_LFN_ENTRIES entries        */
/* That means tha the max file name length is                               */
/* 12 + (MAX_LFN_ENTRIES - 1 ) * 13                                         */
/* Size in pdata zone is 256 bytes.                                         */
/* gl_buffer use 32 bytes in pdata                                          */
/* We need 15 bytes for scrolling display                                   */
/* Maximum size for LFN name is 256 - 32 - 15 = 209 bytes                   */
/* And so MAX_LFN_ENTRIES = (209 - 12) / 13 + 1 = 16                        */
/* And size of LFN string is                                                */
/* MAX_FILENAME_LEN = 12 + (MAX_LFN_ENTRIES - 1) * 13 + 15 + 1 + 1          */
/*                                                           |   |          */
/*                                  +1 because we start at 0 -   |          */
/*                                  +1 for '\0' character    -----          */

/* maximum number of LFN entries */
#define MAX_LFN_ENTRIES   (16)       
/* maximum file name length      */
#define MAX_FILENAME_LEN  ((12 + (MAX_LFN_ENTRIES - 1) * 13 + 15 + 1 + 1))      

#define MAX_FILE_FRAGMENT_NUMBER (150)/* maximum number of authorized
                                            /* fragment for a file          */
#define MAX_DIR_FRAGMENT_NUMBER (5)   /* maximum number of authorized
                                            /* fragment for a directory     */
#define MAX_DIRECTORY_FILE (512)    /* maximum number of file in    */
                                            /* a directory                  */
//#define MAX_DIRECTORY_GAP_FILE ((Uint16)(65535))
#define MAX_DIRECTORY_GAP_FILE ((255))
                                            /* maximum delta between 2      */
                                            /* specified entries            */
                                            /* Can be replace 255 or 65535  */
                                            /* case of type used for        */
                                            /* fat_directory_chain          */

#define DEL_RET_OK                        (0)
#define DEL_RET_NO_MORE_FILE              (1)
#define DEL_RET_ERROR_DIR                 (2)

/*Definition of the Read/Write Structure For Dir Entry 
*/
typedef struct {
	unsigned char FileName[8];
	unsigned char ExtName[3];
	unsigned char attribute;
	unsigned char reserved[10];
	unsigned char time[2];
	unsigned char data[2];
	unsigned char StartClus[2];
	unsigned char FileLength[4];
} DIR_ENTRY;

/* MP3 Audio Header Define
*/
typedef union{
    struct _MPEG_HEADER {
	unsigned long int emphasis:2;    
	unsigned long int original:1;    
	unsigned long int copyright:1;    
	unsigned long int mode_extension:2;    
	unsigned long int mode:2;	
	unsigned long int private_bit:1;
	unsigned long int padding_bit:1;
	unsigned long int sampling_frequency:2;
	unsigned long int bitrate_index:4;	
	unsigned long int protection_bit:1;		
	unsigned long int layer:2;	
	unsigned long int ID:1;		
	unsigned long int syncword:12;
}	mpegHead;
	unsigned long int u32;
} 	MPEG_HEADER;

/* Definition of the control structure for streams
*/
typedef struct  {
	unsigned int StartClus;
	unsigned int CurrentClus;
	unsigned int NextClus;
	unsigned long FileLen;
	unsigned long FileCount;
} FILE;
	
/*_____    声明     ________________________________________________________*/
/*File Manage Function
*/
unsigned int FAT_FileReWind();
unsigned int FAT_FileFindNext(unsigned int *pch);
unsigned int FAT_FileFindPrev(unsigned int *pch);

/*File Control Function 
*/
unsigned int FAT_Open(unsigned int *pch);
void FAT_Close();

/*File Read/Write Function
*/
void FAT_Putc(unsigned char ch);
unsigned int FAT_Getc();
void FAT_WriteSector();
unsigned int FAT_ReadSector();

/*File Operation Function
*/
void FAT_ReWind(FILE *fp);

/*File Check Function
*/
unsigned int FAT_Eof();

void	FormatFAT16(void);		
void 	BlockRead();
	
#endif

⌨️ 快捷键说明

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