📄 fat.h
字号:
/**
* @file $RCSfile: fat.h,v $
*
* Copyright (c) 2006 XXXXX INC., All Rights Reserved
*
* @author YongJian Guo <XXX@XXX>
*
* @version $Revision: 1.2.0.00 $
* @date $Date: 2006/10/13 06:46:18 $
* @update $Date: 2007/01/24 14:06:17 $
* $Header: $
**/
#ifndef __FATFS_H__
#define _FS_MINIMIZE 0
/* The _FS_MINIMIZE defines minimization level to remove some functions.
/ 0: Not minimized.
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod and f_rename are removed.
/ 2: f_opendir and f_readdir are removed in addition to level 1. */
#define _USE_SJIS
/* When _USE_SJIS is defined, Shift-JIS code transparency is enabled, otherwise
/ only US-ASCII(7bit) code can be accepted as file/directory name. */
#define _FOLDER_OP
#include "sdshare.h"
/* Result type for fatfs application interface */
/* File system object structure */
typedef struct _FATFS {
uint8 fs_type; /* FAT type */
uint8 files; /* Number of files currently opend */
uint8 sects_clust; /* Sectors per cluster */
uint8 n_fats; /* Number of FAT copies */
uint16 n_rootdir; /* Number of root directory entry */
uint8 winflag; /* win[] dirty flag (1:must be written back) */
uint8 pad1;
uint32 winsect; /* Current sector appearing in the win[] */
uint32 sects_fat; /* Sectors per fat */
uint32 max_clust; /* Maximum cluster# + 1 */
uint32 fatbase; /* FAT start sector */
uint32 dirbase; /* Root directory start sector (cluster# for FAT32) */
uint32 database; /* Data start sector */
uint32 last_clust; /* Last allocated cluster */
uint8 win[512]; /* Disk access window for Directory/FAT */
} FATFS;
/* Directory object structure */
typedef struct _DIR {
uint32 sclust; /* Start cluster */
uint32 clust; /* Current cluster */
uint32 sect; /* Current sector */
uint16 index; /* Current index */
} DIR;
/* File object structure */
typedef struct _FIL {
uint32 fptr; /* File R/W pointer */
uint32 fsize; /* File size */
uint32 org_clust; /* File start cluster */
uint32 curr_clust; /* Current cluster */
uint32 curr_sect; /* Current sector */
uint32 dir_sect; /* Sector containing the directory entry */
uint8* dir_ptr; /* Ponter to the directory entry in the window */
uint8 flag; /* File status flags */
uint8 sect_clust; /* Left sectors in cluster */
uint8 buffer[512]; /* File R/W buffer */
BOOL isused; /* used flag */
} FIL;
/* File status structure */
typedef struct _FILINFO {
uint32 fsize; /* Size */
uint16 fdate; /* Date */
uint16 ftime; /* Time */
uint8 fattrib; /* Attribute */
sint8 fname[8+1+3+1]; /* Name (8.3 format) */
} FILINFO;
/*-----------------------------------------------------*/
/* FatFs module application interface */
extern FATFS *FatFs; /* Pointer to active file system object */
uint16 f_open (FIL*, const sint8*, uint8); /* Open or create a file */
uint16 f_read (FIL*, void*, uint16, uint16*); /* Read file */
uint16 f_close (FIL*); /* Close file */
uint16 f_lseek (FIL*, uint32); /* Seek file pointer */
uint16 f_opendir (DIR*, const sint8*); /* Open a directory */
uint16 f_readdir (DIR*, FILINFO*); /* Read a directory item */
uint16 f_stat (const sint8*, FILINFO*); /* Get file status */
uint16 f_getfree (uint32*); /* Get number of free clusters */
uint16 f_mountdrv (void); /* Force initialized the file system */
uint16 f_write (FIL*, const void*, uint16, uint16*); /* Write file */
uint16 f_sync (FIL*); /* Flush cached data of a writing file */
uint16 f_unlink (const sint8*); /* Delete a file or directory */
uint16 f_mkdir (const sint8*); /* Create a directory */
uint16 f_chmod (const sint8*, uint8, uint8); /* Change file attriburte */
uint16 f_rename (const sint8*, const sint8*); /* Rename a file or directory */
uint16 f_formatfat16(void); /* format sd Card */
/* User defined function to give a current time to fatfs module */
uint32 get_fattime(void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
/* File function return code (uint16) */
#define FR_OK EC_SUCCESS
#define FR_NOT_READY EC_SD_NOT_READY
#define FR_NO_FILE EC_NO_FILE
#define FR_NO_PATH EC_NO_PATH
#define FR_INVALID_NAME EC_INVALID_NAME
#define FR_DENIED EC_DENIED
#define FR_DISK_FULL EC_SD_FULL
#define FR_RW_ERROR EC_RW_ERROR
#define FR_INCORRECT_DISK_CHANGE EC_SD_CHANGE
#define FR_WRITE_PROTECTED EC_SD_WRITE_PROTECTED
#define FR_NOT_ENABLED EC_SD_NOT_ENABLED
#define FR_NO_FILESYSTEM EC_INVALID_FILE_SYSTEM
/* File access control and file status flags (FIL.flag) */
#define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#define FA_WRITE 0x02
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA__WRITTEN 0x20
#define FA__DIRTY 0x40
#define FA__ERROR 0x80
/* FAT type signature (FATFS.fs_type) */
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
/* File attribute bits for directory entry */
#define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */
#define AM_VOL 0x08 /* Volume label */
#define AM_LFN 0x0F /* LFN entry */
#define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */
/* Multi-byte word access macros */
#ifdef _BYTE_ACC
#define LD_WORD(ptr) (uint16)(((uint16)*(uint8*)((ptr)+1)<<8)|(uint16)*(uint8*)(ptr))
#define LD_DWORD(ptr) (uint32)(((uint32)*(uint8*)((ptr)+3)<<24)|((uint32)*(uint8*)((ptr)+2)<<16)|((uint16)*(uint8*)((ptr)+1)<<8)|*(uint8*)(ptr))
#define ST_WORD(ptr,val) *(uint8*)(ptr)=(uint8)(val); *(uint8*)((ptr)+1)=(uint8)((uint16)(val)>>8)
#define ST_DWORD(ptr,val) *(uint8*)(ptr)=(uint8)(val); *(uint8*)((ptr)+1)=(uint8)((uint16)(val)>>8); *(uint8*)((ptr)+2)=(uint8)((uint32)(val)>>16); *(uint8*)((ptr)+3)=(uint8)((uint32)(val)>>24)
#else
#define LDN_WORD(ptr) (uint16)(*(near uint16*)(uint8*)(ptr))
#define LDN_DWORD(ptr) (uint32)(*(near uint32*)(uint8*)(ptr))
#define LDF_WORD(ptr) (uint16)(*(far uint16*)(ptr))
#define LDF_DWORD(ptr) (uint32)(*(far uint32*)(ptr))
#define ST_WORD(ptr,val) *(uint16*)(uint8*)(ptr)=(uint16)(val)
#define ST_DWORD(ptr,val) *(uint32*)(uint8*)(ptr)=(uint32)(val)
#endif
#define __FATFS_H__
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -