SAM4S-EK_FreeRTOS+FAT-SL  1.0
An example project to test the functionality of FreeRTOS+FAT-SL using SD card as data storage medium
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
fat_sl.h
Go to the documentation of this file.
1 /*
2  * FreeRTOS+FAT SL V1.0.1 (C) 2014 HCC Embedded
3  *
4  * The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
5  * terms.
6  *
7  * FreeRTOS+FAT SL uses a dual license model that allows the software to be used
8  * under a standard GPL open source license, or a commercial license. The
9  * standard GPL license (unlike the modified GPL license under which FreeRTOS
10  * itself is distributed) requires that all software statically linked with
11  * FreeRTOS+FAT SL is also distributed under the same GPL V2 license terms.
12  * Details of both license options follow:
13  *
14  * - Open source licensing -
15  * FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
16  * distributed without charge provided the user adheres to version two of the
17  * GNU General Public License (GPL) and does not remove the copyright notice or
18  * this text. The GPL V2 text is available on the gnu.org web site, and on the
19  * following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
20  *
21  * - Commercial licensing -
22  * Businesses and individuals who for commercial or other reasons cannot comply
23  * with the terms of the GPL V2 license must obtain a commercial license before
24  * incorporating FreeRTOS+FAT SL into proprietary software for distribution in
25  * any form. Commercial licenses can be purchased from
26  * http://shop.freertos.org/fat_sl and do not require any source files to be
27  * changed.
28  *
29  * FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
30  * cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
31  * is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
32  * implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
33  * PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
34  * conditions and terms, be they implied, expressed, or statutory.
35  *
36  * http://www.FreeRTOS.org
37  * http://www.FreeRTOS.org/FreeRTOS-Plus
38  *
39  */
40 
41 #ifndef _API_FAT_SL_H_
42 #define _API_FAT_SL_H_
43 
44 #include "config_fat_sl.h"
45 
46 #include "ver_fat_sl.h"
47 #if VER_FAT_SL_MAJOR != 5 || VER_FAT_SL_MINOR != 2
48  #error Incompatible FAT_SL version number!
49 #endif
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 #define F_MAXNAME 8 /* 8 byte name */
56 #define F_MAXEXT 3 /* 3 byte extension */
57 
58 typedef struct
59 {
60  char path[F_MAXPATH]; /* /directory1/dir2/ */
61  char filename[F_MAXNAME]; /* filename */
62  char fileext[F_MAXEXT]; /* extension */
63 } F_NAME;
64 
65 typedef struct
66 {
67  unsigned long cluster;
68  unsigned long sector;
69  unsigned long sectorend;
70  unsigned long pos;
71 } F_POS;
72 
73 typedef struct
74 {
75  char filename[F_MAXPATH]; /*file name+ext*/
76  char name[F_MAXNAME]; /*file name*/
77  char ext[F_MAXEXT]; /*file extension*/
78  unsigned char attr; /*attribute of the file*/
79 
80  unsigned short ctime; /*creation time*/
81  unsigned short cdate; /*creation date*/
82  unsigned long cluster;
83 
84  long filesize; /*length of file*/
85 
86  F_NAME findfsname; /*find properties*/
88 } F_FIND;
89 
90 #define F_ATTR_ARC 0x20
91 #define F_ATTR_DIR 0x10
92 #define F_ATTR_VOLUME 0x08
93 #define F_ATTR_SYSTEM 0x04
94 #define F_ATTR_HIDDEN 0x02
95 #define F_ATTR_READONLY 0x01
96 
97 #define F_CLUSTER_FREE ( (unsigned long)0x00000000 )
98 #define F_CLUSTER_RESERVED ( (unsigned long)0x0ffffff0 )
99 #define F_CLUSTER_BAD ( (unsigned long)0x0ffffff7 )
100 #define F_CLUSTER_LAST ( (unsigned long)0x0ffffff8 )
101 #define F_CLUSTER_LASTF32R ( (unsigned long)0x0fffffff )
102 
103 #define F_ST_MISSING 0x00000001
104 #define F_ST_CHANGED 0x00000002
105 #define F_ST_WRPROTECT 0x00000004
106 
107 typedef struct
108 {
109  unsigned long abspos;
110  unsigned long filesize;
111  unsigned long startcluster;
112  unsigned long relpos;
113  unsigned char modified;
114  unsigned char mode;
115  unsigned char _tdata[F_SECTOR_SIZE];
118 #if F_FILE_CHANGED_EVENT
119  char filename[F_MAXPATH]; /* filename with full path */
120 #endif
121 } F_FILE;
122 
123 enum
124 {
129 };
130 
131 enum
132 {
133 /* 0 */
135 
137 
139 
141 
143 
145 
147 
149 
151 
152 /* 9 */ F_ERR_EOF,
153 
155 
157 
158 /* 12 */ F_ERR_LOCKED,
159 
161 
162 /* 14 */ F_ERR_NOTEMPTY,
163 
164 /* 15 */ F_ERR_INITFUNC,
165 
167 
168 /* 17 */ F_ERR_ONDRIVE,
169 
171 
172 /* 19 */ F_ERR_READ,
173 
174 /* 20 */ F_ERR_WRITE,
175 
177 
178 /* 22 */ F_ERR_BUSY,
179 
181 
183 
185 
187 
189 
191 
192 #if F_FS_THREAD_AWARE == 1
193 /* 29 */, F_ERR_OS = 29
194 #endif /* F_FS_THREAD_AWARE */
195 };
196 
197 typedef struct
198 {
199  unsigned long total;
200  unsigned long free;
201  unsigned long used;
202  unsigned long bad;
203 
204  unsigned long total_high;
205  unsigned long free_high;
206  unsigned long used_high;
207  unsigned long bad_high;
208 } F_SPACE;
209 
210 enum
211 {
212  F_SEEK_SET /*Beginning of file*/
213  , F_SEEK_CUR /*Current position of file pointer*/
214  , F_SEEK_END /*End of file*/
215 };
216 
217 
218 /****************************************************************************
219  *
220  * for file changed events
221  *
222  ***************************************************************************/
223 
224 #if F_FILE_CHANGED_EVENT
225 
226 typedef struct
227 {
228  unsigned char action;
229  unsigned char flags;
230  unsigned char attr;
231  unsigned short ctime;
232  unsigned short cdate;
233  unsigned long filesize;
234  char filename[F_MAXPATH];
235 } ST_FILE_CHANGED;
236 
237 typedef void ( *F_FILE_CHANGED_EVENTFUNC )( ST_FILE_CHANGED * fc );
238 
239 extern F_FILE_CHANGED_EVENTFUNC f_filechangedevent;
240 
241  #define f_setfilechangedevent( filechangeevent ) f_filechangedevent = filechangeevent
242 
243 /* flags */
244 
245  #define FFLAGS_NONE 0x00000000
246 
247  #define FFLAGS_FILE_NAME 0x00000001
248  #define FFLAGS_DIR_NAME 0x00000002
249  #define FFLAGS_NAME 0x00000003
250  #define FFLAGS_ATTRIBUTES 0x00000004
251  #define FFLAGS_SIZE 0x00000008
252  #define FFLAGS_LAST_WRITE 0x00000010
253 
254 /* actions */
255 
256  #define FACTION_ADDED 0x00000001
257  #define FACTION_REMOVED 0x00000002
258  #define FACTION_MODIFIED 0x00000003
259  #define FACTION_RENAMED_OLD_NAME 0x00000004
260  #define FACTION_RENAMED_NEW_NAME 0x00000005
261 
262 #endif /* if F_FILE_CHANGED_EVENT */
263 
264 unsigned char fs_init ( void );
265 unsigned char fs_delete ( void );
266 
267 #define f_initvolume fn_initvolume
268 #define f_delvolume fn_delvolume
269 
270 unsigned char fn_initvolume ( F_DRIVERINIT initfunc );
271 unsigned char fn_delvolume ( void );
272 
273 unsigned char fn_getfreespace ( F_SPACE * pspace );
274 
275 unsigned char fn_chdir ( const char * dirname );
276 unsigned char fn_mkdir ( const char * dirname );
277 unsigned char fn_rmdir ( const char * dirname );
278 
279 unsigned char fn_findfirst ( const char * filename, F_FIND * find );
280 unsigned char fn_findnext ( F_FIND * find );
281 
282 long fn_filelength ( const char * filename );
283 
284 unsigned char fn_close ( F_FILE * filehandle );
285 F_FILE * fn_open ( const char * filename, const char * mode );
286 
287 long fn_read ( void * buf, long size, long _size_t, F_FILE * filehandle );
288 
289 long fn_write ( const void * buf, long size, long _size_t, F_FILE * filehandle );
290 
291 unsigned char fn_seek ( F_FILE * filehandle, long offset, unsigned char whence );
292 
293 long fn_tell ( F_FILE * filehandle );
294 int fn_getc ( F_FILE * filehandle );
295 int fn_putc ( int ch, F_FILE * filehandle );
296 unsigned char fn_rewind ( F_FILE * filehandle );
297 unsigned char fn_eof ( F_FILE * filehandle );
298 
299 unsigned char fn_delete ( const char * filename );
300 
301 unsigned char fn_seteof ( F_FILE * );
302 
303 F_FILE * fn_truncate ( const char *, long );
304 
305 unsigned char fn_getcwd ( char * buffer, unsigned char maxlen, char root );
306 
307 unsigned char fn_hardformat ( unsigned char fattype );
308 
309 unsigned char fn_getserial ( unsigned long * );
310 
311 
312 #if F_FS_THREAD_AWARE == 1
313 
314 #include "FreeRTOS.h"
315 #include "semphr.h"
316 
317 unsigned char fr_hardformat ( unsigned char fattype );
318 #define f_hardformat( fattype ) fr_hardformat( fattype )
319 #define f_format( fattype ) fr_hardformat( fattype )
320 
321 unsigned char fr_getcwd ( char * buffer, unsigned char maxlen, char root );
322 #define f_getcwd( buffer, maxlen ) fr_getcwd( buffer, maxlen, 1 )
323 
324 unsigned char fr_getfreespace ( F_SPACE * pspace );
325 #define f_getfreespace fr_getfreespace
326 
327 
328 unsigned char fr_chdir ( const char * dirname );
329 #define f_chdir( dirname ) fr_chdir( dirname )
330 unsigned char fr_mkdir ( const char * dirname );
331 #define f_mkdir( dirname ) fr_mkdir( dirname )
332 unsigned char fr_rmdir ( const char * dirname );
333 #define f_rmdir( dirname ) fr_rmdir( dirname )
334 
335 unsigned char fr_findfirst ( const char * filename, F_FIND * find );
336 unsigned char fr_findnext ( F_FIND * find );
337 #define f_findfirst( filename, find ) fr_findfirst( filename, find )
338 #define f_findnext( find ) fr_findnext( find )
339 
340 long fr_filelength ( const char * filename );
341 #define f_filelength( filename ) fr_filelength( filename )
342 
343 unsigned char fr_close ( F_FILE * filehandle );
344 F_FILE * fr_open ( const char * filename, const char * mode );
345 
346 long fr_read ( void * buf, long size, long _size_t, F_FILE * filehandle );
347 
348 unsigned char fr_getserial ( unsigned long * );
349 #define f_getserial( serial ) fr_getserial( serial )
350 
351 unsigned char fr_flush ( F_FILE * f );
352 #define f_flush( filehandle ) fr_flush( filehandle )
353 
354 long fr_write ( const void * buf, long size, long _size_t, F_FILE * filehandle );
355 #define f_write( buf, size, _size_t, filehandle ) fr_write( buf, size, _size_t, filehandle )
356 
357 unsigned char fr_seek ( F_FILE * filehandle, long offset, unsigned char whence );
358 #define f_seek( filehandle, offset, whence ) fr_seek( filehandle, offset, whence )
359 
360 long fr_tell ( F_FILE * filehandle );
361 #define f_tell( filehandle ) fr_tell( filehandle )
362 int fr_getc ( F_FILE * filehandle );
363 #define f_getc( filehandle ) fr_getc( filehandle )
364 int fr_putc ( int ch, F_FILE * filehandle );
365 #define f_putc( ch, filehandle ) fr_putc( ch, filehandle )
366 unsigned char fr_rewind ( F_FILE * filehandle );
367 #define f_rewind( filehandle ) fr_rewind( filehandle )
368 unsigned char fr_eof ( F_FILE * filehandle );
369 #define f_eof( filehandle ) fr_eof( filehandle )
370 
371 unsigned char fr_delete ( const char * filename );
372 #define f_delete( filename ) fr_delete( filename )
373 
374 unsigned char fr_seteof ( F_FILE * );
375 #define f_seteof( file ) fr_seteof( file )
376 
377 F_FILE * fr_truncate ( const char *, long );
378 #define f_truncate( filename, filesize ) fr_truncate( filename, filesize )
379 
380 #define f_close( filehandle ) fr_close( filehandle )
381 #define f_open( filename, mode ) fr_open( filename, mode )
382 #define f_read( buf, size, _size_t, filehandle ) fr_read( buf, size, _size_t, filehandle )
383 
384 #else /* F_FS_THREAD_AWARE */
385 
386 #define f_hardformat( fattype ) fn_hardformat( fattype )
387 #define f_format( fattype ) fn_hardformat( fattype )
388 
389 #define f_getcwd( buffer, maxlen ) fn_getcwd( buffer, maxlen, 1 )
390 
391 unsigned char fn_getfreespace ( F_SPACE * pspace );
392 #define f_getfreespace fn_getfreespace
393 
394 
395 unsigned char fn_chdir ( const char * dirname );
396 #define f_chdir( dirname ) fn_chdir( dirname )
397 unsigned char fn_mkdir ( const char * dirname );
398 #define f_mkdir( dirname ) fn_mkdir( dirname )
399 unsigned char fn_rmdir ( const char * dirname );
400 #define f_rmdir( dirname ) fn_rmdir( dirname )
401 
402 unsigned char fn_findfirst ( const char * filename, F_FIND * find );
403 unsigned char fn_findnext ( F_FIND * find );
404 #define f_findfirst( filename, find ) fn_findfirst( filename, find )
405 #define f_findnext( find ) fn_findnext( find )
406 
407 #define f_filelength( filename ) fn_filelength( filename )
408 
409 #define f_getserial( serial ) fn_getserial( serial )
410 
411 unsigned char fn_flush ( F_FILE * f );
412 #define f_flush( filehandle ) fn_flush( filehandle )
413 
414 #define f_write( buf, size, _size_t, filehandle ) fn_write( buf, size, _size_t, filehandle )
415 
416 #define f_seek( filehandle, offset, whence ) fn_seek( filehandle, offset, whence )
417 
418 long fn_tell ( F_FILE * filehandle );
419 #define f_tell( filehandle ) fn_tell( filehandle )
420 int fn_getc ( F_FILE * filehandle );
421 #define f_getc( filehandle ) fn_getc( filehandle )
422 int fn_putc ( int ch, F_FILE * filehandle );
423 #define f_putc( ch, filehandle ) fn_putc( ch, filehandle )
424 unsigned char fn_rewind ( F_FILE * filehandle );
425 #define f_rewind( filehandle ) fn_rewind( filehandle )
426 unsigned char fn_eof ( F_FILE * filehandle );
427 #define f_eof( filehandle ) fn_eof( filehandle )
428 
429 unsigned char fn_delete ( const char * filename );
430 #define f_delete( filename ) fn_delete( filename )
431 
432 unsigned char fn_seteof ( F_FILE * );
433 #define f_seteof( file ) fn_seteof( file )
434 
435 F_FILE * fn_truncate ( const char *, long );
436 #define f_truncate( filename, filesize ) fn_truncate( filename, filesize )
437 
438 #define f_close( filehandle ) fn_close( filehandle )
439 #define f_open( filename, mode ) fn_open( filename, mode )
440 #define f_read( buf, size, _size_t, filehandle ) fn_read( buf, size, _size_t, filehandle )
441 
442 #endif /* F_FS_THREAD_AWARE */
443 
444 
445 /****************************************************************************
446  *
447  * end of fat_sl.h
448  *
449  ***************************************************************************/
450 #ifdef __cplusplus
451 }
452 #endif
453 
454 #endif /*_API_FAT_SL_H_*/
455 
unsigned long bad_high
Definition: fat_sl.h:207
long fn_read(void *buf, long size, long _size_t, F_FILE *filehandle)
Definition: file.c:851
unsigned char fn_chdir(const char *dirname)
Definition: dir.c:665
unsigned long abspos
Definition: fat_sl.h:109
long fn_tell(F_FILE *filehandle)
Definition: file.c:1184
unsigned char fn_getcwd(char *buffer, unsigned char maxlen, char root)
Definition: dir.c:513
unsigned long used
Definition: fat_sl.h:201
unsigned char fn_hardformat(unsigned char fattype)
Definition: volume.c:530
unsigned char fn_mkdir(const char *dirname)
Definition: dir.c:925
unsigned char fs_init(void)
Definition: volume.c:881
unsigned long free
Definition: fat_sl.h:200
unsigned char fn_eof(F_FILE *filehandle)
Definition: file.c:1218
unsigned long pos
Definition: fat_sl.h:70
unsigned char fn_seek(F_FILE *filehandle, long offset, unsigned char whence)
Definition: file.c:1130
long filesize
Definition: fat_sl.h:84
Definition: fat_sl.h:58
unsigned char fn_findnext(F_FIND *find)
Definition: dir.c:608
unsigned char fn_close(F_FILE *filehandle)
Definition: file.c:704
F_NAME findfsname
Definition: fat_sl.h:86
F_FILE * fn_open(const char *filename, const char *mode)
Definition: file.c:421
unsigned long startcluster
Definition: fat_sl.h:111
#define F_MAXNAME
Definition: fat_sl.h:55
unsigned char fn_findfirst(const char *filename, F_FIND *find)
Definition: dir.c:562
#define F_MAXPATH
Definition: config_fat_sl.h:59
unsigned char attr
Definition: fat_sl.h:78
unsigned short ctime
Definition: fat_sl.h:80
F_POS dirpos
Definition: fat_sl.h:117
unsigned char fn_delete(const char *filename)
Definition: file.c:1336
unsigned long relpos
Definition: fat_sl.h:112
unsigned long sectorend
Definition: fat_sl.h:69
unsigned long used_high
Definition: fat_sl.h:206
unsigned long total
Definition: fat_sl.h:199
unsigned char fn_initvolume(F_DRIVERINIT initfunc)
Definition: volume.c:932
int fn_putc(int ch, F_FILE *filehandle)
Definition: file.c:1276
int fn_getc(F_FILE *filehandle)
Definition: file.c:1307
unsigned char mode
Definition: fat_sl.h:114
Definition: fat_sl.h:73
unsigned char fn_rmdir(const char *dirname)
Definition: dir.c:1088
F_DRIVER *(* F_DRIVERINIT)(unsigned long driver_param)
Definition: api_mdriver.h:96
unsigned char modified
Definition: fat_sl.h:113
unsigned char fn_delvolume(void)
Definition: volume.c:972
unsigned long free_high
Definition: fat_sl.h:205
unsigned long total_high
Definition: fat_sl.h:204
#define F_SECTOR_SIZE
Definition: config_fat_sl.h:57
unsigned long cluster
Definition: fat_sl.h:82
Definition: fat_sl.h:65
unsigned char fn_flush(F_FILE *f)
Definition: file.c:796
F_POS pos
Definition: fat_sl.h:87
unsigned long sector
Definition: fat_sl.h:68
F_POS pos
Definition: fat_sl.h:116
unsigned short cdate
Definition: fat_sl.h:81
unsigned long filesize
Definition: fat_sl.h:110
long fn_filelength(const char *filename)
Definition: file.c:75
unsigned long bad
Definition: fat_sl.h:202
unsigned char fn_seteof(F_FILE *)
Definition: file.c:1495
F_FILE * fn_truncate(const char *, long)
Definition: file.c:1518
long fn_write(const void *buf, long size, long _size_t, F_FILE *filehandle)
Definition: file.c:969
#define F_MAXEXT
Definition: fat_sl.h:56
Definition: fat_sl.h:107
unsigned char fs_delete(void)
Definition: volume.c:904
unsigned char fn_rewind(F_FILE *filehandle)
Definition: file.c:1252
unsigned char fn_getfreespace(F_SPACE *pspace)
Definition: volume.c:787
unsigned char fn_getserial(unsigned long *)
Definition: volume.c:859
unsigned long cluster
Definition: fat_sl.h:67