Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1 /*---------------------------------------------------------------------------/
marcozecchini 0:9fca2b23d0ba 2 / FatFs - FAT file system module include R0.11a (C)ChaN, 2015
marcozecchini 0:9fca2b23d0ba 3 /----------------------------------------------------------------------------/
marcozecchini 0:9fca2b23d0ba 4 / FatFs module is a free software that opened under license policy of
marcozecchini 0:9fca2b23d0ba 5 / following conditions.
marcozecchini 0:9fca2b23d0ba 6 /
marcozecchini 0:9fca2b23d0ba 7 / Copyright (C) 2015, ChaN, all right reserved.
marcozecchini 0:9fca2b23d0ba 8 /
marcozecchini 0:9fca2b23d0ba 9 / 1. Redistributions of source code must retain the above copyright notice,
marcozecchini 0:9fca2b23d0ba 10 / this condition and the following disclaimer.
marcozecchini 0:9fca2b23d0ba 11 /
marcozecchini 0:9fca2b23d0ba 12 / This software is provided by the copyright holder and contributors "AS IS"
marcozecchini 0:9fca2b23d0ba 13 / and any warranties related to this software are DISCLAIMED.
marcozecchini 0:9fca2b23d0ba 14 / The copyright owner or contributors be NOT LIABLE for any damages caused
marcozecchini 0:9fca2b23d0ba 15 / by use of this software.
marcozecchini 0:9fca2b23d0ba 16 /---------------------------------------------------------------------------*/
marcozecchini 0:9fca2b23d0ba 17
marcozecchini 0:9fca2b23d0ba 18
marcozecchini 0:9fca2b23d0ba 19 #ifndef _FATFS
marcozecchini 0:9fca2b23d0ba 20 #define _FATFS 64180 /* Revision ID */
marcozecchini 0:9fca2b23d0ba 21
marcozecchini 0:9fca2b23d0ba 22 #ifdef __cplusplus
marcozecchini 0:9fca2b23d0ba 23 extern "C" {
marcozecchini 0:9fca2b23d0ba 24 #endif
marcozecchini 0:9fca2b23d0ba 25
marcozecchini 0:9fca2b23d0ba 26 #include "integer.h" /* Basic integer types */
marcozecchini 0:9fca2b23d0ba 27 #include "ffconf.h" /* FatFs configuration options */
marcozecchini 0:9fca2b23d0ba 28 #if _FATFS != _FFCONF
marcozecchini 0:9fca2b23d0ba 29 #error Wrong configuration file (ffconf.h).
marcozecchini 0:9fca2b23d0ba 30 #endif
marcozecchini 0:9fca2b23d0ba 31
marcozecchini 0:9fca2b23d0ba 32
marcozecchini 0:9fca2b23d0ba 33
marcozecchini 0:9fca2b23d0ba 34 /* Definitions of volume management */
marcozecchini 0:9fca2b23d0ba 35
marcozecchini 0:9fca2b23d0ba 36 #if _MULTI_PARTITION /* Multiple partition configuration */
marcozecchini 0:9fca2b23d0ba 37 typedef struct {
marcozecchini 0:9fca2b23d0ba 38 BYTE pd; /* Physical drive number */
marcozecchini 0:9fca2b23d0ba 39 BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
marcozecchini 0:9fca2b23d0ba 40 } PARTITION;
marcozecchini 0:9fca2b23d0ba 41 extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
marcozecchini 0:9fca2b23d0ba 42 #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
marcozecchini 0:9fca2b23d0ba 43 #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
marcozecchini 0:9fca2b23d0ba 44
marcozecchini 0:9fca2b23d0ba 45 #else /* Single partition configuration */
marcozecchini 0:9fca2b23d0ba 46 #define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */
marcozecchini 0:9fca2b23d0ba 47 #define LD2PT(vol) 0 /* Find first valid partition or in SFD */
marcozecchini 0:9fca2b23d0ba 48
marcozecchini 0:9fca2b23d0ba 49 #endif
marcozecchini 0:9fca2b23d0ba 50
marcozecchini 0:9fca2b23d0ba 51
marcozecchini 0:9fca2b23d0ba 52
marcozecchini 0:9fca2b23d0ba 53 /* Type of path name strings on FatFs API */
marcozecchini 0:9fca2b23d0ba 54
marcozecchini 0:9fca2b23d0ba 55 #if _LFN_UNICODE /* Unicode string */
marcozecchini 0:9fca2b23d0ba 56 #if !_USE_LFN
marcozecchini 0:9fca2b23d0ba 57 #error _LFN_UNICODE must be 0 at non-LFN cfg.
marcozecchini 0:9fca2b23d0ba 58 #endif
marcozecchini 0:9fca2b23d0ba 59 #ifndef _INC_TCHAR
marcozecchini 0:9fca2b23d0ba 60 typedef WCHAR TCHAR;
marcozecchini 0:9fca2b23d0ba 61 #define _T(x) L ## x
marcozecchini 0:9fca2b23d0ba 62 #define _TEXT(x) L ## x
marcozecchini 0:9fca2b23d0ba 63 #endif
marcozecchini 0:9fca2b23d0ba 64
marcozecchini 0:9fca2b23d0ba 65 #else /* ANSI/OEM string */
marcozecchini 0:9fca2b23d0ba 66 #ifndef _INC_TCHAR
marcozecchini 0:9fca2b23d0ba 67 typedef char TCHAR;
marcozecchini 0:9fca2b23d0ba 68 #define _T(x) x
marcozecchini 0:9fca2b23d0ba 69 #define _TEXT(x) x
marcozecchini 0:9fca2b23d0ba 70 #endif
marcozecchini 0:9fca2b23d0ba 71
marcozecchini 0:9fca2b23d0ba 72 #endif
marcozecchini 0:9fca2b23d0ba 73
marcozecchini 0:9fca2b23d0ba 74
marcozecchini 0:9fca2b23d0ba 75
marcozecchini 0:9fca2b23d0ba 76 /* File system object structure (FATFS) */
marcozecchini 0:9fca2b23d0ba 77
marcozecchini 0:9fca2b23d0ba 78 typedef struct {
marcozecchini 0:9fca2b23d0ba 79 BYTE fs_type; /* FAT sub-type (0:Not mounted) */
marcozecchini 0:9fca2b23d0ba 80 BYTE drv; /* Physical drive number */
marcozecchini 0:9fca2b23d0ba 81 BYTE csize; /* Sectors per cluster (1,2,4...128) */
marcozecchini 0:9fca2b23d0ba 82 BYTE n_fats; /* Number of FAT copies (1 or 2) */
marcozecchini 0:9fca2b23d0ba 83 BYTE wflag; /* win[] flag (b0:dirty) */
marcozecchini 0:9fca2b23d0ba 84 BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
marcozecchini 0:9fca2b23d0ba 85 WORD id; /* File system mount ID */
marcozecchini 0:9fca2b23d0ba 86 WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
marcozecchini 0:9fca2b23d0ba 87 #if _MAX_SS != _MIN_SS
marcozecchini 0:9fca2b23d0ba 88 WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
marcozecchini 0:9fca2b23d0ba 89 #endif
marcozecchini 0:9fca2b23d0ba 90 #if _FS_REENTRANT
marcozecchini 0:9fca2b23d0ba 91 _SYNC_t sobj; /* Identifier of sync object */
marcozecchini 0:9fca2b23d0ba 92 #endif
marcozecchini 0:9fca2b23d0ba 93 #if !_FS_READONLY
marcozecchini 0:9fca2b23d0ba 94 DWORD last_clust; /* Last allocated cluster */
marcozecchini 0:9fca2b23d0ba 95 DWORD free_clust; /* Number of free clusters */
marcozecchini 0:9fca2b23d0ba 96 #endif
marcozecchini 0:9fca2b23d0ba 97 #if _FS_RPATH
marcozecchini 0:9fca2b23d0ba 98 DWORD cdir; /* Current directory start cluster (0:root) */
marcozecchini 0:9fca2b23d0ba 99 #endif
marcozecchini 0:9fca2b23d0ba 100 DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */
marcozecchini 0:9fca2b23d0ba 101 DWORD fsize; /* Sectors per FAT */
marcozecchini 0:9fca2b23d0ba 102 DWORD volbase; /* Volume start sector */
marcozecchini 0:9fca2b23d0ba 103 DWORD fatbase; /* FAT start sector */
marcozecchini 0:9fca2b23d0ba 104 DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
marcozecchini 0:9fca2b23d0ba 105 DWORD database; /* Data start sector */
marcozecchini 0:9fca2b23d0ba 106 DWORD winsect; /* Current sector appearing in the win[] */
marcozecchini 0:9fca2b23d0ba 107 #if _FS_HEAPBUF
marcozecchini 0:9fca2b23d0ba 108 BYTE *win; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
marcozecchini 0:9fca2b23d0ba 109 #else
marcozecchini 0:9fca2b23d0ba 110 BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
marcozecchini 0:9fca2b23d0ba 111 #endif
marcozecchini 0:9fca2b23d0ba 112 } FATFS;
marcozecchini 0:9fca2b23d0ba 113
marcozecchini 0:9fca2b23d0ba 114
marcozecchini 0:9fca2b23d0ba 115
marcozecchini 0:9fca2b23d0ba 116 /* File object structure (FIL) */
marcozecchini 0:9fca2b23d0ba 117
marcozecchini 0:9fca2b23d0ba 118 typedef struct {
marcozecchini 0:9fca2b23d0ba 119 FATFS* fs; /* Pointer to the related file system object (**do not change order**) */
marcozecchini 0:9fca2b23d0ba 120 WORD id; /* Owner file system mount ID (**do not change order**) */
marcozecchini 0:9fca2b23d0ba 121 BYTE flag; /* Status flags */
marcozecchini 0:9fca2b23d0ba 122 BYTE err; /* Abort flag (error code) */
marcozecchini 0:9fca2b23d0ba 123 DWORD fptr; /* File read/write pointer (Zeroed on file open) */
marcozecchini 0:9fca2b23d0ba 124 DWORD fsize; /* File size */
marcozecchini 0:9fca2b23d0ba 125 DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
marcozecchini 0:9fca2b23d0ba 126 DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
marcozecchini 0:9fca2b23d0ba 127 DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */
marcozecchini 0:9fca2b23d0ba 128 #if !_FS_READONLY
marcozecchini 0:9fca2b23d0ba 129 DWORD dir_sect; /* Sector number containing the directory entry */
marcozecchini 0:9fca2b23d0ba 130 BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */
marcozecchini 0:9fca2b23d0ba 131 #endif
marcozecchini 0:9fca2b23d0ba 132 #if _USE_FASTSEEK
marcozecchini 0:9fca2b23d0ba 133 DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
marcozecchini 0:9fca2b23d0ba 134 #endif
marcozecchini 0:9fca2b23d0ba 135 #if _FS_LOCK
marcozecchini 0:9fca2b23d0ba 136 UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
marcozecchini 0:9fca2b23d0ba 137 #endif
marcozecchini 0:9fca2b23d0ba 138 #if !_FS_TINY
marcozecchini 0:9fca2b23d0ba 139 #if _FS_HEAPBUF
marcozecchini 0:9fca2b23d0ba 140 BYTE *buf; /* File private data read/write window */
marcozecchini 0:9fca2b23d0ba 141 #else
marcozecchini 0:9fca2b23d0ba 142 BYTE buf[_MAX_SS]; /* File private data read/write window */
marcozecchini 0:9fca2b23d0ba 143 #endif
marcozecchini 0:9fca2b23d0ba 144 #endif
marcozecchini 0:9fca2b23d0ba 145 } FIL;
marcozecchini 0:9fca2b23d0ba 146
marcozecchini 0:9fca2b23d0ba 147
marcozecchini 0:9fca2b23d0ba 148
marcozecchini 0:9fca2b23d0ba 149 /* Directory object structure (FATFS_DIR) */
marcozecchini 0:9fca2b23d0ba 150
marcozecchini 0:9fca2b23d0ba 151 typedef struct {
marcozecchini 0:9fca2b23d0ba 152 FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */
marcozecchini 0:9fca2b23d0ba 153 WORD id; /* Owner file system mount ID (**do not change order**) */
marcozecchini 0:9fca2b23d0ba 154 WORD index; /* Current read/write index number */
marcozecchini 0:9fca2b23d0ba 155 DWORD sclust; /* Table start cluster (0:Root dir) */
marcozecchini 0:9fca2b23d0ba 156 DWORD clust; /* Current cluster */
marcozecchini 0:9fca2b23d0ba 157 DWORD sect; /* Current sector */
marcozecchini 0:9fca2b23d0ba 158 BYTE* dir; /* Pointer to the current SFN entry in the win[] */
marcozecchini 0:9fca2b23d0ba 159 BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
marcozecchini 0:9fca2b23d0ba 160 #if _FS_LOCK
marcozecchini 0:9fca2b23d0ba 161 UINT lockid; /* File lock ID (index of file semaphore table Files[]) */
marcozecchini 0:9fca2b23d0ba 162 #endif
marcozecchini 0:9fca2b23d0ba 163 #if _USE_LFN
marcozecchini 0:9fca2b23d0ba 164 WCHAR* lfn; /* Pointer to the LFN working buffer */
marcozecchini 0:9fca2b23d0ba 165 WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
marcozecchini 0:9fca2b23d0ba 166 #endif
marcozecchini 0:9fca2b23d0ba 167 #if _USE_FIND
marcozecchini 0:9fca2b23d0ba 168 const TCHAR* pat; /* Pointer to the name matching pattern */
marcozecchini 0:9fca2b23d0ba 169 #endif
marcozecchini 0:9fca2b23d0ba 170 } FATFS_DIR;
marcozecchini 0:9fca2b23d0ba 171
marcozecchini 0:9fca2b23d0ba 172
marcozecchini 0:9fca2b23d0ba 173
marcozecchini 0:9fca2b23d0ba 174 /* File information structure (FILINFO) */
marcozecchini 0:9fca2b23d0ba 175
marcozecchini 0:9fca2b23d0ba 176 typedef struct {
marcozecchini 0:9fca2b23d0ba 177 DWORD fsize; /* File size */
marcozecchini 0:9fca2b23d0ba 178 WORD fdate; /* Last modified date */
marcozecchini 0:9fca2b23d0ba 179 WORD ftime; /* Last modified time */
marcozecchini 0:9fca2b23d0ba 180 BYTE fattrib; /* Attribute */
marcozecchini 0:9fca2b23d0ba 181 TCHAR fname[13]; /* Short file name (8.3 format) */
marcozecchini 0:9fca2b23d0ba 182 #if _USE_LFN
marcozecchini 0:9fca2b23d0ba 183 TCHAR* lfname; /* Pointer to the LFN buffer */
marcozecchini 0:9fca2b23d0ba 184 UINT lfsize; /* Size of LFN buffer in TCHAR */
marcozecchini 0:9fca2b23d0ba 185 #endif
marcozecchini 0:9fca2b23d0ba 186 } FILINFO;
marcozecchini 0:9fca2b23d0ba 187
marcozecchini 0:9fca2b23d0ba 188
marcozecchini 0:9fca2b23d0ba 189
marcozecchini 0:9fca2b23d0ba 190 /* File function return code (FRESULT) */
marcozecchini 0:9fca2b23d0ba 191
marcozecchini 0:9fca2b23d0ba 192 typedef enum {
marcozecchini 0:9fca2b23d0ba 193 FR_OK = 0, /* (0) Succeeded */
marcozecchini 0:9fca2b23d0ba 194 FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
marcozecchini 0:9fca2b23d0ba 195 FR_INT_ERR, /* (2) Assertion failed */
marcozecchini 0:9fca2b23d0ba 196 FR_NOT_READY, /* (3) The physical drive cannot work */
marcozecchini 0:9fca2b23d0ba 197 FR_NO_FILE, /* (4) Could not find the file */
marcozecchini 0:9fca2b23d0ba 198 FR_NO_PATH, /* (5) Could not find the path */
marcozecchini 0:9fca2b23d0ba 199 FR_INVALID_NAME, /* (6) The path name format is invalid */
marcozecchini 0:9fca2b23d0ba 200 FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
marcozecchini 0:9fca2b23d0ba 201 FR_EXIST, /* (8) Access denied due to prohibited access */
marcozecchini 0:9fca2b23d0ba 202 FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
marcozecchini 0:9fca2b23d0ba 203 FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
marcozecchini 0:9fca2b23d0ba 204 FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
marcozecchini 0:9fca2b23d0ba 205 FR_NOT_ENABLED, /* (12) The volume has no work area */
marcozecchini 0:9fca2b23d0ba 206 FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
marcozecchini 0:9fca2b23d0ba 207 FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
marcozecchini 0:9fca2b23d0ba 208 FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
marcozecchini 0:9fca2b23d0ba 209 FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
marcozecchini 0:9fca2b23d0ba 210 FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
marcozecchini 0:9fca2b23d0ba 211 FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_LOCK */
marcozecchini 0:9fca2b23d0ba 212 FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
marcozecchini 0:9fca2b23d0ba 213 } FRESULT;
marcozecchini 0:9fca2b23d0ba 214
marcozecchini 0:9fca2b23d0ba 215
marcozecchini 0:9fca2b23d0ba 216
marcozecchini 0:9fca2b23d0ba 217 /*--------------------------------------------------------------*/
marcozecchini 0:9fca2b23d0ba 218 /* FatFs module application interface */
marcozecchini 0:9fca2b23d0ba 219
marcozecchini 0:9fca2b23d0ba 220 FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
marcozecchini 0:9fca2b23d0ba 221 FRESULT f_close (FIL* fp); /* Close an open file object */
marcozecchini 0:9fca2b23d0ba 222 FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
marcozecchini 0:9fca2b23d0ba 223 FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
marcozecchini 0:9fca2b23d0ba 224 FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
marcozecchini 0:9fca2b23d0ba 225 FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
marcozecchini 0:9fca2b23d0ba 226 FRESULT f_truncate (FIL* fp); /* Truncate file */
marcozecchini 0:9fca2b23d0ba 227 FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
marcozecchini 0:9fca2b23d0ba 228 FRESULT f_opendir (FATFS_DIR* dp, const TCHAR* path); /* Open a directory */
marcozecchini 0:9fca2b23d0ba 229 FRESULT f_closedir (FATFS_DIR* dp); /* Close an open directory */
marcozecchini 0:9fca2b23d0ba 230 FRESULT f_readdir (FATFS_DIR* dp, FILINFO* fno); /* Read a directory item */
marcozecchini 0:9fca2b23d0ba 231 FRESULT f_findfirst (FATFS_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
marcozecchini 0:9fca2b23d0ba 232 FRESULT f_findnext (FATFS_DIR* dp, FILINFO* fno); /* Find next file */
marcozecchini 0:9fca2b23d0ba 233 FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
marcozecchini 0:9fca2b23d0ba 234 FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
marcozecchini 0:9fca2b23d0ba 235 FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
marcozecchini 0:9fca2b23d0ba 236 FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
marcozecchini 0:9fca2b23d0ba 237 FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */
marcozecchini 0:9fca2b23d0ba 238 FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */
marcozecchini 0:9fca2b23d0ba 239 FRESULT f_chdir (const TCHAR* path); /* Change current directory */
marcozecchini 0:9fca2b23d0ba 240 FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
marcozecchini 0:9fca2b23d0ba 241 FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
marcozecchini 0:9fca2b23d0ba 242 FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
marcozecchini 0:9fca2b23d0ba 243 FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
marcozecchini 0:9fca2b23d0ba 244 FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
marcozecchini 0:9fca2b23d0ba 245 FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
marcozecchini 0:9fca2b23d0ba 246 FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
marcozecchini 0:9fca2b23d0ba 247 FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
marcozecchini 0:9fca2b23d0ba 248 int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
marcozecchini 0:9fca2b23d0ba 249 int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
marcozecchini 0:9fca2b23d0ba 250 int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
marcozecchini 0:9fca2b23d0ba 251 TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
marcozecchini 0:9fca2b23d0ba 252
marcozecchini 0:9fca2b23d0ba 253 #define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
marcozecchini 0:9fca2b23d0ba 254 #define f_error(fp) ((fp)->err)
marcozecchini 0:9fca2b23d0ba 255 #define f_tell(fp) ((fp)->fptr)
marcozecchini 0:9fca2b23d0ba 256 #define f_size(fp) ((fp)->fsize)
marcozecchini 0:9fca2b23d0ba 257 #define f_rewind(fp) f_lseek((fp), 0)
marcozecchini 0:9fca2b23d0ba 258 #define f_rewinddir(dp) f_readdir((dp), 0)
marcozecchini 0:9fca2b23d0ba 259
marcozecchini 0:9fca2b23d0ba 260 #ifndef EOF
marcozecchini 0:9fca2b23d0ba 261 #define EOF (-1)
marcozecchini 0:9fca2b23d0ba 262 #endif
marcozecchini 0:9fca2b23d0ba 263
marcozecchini 0:9fca2b23d0ba 264
marcozecchini 0:9fca2b23d0ba 265
marcozecchini 0:9fca2b23d0ba 266
marcozecchini 0:9fca2b23d0ba 267 /*--------------------------------------------------------------*/
marcozecchini 0:9fca2b23d0ba 268 /* Additional user defined functions */
marcozecchini 0:9fca2b23d0ba 269
marcozecchini 0:9fca2b23d0ba 270 /* RTC function */
marcozecchini 0:9fca2b23d0ba 271 #if !_FS_READONLY && !_FS_NORTC
marcozecchini 0:9fca2b23d0ba 272 DWORD get_fattime (void);
marcozecchini 0:9fca2b23d0ba 273 #endif
marcozecchini 0:9fca2b23d0ba 274
marcozecchini 0:9fca2b23d0ba 275 /* Memory functions */
marcozecchini 0:9fca2b23d0ba 276 #if _USE_LFN == 3 || _FS_HEAPBUF
marcozecchini 0:9fca2b23d0ba 277 void* ff_memalloc (UINT msize); /* Allocate memory block */
marcozecchini 0:9fca2b23d0ba 278 void ff_memfree (void* mblock); /* Free memory block */
marcozecchini 0:9fca2b23d0ba 279 #endif
marcozecchini 0:9fca2b23d0ba 280
marcozecchini 0:9fca2b23d0ba 281 /* Unicode support functions */
marcozecchini 0:9fca2b23d0ba 282 #if _USE_LFN /* Unicode - OEM code conversion */
marcozecchini 0:9fca2b23d0ba 283 WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */
marcozecchini 0:9fca2b23d0ba 284 WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */
marcozecchini 0:9fca2b23d0ba 285 #endif
marcozecchini 0:9fca2b23d0ba 286
marcozecchini 0:9fca2b23d0ba 287 /* Sync functions */
marcozecchini 0:9fca2b23d0ba 288 #if _FS_REENTRANT
marcozecchini 0:9fca2b23d0ba 289 int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj); /* Create a sync object */
marcozecchini 0:9fca2b23d0ba 290 int ff_req_grant (_SYNC_t sobj); /* Lock sync object */
marcozecchini 0:9fca2b23d0ba 291 void ff_rel_grant (_SYNC_t sobj); /* Unlock sync object */
marcozecchini 0:9fca2b23d0ba 292 int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
marcozecchini 0:9fca2b23d0ba 293 #endif
marcozecchini 0:9fca2b23d0ba 294
marcozecchini 0:9fca2b23d0ba 295
marcozecchini 0:9fca2b23d0ba 296
marcozecchini 0:9fca2b23d0ba 297
marcozecchini 0:9fca2b23d0ba 298 /*--------------------------------------------------------------*/
marcozecchini 0:9fca2b23d0ba 299 /* Flags and offset address */
marcozecchini 0:9fca2b23d0ba 300
marcozecchini 0:9fca2b23d0ba 301
marcozecchini 0:9fca2b23d0ba 302 /* File access control and file status flags (FIL.flag) */
marcozecchini 0:9fca2b23d0ba 303
marcozecchini 0:9fca2b23d0ba 304 #define FA_READ 0x01
marcozecchini 0:9fca2b23d0ba 305 #define FA_OPEN_EXISTING 0x00
marcozecchini 0:9fca2b23d0ba 306
marcozecchini 0:9fca2b23d0ba 307 #if !_FS_READONLY
marcozecchini 0:9fca2b23d0ba 308 #define FA_WRITE 0x02
marcozecchini 0:9fca2b23d0ba 309 #define FA_CREATE_NEW 0x04
marcozecchini 0:9fca2b23d0ba 310 #define FA_CREATE_ALWAYS 0x08
marcozecchini 0:9fca2b23d0ba 311 #define FA_OPEN_ALWAYS 0x10
marcozecchini 0:9fca2b23d0ba 312 #define FA__WRITTEN 0x20
marcozecchini 0:9fca2b23d0ba 313 #define FA__DIRTY 0x40
marcozecchini 0:9fca2b23d0ba 314 #endif
marcozecchini 0:9fca2b23d0ba 315
marcozecchini 0:9fca2b23d0ba 316
marcozecchini 0:9fca2b23d0ba 317 /* FAT sub type (FATFS.fs_type) */
marcozecchini 0:9fca2b23d0ba 318
marcozecchini 0:9fca2b23d0ba 319 #define FS_FAT12 1
marcozecchini 0:9fca2b23d0ba 320 #define FS_FAT16 2
marcozecchini 0:9fca2b23d0ba 321 #define FS_FAT32 3
marcozecchini 0:9fca2b23d0ba 322
marcozecchini 0:9fca2b23d0ba 323
marcozecchini 0:9fca2b23d0ba 324 /* File attribute bits for directory entry */
marcozecchini 0:9fca2b23d0ba 325
marcozecchini 0:9fca2b23d0ba 326 #define AM_RDO 0x01 /* Read only */
marcozecchini 0:9fca2b23d0ba 327 #define AM_HID 0x02 /* Hidden */
marcozecchini 0:9fca2b23d0ba 328 #define AM_SYS 0x04 /* System */
marcozecchini 0:9fca2b23d0ba 329 #define AM_VOL 0x08 /* Volume label */
marcozecchini 0:9fca2b23d0ba 330 #define AM_LFN 0x0F /* LFN entry */
marcozecchini 0:9fca2b23d0ba 331 #define AM_DIR 0x10 /* Directory */
marcozecchini 0:9fca2b23d0ba 332 #define AM_ARC 0x20 /* Archive */
marcozecchini 0:9fca2b23d0ba 333 #define AM_MASK 0x3F /* Mask of defined bits */
marcozecchini 0:9fca2b23d0ba 334
marcozecchini 0:9fca2b23d0ba 335
marcozecchini 0:9fca2b23d0ba 336 /* Fast seek feature */
marcozecchini 0:9fca2b23d0ba 337 #define CREATE_LINKMAP 0xFFFFFFFF
marcozecchini 0:9fca2b23d0ba 338
marcozecchini 0:9fca2b23d0ba 339
marcozecchini 0:9fca2b23d0ba 340
marcozecchini 0:9fca2b23d0ba 341 /*--------------------------------*/
marcozecchini 0:9fca2b23d0ba 342 /* Multi-byte word access macros */
marcozecchini 0:9fca2b23d0ba 343
marcozecchini 0:9fca2b23d0ba 344 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
marcozecchini 0:9fca2b23d0ba 345 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
marcozecchini 0:9fca2b23d0ba 346 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
marcozecchini 0:9fca2b23d0ba 347 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
marcozecchini 0:9fca2b23d0ba 348 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
marcozecchini 0:9fca2b23d0ba 349 #else /* Use byte-by-byte access to the FAT structure */
marcozecchini 0:9fca2b23d0ba 350 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
marcozecchini 0:9fca2b23d0ba 351 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
marcozecchini 0:9fca2b23d0ba 352 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
marcozecchini 0:9fca2b23d0ba 353 #define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
marcozecchini 0:9fca2b23d0ba 354 #endif
marcozecchini 0:9fca2b23d0ba 355
marcozecchini 0:9fca2b23d0ba 356 #ifdef __cplusplus
marcozecchini 0:9fca2b23d0ba 357 }
marcozecchini 0:9fca2b23d0ba 358 #endif
marcozecchini 0:9fca2b23d0ba 359
marcozecchini 0:9fca2b23d0ba 360 #endif /* _FATFS */