1 |
/*--------------------------------------------------------------------------/ |
1 |
/*--------------------------------------------------------------------------/ |
2 |
/ Tiny-FatFs - FAT file system module include file R0.04b (C)ChaN, 2007 |
2 |
/ Tiny-FatFs - FAT file system module include file R0.04b (C)ChaN, 2007 |
3 |
/---------------------------------------------------------------------------/ |
3 |
/---------------------------------------------------------------------------/ |
4 |
/ FatFs module is an experimenal project to implement FAT file system to |
4 |
/ FatFs module is an experimenal project to implement FAT file system to |
5 |
/ cheap microcontrollers. This is a free software and is opened for education, |
5 |
/ cheap microcontrollers. This is a free software and is opened for education, |
6 |
/ research and development under license policy of following trems. |
6 |
/ research and development under license policy of following trems. |
7 |
/ |
7 |
/ |
8 |
/ Copyright (C) 2007, ChaN, all right reserved. |
8 |
/ Copyright (C) 2007, ChaN, all right reserved. |
9 |
/ |
9 |
/ |
10 |
/ * The FatFs module is a free software and there is no warranty. |
10 |
/ * The FatFs module is a free software and there is no warranty. |
11 |
/ * You can use, modify and/or redistribute it for personal, non-profit or |
11 |
/ * You can use, modify and/or redistribute it for personal, non-profit or |
12 |
/ profit use without any restriction under your responsibility. |
12 |
/ profit use without any restriction under your responsibility. |
13 |
/ * Redistributions of source code must retain the above copyright notice. |
13 |
/ * Redistributions of source code must retain the above copyright notice. |
14 |
/ |
14 |
/ |
15 |
/---------------------------------------------------------------------------*/ |
15 |
/---------------------------------------------------------------------------*/ |
16 |
|
16 |
|
17 |
#ifndef _FATFS |
17 |
#ifndef _FATFS |
18 |
|
18 |
|
19 |
#define _MCU_ENDIAN 1 |
19 |
#define _MCU_ENDIAN 1 |
20 |
/* The _MCU_ENDIAN defines which access method is used to the FAT structure. |
20 |
/* The _MCU_ENDIAN defines which access method is used to the FAT structure. |
21 |
/ 1: Enable word access. |
21 |
/ 1: Enable word access. |
22 |
/ 2: Disable word access and use byte-by-byte access instead. |
22 |
/ 2: Disable word access and use byte-by-byte access instead. |
23 |
/ When the architectural byte order of the MCU is big-endian and/or address |
23 |
/ When the architectural byte order of the MCU is big-endian and/or address |
24 |
/ miss-aligned access is prohibited, the _MCU_ENDIAN must be set to 2. |
24 |
/ miss-aligned access is prohibited, the _MCU_ENDIAN must be set to 2. |
25 |
/ If it is not the case, it can be set to 1 for good code efficiency. */ |
25 |
/ If it is not the case, it can be set to 1 for good code efficiency. */ |
26 |
|
26 |
|
27 |
#define _FS_READONLY 0 |
27 |
#define _FS_READONLY 0 |
28 |
/* Setting _FS_READONLY to 1 defines read only configuration. This removes |
28 |
/* Setting _FS_READONLY to 1 defines read only configuration. This removes |
29 |
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename |
29 |
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename |
30 |
/ and useless f_getfree. */ |
30 |
/ and useless f_getfree. */ |
31 |
|
31 |
|
32 |
#define _FS_MINIMIZE 2 |
32 |
#define _FS_MINIMIZE 2 |
33 |
/* The _FS_MINIMIZE option defines minimization level to remove some functions. |
33 |
/* The _FS_MINIMIZE option defines minimization level to remove some functions. |
34 |
/ 0: Full function. |
34 |
/ 0: Full function. |
35 |
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod and f_rename are removed. |
35 |
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod and f_rename are removed. |
36 |
/ 2: f_opendir and f_readdir are removed in addition to level 1. |
36 |
/ 2: f_opendir and f_readdir are removed in addition to level 1. |
37 |
/ 3: f_lseek is removed in addition to level 2. */ |
37 |
/ 3: f_lseek is removed in addition to level 2. */ |
38 |
|
38 |
|
39 |
#define _FAT32 0 |
39 |
#define _FAT32 0 |
40 |
/* To support FAT32 in addition of FAT12/16, set _FAT32 to 1. */ |
40 |
/* To support FAT32 in addition of FAT12/16, set _FAT32 to 1. */ |
41 |
|
41 |
|
42 |
#define _USE_FSINFO 0 |
42 |
#define _USE_FSINFO 0 |
43 |
/* To support FSInfo on FAT32 volume, set _USE_FSINFO to 1. */ |
43 |
/* To support FSInfo on FAT32 volume, set _USE_FSINFO to 1. */ |
44 |
|
44 |
|
45 |
#define _USE_SJIS 0 |
45 |
#define _USE_SJIS 0 |
46 |
/* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise |
46 |
/* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise |
47 |
/ only US-ASCII(7bit) code can be accepted as file/directory name. */ |
47 |
/ only US-ASCII(7bit) code can be accepted as file/directory name. */ |
48 |
|
48 |
|
49 |
#define _USE_NTFLAG 1 |
49 |
#define _USE_NTFLAG 1 |
50 |
/* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved. */ |
50 |
/* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved. */ |
51 |
|
51 |
|
52 |
|
52 |
|
53 |
#include "integer.h" |
53 |
#include "integer.h" |
54 |
|
54 |
|
55 |
|
55 |
|
56 |
/* Type definition for cluster number */ |
56 |
/* Type definition for cluster number */ |
57 |
#if _FAT32 |
57 |
#if _FAT32 |
58 |
typedef DWORD CLUST; |
58 |
typedef DWORD CLUST; |
59 |
#else |
59 |
#else |
60 |
typedef WORD CLUST; |
60 |
typedef WORD CLUST; |
61 |
#undef _USE_FSINFO |
61 |
#undef _USE_FSINFO |
62 |
#define _USE_FSINFO 0 |
62 |
#define _USE_FSINFO 0 |
63 |
#endif |
63 |
#endif |
64 |
|
64 |
|
65 |
|
65 |
|
66 |
/* File system object structure */ |
66 |
/* File system object structure */ |
67 |
typedef struct _FATFS { |
67 |
typedef struct _FATFS { |
68 |
WORD id; /* File system mount ID */ |
68 |
WORD id; /* File system mount ID */ |
69 |
WORD n_rootdir; /* Number of root directory entries */ |
69 |
WORD n_rootdir; /* Number of root directory entries */ |
70 |
DWORD winsect; /* Current sector appearing in the win[] */ |
70 |
DWORD winsect; /* Current sector appearing in the win[] */ |
71 |
DWORD fatbase; /* FAT start sector */ |
71 |
DWORD fatbase; /* FAT start sector */ |
72 |
DWORD dirbase; /* Root directory start sector */ |
72 |
DWORD dirbase; /* Root directory start sector */ |
73 |
DWORD database; /* Data start sector */ |
73 |
DWORD database; /* Data start sector */ |
74 |
CLUST sects_fat; /* Sectors per fat */ |
74 |
CLUST sects_fat; /* Sectors per fat */ |
75 |
CLUST max_clust; /* Maximum cluster# + 1 */ |
75 |
CLUST max_clust; /* Maximum cluster# + 1 */ |
76 |
#if !_FS_READONLY |
76 |
#if !_FS_READONLY |
77 |
CLUST last_clust; /* Last allocated cluster */ |
77 |
CLUST last_clust; /* Last allocated cluster */ |
78 |
CLUST free_clust; /* Number of free clusters */ |
78 |
CLUST free_clust; /* Number of free clusters */ |
79 |
#if _USE_FSINFO |
79 |
#if _USE_FSINFO |
80 |
DWORD fsi_sector; /* fsinfo sector */ |
80 |
DWORD fsi_sector; /* fsinfo sector */ |
81 |
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ |
81 |
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ |
82 |
BYTE pad1; |
82 |
BYTE pad1; |
83 |
#endif |
83 |
#endif |
84 |
#endif |
84 |
#endif |
85 |
BYTE fs_type; /* FAT sub type */ |
85 |
BYTE fs_type; /* FAT sub type */ |
86 |
BYTE sects_clust; /* Sectors per cluster */ |
86 |
BYTE sects_clust; /* Sectors per cluster */ |
87 |
BYTE n_fats; /* Number of FAT copies */ |
87 |
BYTE n_fats; /* Number of FAT copies */ |
88 |
BYTE winflag; /* win[] dirty flag (1:must be written back) */ |
88 |
BYTE winflag; /* win[] dirty flag (1:must be written back) */ |
89 |
BYTE win[512]; /* Disk access window for Directory/FAT/File */ |
89 |
BYTE win[512]; /* Disk access window for Directory/FAT/File */ |
90 |
} FATFS; |
90 |
} FATFS; |
91 |
|
91 |
|
92 |
|
92 |
|
93 |
/* Directory object structure */ |
93 |
/* Directory object structure */ |
94 |
typedef struct _DIR { |
94 |
typedef struct _DIR { |
95 |
WORD id; /* Owner file system mount ID */ |
95 |
WORD id; /* Owner file system mount ID */ |
96 |
WORD index; /* Current index */ |
96 |
WORD index; /* Current index */ |
97 |
FATFS* fs; /* Pointer to the owner file system object */ |
97 |
FATFS* fs; /* Pointer to the owner file system object */ |
98 |
CLUST sclust; /* Start cluster */ |
98 |
CLUST sclust; /* Start cluster */ |
99 |
CLUST clust; /* Current cluster */ |
99 |
CLUST clust; /* Current cluster */ |
100 |
DWORD sect; /* Current sector */ |
100 |
DWORD sect; /* Current sector */ |
101 |
} DIR; |
101 |
} DIR; |
102 |
|
102 |
|
103 |
|
103 |
|
104 |
/* File object structure */ |
104 |
/* File object structure */ |
105 |
typedef struct _FIL { |
105 |
typedef struct _FIL { |
106 |
WORD id; /* Owner file system mount ID */ |
106 |
WORD id; /* Owner file system mount ID */ |
107 |
BYTE flag; /* File status flags */ |
107 |
BYTE flag; /* File status flags */ |
108 |
BYTE sect_clust; /* Left sectors in cluster */ |
108 |
BYTE sect_clust; /* Left sectors in cluster */ |
109 |
FATFS* fs; /* Pointer to owner file system */ |
109 |
FATFS* fs; /* Pointer to owner file system */ |
110 |
DWORD fptr; /* File R/W pointer */ |
110 |
DWORD fptr; /* File R/W pointer */ |
111 |
DWORD fsize; /* File size */ |
111 |
DWORD fsize; /* File size */ |
112 |
CLUST org_clust; /* File start cluster */ |
112 |
CLUST org_clust; /* File start cluster */ |
113 |
CLUST curr_clust; /* Current cluster */ |
113 |
CLUST curr_clust; /* Current cluster */ |
114 |
DWORD curr_sect; /* Current sector */ |
114 |
DWORD curr_sect; /* Current sector */ |
115 |
#if !_FS_READONLY |
115 |
#if !_FS_READONLY |
116 |
DWORD dir_sect; /* Sector containing the directory entry */ |
116 |
DWORD dir_sect; /* Sector containing the directory entry */ |
117 |
BYTE* dir_ptr; /* Ponter to the directory entry in the window */ |
117 |
BYTE* dir_ptr; /* Ponter to the directory entry in the window */ |
118 |
#endif |
118 |
#endif |
119 |
} FIL; |
119 |
} FIL; |
120 |
|
120 |
|
121 |
|
121 |
|
122 |
/* File status structure */ |
122 |
/* File status structure */ |
123 |
typedef struct _FILINFO { |
123 |
typedef struct _FILINFO { |
124 |
DWORD fsize; /* Size */ |
124 |
DWORD fsize; /* Size */ |
125 |
WORD fdate; /* Date */ |
125 |
WORD fdate; /* Date */ |
126 |
WORD ftime; /* Time */ |
126 |
WORD ftime; /* Time */ |
127 |
BYTE fattrib; /* Attribute */ |
127 |
BYTE fattrib; /* Attribute */ |
128 |
char fname[8+1+3+1]; /* Name (8.3 format) */ |
128 |
char fname[8+1+3+1]; /* Name (8.3 format) */ |
129 |
} FILINFO; |
129 |
} FILINFO; |
130 |
|
130 |
|
131 |
|
131 |
|
132 |
/* File function return code (FRESULT) */ |
132 |
/* File function return code (FRESULT) */ |
133 |
|
133 |
|
134 |
typedef enum { |
134 |
typedef enum { |
135 |
FR_OK = 0, /* 0 */ |
135 |
FR_OK = 0, /* 0 */ |
136 |
FR_NOT_READY, /* 1 */ |
136 |
FR_NOT_READY, /* 1 */ |
137 |
FR_NO_FILE, /* 2 */ |
137 |
FR_NO_FILE, /* 2 */ |
138 |
FR_NO_PATH, /* 3 */ |
138 |
FR_NO_PATH, /* 3 */ |
139 |
FR_INVALID_NAME, /* 4 */ |
139 |
FR_INVALID_NAME, /* 4 */ |
140 |
FR_INVALID_DRIVE, /* 5 */ |
140 |
FR_INVALID_DRIVE, /* 5 */ |
141 |
FR_DENIED, /* 6 */ |
141 |
FR_DENIED, /* 6 */ |
142 |
FR_EXIST, /* 7 */ |
142 |
FR_EXIST, /* 7 */ |
143 |
FR_RW_ERROR, /* 8 */ |
143 |
FR_RW_ERROR, /* 8 */ |
144 |
FR_WRITE_PROTECTED, /* 9 */ |
144 |
FR_WRITE_PROTECTED, /* 9 */ |
145 |
FR_NOT_ENABLED, /* 10 */ |
145 |
FR_NOT_ENABLED, /* 10 */ |
146 |
FR_NO_FILESYSTEM, /* 11 */ |
146 |
FR_NO_FILESYSTEM, /* 11 */ |
147 |
FR_INVALID_OBJECT /* 12 */ |
147 |
FR_INVALID_OBJECT /* 12 */ |
148 |
} FRESULT; |
148 |
} FRESULT; |
149 |
|
149 |
|
150 |
|
150 |
|
151 |
|
151 |
|
152 |
/*-----------------------------------------------------*/ |
152 |
/*-----------------------------------------------------*/ |
153 |
/* FatFs module application interface */ |
153 |
/* FatFs module application interface */ |
154 |
|
154 |
|
155 |
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ |
155 |
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ |
156 |
FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */ |
156 |
FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */ |
157 |
FRESULT f_read (FIL*, void*, WORD, WORD*); /* Read data from a file */ |
157 |
FRESULT f_read (FIL*, void*, WORD, WORD*); /* Read data from a file */ |
158 |
FRESULT f_write (FIL*, const void*, WORD, WORD*); /* Write data to a file */ |
158 |
FRESULT f_write (FIL*, const void*, WORD, WORD*); /* Write data to a file */ |
159 |
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ |
159 |
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ |
160 |
FRESULT f_close (FIL*); /* Close an open file object */ |
160 |
FRESULT f_close (FIL*); /* Close an open file object */ |
161 |
FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */ |
161 |
FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */ |
162 |
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */ |
162 |
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */ |
163 |
FRESULT f_stat (const char*, FILINFO*); /* Get file status */ |
163 |
FRESULT f_stat (const char*, FILINFO*); /* Get file status */ |
164 |
FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ |
164 |
FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ |
165 |
FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ |
165 |
FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ |
166 |
FRESULT f_unlink (const char*); /* Delete an existing file or directory */ |
166 |
FRESULT f_unlink (const char*); /* Delete an existing file or directory */ |
167 |
FRESULT f_mkdir (const char*); /* Create a new directory */ |
167 |
FRESULT f_mkdir (const char*); /* Create a new directory */ |
168 |
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */ |
168 |
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */ |
169 |
FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */ |
169 |
FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */ |
170 |
|
170 |
|
171 |
|
171 |
|
172 |
/* User defined function to give a current time to fatfs module */ |
172 |
/* User defined function to give a current time to fatfs module */ |
173 |
|
173 |
|
174 |
DWORD get_fattime (void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */ |
174 |
DWORD get_fattime (void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */ |
175 |
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ |
175 |
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ |
176 |
|
176 |
|
177 |
|
177 |
|
178 |
|
178 |
|
179 |
/* File access control and file status flags (FIL.flag) */ |
179 |
/* File access control and file status flags (FIL.flag) */ |
180 |
|
180 |
|
181 |
#define FA_READ 0x01 |
181 |
#define FA_READ 0x01 |
182 |
#define FA_OPEN_EXISTING 0x00 |
182 |
#define FA_OPEN_EXISTING 0x00 |
183 |
#if !_FS_READONLY |
183 |
#if !_FS_READONLY |
184 |
#define FA_WRITE 0x02 |
184 |
#define FA_WRITE 0x02 |
185 |
#define FA_CREATE_NEW 0x04 |
185 |
#define FA_CREATE_NEW 0x04 |
186 |
#define FA_CREATE_ALWAYS 0x08 |
186 |
#define FA_CREATE_ALWAYS 0x08 |
187 |
#define FA_OPEN_ALWAYS 0x10 |
187 |
#define FA_OPEN_ALWAYS 0x10 |
188 |
#define FA__WRITTEN 0x20 |
188 |
#define FA__WRITTEN 0x20 |
189 |
#endif |
189 |
#endif |
190 |
#define FA__ERROR 0x80 |
190 |
#define FA__ERROR 0x80 |
191 |
|
191 |
|
192 |
|
192 |
|
193 |
/* FAT sub type (FATFS.fs_type) */ |
193 |
/* FAT sub type (FATFS.fs_type) */ |
194 |
|
194 |
|
195 |
#define FS_FAT12 1 |
195 |
#define FS_FAT12 1 |
196 |
#define FS_FAT16 2 |
196 |
#define FS_FAT16 2 |
197 |
#define FS_FAT32 3 |
197 |
#define FS_FAT32 3 |
198 |
|
198 |
|
199 |
|
199 |
|
200 |
/* File attribute bits for directory entry */ |
200 |
/* File attribute bits for directory entry */ |
201 |
|
201 |
|
202 |
#define AM_RDO 0x01 /* Read only */ |
202 |
#define AM_RDO 0x01 /* Read only */ |
203 |
#define AM_HID 0x02 /* Hidden */ |
203 |
#define AM_HID 0x02 /* Hidden */ |
204 |
#define AM_SYS 0x04 /* System */ |
204 |
#define AM_SYS 0x04 /* System */ |
205 |
#define AM_VOL 0x08 /* Volume label */ |
205 |
#define AM_VOL 0x08 /* Volume label */ |
206 |
#define AM_LFN 0x0F /* LFN entry */ |
206 |
#define AM_LFN 0x0F /* LFN entry */ |
207 |
#define AM_DIR 0x10 /* Directory */ |
207 |
#define AM_DIR 0x10 /* Directory */ |
208 |
#define AM_ARC 0x20 /* Archive */ |
208 |
#define AM_ARC 0x20 /* Archive */ |
209 |
|
209 |
|
210 |
|
210 |
|
211 |
|
211 |
|
212 |
/* Offset of FAT structure members */ |
212 |
/* Offset of FAT structure members */ |
213 |
|
213 |
|
214 |
#define BS_jmpBoot 0 |
214 |
#define BS_jmpBoot 0 |
215 |
#define BS_OEMName 3 |
215 |
#define BS_OEMName 3 |
216 |
#define BPB_BytsPerSec 11 |
216 |
#define BPB_BytsPerSec 11 |
217 |
#define BPB_SecPerClus 13 |
217 |
#define BPB_SecPerClus 13 |
218 |
#define BPB_RsvdSecCnt 14 |
218 |
#define BPB_RsvdSecCnt 14 |
219 |
#define BPB_NumFATs 16 |
219 |
#define BPB_NumFATs 16 |
220 |
#define BPB_RootEntCnt 17 |
220 |
#define BPB_RootEntCnt 17 |
221 |
#define BPB_TotSec16 19 |
221 |
#define BPB_TotSec16 19 |
222 |
#define BPB_Media 21 |
222 |
#define BPB_Media 21 |
223 |
#define BPB_FATSz16 22 |
223 |
#define BPB_FATSz16 22 |
224 |
#define BPB_SecPerTrk 24 |
224 |
#define BPB_SecPerTrk 24 |
225 |
#define BPB_NumHeads 26 |
225 |
#define BPB_NumHeads 26 |
226 |
#define BPB_HiddSec 28 |
226 |
#define BPB_HiddSec 28 |
227 |
#define BPB_TotSec32 32 |
227 |
#define BPB_TotSec32 32 |
228 |
#define BS_55AA 510 |
228 |
#define BS_55AA 510 |
229 |
|
229 |
|
230 |
#define BS_DrvNum 36 |
230 |
#define BS_DrvNum 36 |
231 |
#define BS_BootSig 38 |
231 |
#define BS_BootSig 38 |
232 |
#define BS_VolID 39 |
232 |
#define BS_VolID 39 |
233 |
#define BS_VolLab 43 |
233 |
#define BS_VolLab 43 |
234 |
#define BS_FilSysType 54 |
234 |
#define BS_FilSysType 54 |
235 |
|
235 |
|
236 |
#define BPB_FATSz32 36 |
236 |
#define BPB_FATSz32 36 |
237 |
#define BPB_ExtFlags 40 |
237 |
#define BPB_ExtFlags 40 |
238 |
#define BPB_FSVer 42 |
238 |
#define BPB_FSVer 42 |
239 |
#define BPB_RootClus 44 |
239 |
#define BPB_RootClus 44 |
240 |
#define BPB_FSInfo 48 |
240 |
#define BPB_FSInfo 48 |
241 |
#define BPB_BkBootSec 50 |
241 |
#define BPB_BkBootSec 50 |
242 |
#define BS_DrvNum32 64 |
242 |
#define BS_DrvNum32 64 |
243 |
#define BS_BootSig32 66 |
243 |
#define BS_BootSig32 66 |
244 |
#define BS_VolID32 67 |
244 |
#define BS_VolID32 67 |
245 |
#define BS_VolLab32 71 |
245 |
#define BS_VolLab32 71 |
246 |
#define BS_FilSysType32 82 |
246 |
#define BS_FilSysType32 82 |
247 |
|
247 |
|
248 |
#define FSI_LeadSig 0 |
248 |
#define FSI_LeadSig 0 |
249 |
#define FSI_StrucSig 484 |
249 |
#define FSI_StrucSig 484 |
250 |
#define FSI_Free_Count 488 |
250 |
#define FSI_Free_Count 488 |
251 |
#define FSI_Nxt_Free 492 |
251 |
#define FSI_Nxt_Free 492 |
252 |
|
252 |
|
253 |
#define MBR_Table 446 |
253 |
#define MBR_Table 446 |
254 |
|
254 |
|
255 |
#define DIR_Name 0 |
255 |
#define DIR_Name 0 |
256 |
#define DIR_Attr 11 |
256 |
#define DIR_Attr 11 |
257 |
#define DIR_NTres 12 |
257 |
#define DIR_NTres 12 |
258 |
#define DIR_CrtTime 14 |
258 |
#define DIR_CrtTime 14 |
259 |
#define DIR_CrtDate 16 |
259 |
#define DIR_CrtDate 16 |
260 |
#define DIR_FstClusHI 20 |
260 |
#define DIR_FstClusHI 20 |
261 |
#define DIR_WrtTime 22 |
261 |
#define DIR_WrtTime 22 |
262 |
#define DIR_WrtDate 24 |
262 |
#define DIR_WrtDate 24 |
263 |
#define DIR_FstClusLO 26 |
263 |
#define DIR_FstClusLO 26 |
264 |
#define DIR_FileSize 28 |
264 |
#define DIR_FileSize 28 |
265 |
|
265 |
|
266 |
|
266 |
|
267 |
|
267 |
|
268 |
/* Multi-byte word access macros */ |
268 |
/* Multi-byte word access macros */ |
269 |
|
269 |
|
270 |
#if _MCU_ENDIAN == 1 /* Use word access */ |
270 |
#if _MCU_ENDIAN == 1 /* Use word access */ |
271 |
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) |
271 |
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) |
272 |
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) |
272 |
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) |
273 |
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) |
273 |
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) |
274 |
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) |
274 |
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) |
275 |
#else |
275 |
#else |
276 |
#if _MCU_ENDIAN == 2 /* Use byte-by-byte access */ |
276 |
#if _MCU_ENDIAN == 2 /* Use byte-by-byte access */ |
277 |
#define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) |
277 |
#define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) |
278 |
#define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr)) |
278 |
#define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr)) |
279 |
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8) |
279 |
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8) |
280 |
#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) |
280 |
#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) |
281 |
#else |
281 |
#else |
282 |
#error Do not forget to set _MCU_ENDIAN properly! |
282 |
#error Do not forget to set _MCU_ENDIAN properly! |
283 |
#endif |
283 |
#endif |
284 |
#endif |
284 |
#endif |
285 |
|
285 |
|
286 |
|
286 |
|
287 |
|
287 |
|
288 |
#define _FATFS |
288 |
#define _FATFS |
289 |
#endif /* _FATFS */ |
289 |
#endif /* _FATFS */ |