2 * FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
\r
4 * The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
\r
7 * FreeRTOS+FAT SL uses a dual license model that allows the software to be used
\r
8 * under a pure GPL open source license (as opposed to the modified GPL licence
\r
9 * under which FreeRTOS is distributed) or a commercial license. Details of
\r
10 * both license options follow:
\r
12 * - Open source licensing -
\r
13 * FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
\r
14 * distributed without charge provided the user adheres to version two of the
\r
15 * GNU General Public License (GPL) and does not remove the copyright notice or
\r
16 * this text. The GPL V2 text is available on the gnu.org web site, and on the
\r
17 * following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
\r
19 * - Commercial licensing -
\r
20 * Businesses and individuals who for commercial or other reasons cannot comply
\r
21 * with the terms of the GPL V2 license must obtain a commercial license before
\r
22 * incorporating FreeRTOS+FAT SL into proprietary software for distribution in
\r
23 * any form. Commercial licenses can be purchased from
\r
24 * http://shop.freertos.org/fat_sl and do not require any source files to be
\r
27 * FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
\r
28 * cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
\r
29 * is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
\r
30 * implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
\r
31 * PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
\r
32 * conditions and terms, be they implied, expressed, or statutory.
\r
34 * http://www.FreeRTOS.org
\r
35 * http://www.FreeRTOS.org/FreeRTOS-Plus
\r
39 #ifndef _API_FAT_SL_H_
\r
40 #define _API_FAT_SL_H_
\r
42 #include "config_fat_sl.h"
\r
44 #include "../version/ver_fat_sl.h"
\r
45 #if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
\r
46 #error Incompatible FAT_SL version number!
\r
53 #define F_MAXNAME 8 /* 8 byte name */
\r
54 #define F_MAXEXT 3 /* 3 byte extension */
\r
58 char path[F_MAXPATH]; /* /directory1/dir2/ */
\r
59 char filename[F_MAXNAME]; /* filename */
\r
60 char fileext[F_MAXEXT]; /* extension */
\r
65 unsigned long cluster;
\r
66 unsigned long sector;
\r
67 unsigned long sectorend;
\r
73 char filename[F_MAXPATH]; /*file name+ext*/
\r
74 char name[F_MAXNAME]; /*file name*/
\r
75 char ext[F_MAXEXT]; /*file extension*/
\r
76 unsigned char attr; /*attribute of the file*/
\r
78 unsigned short ctime; /*creation time*/
\r
79 unsigned short cdate; /*creation date*/
\r
80 unsigned long cluster;
\r
82 long filesize; /*length of file*/
\r
84 F_NAME findfsname; /*find properties*/
\r
88 /* definitions for ctime */
\r
89 #define F_CTIME_SEC_SHIFT 0
\r
90 #define F_CTIME_SEC_MASK 0x001f /*0-30 in 2seconds*/
\r
91 #define F_CTIME_MIN_SHIFT 5
\r
92 #define F_CTIME_MIN_MASK 0x07e0 /*0-59 */
\r
93 #define F_CTIME_HOUR_SHIFT 11
\r
94 #define F_CTIME_HOUR_MASK 0xf800 /*0-23*/
\r
97 /* definitions for cdate */
\r
98 #define F_CDATE_DAY_SHIFT 0
\r
99 #define F_CDATE_DAY_MASK 0x001f /*0-31*/
\r
100 #define F_CDATE_MONTH_SHIFT 5
\r
101 #define F_CDATE_MONTH_MASK 0x01e0 /*1-12*/
\r
102 #define F_CDATE_YEAR_SHIFT 9
\r
103 #define F_CDATE_YEAR_MASK 0xfe00 /*0-119 (1980+value)*/
\r
105 #define F_ATTR_ARC 0x20
\r
106 #define F_ATTR_DIR 0x10
\r
107 #define F_ATTR_VOLUME 0x08
\r
108 #define F_ATTR_SYSTEM 0x04
\r
109 #define F_ATTR_HIDDEN 0x02
\r
110 #define F_ATTR_READONLY 0x01
\r
112 #define F_CLUSTER_FREE ( (unsigned long)0x00000000 )
\r
113 #define F_CLUSTER_RESERVED ( (unsigned long)0x0ffffff0 )
\r
114 #define F_CLUSTER_BAD ( (unsigned long)0x0ffffff7 )
\r
115 #define F_CLUSTER_LAST ( (unsigned long)0x0ffffff8 )
\r
116 #define F_CLUSTER_LASTF32R ( (unsigned long)0x0fffffff )
\r
118 #define F_ST_MISSING 0x00000001
\r
119 #define F_ST_CHANGED 0x00000002
\r
120 #define F_ST_WRPROTECT 0x00000004
\r
124 unsigned long abspos;
\r
125 unsigned long filesize;
\r
126 unsigned long startcluster;
\r
127 unsigned long prevcluster;
\r
128 unsigned long relpos;
\r
129 unsigned char modified;
\r
130 unsigned char mode;
\r
131 unsigned char _tdata[F_SECTOR_SIZE];
\r
134 #if F_FILE_CHANGED_EVENT
\r
135 char filename[F_MAXPATH]; /* filename with full path */
\r
152 /* 1 */ F_ERR_RESERVED_1,
\r
154 /* 2 */ F_ERR_NOTFORMATTED,
\r
156 /* 3 */ F_ERR_INVALIDDIR,
\r
158 /* 4 */ F_ERR_INVALIDNAME,
\r
160 /* 5 */ F_ERR_NOTFOUND,
\r
162 /* 6 */ F_ERR_DUPLICATED,
\r
164 /* 7 */ F_ERR_NOMOREENTRY,
\r
166 /* 8 */ F_ERR_NOTOPEN,
\r
170 /* 10 */ F_ERR_RESERVED_2,
\r
172 /* 11 */ F_ERR_NOTUSEABLE,
\r
174 /* 12 */ F_ERR_LOCKED,
\r
176 /* 13 */ F_ERR_ACCESSDENIED,
\r
178 /* 14 */ F_ERR_NOTEMPTY,
\r
180 /* 15 */ F_ERR_INITFUNC,
\r
182 /* 16 */ F_ERR_CARDREMOVED,
\r
184 /* 17 */ F_ERR_ONDRIVE,
\r
186 /* 18 */ F_ERR_INVALIDSECTOR,
\r
188 /* 19 */ F_ERR_READ,
\r
190 /* 20 */ F_ERR_WRITE,
\r
192 /* 21 */ F_ERR_INVALIDMEDIA,
\r
194 /* 22 */ F_ERR_BUSY,
\r
196 /* 23 */ F_ERR_WRITEPROTECT,
\r
198 /* 24 */ F_ERR_INVFATTYPE,
\r
200 /* 25 */ F_ERR_MEDIATOOSMALL,
\r
202 /* 26 */ F_ERR_MEDIATOOLARGE,
\r
204 /* 27 */ F_ERR_NOTSUPPSECTORSIZE
\r
206 /* 28 */, F_ERR_ALLOCATION
\r
208 #if F_FS_THREAD_AWARE == 1
\r
209 /* 29 */, F_ERR_OS = 29
\r
210 #endif /* F_FS_THREAD_AWARE */
\r
215 unsigned long total;
\r
216 unsigned long free;
\r
217 unsigned long used;
\r
220 unsigned long total_high;
\r
221 unsigned long free_high;
\r
222 unsigned long used_high;
\r
223 unsigned long bad_high;
\r
228 F_SEEK_SET /*Beginning of file*/
\r
229 , F_SEEK_CUR /*Current position of file pointer*/
\r
230 , F_SEEK_END /*End of file*/
\r
234 /****************************************************************************
\r
236 * for file changed events
\r
238 ***************************************************************************/
\r
239 #ifndef F_FILE_CHANGED_EVENT
\r
240 #define F_FILE_CHANGED_EVENT 0
\r
243 #if F_FILE_CHANGED_EVENT
\r
247 unsigned char action;
\r
248 unsigned char flags;
\r
249 unsigned char attr;
\r
250 unsigned short ctime;
\r
251 unsigned short cdate;
\r
252 unsigned long filesize;
\r
253 char filename[F_MAXPATH];
\r
256 typedef void ( *F_FILE_CHANGED_EVENTFUNC )( ST_FILE_CHANGED * fc );
\r
258 extern F_FILE_CHANGED_EVENTFUNC f_filechangedevent;
\r
260 #define f_setfilechangedevent( filechangeevent ) f_filechangedevent = filechangeevent
\r
264 #define FFLAGS_NONE 0x00000000
\r
266 #define FFLAGS_FILE_NAME 0x00000001
\r
267 #define FFLAGS_DIR_NAME 0x00000002
\r
268 #define FFLAGS_NAME 0x00000003
\r
269 #define FFLAGS_ATTRIBUTES 0x00000004
\r
270 #define FFLAGS_SIZE 0x00000008
\r
271 #define FFLAGS_LAST_WRITE 0x00000010
\r
275 #define FACTION_ADDED 0x00000001
\r
276 #define FACTION_REMOVED 0x00000002
\r
277 #define FACTION_MODIFIED 0x00000003
\r
279 #endif /* if F_FILE_CHANGED_EVENT */
\r
281 unsigned char fn_initvolume ( F_DRIVERINIT initfunc );
\r
282 unsigned char fn_delvolume ( void );
\r
284 unsigned char fn_getfreespace ( F_SPACE * pspace );
\r
286 unsigned char fn_chdir ( const char * dirname );
\r
287 unsigned char fn_mkdir ( const char * dirname );
\r
288 unsigned char fn_rmdir ( const char * dirname );
\r
290 unsigned char fn_findfirst ( const char * filename, F_FIND * find );
\r
291 unsigned char fn_findnext ( F_FIND * find );
\r
293 long fn_filelength ( const char * filename );
\r
295 unsigned char fn_close ( F_FILE * filehandle );
\r
296 F_FILE * fn_open ( const char * filename, const char * mode );
\r
298 long fn_read ( void * buf, long size, long _size_t, F_FILE * filehandle );
\r
300 long fn_write ( const void * buf, long size, long _size_t, F_FILE * filehandle );
\r
302 unsigned char fn_seek ( F_FILE * filehandle, long offset, unsigned char whence );
\r
304 long fn_tell ( F_FILE * filehandle );
\r
305 int fn_getc ( F_FILE * filehandle );
\r
306 int fn_putc ( int ch, F_FILE * filehandle );
\r
307 unsigned char fn_rewind ( F_FILE * filehandle );
\r
308 unsigned char fn_eof ( F_FILE * filehandle );
\r
310 unsigned char fn_delete ( const char * filename );
\r
312 unsigned char fn_seteof ( F_FILE * );
\r
314 F_FILE * fn_truncate ( const char *, long );
\r
316 unsigned char fn_getcwd ( char * buffer, unsigned char maxlen, char root );
\r
318 unsigned char fn_hardformat ( unsigned char fattype );
\r
319 unsigned char fn_format ( unsigned char fattype );
\r
321 unsigned char fn_getserial ( unsigned long * );
\r
324 #if F_FS_THREAD_AWARE == 1
\r
326 #include "FreeRTOS.h"
\r
327 #include "semphr.h"
\r
328 #ifndef FS_MUTEX_DEFINED
\r
329 extern xSemaphoreHandle fs_lock_semaphore;
\r
330 #endif /* FS_MUTEX_DEFINED */
\r
332 unsigned char fn_init ( void );
\r
333 #define f_init fn_init
\r
334 #define f_initvolume fn_initvolume
\r
335 #define f_delvolume fn_delvolume
\r
337 unsigned char fr_hardformat ( unsigned char fattype );
\r
338 #define f_hardformat( fattype ) fr_hardformat( fattype )
\r
339 #define f_format( fattype ) fr_hardformat( fattype )
\r
341 unsigned char fr_getcwd ( char * buffer, unsigned char maxlen, char root );
\r
342 #define f_getcwd( buffer, maxlen ) fr_getcwd( buffer, maxlen, 1 )
\r
344 unsigned char fr_getfreespace ( F_SPACE * pspace );
\r
345 #define f_getfreespace fr_getfreespace
\r
348 unsigned char fr_chdir ( const char * dirname );
\r
349 #define f_chdir( dirname ) fr_chdir( dirname )
\r
350 unsigned char fr_mkdir ( const char * dirname );
\r
351 #define f_mkdir( dirname ) fr_mkdir( dirname )
\r
352 unsigned char fr_rmdir ( const char * dirname );
\r
353 #define f_rmdir( dirname ) fr_rmdir( dirname )
\r
355 unsigned char fr_findfirst ( const char * filename, F_FIND * find );
\r
356 unsigned char fr_findnext ( F_FIND * find );
\r
357 #define f_findfirst( filename, find ) fr_findfirst( filename, find )
\r
358 #define f_findnext( find ) fr_findnext( find )
\r
360 long fr_filelength ( const char * filename );
\r
361 #define f_filelength( filename ) fr_filelength( filename )
\r
363 unsigned char fr_close ( F_FILE * filehandle );
\r
364 F_FILE * fr_open ( const char * filename, const char * mode );
\r
366 long fr_read ( void * buf, long size, long _size_t, F_FILE * filehandle );
\r
368 unsigned char fr_getserial ( unsigned long * );
\r
369 #define f_getserial( serial ) fr_getserial( serial )
\r
371 unsigned char fr_flush ( F_FILE * f );
\r
372 #define f_flush( filehandle ) fr_flush( filehandle )
\r
374 long fr_write ( const void * buf, long size, long _size_t, F_FILE * filehandle );
\r
375 #define f_write( buf, size, _size_t, filehandle ) fr_write( buf, size, _size_t, filehandle )
\r
377 unsigned char fr_seek ( F_FILE * filehandle, long offset, unsigned char whence );
\r
378 #define f_seek( filehandle, offset, whence ) fr_seek( filehandle, offset, whence )
\r
380 long fr_tell ( F_FILE * filehandle );
\r
381 #define f_tell( filehandle ) fr_tell( filehandle )
\r
382 int fr_getc ( F_FILE * filehandle );
\r
383 #define f_getc( filehandle ) fr_getc( filehandle )
\r
384 int fr_putc ( int ch, F_FILE * filehandle );
\r
385 #define f_putc( ch, filehandle ) fr_putc( ch, filehandle )
\r
386 unsigned char fr_rewind ( F_FILE * filehandle );
\r
387 #define f_rewind( filehandle ) fr_rewind( filehandle )
\r
388 unsigned char fr_eof ( F_FILE * filehandle );
\r
389 #define f_eof( filehandle ) fr_eof( filehandle )
\r
391 unsigned char fr_delete ( const char * filename );
\r
392 #define f_delete( filename ) fr_delete( filename )
\r
394 unsigned char fr_seteof ( F_FILE * );
\r
395 #define f_seteof( file ) fr_seteof( file )
\r
397 F_FILE * fr_truncate ( const char *, long );
\r
398 #define f_truncate( filename, filesize ) fr_truncate( filename, filesize )
\r
400 #define f_close( filehandle ) fr_close( filehandle )
\r
401 #define f_open( filename, mode ) fr_open( filename, mode )
\r
402 #define f_read( buf, size, _size_t, filehandle ) fr_read( buf, size, _size_t, filehandle )
\r
404 #else /* F_FS_THREAD_AWARE */
\r
406 unsigned char fn_init ( void );
\r
407 #define f_init fn_init
\r
408 #define f_initvolume fn_initvolume
\r
409 #define f_delvolume fn_delvolume
\r
411 #define f_hardformat( fattype ) fn_hardformat( fattype )
\r
412 #define f_format( fattype ) fn_hardformat( fattype )
\r
414 #define f_getcwd( buffer, maxlen ) fn_getcwd( buffer, maxlen, 1 )
\r
416 unsigned char fn_getfreespace ( F_SPACE * pspace );
\r
417 #define f_getfreespace fn_getfreespace
\r
420 unsigned char fn_chdir ( const char * dirname );
\r
421 #define f_chdir( dirname ) fn_chdir( dirname )
\r
422 unsigned char fn_mkdir ( const char * dirname );
\r
423 #define f_mkdir( dirname ) fn_mkdir( dirname )
\r
424 unsigned char fn_rmdir ( const char * dirname );
\r
425 #define f_rmdir( dirname ) fn_rmdir( dirname )
\r
427 unsigned char fn_findfirst ( const char * filename, F_FIND * find );
\r
428 unsigned char fn_findnext ( F_FIND * find );
\r
429 #define f_findfirst( filename, find ) fn_findfirst( filename, find )
\r
430 #define f_findnext( find ) fn_findnext( find )
\r
432 #define f_filelength( filename ) fn_filelength( filename )
\r
434 #define f_getserial( serial ) fn_getserial( serial )
\r
436 unsigned char fn_flush ( F_FILE * f );
\r
437 #define f_flush( filehandle ) fn_flush( filehandle )
\r
439 #define f_write( buf, size, _size_t, filehandle ) fn_write( buf, size, _size_t, filehandle )
\r
441 #define f_seek( filehandle, offset, whence ) fn_seek( filehandle, offset, whence )
\r
443 long fn_tell ( F_FILE * filehandle );
\r
444 #define f_tell( filehandle ) fn_tell( filehandle )
\r
445 int fn_getc ( F_FILE * filehandle );
\r
446 #define f_getc( filehandle ) fn_getc( filehandle )
\r
447 int fn_putc ( int ch, F_FILE * filehandle );
\r
448 #define f_putc( ch, filehandle ) fn_putc( ch, filehandle )
\r
449 unsigned char fn_rewind ( F_FILE * filehandle );
\r
450 #define f_rewind( filehandle ) fn_rewind( filehandle )
\r
451 unsigned char fn_eof ( F_FILE * filehandle );
\r
452 #define f_eof( filehandle ) fn_eof( filehandle )
\r
454 unsigned char fn_delete ( const char * filename );
\r
455 #define f_delete( filename ) fn_delete( filename )
\r
457 unsigned char fn_seteof ( F_FILE * );
\r
458 #define f_seteof( file ) fn_seteof( file )
\r
460 F_FILE * fn_truncate ( const char *, long );
\r
461 #define f_truncate( filename, filesize ) fn_truncate( filename, filesize )
\r
463 #define f_close( filehandle ) fn_close( filehandle )
\r
464 #define f_open( filename, mode ) fn_open( filename, mode )
\r
465 #define f_read( buf, size, _size_t, filehandle ) fn_read( buf, size, _size_t, filehandle )
\r
467 #endif /* F_FS_THREAD_AWARE */
\r
469 /****************************************************************************
\r
473 ***************************************************************************/
\r
478 #endif /*_API_FAT_SL_H_*/
\r