📄 file_sys.h
字号:
#define _FF_free free
#endif
enum {NO_ERR=0, INIT_ERR, FILE_ERR, WRITE_ERR, READ_ERR, NAME_ERR, READONLY_ERR,
SOF_ERR, EOF_ERR, ALLOC_ERR, POS_ERR, MODE_ERR, FAT_ERR, DISK_FULL,
PATH_ERR, NO_ENTRY_AVAL, EXIST_ERR, INV_BOOTSEC_ERR, INV_PARTTABLE_ERR,
INV_PARTENTRY_ERR};
enum {CLOSED = 0, READ, WRITE, APPEND};
enum {SCAN_DIR_R, SCAN_DIR_W, SCAN_FILE_R, SCAN_FILE_W};
enum {CHAIN_R, CHAIN_W, SINGLE, START_CHAIN, END_CHAIN};
enum {SEEK_CUR, SEEK_END, SEEK_SET};
#ifdef _DEBUG_FUNCTIONS_
#define _DEBUG_SCANDIR_
#define _DEBUG_C2A_
#define _DEBUG_A2C_
#define _DEBUG_NEXTCLUS_
#define _DEBUG_PREVCLUS_
#define _DEBUG_WRITE_CLUSTER_TABLE_
#define _DEBUG_APPRNDTOC_
#define _DEBUG_MKDIR_
#define _DEBUG_CHDIR_
#define _DEBUG_FF_CHDIR_
#define _DEBUG_FOPEN_
#define _DEBUG_FCREATE_
#define _DEBUG_FFLUSH_
/*#define _DEBUG_FPUTC_*/
#define _DEBUG_STREAM_START_
#endif
#ifndef _BIG_ENDIAN_
#define CREATE_DATE_VLAUE 0x0021
#else
#define CREATE_DATE_VLAUE 0x2100
#endif
/****************************************************************************
**
** TYPEDEFS AND STRUCTURES
**
****************************************************************************/
/* 32 byte structure */
typedef struct
{
int8 name_entry[11];
uint8 attr;
uint8 reserved;
uint8 crt_tenth_sec;
#if !defined (_BIG_ENDIAN_)
uint16 crt_time;
uint16 crt_date;
uint16 acc_date;
uint16 start_clus_hi;
uint16 mod_time;
uint16 mod_date;
uint16 start_clus_lo;
uint32 file_size;
#else
HiLo16Union crt_time;
HiLo16Union crt_date;
HiLo16Union acc_date;
uint16 start_clus_hi;
HiLo16Union mod_time;
HiLo16Union mod_date;
HiLo16Union start_clus_lo;
HiLo32Union file_size;
#endif
} FileDirEntryStruct;
/* 552 bytes (+4 overhead using malloc) ==> 556 bytes required per file opened */
typedef struct
{
uint16 clus_start; /* Starting cluster of open file */
uint16 clus_current; /* Current cluster of open file */
uint16 clus_next; /* Next (reading) cluster of open file */
uint16 clus_prev; /* Previous cluster of open file */
uint8 sec_offset; /* Current sector withing current cluster */
uint32 entry_sec_addr; /* Sector address of File entry of open file */
FileDirEntryStruct *file_dep; /* Entry Pointer to the offset of the File Info */
#ifndef _NO_FILE_DATA_BUFFER_
uint8 buff[512]; /* Open file read/write buffer */
#endif
uint32 length; /* Length of file */
uint32 position; /* Current position in file relative to begining */
uint8 mode; /* 0=>closed, 1=>open for read, 2=>open for write, 3=> open for append */
uint8 error; /* Error indicator */
uint8 EOF_flag; /* End of File Flag */
uint8 *pntr; /* Pointer for file data use */
#ifdef _NO_MALLOC_
uint8 used_flag; /* Flag to see if the file is used or not */
#endif
} FileStruct;
#endif /*_FILE_SYS_INCLUDED*/
/****************************************************************************
**
** EXPORTED VARIABLES
**
****************************************************************************/
#ifndef _FILE_SYS_C_SRC
extern flash int8 _FF_VERSION_[];
#ifdef _RTC_ON_
extern int8 RTCHour, RTCMin, RTCSec;
extern int8 RTCDay, RTCMonth;
extern int16 RTCYear;
#endif
#ifdef _NO_MALLOC_
extern FILE _FF_FileSpaceAllocation[_FF_MAX_FILES_OPEN];
#endif
#endif /*_FILE_SYS_C_SRC*/
/****************************************************************************
**
** EXPORTED FUNCTIONS
**
****************************************************************************/
int8 ascii_to_char(int8 ascii_char);
int8 valid_file_char(int8 file_char);
#ifdef _DEBUG_ON_
void read_directory(void);
#ifndef _NO_FILE_DATA_BUFFER_
void dump_file_data_hex(FILE *rp);
void dump_file_data_view(FILE *rp);
#endif
void dump_buff_data_hex(void);
void dump_file_entry_hex(FileDirEntryStruct *dep);
#endif
void GetVolID(void);
#ifndef _READ_ONLY_
int16 fquickformat(void);
FILE *fcreate(int8 *fname, uint8 fmode);
int16 remove(int8 *fname);
int16 rename(int8 *name_old, int8 *name_new);
#ifdef _DIRECTORIES_SUPPORTED_
int16 mkdir(int8 *f_path);
int16 rmdir(int8 *f_path);
#endif
int16 ungetc(uint8 file_data, FILE *rp);
int16 fwrite(void *wr_buff, int16 dat_size, int16 num_items, FILE *rp);
int16 fputs(int8 *file_data, FILE *rp);
#if defined(_CVAVR_) || defined(_ICCAVR_) || defined(_ROWLEY_CWAVR_)
FILE *fcreatec(flash int8 *fname, uint8 fmode);
int16 removec(flash int8 *fname);
int16 fputsc(flash int8 *file_data, FILE *rp);
void fprintf(FILE *rp, flash int8 *pstr, ...);
#elif defined(IAR_EWAVR_)
FILE *fcreatec(PGM_P fname, uint8 fmode);
int16 removec(PGM_P fname);
int16 fputsc(PGM_P file_data, FILE *rp);
void fprintf(FILE *rp, PGM_P pstr, ...);
#endif
int16 fputc_(uint8 file_data, FILE *rp);
int16 fflush(FILE *rp);
#endif
#if defined(_CVAVR_) || defined(_ICCAVR_) || defined(_ROWLEY_CWAVR_)
FILE *fopenc(flash int8 *fname, uint8 MODEC);
#elif defined(IAR_EWAVR_)
FILE *fopenc(PGM_P fname, uint8 MODEC);
#endif
FILE *fopen(int8 *fname, uint8 fmode);
int16 fclose(FILE *rp);
int16 ffreemem(FILE *rp);
#ifdef _DIRECTORIES_SUPPORTED_
#if defined(_CVAVR_) || defined(_ICCAVR_) || defined(_ROWLEY_CWAVR_)
int16 chdirc(flash int8 *f_path);
#elif defined(IAR_EWAVR_)
int16 chdirc(PGM_P f_path);
#endif
int16 chdir(int8 *f_path);
int8 _FF_chdir(int8 *f_path);
#endif
int16 fget_file_info(int8 *fname, uint32 *fsize, int8 *create_date,
int8 *mod_date, uint8 *attribute, uint16 *fclus);
#if defined(_CVAVR_) || defined(_ICCAVR_) || defined(_ROWLEY_CWAVR_)
int16 fget_file_infoc(flash int8 *fname, uint32 *fsize, int8 *create_date,
int8 *mod_date, uint8 *attribute, uint16 *fclus);
#elif defined(IAR_EWAVR_)
int16 fget_file_infoc(PGM_P fname, uint32 *fsize, int8 *create_date,
int8 *mod_date, uint8 *attribute, uint16 *fclus);
#endif
int16 fgetc_(FILE *rp);
int16 fread(void *rd_buff, int16 dat_size, int16 num_items, FILE *rp);
int8 *fgets(int8 *buffer, int16 n, FILE *rp);
int16 fend(FILE *rp);
int16 fseek(FILE *rp, int32 off_set, uint8 fmode);
uint32 ftell(FILE *rp);
int16 feof(FILE *rp);
#if defined(_SD_MMC_MEDIA_)
#if defined(_CVAVR_) || defined(_ICCAVR_) || defined(_ROWLEY_CWAVR_)
int16 fstream_filec(flash int8 *fname, uint32 fsize);
#elif defined(_IAR_EWAVR_)
int16 fstream_filec(PGM_P fname, uint32 fsize);
#endif
int16 fstream_file(int8 *fname, uint32 fsize);
#endif
/****************************************************************************
**
** EOF
**
****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -