test
Dependencies: Nanopb iSerial mbed BaseJpegDecode FatFileSystem SDFileSystem RingBuffer Camera_LS_Y201
extlib/FATFileSystem/ff.h@0:d69efd0ee139, 2014-09-18 (annotated)
- Committer:
- cgraham
- Date:
- Thu Sep 18 15:21:47 2014 +0000
- Revision:
- 0:d69efd0ee139
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cgraham | 0:d69efd0ee139 | 1 | /*--------------------------------------------------------------------------/ |
cgraham | 0:d69efd0ee139 | 2 | / FatFs - FAT file system module include file R0.06 (C)ChaN, 2008 |
cgraham | 0:d69efd0ee139 | 3 | /---------------------------------------------------------------------------/ |
cgraham | 0:d69efd0ee139 | 4 | / FatFs module is an experimenal project to implement FAT file system to |
cgraham | 0:d69efd0ee139 | 5 | / cheap microcontrollers. This is a free software and is opened for education, |
cgraham | 0:d69efd0ee139 | 6 | / research and development under license policy of following trems. |
cgraham | 0:d69efd0ee139 | 7 | / |
cgraham | 0:d69efd0ee139 | 8 | / Copyright (C) 2008, ChaN, all right reserved. |
cgraham | 0:d69efd0ee139 | 9 | / |
cgraham | 0:d69efd0ee139 | 10 | / * The FatFs module is a free software and there is no warranty. |
cgraham | 0:d69efd0ee139 | 11 | / * You can use, modify and/or redistribute it for personal, non-profit or |
cgraham | 0:d69efd0ee139 | 12 | / commercial use without any restriction under your responsibility. |
cgraham | 0:d69efd0ee139 | 13 | / * Redistributions of source code must retain the above copyright notice. |
cgraham | 0:d69efd0ee139 | 14 | / |
cgraham | 0:d69efd0ee139 | 15 | /---------------------------------------------------------------------------*/ |
cgraham | 0:d69efd0ee139 | 16 | |
cgraham | 0:d69efd0ee139 | 17 | #ifndef _FATFS |
cgraham | 0:d69efd0ee139 | 18 | |
cgraham | 0:d69efd0ee139 | 19 | #define _MCU_ENDIAN 2 |
cgraham | 0:d69efd0ee139 | 20 | /* The _MCU_ENDIAN defines which access method is used to the FAT structure. |
cgraham | 0:d69efd0ee139 | 21 | / 1: Enable word access. |
cgraham | 0:d69efd0ee139 | 22 | / 2: Disable word access and use byte-by-byte access instead. |
cgraham | 0:d69efd0ee139 | 23 | / When the architectural byte order of the MCU is big-endian and/or address |
cgraham | 0:d69efd0ee139 | 24 | / miss-aligned access results incorrect behavior, the _MCU_ENDIAN must be set to 2. |
cgraham | 0:d69efd0ee139 | 25 | / If it is not the case, it can also be set to 1 for good code efficiency. */ |
cgraham | 0:d69efd0ee139 | 26 | |
cgraham | 0:d69efd0ee139 | 27 | #define _FS_READONLY 0 |
cgraham | 0:d69efd0ee139 | 28 | /* Setting _FS_READONLY to 1 defines read only configuration. This removes |
cgraham | 0:d69efd0ee139 | 29 | / writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename, |
cgraham | 0:d69efd0ee139 | 30 | / f_truncate and useless f_getfree. */ |
cgraham | 0:d69efd0ee139 | 31 | |
cgraham | 0:d69efd0ee139 | 32 | #define _FS_MINIMIZE 0 |
cgraham | 0:d69efd0ee139 | 33 | /* The _FS_MINIMIZE option defines minimization level to remove some functions. |
cgraham | 0:d69efd0ee139 | 34 | / 0: Full function. |
cgraham | 0:d69efd0ee139 | 35 | / 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename are removed. |
cgraham | 0:d69efd0ee139 | 36 | / 2: f_opendir and f_readdir are removed in addition to level 1. |
cgraham | 0:d69efd0ee139 | 37 | / 3: f_lseek is removed in addition to level 2. */ |
cgraham | 0:d69efd0ee139 | 38 | |
cgraham | 0:d69efd0ee139 | 39 | #define _USE_STRFUNC 0 |
cgraham | 0:d69efd0ee139 | 40 | /* To enable string functions, set _USE_STRFUNC to 1 or 2. */ |
cgraham | 0:d69efd0ee139 | 41 | |
cgraham | 0:d69efd0ee139 | 42 | #define _USE_MKFS 1 |
cgraham | 0:d69efd0ee139 | 43 | /* When _USE_MKFS is set to 1 and _FS_READONLY is set to 0, f_mkfs function is |
cgraham | 0:d69efd0ee139 | 44 | / enabled. */ |
cgraham | 0:d69efd0ee139 | 45 | |
cgraham | 0:d69efd0ee139 | 46 | #define _DRIVES 4 |
cgraham | 0:d69efd0ee139 | 47 | /* Number of logical drives to be used. This affects the size of internal table. */ |
cgraham | 0:d69efd0ee139 | 48 | |
cgraham | 0:d69efd0ee139 | 49 | #define _MULTI_PARTITION 0 |
cgraham | 0:d69efd0ee139 | 50 | /* When _MULTI_PARTITION is set to 0, each logical drive is bound to same |
cgraham | 0:d69efd0ee139 | 51 | / physical drive number and can mount only 1st primaly partition. When it is |
cgraham | 0:d69efd0ee139 | 52 | / set to 1, each logical drive can mount a partition listed in Drives[]. */ |
cgraham | 0:d69efd0ee139 | 53 | |
cgraham | 0:d69efd0ee139 | 54 | #define _USE_FSINFO 0 |
cgraham | 0:d69efd0ee139 | 55 | /* To enable FSInfo support on FAT32 volume, set _USE_FSINFO to 1. */ |
cgraham | 0:d69efd0ee139 | 56 | |
cgraham | 0:d69efd0ee139 | 57 | #define _USE_SJIS 1 |
cgraham | 0:d69efd0ee139 | 58 | /* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise |
cgraham | 0:d69efd0ee139 | 59 | / only US-ASCII(7bit) code can be accepted as file/directory name. */ |
cgraham | 0:d69efd0ee139 | 60 | |
cgraham | 0:d69efd0ee139 | 61 | #define _USE_NTFLAG 1 |
cgraham | 0:d69efd0ee139 | 62 | /* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved. |
cgraham | 0:d69efd0ee139 | 63 | / Note that the files are always accessed in case insensitive. */ |
cgraham | 0:d69efd0ee139 | 64 | |
cgraham | 0:d69efd0ee139 | 65 | |
cgraham | 0:d69efd0ee139 | 66 | #include "integer.h" |
cgraham | 0:d69efd0ee139 | 67 | |
cgraham | 0:d69efd0ee139 | 68 | #ifdef __cplusplus |
cgraham | 0:d69efd0ee139 | 69 | extern "C" { |
cgraham | 0:d69efd0ee139 | 70 | #endif |
cgraham | 0:d69efd0ee139 | 71 | |
cgraham | 0:d69efd0ee139 | 72 | /* Definitions corresponds to multiple sector size (not tested) */ |
cgraham | 0:d69efd0ee139 | 73 | #define S_MAX_SIZ 512U /* Do not change */ |
cgraham | 0:d69efd0ee139 | 74 | #if S_MAX_SIZ > 512U |
cgraham | 0:d69efd0ee139 | 75 | #define SS(fs) ((fs)->s_size) |
cgraham | 0:d69efd0ee139 | 76 | #else |
cgraham | 0:d69efd0ee139 | 77 | #define SS(fs) 512U |
cgraham | 0:d69efd0ee139 | 78 | #endif |
cgraham | 0:d69efd0ee139 | 79 | |
cgraham | 0:d69efd0ee139 | 80 | |
cgraham | 0:d69efd0ee139 | 81 | /* File system object structure */ |
cgraham | 0:d69efd0ee139 | 82 | typedef struct _FATFS { |
cgraham | 0:d69efd0ee139 | 83 | WORD id; /* File system mount ID */ |
cgraham | 0:d69efd0ee139 | 84 | WORD n_rootdir; /* Number of root directory entries */ |
cgraham | 0:d69efd0ee139 | 85 | DWORD winsect; /* Current sector appearing in the win[] */ |
cgraham | 0:d69efd0ee139 | 86 | DWORD sects_fat; /* Sectors per fat */ |
cgraham | 0:d69efd0ee139 | 87 | DWORD max_clust; /* Maximum cluster# + 1 */ |
cgraham | 0:d69efd0ee139 | 88 | DWORD fatbase; /* FAT start sector */ |
cgraham | 0:d69efd0ee139 | 89 | DWORD dirbase; /* Root directory start sector (cluster# for FAT32) */ |
cgraham | 0:d69efd0ee139 | 90 | DWORD database; /* Data start sector */ |
cgraham | 0:d69efd0ee139 | 91 | #if !_FS_READONLY |
cgraham | 0:d69efd0ee139 | 92 | DWORD last_clust; /* Last allocated cluster */ |
cgraham | 0:d69efd0ee139 | 93 | DWORD free_clust; /* Number of free clusters */ |
cgraham | 0:d69efd0ee139 | 94 | #if _USE_FSINFO |
cgraham | 0:d69efd0ee139 | 95 | DWORD fsi_sector; /* fsinfo sector */ |
cgraham | 0:d69efd0ee139 | 96 | BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ |
cgraham | 0:d69efd0ee139 | 97 | BYTE pad2; |
cgraham | 0:d69efd0ee139 | 98 | #endif |
cgraham | 0:d69efd0ee139 | 99 | #endif |
cgraham | 0:d69efd0ee139 | 100 | BYTE fs_type; /* FAT sub type */ |
cgraham | 0:d69efd0ee139 | 101 | BYTE csize; /* Number of sectors per cluster */ |
cgraham | 0:d69efd0ee139 | 102 | #if S_MAX_SIZ > 512U |
cgraham | 0:d69efd0ee139 | 103 | WORD s_size; /* Sector size */ |
cgraham | 0:d69efd0ee139 | 104 | #endif |
cgraham | 0:d69efd0ee139 | 105 | BYTE n_fats; /* Number of FAT copies */ |
cgraham | 0:d69efd0ee139 | 106 | BYTE drive; /* Physical drive number */ |
cgraham | 0:d69efd0ee139 | 107 | BYTE winflag; /* win[] dirty flag (1:must be written back) */ |
cgraham | 0:d69efd0ee139 | 108 | BYTE pad1; |
cgraham | 0:d69efd0ee139 | 109 | BYTE win[S_MAX_SIZ]; /* Disk access window for Directory/FAT */ |
cgraham | 0:d69efd0ee139 | 110 | } FATFS; |
cgraham | 0:d69efd0ee139 | 111 | |
cgraham | 0:d69efd0ee139 | 112 | |
cgraham | 0:d69efd0ee139 | 113 | /* Directory object structure */ |
cgraham | 0:d69efd0ee139 | 114 | typedef struct _DIR { |
cgraham | 0:d69efd0ee139 | 115 | WORD id; /* Owner file system mount ID */ |
cgraham | 0:d69efd0ee139 | 116 | WORD index; /* Current index */ |
cgraham | 0:d69efd0ee139 | 117 | FATFS* fs; /* Pointer to the owner file system object */ |
cgraham | 0:d69efd0ee139 | 118 | DWORD sclust; /* Start cluster */ |
cgraham | 0:d69efd0ee139 | 119 | DWORD clust; /* Current cluster */ |
cgraham | 0:d69efd0ee139 | 120 | DWORD sect; /* Current sector */ |
cgraham | 0:d69efd0ee139 | 121 | } FATFS_DIR; |
cgraham | 0:d69efd0ee139 | 122 | |
cgraham | 0:d69efd0ee139 | 123 | |
cgraham | 0:d69efd0ee139 | 124 | /* File object structure */ |
cgraham | 0:d69efd0ee139 | 125 | typedef struct _FIL { |
cgraham | 0:d69efd0ee139 | 126 | WORD id; /* Owner file system mount ID */ |
cgraham | 0:d69efd0ee139 | 127 | BYTE flag; /* File status flags */ |
cgraham | 0:d69efd0ee139 | 128 | BYTE csect; /* Sector address in the cluster */ |
cgraham | 0:d69efd0ee139 | 129 | FATFS* fs; /* Pointer to the owner file system object */ |
cgraham | 0:d69efd0ee139 | 130 | DWORD fptr; /* File R/W pointer */ |
cgraham | 0:d69efd0ee139 | 131 | DWORD fsize; /* File size */ |
cgraham | 0:d69efd0ee139 | 132 | DWORD org_clust; /* File start cluster */ |
cgraham | 0:d69efd0ee139 | 133 | DWORD curr_clust; /* Current cluster */ |
cgraham | 0:d69efd0ee139 | 134 | DWORD curr_sect; /* Current sector */ |
cgraham | 0:d69efd0ee139 | 135 | #if _FS_READONLY == 0 |
cgraham | 0:d69efd0ee139 | 136 | DWORD dir_sect; /* Sector containing the directory entry */ |
cgraham | 0:d69efd0ee139 | 137 | BYTE* dir_ptr; /* Ponter to the directory entry in the window */ |
cgraham | 0:d69efd0ee139 | 138 | #endif |
cgraham | 0:d69efd0ee139 | 139 | BYTE buffer[S_MAX_SIZ]; /* File R/W buffer */ |
cgraham | 0:d69efd0ee139 | 140 | } FIL; |
cgraham | 0:d69efd0ee139 | 141 | |
cgraham | 0:d69efd0ee139 | 142 | |
cgraham | 0:d69efd0ee139 | 143 | /* File status structure */ |
cgraham | 0:d69efd0ee139 | 144 | typedef struct _FILINFO { |
cgraham | 0:d69efd0ee139 | 145 | DWORD fsize; /* Size */ |
cgraham | 0:d69efd0ee139 | 146 | WORD fdate; /* Date */ |
cgraham | 0:d69efd0ee139 | 147 | WORD ftime; /* Time */ |
cgraham | 0:d69efd0ee139 | 148 | BYTE fattrib; /* Attribute */ |
cgraham | 0:d69efd0ee139 | 149 | char fname[8+1+3+1]; /* Name (8.3 format) */ |
cgraham | 0:d69efd0ee139 | 150 | } FILINFO; |
cgraham | 0:d69efd0ee139 | 151 | |
cgraham | 0:d69efd0ee139 | 152 | |
cgraham | 0:d69efd0ee139 | 153 | |
cgraham | 0:d69efd0ee139 | 154 | /* Definitions corresponds to multi partition */ |
cgraham | 0:d69efd0ee139 | 155 | |
cgraham | 0:d69efd0ee139 | 156 | #if _MULTI_PARTITION != 0 /* Multiple partition cfg */ |
cgraham | 0:d69efd0ee139 | 157 | |
cgraham | 0:d69efd0ee139 | 158 | typedef struct _PARTITION { |
cgraham | 0:d69efd0ee139 | 159 | BYTE pd; /* Physical drive # (0-255) */ |
cgraham | 0:d69efd0ee139 | 160 | BYTE pt; /* Partition # (0-3) */ |
cgraham | 0:d69efd0ee139 | 161 | } PARTITION; |
cgraham | 0:d69efd0ee139 | 162 | extern |
cgraham | 0:d69efd0ee139 | 163 | const PARTITION Drives[]; /* Logical drive# to physical location conversion table */ |
cgraham | 0:d69efd0ee139 | 164 | #define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */ |
cgraham | 0:d69efd0ee139 | 165 | #define LD2PT(drv) (Drives[drv].pt) /* Get partition# */ |
cgraham | 0:d69efd0ee139 | 166 | |
cgraham | 0:d69efd0ee139 | 167 | #else /* Single partition cfg */ |
cgraham | 0:d69efd0ee139 | 168 | |
cgraham | 0:d69efd0ee139 | 169 | #define LD2PD(drv) (drv) /* Physical drive# is equal to logical drive# */ |
cgraham | 0:d69efd0ee139 | 170 | #define LD2PT(drv) 0 /* Always mounts the 1st partition */ |
cgraham | 0:d69efd0ee139 | 171 | |
cgraham | 0:d69efd0ee139 | 172 | #endif |
cgraham | 0:d69efd0ee139 | 173 | |
cgraham | 0:d69efd0ee139 | 174 | |
cgraham | 0:d69efd0ee139 | 175 | /* File function return code (FRESULT) */ |
cgraham | 0:d69efd0ee139 | 176 | |
cgraham | 0:d69efd0ee139 | 177 | typedef enum { |
cgraham | 0:d69efd0ee139 | 178 | FR_OK = 0, /* 0 */ |
cgraham | 0:d69efd0ee139 | 179 | FR_NOT_READY, /* 1 */ |
cgraham | 0:d69efd0ee139 | 180 | FR_NO_FILE, /* 2 */ |
cgraham | 0:d69efd0ee139 | 181 | FR_NO_PATH, /* 3 */ |
cgraham | 0:d69efd0ee139 | 182 | FR_INVALID_NAME, /* 4 */ |
cgraham | 0:d69efd0ee139 | 183 | FR_INVALID_DRIVE, /* 5 */ |
cgraham | 0:d69efd0ee139 | 184 | FR_DENIED, /* 6 */ |
cgraham | 0:d69efd0ee139 | 185 | FR_EXIST, /* 7 */ |
cgraham | 0:d69efd0ee139 | 186 | FR_RW_ERROR, /* 8 */ |
cgraham | 0:d69efd0ee139 | 187 | FR_WRITE_PROTECTED, /* 9 */ |
cgraham | 0:d69efd0ee139 | 188 | FR_NOT_ENABLED, /* 10 */ |
cgraham | 0:d69efd0ee139 | 189 | FR_NO_FILESYSTEM, /* 11 */ |
cgraham | 0:d69efd0ee139 | 190 | FR_INVALID_OBJECT, /* 12 */ |
cgraham | 0:d69efd0ee139 | 191 | FR_MKFS_ABORTED /* 13 */ |
cgraham | 0:d69efd0ee139 | 192 | } FRESULT; |
cgraham | 0:d69efd0ee139 | 193 | |
cgraham | 0:d69efd0ee139 | 194 | |
cgraham | 0:d69efd0ee139 | 195 | |
cgraham | 0:d69efd0ee139 | 196 | /*-----------------------------------------------------*/ |
cgraham | 0:d69efd0ee139 | 197 | /* FatFs module application interface */ |
cgraham | 0:d69efd0ee139 | 198 | |
cgraham | 0:d69efd0ee139 | 199 | FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ |
cgraham | 0:d69efd0ee139 | 200 | FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */ |
cgraham | 0:d69efd0ee139 | 201 | FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ |
cgraham | 0:d69efd0ee139 | 202 | FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ |
cgraham | 0:d69efd0ee139 | 203 | FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ |
cgraham | 0:d69efd0ee139 | 204 | FRESULT f_close (FIL*); /* Close an open file object */ |
cgraham | 0:d69efd0ee139 | 205 | FRESULT f_opendir (FATFS_DIR*, const char*); /* Open an existing directory */ |
cgraham | 0:d69efd0ee139 | 206 | FRESULT f_readdir (FATFS_DIR*, FILINFO*); /* Read a directory item */ |
cgraham | 0:d69efd0ee139 | 207 | FRESULT f_stat (const char*, FILINFO*); /* Get file status */ |
cgraham | 0:d69efd0ee139 | 208 | FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ |
cgraham | 0:d69efd0ee139 | 209 | FRESULT f_truncate (FIL*); /* Truncate file */ |
cgraham | 0:d69efd0ee139 | 210 | FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ |
cgraham | 0:d69efd0ee139 | 211 | FRESULT f_unlink (const char*); /* Delete an existing file or directory */ |
cgraham | 0:d69efd0ee139 | 212 | FRESULT f_mkdir (const char*); /* Create a new directory */ |
cgraham | 0:d69efd0ee139 | 213 | FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */ |
cgraham | 0:d69efd0ee139 | 214 | FRESULT f_utime (const char*, const FILINFO*); /* Change file/dir timestamp */ |
cgraham | 0:d69efd0ee139 | 215 | FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */ |
cgraham | 0:d69efd0ee139 | 216 | FRESULT f_mkfs (BYTE, BYTE, WORD); /* Create a file system on the drive */ |
cgraham | 0:d69efd0ee139 | 217 | #if _USE_STRFUNC |
cgraham | 0:d69efd0ee139 | 218 | #define feof(fp) ((fp)->fptr == (fp)->fsize) |
cgraham | 0:d69efd0ee139 | 219 | #define EOF -1 |
cgraham | 0:d69efd0ee139 | 220 | int fputc (int, FIL*); /* Put a character to the file */ |
cgraham | 0:d69efd0ee139 | 221 | int fputs (const char*, FIL*); /* Put a string to the file */ |
cgraham | 0:d69efd0ee139 | 222 | int fprintf (FIL*, const char*, ...); /* Put a formatted string to the file */ |
cgraham | 0:d69efd0ee139 | 223 | char* fgets (char*, int, FIL*); /* Get a string from the file */ |
cgraham | 0:d69efd0ee139 | 224 | #endif |
cgraham | 0:d69efd0ee139 | 225 | |
cgraham | 0:d69efd0ee139 | 226 | /* User defined function to give a current time to fatfs module */ |
cgraham | 0:d69efd0ee139 | 227 | |
cgraham | 0:d69efd0ee139 | 228 | DWORD get_fattime (void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */ |
cgraham | 0:d69efd0ee139 | 229 | /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ |
cgraham | 0:d69efd0ee139 | 230 | |
cgraham | 0:d69efd0ee139 | 231 | |
cgraham | 0:d69efd0ee139 | 232 | |
cgraham | 0:d69efd0ee139 | 233 | /* File access control and file status flags (FIL.flag) */ |
cgraham | 0:d69efd0ee139 | 234 | |
cgraham | 0:d69efd0ee139 | 235 | #define FA_READ 0x01 |
cgraham | 0:d69efd0ee139 | 236 | #define FA_OPEN_EXISTING 0x00 |
cgraham | 0:d69efd0ee139 | 237 | #if _FS_READONLY == 0 |
cgraham | 0:d69efd0ee139 | 238 | #define FA_WRITE 0x02 |
cgraham | 0:d69efd0ee139 | 239 | #define FA_CREATE_NEW 0x04 |
cgraham | 0:d69efd0ee139 | 240 | #define FA_CREATE_ALWAYS 0x08 |
cgraham | 0:d69efd0ee139 | 241 | #define FA_OPEN_ALWAYS 0x10 |
cgraham | 0:d69efd0ee139 | 242 | #define FA__WRITTEN 0x20 |
cgraham | 0:d69efd0ee139 | 243 | #define FA__DIRTY 0x40 |
cgraham | 0:d69efd0ee139 | 244 | #endif |
cgraham | 0:d69efd0ee139 | 245 | #define FA__ERROR 0x80 |
cgraham | 0:d69efd0ee139 | 246 | |
cgraham | 0:d69efd0ee139 | 247 | |
cgraham | 0:d69efd0ee139 | 248 | /* FAT sub type (FATFS.fs_type) */ |
cgraham | 0:d69efd0ee139 | 249 | |
cgraham | 0:d69efd0ee139 | 250 | #define FS_FAT12 1 |
cgraham | 0:d69efd0ee139 | 251 | #define FS_FAT16 2 |
cgraham | 0:d69efd0ee139 | 252 | #define FS_FAT32 3 |
cgraham | 0:d69efd0ee139 | 253 | |
cgraham | 0:d69efd0ee139 | 254 | |
cgraham | 0:d69efd0ee139 | 255 | /* File attribute bits for directory entry */ |
cgraham | 0:d69efd0ee139 | 256 | |
cgraham | 0:d69efd0ee139 | 257 | #define AM_RDO 0x01 /* Read only */ |
cgraham | 0:d69efd0ee139 | 258 | #define AM_HID 0x02 /* Hidden */ |
cgraham | 0:d69efd0ee139 | 259 | #define AM_SYS 0x04 /* System */ |
cgraham | 0:d69efd0ee139 | 260 | #define AM_VOL 0x08 /* Volume label */ |
cgraham | 0:d69efd0ee139 | 261 | #define AM_LFN 0x0F /* LFN entry */ |
cgraham | 0:d69efd0ee139 | 262 | #define AM_DIR 0x10 /* Directory */ |
cgraham | 0:d69efd0ee139 | 263 | #define AM_ARC 0x20 /* Archive */ |
cgraham | 0:d69efd0ee139 | 264 | |
cgraham | 0:d69efd0ee139 | 265 | |
cgraham | 0:d69efd0ee139 | 266 | |
cgraham | 0:d69efd0ee139 | 267 | /* Offset of FAT structure members */ |
cgraham | 0:d69efd0ee139 | 268 | |
cgraham | 0:d69efd0ee139 | 269 | #define BS_jmpBoot 0 |
cgraham | 0:d69efd0ee139 | 270 | #define BS_OEMName 3 |
cgraham | 0:d69efd0ee139 | 271 | #define BPB_BytsPerSec 11 |
cgraham | 0:d69efd0ee139 | 272 | #define BPB_SecPerClus 13 |
cgraham | 0:d69efd0ee139 | 273 | #define BPB_RsvdSecCnt 14 |
cgraham | 0:d69efd0ee139 | 274 | #define BPB_NumFATs 16 |
cgraham | 0:d69efd0ee139 | 275 | #define BPB_RootEntCnt 17 |
cgraham | 0:d69efd0ee139 | 276 | #define BPB_TotSec16 19 |
cgraham | 0:d69efd0ee139 | 277 | #define BPB_Media 21 |
cgraham | 0:d69efd0ee139 | 278 | #define BPB_FATSz16 22 |
cgraham | 0:d69efd0ee139 | 279 | #define BPB_SecPerTrk 24 |
cgraham | 0:d69efd0ee139 | 280 | #define BPB_NumHeads 26 |
cgraham | 0:d69efd0ee139 | 281 | #define BPB_HiddSec 28 |
cgraham | 0:d69efd0ee139 | 282 | #define BPB_TotSec32 32 |
cgraham | 0:d69efd0ee139 | 283 | #define BS_55AA 510 |
cgraham | 0:d69efd0ee139 | 284 | |
cgraham | 0:d69efd0ee139 | 285 | #define BS_DrvNum 36 |
cgraham | 0:d69efd0ee139 | 286 | #define BS_BootSig 38 |
cgraham | 0:d69efd0ee139 | 287 | #define BS_VolID 39 |
cgraham | 0:d69efd0ee139 | 288 | #define BS_VolLab 43 |
cgraham | 0:d69efd0ee139 | 289 | #define BS_FilSysType 54 |
cgraham | 0:d69efd0ee139 | 290 | |
cgraham | 0:d69efd0ee139 | 291 | #define BPB_FATSz32 36 |
cgraham | 0:d69efd0ee139 | 292 | #define BPB_ExtFlags 40 |
cgraham | 0:d69efd0ee139 | 293 | #define BPB_FSVer 42 |
cgraham | 0:d69efd0ee139 | 294 | #define BPB_RootClus 44 |
cgraham | 0:d69efd0ee139 | 295 | #define BPB_FSInfo 48 |
cgraham | 0:d69efd0ee139 | 296 | #define BPB_BkBootSec 50 |
cgraham | 0:d69efd0ee139 | 297 | #define BS_DrvNum32 64 |
cgraham | 0:d69efd0ee139 | 298 | #define BS_BootSig32 66 |
cgraham | 0:d69efd0ee139 | 299 | #define BS_VolID32 67 |
cgraham | 0:d69efd0ee139 | 300 | #define BS_VolLab32 71 |
cgraham | 0:d69efd0ee139 | 301 | #define BS_FilSysType32 82 |
cgraham | 0:d69efd0ee139 | 302 | |
cgraham | 0:d69efd0ee139 | 303 | #define FSI_LeadSig 0 |
cgraham | 0:d69efd0ee139 | 304 | #define FSI_StrucSig 484 |
cgraham | 0:d69efd0ee139 | 305 | #define FSI_Free_Count 488 |
cgraham | 0:d69efd0ee139 | 306 | #define FSI_Nxt_Free 492 |
cgraham | 0:d69efd0ee139 | 307 | |
cgraham | 0:d69efd0ee139 | 308 | #define MBR_Table 446 |
cgraham | 0:d69efd0ee139 | 309 | |
cgraham | 0:d69efd0ee139 | 310 | #define DIR_Name 0 |
cgraham | 0:d69efd0ee139 | 311 | #define DIR_Attr 11 |
cgraham | 0:d69efd0ee139 | 312 | #define DIR_NTres 12 |
cgraham | 0:d69efd0ee139 | 313 | #define DIR_CrtTime 14 |
cgraham | 0:d69efd0ee139 | 314 | #define DIR_CrtDate 16 |
cgraham | 0:d69efd0ee139 | 315 | #define DIR_FstClusHI 20 |
cgraham | 0:d69efd0ee139 | 316 | #define DIR_WrtTime 22 |
cgraham | 0:d69efd0ee139 | 317 | #define DIR_WrtDate 24 |
cgraham | 0:d69efd0ee139 | 318 | #define DIR_FstClusLO 26 |
cgraham | 0:d69efd0ee139 | 319 | #define DIR_FileSize 28 |
cgraham | 0:d69efd0ee139 | 320 | |
cgraham | 0:d69efd0ee139 | 321 | |
cgraham | 0:d69efd0ee139 | 322 | |
cgraham | 0:d69efd0ee139 | 323 | /* Multi-byte word access macros */ |
cgraham | 0:d69efd0ee139 | 324 | |
cgraham | 0:d69efd0ee139 | 325 | #if _MCU_ENDIAN == 1 /* Use word access */ |
cgraham | 0:d69efd0ee139 | 326 | #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) |
cgraham | 0:d69efd0ee139 | 327 | #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) |
cgraham | 0:d69efd0ee139 | 328 | #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) |
cgraham | 0:d69efd0ee139 | 329 | #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) |
cgraham | 0:d69efd0ee139 | 330 | #elif _MCU_ENDIAN == 2 /* Use byte-by-byte access */ |
cgraham | 0:d69efd0ee139 | 331 | #define LD_WORD(ptr) (WORD)(((WORD)*(volatile BYTE*)((ptr)+1)<<8)|(WORD)*(volatile BYTE*)(ptr)) |
cgraham | 0:d69efd0ee139 | 332 | #define LD_DWORD(ptr) (DWORD)(((DWORD)*(volatile BYTE*)((ptr)+3)<<24)|((DWORD)*(volatile BYTE*)((ptr)+2)<<16)|((WORD)*(volatile BYTE*)((ptr)+1)<<8)|*(volatile BYTE*)(ptr)) |
cgraham | 0:d69efd0ee139 | 333 | #define ST_WORD(ptr,val) *(volatile BYTE*)(ptr)=(BYTE)(val); *(volatile BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8) |
cgraham | 0:d69efd0ee139 | 334 | #define ST_DWORD(ptr,val) *(volatile BYTE*)(ptr)=(BYTE)(val); *(volatile BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8); *(volatile BYTE*)((ptr)+2)=(BYTE)((DWORD)(val)>>16); *(volatile BYTE*)((ptr)+3)=(BYTE)((DWORD)(val)>>24) |
cgraham | 0:d69efd0ee139 | 335 | #else |
cgraham | 0:d69efd0ee139 | 336 | #error Do not forget to set _MCU_ENDIAN properly! |
cgraham | 0:d69efd0ee139 | 337 | #endif |
cgraham | 0:d69efd0ee139 | 338 | |
cgraham | 0:d69efd0ee139 | 339 | #ifdef __cplusplus |
cgraham | 0:d69efd0ee139 | 340 | }; |
cgraham | 0:d69efd0ee139 | 341 | #endif |
cgraham | 0:d69efd0ee139 | 342 | |
cgraham | 0:d69efd0ee139 | 343 | #define _FATFS |
cgraham | 0:d69efd0ee139 | 344 | #endif /* _FATFS */ |