Add FAT SL code and demo project.

This commit is contained in:
Richard Barry 2013-04-30 20:37:52 +00:00
parent bbe48d31a4
commit a4a830c44d
51 changed files with 13847 additions and 4 deletions

View file

@ -0,0 +1,5 @@
[InternetShortcut]
URL=http://www.freertos.org/fat
IDList=
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2

View file

@ -0,0 +1,102 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _API_MDRIVER_H_
#define _API_MDRIVER_H_
#include "../version/ver_mdriver.h"
#if VER_MDRIVER_MAJOR != 1 || VER_MDRIVER_MINOR != 0
#error Incompatible MDRIVER version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
unsigned short number_of_cylinders;
unsigned short sector_per_track;
unsigned short number_of_heads;
unsigned long number_of_sectors;
unsigned char media_descriptor;
unsigned short bytes_per_sector;
} F_PHY;
/* media descriptor to be set in getphy function */
#define F_MEDIADESC_REMOVABLE 0xf0
#define F_MEDIADESC_FIX 0xf8
/* return bitpattern for driver getphy function */
#define F_ST_MISSING 0x00000001
#define F_ST_CHANGED 0x00000002
#define F_ST_WRPROTECT 0x00000004
/* Driver definitions */
typedef struct F_DRIVER F_DRIVER;
typedef int ( *F_WRITESECTOR )( F_DRIVER * driver, void * data, unsigned long sector );
typedef int ( *F_READSECTOR )( F_DRIVER * driver, void * data, unsigned long sector );
typedef int ( *F_GETPHY )( F_DRIVER * driver, F_PHY * phy );
typedef long ( *F_GETSTATUS )( F_DRIVER * driver );
typedef void ( *F_RELEASE )( F_DRIVER * driver );
typedef struct F_DRIVER
{
unsigned long user_data; /* user defined data */
void * user_ptr; /* user define pointer */
/* driver functions */
F_WRITESECTOR writesector;
F_READSECTOR readsector;
F_GETPHY getphy;
F_GETSTATUS getstatus;
F_RELEASE release;
} _F_DRIVER;
typedef F_DRIVER *( *F_DRIVERINIT )( unsigned long driver_param );
#ifdef __cplusplus
}
#endif
#endif /* _API_MDRIVER_H_ */

View file

@ -0,0 +1,70 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _API_MDRIVER_RAM_H_
#define _API_MDRIVER_RAM_H_
#include "api_mdriver.h"
#include "../version/ver_mdriver_ram.h"
#if VER_MDRIVER_RAM_MAJOR != 1 || VER_MDRIVER_RAM_MINOR != 2
#error Incompatible MDRIVER_RAM version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define F_RAM_DRIVE0 0
enum
{
MDRIVER_RAM_NO_ERROR
, MDRIVER_RAM_ERR_SECTOR = 101
, MDRIVER_RAM_ERR_NOTAVAILABLE
};
F_DRIVER * ram_initfunc ( unsigned long driver_param );
#ifdef __cplusplus
}
#endif
#endif /* _API_MDRIVER_RAM_H_ */

View file

@ -0,0 +1,479 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _API_FAT_SL_H_
#define _API_FAT_SL_H_
#include "config_fat_sl.h"
#include "../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define F_MAXNAME 8 /* 8 byte name */
#define F_MAXEXT 3 /* 3 byte extension */
typedef struct
{
char path[F_MAXPATH]; /* /directory1/dir2/ */
char filename[F_MAXNAME]; /* filename */
char fileext[F_MAXEXT]; /* extension */
} F_NAME;
typedef struct
{
unsigned long cluster;
unsigned long sector;
unsigned long sectorend;
unsigned long pos;
} F_POS;
typedef struct
{
char filename[F_MAXPATH]; /*file name+ext*/
char name[F_MAXNAME]; /*file name*/
char ext[F_MAXEXT]; /*file extension*/
unsigned char attr; /*attribute of the file*/
unsigned short ctime; /*creation time*/
unsigned short cdate; /*creation date*/
unsigned long cluster;
long filesize; /*length of file*/
F_NAME findfsname; /*find properties*/
F_POS pos;
} F_FIND;
/* definitions for ctime */
#define F_CTIME_SEC_SHIFT 0
#define F_CTIME_SEC_MASK 0x001f /*0-30 in 2seconds*/
#define F_CTIME_MIN_SHIFT 5
#define F_CTIME_MIN_MASK 0x07e0 /*0-59 */
#define F_CTIME_HOUR_SHIFT 11
#define F_CTIME_HOUR_MASK 0xf800 /*0-23*/
/* definitions for cdate */
#define F_CDATE_DAY_SHIFT 0
#define F_CDATE_DAY_MASK 0x001f /*0-31*/
#define F_CDATE_MONTH_SHIFT 5
#define F_CDATE_MONTH_MASK 0x01e0 /*1-12*/
#define F_CDATE_YEAR_SHIFT 9
#define F_CDATE_YEAR_MASK 0xfe00 /*0-119 (1980+value)*/
#define F_ATTR_ARC 0x20
#define F_ATTR_DIR 0x10
#define F_ATTR_VOLUME 0x08
#define F_ATTR_SYSTEM 0x04
#define F_ATTR_HIDDEN 0x02
#define F_ATTR_READONLY 0x01
#define F_CLUSTER_FREE ( (unsigned long)0x00000000 )
#define F_CLUSTER_RESERVED ( (unsigned long)0x0ffffff0 )
#define F_CLUSTER_BAD ( (unsigned long)0x0ffffff7 )
#define F_CLUSTER_LAST ( (unsigned long)0x0ffffff8 )
#define F_CLUSTER_LASTF32R ( (unsigned long)0x0fffffff )
#define F_ST_MISSING 0x00000001
#define F_ST_CHANGED 0x00000002
#define F_ST_WRPROTECT 0x00000004
typedef struct
{
unsigned long abspos;
unsigned long filesize;
unsigned long startcluster;
unsigned long prevcluster;
unsigned long relpos;
unsigned char modified;
unsigned char mode;
unsigned char _tdata[F_SECTOR_SIZE];
F_POS pos;
F_POS dirpos;
#if F_FILE_CHANGED_EVENT
char filename[F_MAXPATH]; /* filename with full path */
#endif
} F_FILE;
enum
{
F_UNKNOWN_MEDIA
, F_FAT12_MEDIA
, F_FAT16_MEDIA
, F_FAT32_MEDIA
};
enum
{
/* 0 */
F_NO_ERROR,
/* 1 */ F_ERR_RESERVED_1,
/* 2 */ F_ERR_NOTFORMATTED,
/* 3 */ F_ERR_INVALIDDIR,
/* 4 */ F_ERR_INVALIDNAME,
/* 5 */ F_ERR_NOTFOUND,
/* 6 */ F_ERR_DUPLICATED,
/* 7 */ F_ERR_NOMOREENTRY,
/* 8 */ F_ERR_NOTOPEN,
/* 9 */ F_ERR_EOF,
/* 10 */ F_ERR_RESERVED_2,
/* 11 */ F_ERR_NOTUSEABLE,
/* 12 */ F_ERR_LOCKED,
/* 13 */ F_ERR_ACCESSDENIED,
/* 14 */ F_ERR_NOTEMPTY,
/* 15 */ F_ERR_INITFUNC,
/* 16 */ F_ERR_CARDREMOVED,
/* 17 */ F_ERR_ONDRIVE,
/* 18 */ F_ERR_INVALIDSECTOR,
/* 19 */ F_ERR_READ,
/* 20 */ F_ERR_WRITE,
/* 21 */ F_ERR_INVALIDMEDIA,
/* 22 */ F_ERR_BUSY,
/* 23 */ F_ERR_WRITEPROTECT,
/* 24 */ F_ERR_INVFATTYPE,
/* 25 */ F_ERR_MEDIATOOSMALL,
/* 26 */ F_ERR_MEDIATOOLARGE,
/* 27 */ F_ERR_NOTSUPPSECTORSIZE
/* 28 */, F_ERR_ALLOCATION
#if F_FS_THREAD_AWARE == 1
/* 29 */, F_ERR_OS = 29
#endif /* F_FS_THREAD_AWARE */
};
typedef struct
{
unsigned long total;
unsigned long free;
unsigned long used;
unsigned long bad;
unsigned long total_high;
unsigned long free_high;
unsigned long used_high;
unsigned long bad_high;
} F_SPACE;
enum
{
F_SEEK_SET /*Beginning of file*/
, F_SEEK_CUR /*Current position of file pointer*/
, F_SEEK_END /*End of file*/
};
/****************************************************************************
*
* for file changed events
*
***************************************************************************/
#ifndef F_FILE_CHANGED_EVENT
#define F_FILE_CHANGED_EVENT 0
#endif
#if F_FILE_CHANGED_EVENT
typedef struct
{
unsigned char action;
unsigned char flags;
unsigned char attr;
unsigned short ctime;
unsigned short cdate;
unsigned long filesize;
char filename[F_MAXPATH];
} ST_FILE_CHANGED;
typedef void ( *F_FILE_CHANGED_EVENTFUNC )( ST_FILE_CHANGED * fc );
extern F_FILE_CHANGED_EVENTFUNC f_filechangedevent;
#define f_setfilechangedevent( filechangeevent ) f_filechangedevent = filechangeevent
/* flags */
#define FFLAGS_NONE 0x00000000
#define FFLAGS_FILE_NAME 0x00000001
#define FFLAGS_DIR_NAME 0x00000002
#define FFLAGS_NAME 0x00000003
#define FFLAGS_ATTRIBUTES 0x00000004
#define FFLAGS_SIZE 0x00000008
#define FFLAGS_LAST_WRITE 0x00000010
/* actions */
#define FACTION_ADDED 0x00000001
#define FACTION_REMOVED 0x00000002
#define FACTION_MODIFIED 0x00000003
#endif /* if F_FILE_CHANGED_EVENT */
unsigned char fn_initvolume ( F_DRIVERINIT initfunc );
unsigned char fn_delvolume ( void );
unsigned char fn_getfreespace ( F_SPACE * pspace );
unsigned char fn_chdir ( const char * dirname );
unsigned char fn_mkdir ( const char * dirname );
unsigned char fn_rmdir ( const char * dirname );
unsigned char fn_findfirst ( const char * filename, F_FIND * find );
unsigned char fn_findnext ( F_FIND * find );
long fn_filelength ( const char * filename );
unsigned char fn_close ( F_FILE * filehandle );
F_FILE * fn_open ( const char * filename, const char * mode );
long fn_read ( void * buf, long size, long _size_t, F_FILE * filehandle );
long fn_write ( const void * buf, long size, long _size_t, F_FILE * filehandle );
unsigned char fn_seek ( F_FILE * filehandle, long offset, unsigned char whence );
long fn_tell ( F_FILE * filehandle );
int fn_getc ( F_FILE * filehandle );
int fn_putc ( int ch, F_FILE * filehandle );
unsigned char fn_rewind ( F_FILE * filehandle );
unsigned char fn_eof ( F_FILE * filehandle );
unsigned char fn_delete ( const char * filename );
unsigned char fn_seteof ( F_FILE * );
F_FILE * fn_truncate ( const char *, long );
unsigned char fn_getcwd ( char * buffer, unsigned char maxlen, char root );
unsigned char fn_hardformat ( unsigned char fattype );
unsigned char fn_format ( unsigned char fattype );
unsigned char fn_getserial ( unsigned long * );
#if F_FS_THREAD_AWARE == 1
#include "FreeRTOS.h"
#include "semphr.h"
#ifndef FS_MUTEX_DEFINED
extern xSemaphoreHandle fs_lock_semaphore;
#endif /* FS_MUTEX_DEFINED */
unsigned char fn_init ( void );
#define f_init fn_init
#define f_initvolume fn_initvolume
#define f_delvolume fn_delvolume
unsigned char fr_hardformat ( unsigned char fattype );
#define f_hardformat( fattype ) fr_hardformat( fattype )
#define f_format( fattype ) fr_hardformat( fattype )
unsigned char fr_getcwd ( char * buffer, unsigned char maxlen, char root );
#define f_getcwd( buffer, maxlen ) fr_getcwd( buffer, maxlen, 1 )
unsigned char fr_getfreespace ( F_SPACE * pspace );
#define f_getfreespace fr_getfreespace
unsigned char fr_chdir ( const char * dirname );
#define f_chdir( dirname ) fr_chdir( dirname )
unsigned char fr_mkdir ( const char * dirname );
#define f_mkdir( dirname ) fr_mkdir( dirname )
unsigned char fr_rmdir ( const char * dirname );
#define f_rmdir( dirname ) fr_rmdir( dirname )
unsigned char fr_findfirst ( const char * filename, F_FIND * find );
unsigned char fr_findnext ( F_FIND * find );
#define f_findfirst( filename, find ) fr_findfirst( filename, find )
#define f_findnext( find ) fr_findnext( find )
long fr_filelength ( const char * filename );
#define f_filelength( filename ) fr_filelength( filename )
unsigned char fr_close ( F_FILE * filehandle );
F_FILE * fr_open ( const char * filename, const char * mode );
long fr_read ( void * buf, long size, long _size_t, F_FILE * filehandle );
unsigned char fr_getserial ( unsigned long * );
#define f_getserial( serial ) fr_getserial( serial )
unsigned char fr_flush ( F_FILE * f );
#define f_flush( filehandle ) fr_flush( filehandle )
long fr_write ( const void * buf, long size, long _size_t, F_FILE * filehandle );
#define f_write( buf, size, _size_t, filehandle ) fr_write( buf, size, _size_t, filehandle )
unsigned char fr_seek ( F_FILE * filehandle, long offset, unsigned char whence );
#define f_seek( filehandle, offset, whence ) fr_seek( filehandle, offset, whence )
long fr_tell ( F_FILE * filehandle );
#define f_tell( filehandle ) fr_tell( filehandle )
int fr_getc ( F_FILE * filehandle );
#define f_getc( filehandle ) fr_getc( filehandle )
int fr_putc ( int ch, F_FILE * filehandle );
#define f_putc( ch, filehandle ) fr_putc( ch, filehandle )
unsigned char fr_rewind ( F_FILE * filehandle );
#define f_rewind( filehandle ) fr_rewind( filehandle )
unsigned char fr_eof ( F_FILE * filehandle );
#define f_eof( filehandle ) fr_eof( filehandle )
unsigned char fr_delete ( const char * filename );
#define f_delete( filename ) fr_delete( filename )
unsigned char fr_seteof ( F_FILE * );
#define f_seteof( file ) fr_seteof( file )
F_FILE * fr_truncate ( const char *, long );
#define f_truncate( filename, filesize ) fr_truncate( filename, filesize )
#define f_close( filehandle ) fr_close( filehandle )
#define f_open( filename, mode ) fr_open( filename, mode )
#define f_read( buf, size, _size_t, filehandle ) fr_read( buf, size, _size_t, filehandle )
#else /* F_FS_THREAD_AWARE */
unsigned char fn_init ( void );
#define f_init fn_init
#define f_initvolume fn_initvolume
#define f_delvolume fn_delvolume
#define f_hardformat( fattype ) fn_hardformat( fattype )
#define f_format( fattype ) fn_hardformat( fattype )
#define f_getcwd( buffer, maxlen ) fn_getcwd( buffer, maxlen, 1 )
unsigned char fn_getfreespace ( F_SPACE * pspace );
#define f_getfreespace fn_getfreespace
unsigned char fn_chdir ( const char * dirname );
#define f_chdir( dirname ) fn_chdir( dirname )
unsigned char fn_mkdir ( const char * dirname );
#define f_mkdir( dirname ) fn_mkdir( dirname )
unsigned char fn_rmdir ( const char * dirname );
#define f_rmdir( dirname ) fn_rmdir( dirname )
unsigned char fn_findfirst ( const char * filename, F_FIND * find );
unsigned char fn_findnext ( F_FIND * find );
#define f_findfirst( filename, find ) fn_findfirst( filename, find )
#define f_findnext( find ) fn_findnext( find )
#define f_filelength( filename ) fn_filelength( filename )
#define f_getserial( serial ) fn_getserial( serial )
unsigned char fn_flush ( F_FILE * f );
#define f_flush( filehandle ) fn_flush( filehandle )
#define f_write( buf, size, _size_t, filehandle ) fn_write( buf, size, _size_t, filehandle )
#define f_seek( filehandle, offset, whence ) fn_seek( filehandle, offset, whence )
long fn_tell ( F_FILE * filehandle );
#define f_tell( filehandle ) fn_tell( filehandle )
int fn_getc ( F_FILE * filehandle );
#define f_getc( filehandle ) fn_getc( filehandle )
int fn_putc ( int ch, F_FILE * filehandle );
#define f_putc( ch, filehandle ) fn_putc( ch, filehandle )
unsigned char fn_rewind ( F_FILE * filehandle );
#define f_rewind( filehandle ) fn_rewind( filehandle )
unsigned char fn_eof ( F_FILE * filehandle );
#define f_eof( filehandle ) fn_eof( filehandle )
unsigned char fn_delete ( const char * filename );
#define f_delete( filename ) fn_delete( filename )
unsigned char fn_seteof ( F_FILE * );
#define f_seteof( file ) fn_seteof( file )
F_FILE * fn_truncate ( const char *, long );
#define f_truncate( filename, filesize ) fn_truncate( filename, filesize )
#define f_close( filehandle ) fn_close( filehandle )
#define f_open( filename, mode ) fn_open( filename, mode )
#define f_read( buf, size, _size_t, filehandle ) fn_read( buf, size, _size_t, filehandle )
#endif /* F_FS_THREAD_AWARE */
/****************************************************************************
*
* end of fat_sl.h
*
***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif /*_API_FAT_SL_H_*/

View file

@ -0,0 +1,69 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _CONFIG_FAT_SL_H
#define _CONFIG_FAT_SL_H
#include "../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#include "../api/api_mdriver.h"
#ifdef __cplusplus
extern "C" {
#endif
/**************************************************************************
**
** FAT SL user settings
**
**************************************************************************/
#define F_SECTOR_SIZE 512u /* Disk sector size. */
#define F_FS_THREAD_AWARE 1 /* Set to one if the file system will be access from more than one task. */
#define F_MAXPATH 64 /* Maximum length a file name (including its full path) can be. */
#define F_MAX_LOCK_WAIT_TICKS 20 /* The maximum number of RTOS ticks to wait when attempting to obtain a lock on the file system when F_FS_THREAD_AWARE is set to 1. */
#ifdef __cplusplus
}
#endif
#endif /* _CONFIG_FAT_SL_H */

View file

@ -0,0 +1,54 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _CONFIG_MDRIVER_RAM_H_
#define _CONFIG_MDRIVER_RAM_H_
#include "../version/ver_mdriver_ram.h"
#if VER_MDRIVER_RAM_MAJOR != 1 || VER_MDRIVER_RAM_MINOR != 2
#error Incompatible MDRIVER_RAM version number!
#endif
#define MDRIVER_RAM_SECTOR_SIZE 512 /* Sector size */
#define MDRIVER_RAM_VOLUME0_SIZE (128 * 1024) /* defintion for size of ramdrive0 */
#define MDRIVER_MEM_LONG_ACCESS 1 /* set this value to 1 if 32bit access available */
#endif /* ifndef _CONFIG_MDRIVER_RAM_H_ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,90 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef __DIR_H
#define __DIR_H
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define NTRES_LOW 0x08 /*lower case name*/
typedef struct
{
unsigned char name[F_MAXNAME]; /* 8+3 */
unsigned char ext[F_MAXEXT];
unsigned char attr; /* 00ADVSHR */
unsigned char ntres; /* FAT32 only */
unsigned char crttimetenth; /* FAT32 only */
unsigned char crttime[2]; /* FAT32 only */
unsigned char crtdate[2]; /* FAT32 only */
unsigned char lastaccessdate[2]; /* FAT32 only */
unsigned char clusterhi[2]; /* FAT32 only */
unsigned char ctime[2];
unsigned char cdate[2];
unsigned char clusterlo[2]; /* fat12,fat16,fat32 */
unsigned char filesize[4];
} F_DIRENTRY;
unsigned char _f_getdirsector ( unsigned long );
unsigned char _f_findfilewc ( char *, char *, F_POS *, F_DIRENTRY * *, unsigned char );
unsigned char _f_findpath ( F_NAME *, F_POS * );
unsigned long _f_getdecluster ( F_DIRENTRY * );
unsigned char _f_writedirsector ( void );
void _f_setdecluster ( F_DIRENTRY *, unsigned long );
unsigned char _f_addentry ( F_NAME *, F_POS *, F_DIRENTRY * * );
#ifdef __cplusplus
}
#endif
#endif /* ifndef __DIR_H */

View file

@ -0,0 +1,216 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#include "../../api/fat_sl.h"
#include "../../psp/include/psp_string.h"
#include "drv.h"
#include "util.h"
#include "volume.h"
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
F_DRIVER * mdrv = NULL; /* driver structure */
/****************************************************************************
*
* _f_checkstatus
*
* checking a volume driver status, if media is removed or has been changed
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_checkstatus ( void )
{
if ( mdrv->getstatus != NULL )
{
if ( mdrv->getstatus( mdrv ) & ( F_ST_MISSING | F_ST_CHANGED ) )
{
gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
return F_ERR_CARDREMOVED;
}
}
return F_NO_ERROR;
}
/****************************************************************************
*
* _f_writesector
*
* write sector data on a volume, it calls low level driver function, it
* writes a complete sector
*
* INPUTS
* sector - which physical sector
*
* RETURNS
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_writeglsector ( unsigned long sector )
{
unsigned char retry;
if ( mdrv->writesector == NULL )
{
gl_volume.state = F_STATE_NEEDMOUNT; /*no write function*/
return F_ERR_ACCESSDENIED;
}
if ( sector == (unsigned long)-1 )
{
if ( gl_file.modified )
{
sector = gl_file.pos.sector;
}
else
{
sector = gl_volume.actsector;
}
}
if ( sector != (unsigned long)-1 )
{
if ( mdrv->getstatus != NULL )
{
unsigned int status;
status = mdrv->getstatus( mdrv );
if ( status & ( F_ST_MISSING | F_ST_CHANGED ) )
{
gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
return F_ERR_CARDREMOVED;
}
if ( status & ( F_ST_WRPROTECT ) )
{
gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
return F_ERR_WRITEPROTECT;
}
}
gl_volume.modified = 0;
gl_file.modified = 0;
gl_volume.actsector = sector;
for ( retry = 3 ; retry ; retry-- )
{
int mdrv_ret;
mdrv_ret = mdrv->writesector( mdrv, (unsigned char *)gl_sector, sector );
if ( !mdrv_ret )
{
return F_NO_ERROR;
}
if ( mdrv_ret == -1 )
{
gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
return F_ERR_CARDREMOVED;
}
}
}
return F_ERR_ONDRIVE;
} /* _f_writeglsector */
/****************************************************************************
*
* _f_readsector
*
* read sector data from a volume, it calls low level driver function, it
* reads a complete sector
*
* INPUTS
* sector - which physical sector is read
*
* RETURNS
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_readglsector ( unsigned long sector )
{
unsigned char retry;
unsigned char ret;
if ( sector == gl_volume.actsector )
{
return F_NO_ERROR;
}
if ( gl_volume.modified || gl_file.modified )
{
ret = _f_writeglsector( (unsigned long)-1 );
if ( ret )
{
return ret;
}
}
for ( retry = 3 ; retry ; retry-- )
{
int mdrv_ret;
mdrv_ret = mdrv->readsector( mdrv, (unsigned char *)gl_sector, sector );
if ( !mdrv_ret )
{
gl_volume.actsector = sector;
return F_NO_ERROR;
}
if ( mdrv_ret == -1 )
{
gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
return F_ERR_CARDREMOVED;
}
}
gl_volume.actsector = (unsigned long)-1;
return F_ERR_ONDRIVE;
} /* _f_readglsector */

View file

@ -0,0 +1,61 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef __DRV_H
#define __DRV_H
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern F_DRIVER * mdrv; /* driver structure */
unsigned char _f_checkstatus ( void );
unsigned char _f_readglsector ( unsigned long );
unsigned char _f_writeglsector ( unsigned long );
#ifdef __cplusplus
}
#endif
#endif /* ifndef __DRV_H */

View file

@ -0,0 +1,642 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#define FS_MUTEX_DEFINED
#include "../../api/fat_sl.h"
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#if F_FS_THREAD_AWARE == 1
xSemaphoreHandle fs_lock_semaphore;
/*
** fr_findfirst
**
** find first time a file using wildcards
**
** INPUT : filename - name of the file
** *find - pointer to a pre-define F_FIND structure
** RETURN: F_NOERR - on success
** F_ERR_NOTFOUND - if not found
*/
unsigned char fr_findfirst ( const char * filename, F_FIND * find )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_findfirst( filename, find );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_findnext
**
** find next time a file using wildcards
**
** INPUT : *find - pointer to a pre-define F_FIND structure
** RETURN: F_NOERR - on success
** F_ERR_NOTFOUND - if not found
*/
unsigned char fr_findnext ( F_FIND * find )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_findnext( find );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_filelength
**
** Get the length of a file
**
** INPUT : filename - name of the file
** RETURN: size of the file or F_ERR_INVALID if not exists or volume not working
*/
long fr_filelength ( const char * filename )
{
unsigned long rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_filelength( filename );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = 0;
}
return rc;
}
/*
** fr_open
**
** open a file
**
** INPUT : filename - file to be opened
** mode - open method (r,w,a,r+,w+,a+)
** RETURN: pointer to a file descriptor or 0 on error
*/
F_FILE * fr_open ( const char * filename, const char * mode )
{
F_FILE * rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_open( filename, mode );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = NULL;
}
return rc;
}
/*
** fr_close
**
** Close a previously opened file.
**
** INPUT : *filehandle - pointer to the file descriptor
** RETURN: F_NOERR on success, other if error
*/
unsigned char fr_close ( F_FILE * filehandle )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_close( filehandle );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_read
**
** Read from a file.
**
** INPUT : buf - buffer to read data
** size - number of unique
** size_st - size of unique
** *filehandle - pointer to file descriptor
** OUTPUT: number of read bytes
*/
long fr_read ( void * bbuf, long size, long size_st, F_FILE * filehandle )
{
long rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_read( bbuf, size, size_st, filehandle );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = 0;
}
return rc;
}
/*
** fr_write
**
** INPUT : bbuf - buffer to write from
** size - number of unique
** size_st - size of unique
** *filehandle - pointer to the file descriptor
** RETURN: number of written bytes
*/
long fr_write ( const void * bbuf, long size, long size_st, F_FILE * filehandle )
{
long rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_write( bbuf, size, size_st, filehandle );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = 0;
}
return rc;
}
/*
** fr_seek
**
** Seek in a file.
**
** INPUT : *filehandle - pointer to a file descriptor
** offset - offset
** whence - F_SEEK_SET: position = offset
** F_SEEK_CUR: position = position + offset
** F_SEEK_END: position = end of file (offset=0)
** RETURN: F_NOERR on succes, other if error.
*/
unsigned char fr_seek ( F_FILE * filehandle, long offset, unsigned char whence )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_seek( filehandle, offset, whence );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_tell
**
** get current position in the file
**
** INPUT : *filehandle - pointer to a file descriptor
** RETURN: -1 on error or current position.
*/
long fr_tell ( F_FILE * filehandle )
{
long rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_tell( filehandle );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = -1;
}
return rc;
}
/*
** fr_getc
**
** read one byte from a file
**
** INPUT : *filehandle - pointer to a file descriptor
** RETURN: -1 if error, otherwise the read character.
*/
int fr_getc ( F_FILE * filehandle )
{
int rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_getc( filehandle );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = -1;
}
return rc;
}
/*
** fr_putc
**
** write one byte to a file
**
** INPUT : ch - character to write
** *filehandle - pointer to a file handler
** RETURN: ch on success, -1 on error
*/
int fr_putc ( int ch, F_FILE * filehandle )
{
int rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_putc( ch, filehandle );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = -1;
}
return rc;
}
/*
** fr_rewind
**
** set current position in the file to the beginning
**
** INPUT : *filehandle - pointer to a file descriptor
** RETURN: F_NOERR on succes, other if error.
*/
unsigned char fr_rewind ( F_FILE * filehandle )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_rewind( filehandle );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_eof
**
** check if current position is at the end of the file.
**
** INPUT : *filehandle - pointer to a file descriptor
** RETURN: F_ERR_EOF - at the end of the file
** F_NOERR - no error, end of the file not reached
** other - on error
*/
unsigned char fr_eof ( F_FILE * filehandle )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_eof( filehandle );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** Format the device
*/
unsigned char fr_hardformat ( unsigned char fattype )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_hardformat( fattype );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_get_serial
**
** Get serial number
**
** OUTPUT: serial - where to write the serial number
** RETURN: error code
*/
unsigned char fr_getserial ( unsigned long * serial )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_getserial( serial );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_delete
**
** Delete a file. Removes the chain that belongs to the file and inserts a new descriptor
** to the directory with first_cluster set to 0.
**
** INPUT : filename - name of the file to delete
** RETURN: F_NOERR on success, other if error.
*/
unsigned char fr_delete ( const char * filename )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_delete( filename );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_truncate
**
** Open a file and set end of file
**
** INPUT: filename - name of the file
** filesize - required new size
** RETURN: NULL on error, otherwise file pointer
*/
F_FILE * fr_truncate ( const char * filename, long filesize )
{
F_FILE * f;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
f = fn_truncate( filename, filesize );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
f = NULL;
}
return f;
}
/*
** fr_getfreespace
**
** Get free space on the volume
**
** OUTPUT: *sp - pre-defined F_SPACE structure, where information will be stored
** RETURN: F_NOERR - on success
** F_ERR_NOTFORMATTED - if volume is not formatted
*/
unsigned char fr_getfreespace ( F_SPACE * sp )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_getfreespace( sp );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_chdir
**
** Change to a directory
**
** INPUT: path - path to the dircetory
** RETURN: 0 - on success, other if error
*/
unsigned char fr_chdir ( const char * path )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_chdir( path );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_mkdir
**
** Create a directory
**
** INPUT: path - new directory path
** RETURN: 0 - on success, other if error
*/
unsigned char fr_mkdir ( const char * path )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_mkdir( path );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_rmdir
**
** Removes a directory
**
** INPUT: path - path to remove
** RETURN: 0 - on success, other if error
*/
unsigned char fr_rmdir ( const char * path )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_rmdir( path );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_getcwd
**
** Get current working directory
**
** INPUT: maxlen - maximum length allowed
** OUTPUT: path - current working directory
** RETURN: 0 - on success, other if error
*/
unsigned char fr_getcwd ( char * path, unsigned char maxlen, char root )
{
unsigned char rc;
if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
{
rc = fn_getcwd( path, maxlen, root );
xSemaphoreGive( fs_lock_semaphore );
}
else
{
rc = F_ERR_OS;
}
return rc;
}
/*
** fr_init
**
** Initialize FAT_SL OS module
**
** RETURN: F_NO_ERROR or F_ERR_OS
*/
unsigned char fr_init ( void )
{
return F_NO_ERROR;
}
#endif /* F_FS_THREAD_AWARE */

View file

@ -0,0 +1,59 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _F_RTOS_H
#define _F_RTOS_H
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
unsigned char fr_init ( void );
#ifdef __cplusplus
}
#endif
#endif /* ifndef _F_RTOS_H */

View file

@ -0,0 +1,598 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#include "../../api/fat_sl.h"
#include "fat.h"
#include "util.h"
#include "volume.h"
#include "drv.h"
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
/****************************************************************************
*
* _f_writefatsector
*
* writing fat sector into volume, this function check if fat was modified
* and writes data
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_writefatsector ( void )
{
unsigned char a;
if ( gl_volume.modified )
{
unsigned long fatsector = gl_volume.firstfat.sector + gl_volume.fatsector;
if ( gl_volume.fatsector >= gl_volume.firstfat.num )
{
return F_ERR_INVALIDSECTOR;
}
for ( a = 0 ; a < gl_volume.bootrecord.number_of_FATs ; a++ )
{
unsigned char ret;
ret = _f_writeglsector( fatsector );
if ( ret )
{
return ret;
}
fatsector += gl_volume.firstfat.num;
}
gl_volume.modified = 0;
}
return F_NO_ERROR;
} /* _f_writefatsector */
/****************************************************************************
*
* _f_getfatsector
*
* read a fat sector from media
*
* INPUTS
*
* sector - which fat sector is needed, this sector number is zero based
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_getfatsector ( unsigned long sector )
{
unsigned char a;
if ( gl_volume.fatsector != sector )
{
unsigned long fatsector;
gl_volume.fatsector = sector;
if ( gl_volume.fatsector >= gl_volume.firstfat.num )
{
return F_ERR_INVALIDSECTOR;
}
fatsector = gl_volume.firstfat.sector + gl_volume.fatsector;
for ( a = 0 ; a < gl_volume.bootrecord.number_of_FATs ; a++ )
{
if ( !_f_readglsector( fatsector ) )
{
return F_NO_ERROR;
}
fatsector += gl_volume.firstfat.num;
}
return F_ERR_READ;
}
return F_NO_ERROR;
} /* _f_getfatsector */
/****************************************************************************
*
* _f_setclustervalue
*
* set a cluster value in the FAT
*
* INPUTS
*
* cluster - which cluster's value need to be modified
* data - new value of the cluster
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_setclustervalue ( unsigned long cluster, unsigned long _tdata )
{
unsigned char ret;
switch ( gl_volume.mediatype )
{
case F_FAT16_MEDIA:
{
unsigned long sector = cluster;
unsigned short s_data = (unsigned short)( _tdata & 0xffff ); /*keep 16 bit only*/
sector /= ( F_SECTOR_SIZE / 2 );
cluster -= sector * ( F_SECTOR_SIZE / 2 );
ret = _f_getfatsector( sector );
if ( ret )
{
return ret;
}
if ( _f_getword( &gl_sector[cluster << 1] ) != s_data )
{
_f_setword( &gl_sector[cluster << 1], s_data );
gl_volume.modified = 1;
}
}
break;
case F_FAT12_MEDIA:
{
unsigned char f12new[2];
unsigned long sector = cluster;
unsigned short pos;
unsigned short s_data = (unsigned short)( _tdata & 0x0fff ); /*keep 12 bit only*/
if ( cluster & 1 )
{
s_data <<= 4;
}
_f_setword( f12new, s_data ); /*create new data*/
sector += sector / 2; /*1.5 bytes*/
pos = (unsigned short)( sector % F_SECTOR_SIZE );
sector /= F_SECTOR_SIZE;
ret = _f_getfatsector( sector );
if ( ret )
{
return ret;
}
if ( cluster & 1 )
{
f12new[0] |= gl_sector[pos] & 0x0f;
}
if ( gl_sector[pos] != f12new[0] )
{
gl_sector[pos] = f12new[0];
gl_volume.modified = 1;
}
pos++;
if ( pos >= 512 )
{
ret = _f_getfatsector( sector + 1 );
if ( ret )
{
return ret;
}
pos = 0;
}
if ( !( cluster & 1 ) )
{
f12new[1] |= gl_sector[pos] & 0xf0;
}
if ( gl_sector[pos] != f12new[1] )
{
gl_sector[pos] = f12new[1];
gl_volume.modified = 1;
}
}
break;
case F_FAT32_MEDIA:
{
unsigned long sector = cluster;
unsigned long oldv;
sector /= ( F_SECTOR_SIZE / 4 );
cluster -= sector * ( F_SECTOR_SIZE / 4 );
ret = _f_getfatsector( sector );
if ( ret )
{
return ret;
}
oldv = _f_getlong( &gl_sector[cluster << 2] );
_tdata &= 0x0fffffff;
_tdata |= oldv & 0xf0000000; /*keep 4 top bits*/
if ( _tdata != oldv )
{
_f_setlong( &gl_sector[cluster << 2], _tdata );
gl_volume.modified = 1;
}
}
break;
default:
return F_ERR_INVALIDMEDIA;
} /* switch */
return F_NO_ERROR;
} /* _f_setclustervalue */
/****************************************************************************
*
* _f_getclustervalue
*
* get a cluster value from FAT
*
* INPUTS
*
* cluster - which cluster value is requested
* pvalue - where to store data
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_getclustervalue ( unsigned long cluster, unsigned long * pvalue )
{
unsigned long val;
unsigned char ret;
switch ( gl_volume.mediatype )
{
case F_FAT16_MEDIA:
{
unsigned long sector = cluster;
sector /= ( F_SECTOR_SIZE / 2 );
cluster -= sector * ( F_SECTOR_SIZE / 2 );
ret = _f_getfatsector( sector );
if ( ret )
{
return ret;
}
val = _f_getword( &gl_sector[cluster << 1] );
if ( val >= ( F_CLUSTER_RESERVED & 0xffff ) )
{
val |= 0x0ffff000; /*extends it*/
}
if ( pvalue )
{
*pvalue = val;
}
}
break;
case F_FAT12_MEDIA:
{
unsigned char dataf12[2];
unsigned long sector = cluster;
unsigned short pos;
sector += sector / 2; /*1.5 bytes*/
pos = (unsigned short)( sector % F_SECTOR_SIZE );
sector /= F_SECTOR_SIZE;
ret = _f_getfatsector( sector );
if ( ret )
{
return ret;
}
dataf12[0] = gl_sector[pos++];
if ( pos >= 512 )
{
ret = _f_getfatsector( sector + 1 );
if ( ret )
{
return ret;
}
pos = 0;
}
dataf12[1] = gl_sector[pos];
val = _f_getword( dataf12 );
if ( cluster & 1 )
{
val = val >> 4;
}
else
{
val = val & 0xfff;
}
if ( val >= ( F_CLUSTER_RESERVED & 0xfff ) )
{
val |= 0x0ffff000; /*extends it*/
}
if ( pvalue )
{
*pvalue = val;
}
}
break;
case F_FAT32_MEDIA:
{
unsigned long sector = cluster;
sector /= ( F_SECTOR_SIZE / 4 );
cluster -= sector * ( F_SECTOR_SIZE / 4 );
ret = _f_getfatsector( sector );
if ( ret )
{
return ret;
}
if ( pvalue )
{
*pvalue = _f_getlong( &gl_sector[cluster << 2] ) & 0x0fffffff; /*28bit*/
}
}
break;
default:
return F_ERR_INVALIDMEDIA;
} /* switch */
return F_NO_ERROR;
} /* _f_getclustervalue */
/****************************************************************************
*
* _f_clustertopos
*
* convert a cluster position into physical sector position
*
* INPUTS
*
* cluster - original cluster position
* pos - position structure to fills the position
*
***************************************************************************/
void _f_clustertopos ( unsigned long cluster, F_POS * pos )
{
pos->cluster = cluster;
if ( !cluster )
{
pos->sector = gl_volume.root.sector;
pos->sectorend = pos->sector + gl_volume.root.num;
}
else
{
unsigned long sectorcou = gl_volume.bootrecord.sector_per_cluster;
pos->sector = ( pos->cluster - 2 ) * sectorcou + gl_volume._tdata.sector;
pos->sectorend = pos->sector + sectorcou;
}
if ( cluster >= F_CLUSTER_RESERVED )
{
pos->sectorend = 0;
}
pos->pos = 0;
} /* _f_clustertopos */
/****************************************************************************
*
* _f_getcurrsector
*
* read current sector according in file structure
*
* INPUTS
* f - internal file pointer
*
* RETURNS
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_getcurrsector ( void )
{
unsigned char ret;
unsigned long cluster;
if ( gl_file.pos.sector == gl_file.pos.sectorend )
{
gl_volume.fatsector = (unsigned long)-1;
ret = _f_getclustervalue( gl_file.pos.cluster, &cluster );
if ( ret )
{
return ret;
}
if ( cluster >= F_CLUSTER_RESERVED )
{
return F_ERR_EOF;
}
gl_file.prevcluster = gl_file.pos.cluster;
_f_clustertopos( cluster, &gl_file.pos );
}
return _f_readglsector( gl_file.pos.sector );
} /* _f_getcurrsector */
/****************************************************************************
*
* _f_alloccluster
*
* allocate cluster from FAT
*
* INPUTS
* pcluster - where to store the allocated cluster number
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_alloccluster ( unsigned long * pcluster )
{
unsigned long maxcluster = gl_volume.maxcluster;
unsigned long cou;
unsigned long cluster = gl_volume.lastalloccluster;
unsigned long value;
unsigned char ret;
for ( cou = 0 ; cou < maxcluster ; cou++ )
{
if ( cluster >= maxcluster )
{
cluster = 0;
}
ret = _f_getclustervalue( cluster, &value );
if ( ret )
{
return ret;
}
if ( !value )
{
gl_volume.lastalloccluster = cluster + 1; /*set next one*/
*pcluster = cluster;
return F_NO_ERROR;
}
cluster++;
}
return F_ERR_NOMOREENTRY;
} /* _f_alloccluster */
/****************************************************************************
*
* _f_removechain
*
* remove cluster chain from fat
*
* INPUTS
* cluster - first cluster in the cluster chain
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_removechain ( unsigned long cluster )
{
gl_volume.fatsector = (unsigned long)-1;
if ( cluster < gl_volume.lastalloccluster ) /*this could be the begining of alloc*/
{
gl_volume.lastalloccluster = cluster;
}
while ( cluster < F_CLUSTER_RESERVED && cluster >= 2 )
{
unsigned long nextcluster;
unsigned char ret = _f_getclustervalue( cluster, &nextcluster );
if ( ret )
{
return ret;
}
ret = _f_setclustervalue( cluster, F_CLUSTER_FREE );
if ( ret )
{
return ret;
}
cluster = nextcluster;
}
return _f_writefatsector();
} /* _f_removechain */

View file

@ -0,0 +1,65 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef __FAT_H
#define __FAT_H
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
unsigned char _f_getfatsector ( unsigned long );
unsigned char _f_getclustervalue ( unsigned long, unsigned long * );
void _f_clustertopos ( unsigned long, F_POS * );
unsigned char _f_getcurrsector ( void );
unsigned char _f_writefatsector ( void );
unsigned char _f_setclustervalue ( unsigned long, unsigned long );
unsigned char _f_alloccluster ( unsigned long * );
unsigned char _f_removechain ( unsigned long );
#ifdef __cplusplus
}
#endif
#endif /* ifndef __FAT_H */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,63 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef __FILE_H
#define __FILE_H
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define F_FILE_CLOSE 0x00
#define F_FILE_RD 0x01
#define F_FILE_WR 0x02
#define F_FILE_A 0x04
#define F_FILE_RDP 0x08
#define F_FILE_WRP 0x10
#define F_FILE_AP 0x20
#ifdef __cplusplus
}
#endif
#endif /* ifndef __FILE_H */

View file

@ -0,0 +1,320 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#include "../../api/fat_sl.h"
#include "../../psp/include/psp_rtc.h"
#include "dir.h"
#include "util.h"
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
/****************************************************************************
*
* _f_getword
*
* get a word 16bit number from a memory (it uses LITTLE ENDIAN mode always)
*
* INPUTS
*
* ptr - pointer where data is
*
* RETURNS
*
* word number
*
***************************************************************************/
unsigned short _f_getword ( void * ptr )
{
unsigned char * sptr = (unsigned char *)ptr;
unsigned short ret;
ret = (unsigned short)( sptr[1] & 0xff );
ret <<= 8;
ret |= ( sptr[0] & 0xff );
return ret;
}
/****************************************************************************
*
* _f_setword
*
* set a word 16bit number into a memory (it uses LITTLE ENDIAN mode always)
*
* INPUTS
*
* ptr - where to store data
* num - 16 bit number to store
*
***************************************************************************/
void _f_setword ( void * ptr, unsigned short num )
{
unsigned char * sptr = (unsigned char *)ptr;
sptr[1] = (unsigned char)( num >> 8 );
sptr[0] = (unsigned char)( num );
}
/****************************************************************************
*
* _f_getlong
*
* get a long 32bit number from a memory (it uses LITTLE ENDIAN mode always)
*
* INPUTS
*
* ptr - pointer where data is
*
* RETURNS
*
* long number
*
***************************************************************************/
unsigned long _f_getlong ( void * ptr )
{
unsigned char * sptr = (unsigned char *)ptr;
unsigned long ret;
ret = (unsigned long)( sptr[3] & 0xff );
ret <<= 8;
ret |= ( sptr[2] & 0xff );
ret <<= 8;
ret |= ( sptr[1] & 0xff );
ret <<= 8;
ret |= ( sptr[0] & 0xff );
return ret;
}
/****************************************************************************
*
* _f_setlong
*
* set a long 32bit number into a memory (it uses LITTLE ENDIAN mode always)
*
* INPUTS
*
* ptr - where to store data
* num - 32 bit number to store
*
***************************************************************************/
void _f_setlong ( void * ptr, unsigned long num )
{
unsigned char * sptr = (unsigned char *)ptr;
sptr[3] = (unsigned char)( num >> 24 );
sptr[2] = (unsigned char)( num >> 16 );
sptr[1] = (unsigned char)( num >> 8 );
sptr[0] = (unsigned char)( num );
}
/****************************************************************************
*
* _setcharzero
*
* fills with zero charater to memory
*
* INPUTS
*
* num - number of characters
* ptr - where to store data
*
* RETURNS
*
* last write position
*
***************************************************************************/
unsigned char * _setcharzero ( int num, unsigned char * ptr )
{
while ( num-- )
{
*ptr++ = 0;
}
return ptr;
}
/****************************************************************************
*
* _setchar
*
* copy a charater string to memory
*
* INPUTS
*
* array - original code what to copy
* num - number of characters
* ptr - where to store data
*
* RETURNS
*
* last write position
*
***************************************************************************/
unsigned char * _setchar ( const unsigned char * array, int num, unsigned char * ptr )
{
if ( !array )
{
return _setcharzero( num, ptr );
}
while ( num-- )
{
*ptr++ = *array++;
}
return ptr;
}
/****************************************************************************
*
* _setword
*
* store a 16bit word into memory
*
* INPUTS
*
* num - 16bit number to store
* ptr - where to store data
*
* RETURNS
*
* last write position
*
***************************************************************************/
unsigned char * _setword ( unsigned short num, unsigned char * ptr )
{
_f_setword( ptr, num );
return ptr + 2;
}
/****************************************************************************
*
* _setlong
*
* store a 32bit long number into memory
*
* INPUTS
*
* num - 32bit number to store
* ptr - where to store data
*
* RETURNS
*
* last write position
*
***************************************************************************/
unsigned char * _setlong ( unsigned long num, unsigned char * ptr )
{
_f_setlong( ptr, num );
return ptr + 4;
}
/****************************************************************************
*
* _f_toupper
*
* convert a string into lower case
*
* INPUTS
*
* s - input string to convert
*
***************************************************************************/
char _f_toupper ( char ch )
{
if ( ( ch >= 'a' ) && ( ch <= 'z' ) )
{
return (char)( ch - 'a' + 'A' );
}
return ch;
}
/****************************************************************************
*
* f_igettimedate
*
* INPUTS
* time - pointer to time variable
* date - pointer to date variable
* OUTPUTS
* time - current time
* date - current date
*
* RETURNS
* none
*
***************************************************************************/
void f_igettimedate ( unsigned short * time, unsigned short * date )
{
t_psp_timedate s_timedate;
psp_getcurrenttimedate( &s_timedate );
*time = ( ( (uint16_t)s_timedate.hour << F_CTIME_HOUR_SHIFT ) & F_CTIME_HOUR_MASK )
| ( ( (uint16_t)s_timedate.min << F_CTIME_MIN_SHIFT ) & F_CTIME_MIN_MASK )
| ( ( ( (uint16_t)s_timedate.sec >> 1 ) << F_CTIME_SEC_SHIFT ) & F_CTIME_SEC_MASK );
*date = ( ( ( s_timedate.year - 1980 ) << F_CDATE_YEAR_SHIFT ) & F_CDATE_YEAR_MASK )
| ( ( (uint16_t)s_timedate.month << F_CDATE_MONTH_SHIFT ) & F_CDATE_MONTH_MASK )
| ( ( (uint16_t)s_timedate.day << F_CDATE_DAY_SHIFT ) & F_CDATE_DAY_MASK );
return;
}

View file

@ -0,0 +1,73 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef __UTIL_H
#define __UTIL_H
#include "util_sfn.h"
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
void f_igettimedate ( unsigned short * time, unsigned short * date );
unsigned short _f_getword ( void * );
unsigned long _f_getlong ( void * );
char _f_toupper ( char );
void _f_memset ( void *, unsigned char, int );
void _f_memcpy ( void *, void *, int );
void _f_setword ( void *, unsigned short );
void _f_setlong ( void *, unsigned long );
unsigned char * _setcharzero ( int, unsigned char * );
unsigned char * _setchar ( const unsigned char *, int, unsigned char * );
unsigned char * _setword ( unsigned short, unsigned char * );
unsigned char * _setlong ( unsigned long, unsigned char * );
#ifdef __cplusplus
}
#endif
#endif /* ifndef __UTIL_H */

View file

@ -0,0 +1,540 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#include "../../api/fat_sl.h"
#include "util.h"
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
/****************************************************************************
*
* _f_checknameprim
*
* checking a string if could be valid
*
* INPUTS
*
* ptr - pointer to name or extension
* len - number max char of name or extension
*
* RETURNS
*
***************************************************************************/
static unsigned char _f_checknameprim ( char * ptr, unsigned char len )
{
unsigned char inspace = 0;
while ( len-- )
{
char ch = *ptr++;
if ( !inspace )
{
if ( ch == ' ' )
{
inspace = 1;
}
if ( ( ch == '|' ) || ( ch == '[' ) || ( ch == ']' ) || ( ch == '<' ) || ( ch == '>' ) || ( ch == '/' ) || ( ch == '\\' ) || ( ch == ':' ) )
{
return 1;
}
}
else if ( ch != ' ' )
{
return 1; /*no inspace allowed*/
}
}
return 0;
} /* _f_checknameprim */
/****************************************************************************
*
* _f_checkname
*
* checking filename and extension for special characters
*
* INPUTS
*
* name - filename (e.g.: filename)
* ext - extension of file (e.g.: txt)
*
* RETURNS
*
* 0 - if no contains invalid character
* other - if contains any invalid character
*
***************************************************************************/
unsigned char _f_checkname ( char * name, char * ext )
{
if ( _f_checknameprim( name, F_MAXNAME ) )
{
return 1;
}
if ( _f_checknameprim( ext, F_MAXEXT ) )
{
return 1;
}
return 0;
}
/****************************************************************************
*
* _f_checknamewc
*
* checking filename and extension for wildcard character
*
* INPUTS
*
* name - filename (e.g.: filename)
* ext - extension of file (e.g.: txt)
*
* RETURNS
*
* 0 - if no contains wildcard character (? or *)
* other - if contains any wildcard character
*
***************************************************************************/
unsigned char _f_checknamewc ( const char * name, const char * ext )
{
unsigned char a = 0;
for ( a = 0 ; a < F_MAXNAME ; a++ )
{
char ch = name[a];
if ( ( ch == '?' ) || ( ch == '*' ) )
{
return 1;
}
}
for ( a = 0 ; a < F_MAXEXT ; a++ )
{
char ch = ext[a];
if ( ( ch == '?' ) || ( ch == '*' ) )
{
return 1;
}
}
return _f_checkname( (char *)name, (char *)ext );
} /* _f_checknamewc */
/****************************************************************************
*
* _f_setnameext
*
* convert a string into filename and extension separatelly, the terminator
* character could be zero char, '/' or '\'
*
* INPUTS
*
* s - source string (e.g.: hello.txt)
* name - where to store name (this array size has to be F_MAXNAME (8))
* ext - where to store extension (this array size has to be F_MAXEXT (3))
*
* RETURNS
*
* length of the used bytes from source string array
*
***************************************************************************/
unsigned char _f_setnameext ( char * s, char * name, char * ext )
{
unsigned char len, extlen = 0;
unsigned char a;
unsigned char setext = 1;
for ( len = 0 ; ; )
{
unsigned char ch = s[len];
if ( ( ch == 0 ) || ( ch == '\\' ) || ( ch == '/' ) )
{
break;
}
len++; /*calculate len*/
}
if ( len && ( s[0] == '.' ) )
{
/* if (len==1 || (s[1]=='.' && len==2)) goto dots; */
if ( ( len == 1 ) || ( s[1] == '.' ) )
{
goto dots;
}
}
for ( a = len ; a ; a-- )
{
if ( s[a - 1] == '.' )
{
unsigned char b;
extlen = (unsigned char)( len - a + 1 );
len = (unsigned char)( a - 1 );
for ( b = 0 ; b < F_MAXEXT ; b++ )
{
if ( b < extlen - 1 )
{
ext[b] = _f_toupper( s[a++] );
}
else
{
ext[b] = ' ';
}
}
setext = 0;
break;
}
}
dots:
if ( setext )
{
for ( a = 0 ; a < F_MAXEXT ; a++ )
{
ext[a] = ' ';
}
}
for ( a = 0 ; a < F_MAXNAME ; a++ )
{
if ( a < len )
{
name[a] = _f_toupper( s[a] );
}
else
{
name[a] = ' ';
}
}
return (unsigned char)( len + extlen );
} /* _f_setnameext */
/****************************************************************************
*
* _f_setfsname
*
* convert a single string into F_NAME structure
*
* INPUTS
*
* name - combined name with drive,path,filename,extension used for source
* fsname - where to fill this structure with separated drive,path,name,ext
*
* RETURNS
*
* 0 - if successfully
* other - if name contains invalid path or name
*
***************************************************************************/
unsigned char _f_setfsname ( const char * name, F_NAME * fsname )
{
char s[F_MAXPATH];
unsigned char namepos = 0;
unsigned char pathpos = 0;
unsigned char a;
s[0] = 0;
if ( !name[0] )
{
return 1; /*no name*/
}
if ( name[1] == ':' )
{
name += 2;
}
if ( ( name[0] != '/' ) && ( name[0] != '\\' ) )
{
if ( fn_getcwd( fsname->path, F_MAXPATH, 0 ) )
{
return 1; /*error*/
}
for ( pathpos = 0 ; fsname->path[pathpos] ; )
{
pathpos++;
}
}
for ( ; ; )
{
char ch = _f_toupper( *name++ );
if ( !ch )
{
break;
}
if ( ch == ':' )
{
return 1; /*not allowed*/
}
if ( ( ch == '/' ) || ( ch == '\\' ) )
{
if ( pathpos )
{
if ( fsname->path[pathpos - 1] == '/' )
{
return 1; /*not allowed double */
}
if ( pathpos >= F_MAXPATH - 2 )
{
return 1; /*path too long*/
}
fsname->path[pathpos++] = '/';
}
for ( ; namepos ; )
{
if ( s[namepos - 1] != ' ' )
{
break;
}
namepos--; /*remove end spaces*/
}
for ( a = 0 ; a < namepos ; a++ )
{
if ( pathpos >= F_MAXPATH - 2 )
{
return 1; /*path too long*/
}
fsname->path[pathpos++] = s[a];
}
namepos = 0;
continue;
}
if ( ( ch == ' ' ) && ( !namepos ) )
{
continue; /*remove start spaces*/
}
if ( namepos >= ( sizeof( s ) - 2 ) )
{
return 1; /*name too long*/
}
s[namepos++] = ch;
}
s[namepos] = 0; /*terminates it*/
fsname->path[pathpos] = 0; /*terminates it*/
for ( ; namepos ; )
{
if ( s[namepos - 1] != ' ' )
{
break;
}
s[namepos - 1] = 0; /*remove end spaces*/
namepos--;
}
if ( !_f_setnameext( s, fsname->filename, fsname->fileext ) )
{
return 2; /*no name*/
}
if ( fsname->filename[0] == ' ' )
{
return 1; /*cannot be*/
}
return 0;
} /* _f_setfsname */
/****************************************************************************
*
* _f_createfullname
*
* create full name
*
* INPUTS
*
* buffer - where to create
* buffersize - size of the buffer
* drivenum - drive number
* path - path of the file
* filename - file name
* fileext - file extension
*
* RETURNS
*
* 1 - if found and osize is filled
* 0 - not found
*
***************************************************************************/
int _f_createfullname ( char * buffer, int buffersize, char * path, char * filename, char * fileext )
{
char * fullname = buffer;
int a;
/* adding drive letter */
if ( buffersize < 1 )
{
return 1;
}
*fullname++ = '/';
buffersize -= 1;
/* adding path */
if ( path[0] )
{
for ( ; ; )
{
char ch = *path++;
if ( !ch )
{
break;
}
if ( buffersize <= 0 )
{
return 1;
}
*fullname++ = ch;
buffersize--;
}
/* adding separator */
if ( buffersize <= 0 )
{
return 1;
}
*fullname++ = '/';
}
/* adding name */
for ( a = 0 ; a < F_MAXNAME ; a++ )
{
char ch = *filename++;
if ( ( !ch ) || ( ch == 32 ) )
{
break;
}
if ( buffersize <= 0 )
{
return 1;
}
*fullname++ = ch;
buffersize--;
}
/* adding ext*/
if ( fileext[0] && ( fileext[0] != 32 ) )
{
/* adding dot */
if ( !buffersize )
{
return 1;
}
*fullname++ = '.';
for ( a = 0 ; a < F_MAXEXT ; a++ )
{
char ch = *fileext++;
if ( ( !ch ) || ( ch == 32 ) )
{
break;
}
if ( buffersize <= 0 )
{
return 1;
}
*fullname++ = ch;
buffersize--;
}
}
/* adding terminator */
if ( buffersize <= 0 )
{
return 1;
}
*fullname++ = 0;
return 0;
} /* _f_createfullname */

View file

@ -0,0 +1,62 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef __UTIL_SFN_H
#define __UTIL_SFN_H
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
unsigned char _f_checknamewc ( const char *, const char * );
unsigned char _f_checkname ( char *, char * );
unsigned char _f_setnameext ( char *, char *, char * );
unsigned char _f_setfsname ( const char *, F_NAME * );
int _f_createfullname ( char * buffer, int buffersize, char * path, char * filename, char * fileext );
#ifdef __cplusplus
}
#endif
#endif /* ifndef __UTIL_SFN_H */

View file

@ -0,0 +1,939 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#include "../../api/fat_sl.h"
#include "../../psp/include/psp_string.h"
#include "volume.h"
#include "util.h"
#include "drv.h"
#include "fat.h"
#include "dir.h"
#include "file.h"
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#if F_FS_THREAD_AWARE == 1
#include "f_lock.h"
#endif
F_VOLUME gl_volume; /* only one volume */
F_FILE gl_file; /* file */
char gl_sector[F_SECTOR_SIZE]; /* actual sector */
#if F_FILE_CHANGED_EVENT
F_FILE_CHANGED_EVENTFUNC f_filechangedevent;
#endif
/* Defines the number of sectors per cluster on a sector number basis */
typedef struct
{
unsigned long max_sectors;
unsigned char sector_per_cluster;
} t_FAT32_CS;
static const t_FAT32_CS FAT32_CS[] =
{
{ 0x00020000, 1 } /* ->64MB */
, { 0x00040000, 2 } /* ->128MB */
, { 0x00080000, 4 } /* ->256MB */
, { 0x01000000, 8 } /* ->8GB */
, { 0x02000000, 16 } /* ->16GB */
, { 0x0ffffff0, 32 } /* -> ... */
};
/****************************************************************************
*
* _f_writebootrecord
*
* writing boot record onto a volume, it uses number of hidden sector variable
*
* INPUTS
* phy - media physical descriptor
*
* RETURNS
* error code or zero if successful
*
***************************************************************************/
static unsigned char _f_writebootrecord ( F_PHY * phy )
{
unsigned char jump_code[] =
{
0xeb, 0x3c, 0x90
};
unsigned char oem_name[] = "MSDOS5.0";
unsigned char executable_marker[] =
{
0x55, 0xaa
};
unsigned char * ptr = (unsigned char *)gl_sector;
unsigned char rs;
unsigned short mre;
unsigned char ret;
unsigned char _n = 0;
if ( gl_volume.mediatype == F_FAT32_MEDIA )
{ /*write FS_INFO*/
unsigned char a;
rs = 32 + 4;
mre = 0;
psp_memset( ptr, 0, F_SECTOR_SIZE );
for ( a = 0 ; a < rs ; a++ )
{
ret = _f_writeglsector( a ); /*erase reserved area*/
if ( ret )
{
return ret;
}
}
ptr = _setlong( 0x41615252, ptr ); /*signature*/
ptr = _setcharzero( 480, ptr ); /*reserved*/
ptr = _setlong( 0x61417272, ptr ); /*signature*/
ptr = _setlong( 0xffffffff, ptr ); /*no last*/
ptr = _setlong( 0xffffffff, ptr ); /*no hint*/
ptr = _setcharzero( 12, ptr ); /*reserved*/
ptr = _setlong( 0xaa550000, ptr ); /*trail*/
ret = _f_writeglsector( 1 ); /*write FSINFO*/
if ( ret )
{
return ret;
}
ret = _f_writeglsector( 1 + 6 ); /*write FSINFO*/
if ( ret )
{
return ret;
}
}
else
{
rs = 1;
mre = 512;
}
ptr = (unsigned char *)gl_sector;
ptr = _setchar( jump_code, sizeof( jump_code ), ptr );
ptr = _setchar( oem_name, sizeof( oem_name ) - 1, ptr );
ptr = _setword( F_SECTOR_SIZE, ptr );
*ptr++ = gl_volume.bootrecord.sector_per_cluster;
ptr = _setword( rs, ptr ); /* reserved sectors */
*ptr++ = 2; /* number of FATs */
ptr = _setword( mre, ptr ); /* max root entry */
if ( phy->number_of_sectors < 0x10000 )
{
ptr = _setword( (unsigned short)phy->number_of_sectors, ptr );
}
else
{
ptr = _setword( 0, ptr );
}
*ptr++ = 0xf0; /* media descriptor */
ptr = _setword( (unsigned short)gl_volume.bootrecord.sector_per_FAT, ptr );
ptr = _setword( phy->sector_per_track, ptr );
ptr = _setword( phy->number_of_heads, ptr );
ptr = _setlong( 0, ptr ); /* number of hidden sectors */
if ( phy->number_of_sectors >= 0x10000 )
{
ptr = _setlong( phy->number_of_sectors, ptr );
}
else
{
ptr = _setlong( 0, ptr ); /* number of sectors */
}
if ( gl_volume.mediatype == F_FAT32_MEDIA )
{
ptr = _setlong( gl_volume.bootrecord.sector_per_FAT32, ptr );
ptr = _setword( 0, ptr );
ptr = _setword( 0, ptr );
ptr = _setlong( 2, ptr );
ptr = _setword( 1, ptr );
ptr = _setword( 6, ptr );
ptr = _setchar( NULL, 12, ptr );
_n = 28;
}
ptr = _setword( 0, ptr ); /* logical drive num */
*ptr++ = 0x29; /* extended signature */
ptr = _setlong( 0x11223344, ptr );
ptr = _setchar( (const unsigned char *)"NO NAME ", 11, ptr ); /* volume name */
switch ( gl_volume.mediatype )
{
case F_FAT12_MEDIA:
ptr = _setchar( (const unsigned char *)"FAT12 ", 8, ptr );
break;
case F_FAT16_MEDIA:
ptr = _setchar( (const unsigned char *)"FAT16 ", 8, ptr );
break;
case F_FAT32_MEDIA:
ptr = _setchar( (const unsigned char *)"FAT32 ", 8, ptr );
break;
default:
return F_ERR_INVALIDMEDIA;
} /* switch */
ptr = _setchar( 0, 448 - _n, ptr );
ptr = _setchar( executable_marker, sizeof( executable_marker ), ptr );
if ( _n )
{
ret = _f_writeglsector( 6 );
if ( ret )
{
return ret;
}
}
return _f_writeglsector( 0 ); /*write bootrecord*/
} /* _f_writebootrecord */
/****************************************************************************
*
* _f_buildsectors
*
* INPUTS
* phy - media physical descriptor
*
* calculate relative sector position from boot record
*
***************************************************************************/
static unsigned char _f_buildsectors ( F_PHY * phy )
{
gl_volume.mediatype = F_UNKNOWN_MEDIA;
if ( gl_volume.bootrecord.sector_per_FAT )
{
gl_volume.firstfat.sector = 1;
gl_volume.firstfat.num = gl_volume.bootrecord.sector_per_FAT;
gl_volume.root.sector = gl_volume.firstfat.sector + ( gl_volume.firstfat.num * (unsigned long)( gl_volume.bootrecord.number_of_FATs ) );
gl_volume.root.num = ( 512 * sizeof( F_DIRENTRY ) ) / F_SECTOR_SIZE;
gl_volume._tdata.sector = gl_volume.root.sector + gl_volume.root.num;
gl_volume._tdata.num = 0; /*??*/
}
else
{
gl_volume.firstfat.sector = ( 32 + 4 );
gl_volume.firstfat.num = gl_volume.bootrecord.sector_per_FAT32;
gl_volume._tdata.sector = gl_volume.firstfat.sector;
gl_volume._tdata.sector += gl_volume.firstfat.num * (unsigned long)( gl_volume.bootrecord.number_of_FATs );
gl_volume._tdata.num = 0; /*??*/
{
unsigned long sectorcou = gl_volume.bootrecord.sector_per_cluster;
gl_volume.root.sector = ( ( gl_volume.bootrecord.rootcluster - 2 ) * sectorcou ) + gl_volume._tdata.sector;
gl_volume.root.num = gl_volume.bootrecord.sector_per_cluster;
}
}
{
unsigned long maxcluster;
maxcluster = phy->number_of_sectors;
maxcluster -= gl_volume._tdata.sector;
maxcluster /= gl_volume.bootrecord.sector_per_cluster;
gl_volume.maxcluster = maxcluster;
}
if ( gl_volume.maxcluster < ( F_CLUSTER_RESERVED & 0xfff ) )
{
gl_volume.mediatype = F_FAT12_MEDIA;
}
else if ( gl_volume.maxcluster < ( F_CLUSTER_RESERVED & 0xffff ) )
{
gl_volume.mediatype = F_FAT16_MEDIA;
}
else
{
gl_volume.mediatype = F_FAT32_MEDIA;
}
return F_NO_ERROR;
} /* _f_buildsectors */
/****************************************************************************
*
* _f_prepareformat
*
* preparing boot record for formatting, it sets and calculates values
*
* INPUTS
* phy - media physical descriptor
* f_bootrecord - which bootrecord need to be prepare
* number_of_hidden_sectors - where boot record starts
* fattype - one of this definitions F_FAT12_MEDIA,F_FAT16_MEDIA,F_FAT32_MEDIA
*
* RETURNS
* error code or zero if successful
*
***************************************************************************/
static unsigned char _f_prepareformat ( F_PHY * phy, unsigned char fattype )
{
if ( !phy->number_of_sectors )
{
return F_ERR_INVALIDSECTOR;
}
gl_volume.bootrecord.number_of_FATs = 2;
gl_volume.bootrecord.media_descriptor = 0xf0;
if ( fattype != F_FAT32_MEDIA )
{
unsigned long _n;
switch ( fattype )
{
case F_FAT12_MEDIA:
_n = F_CLUSTER_RESERVED & 0xfff;
break;
case F_FAT16_MEDIA:
_n = F_CLUSTER_RESERVED & 0xffff;
break;
default:
return F_ERR_INVFATTYPE;
}
gl_volume.bootrecord.sector_per_cluster = 1;
while ( gl_volume.bootrecord.sector_per_cluster )
{
if ( phy->number_of_sectors / gl_volume.bootrecord.sector_per_cluster < _n )
{
break;
}
gl_volume.bootrecord.sector_per_cluster <<= 1;
}
if ( !gl_volume.bootrecord.sector_per_cluster )
{
return F_ERR_MEDIATOOLARGE;
}
}
else
{
unsigned char i;
for ( i = 0 ; i<( sizeof( FAT32_CS ) / sizeof( t_FAT32_CS ) ) - 1 && phy->number_of_sectors>FAT32_CS[i].max_sectors ; i++ )
{
}
gl_volume.bootrecord.sector_per_cluster = FAT32_CS[i].sector_per_cluster;
}
if ( !gl_volume.bootrecord.sector_per_cluster )
{
return F_ERR_INVALIDMEDIA; /*fat16 cannot be there*/
}
{
long secpercl = gl_volume.bootrecord.sector_per_cluster;
long nfat = gl_volume.bootrecord.number_of_FATs;
unsigned long roots;
unsigned long fatsec;
roots = ( 512 * sizeof( F_DIRENTRY ) ) / F_SECTOR_SIZE;
switch ( fattype )
{
case F_FAT32_MEDIA:
{
unsigned long _n = (unsigned long)( 128 * secpercl + nfat );
fatsec = ( phy->number_of_sectors - ( 32 + 4 ) + 2 * secpercl );
fatsec += ( _n - 1 );
fatsec /= _n;
gl_volume.bootrecord.sector_per_FAT32 = fatsec;
gl_volume.bootrecord.sector_per_FAT = 0;
}
break;
case F_FAT16_MEDIA:
{
unsigned long _n = (unsigned long)( 256 * secpercl + nfat );
fatsec = ( phy->number_of_sectors - 1 - roots + 2 * secpercl );
fatsec += ( _n - 1 );
fatsec /= _n;
gl_volume.bootrecord.sector_per_FAT = (unsigned short)( fatsec );
}
break;
case F_FAT12_MEDIA:
{
unsigned long _n = (unsigned long)( 1024 * secpercl + 3 * nfat );
fatsec = ( phy->number_of_sectors - 1 - roots + 2 * secpercl );
fatsec *= 3;
fatsec += ( _n - 1 );
fatsec /= _n;
gl_volume.bootrecord.sector_per_FAT = (unsigned short)( fatsec );
}
break;
default:
return F_ERR_INVALIDMEDIA;
} /* switch */
return F_NO_ERROR;
}
} /* _f_prepareformat */
/****************************************************************************
*
* _f_postformat
*
* erase fats, erase root directory, reset variables after formatting
*
* INPUTS
* phy - media physical descriptor
* fattype - one of this definitions F_FAT12_MEDIA,F_FAT16_MEDIA,F_FAT32_MEDIA
*
* RETURNS
* error code or zero if successful
*
***************************************************************************/
static unsigned char _f_postformat ( F_PHY * phy, unsigned char fattype )
{
unsigned long a;
unsigned char ret;
_f_buildsectors( phy ); /*get positions*/
if ( gl_volume.mediatype != fattype )
{
return F_ERR_MEDIATOOSMALL;
}
gl_volume.fatsector = (unsigned long)( -1 );
{
unsigned char * ptr = (unsigned char *)gl_sector;
unsigned char j = 2;
unsigned long i;
psp_memset( ptr, 0, F_SECTOR_SIZE );
switch ( gl_volume.mediatype )
{
case F_FAT16_MEDIA:
j = 3;
break;
case F_FAT32_MEDIA:
j = 11;
break;
}
*ptr = gl_volume.bootrecord.media_descriptor;
psp_memset( ptr + 1, 0xff, j );
if ( gl_volume.mediatype == F_FAT32_MEDIA )
{
*( ptr + 8 ) = (unsigned char)( F_CLUSTER_LAST & 0xff );
}
(void)_f_writeglsector( gl_volume.firstfat.sector );
(void)_f_writeglsector( gl_volume.firstfat.sector + gl_volume.firstfat.num );
psp_memset( ptr, 0, ( j + 1 ) );
for ( i = 1 ; i < gl_volume.firstfat.num ; i++ )
{
(void)_f_writeglsector( gl_volume.firstfat.sector + i );
(void)_f_writeglsector( gl_volume.firstfat.sector + i + gl_volume.firstfat.num );
}
}
for ( a = 0 ; a < gl_volume.root.num ; a++ ) /*reset root direntries*/
{
ret = _f_writeglsector( gl_volume.root.sector + a );
if ( ret )
{
return ret;
}
}
return _f_writebootrecord( phy );
} /* _f_postformat */
/****************************************************************************
*
* fn_hardformat
*
* Making a complete format on media, independently from master boot record,
* according to media physical
*
* INPUTS
* fattype - one of this definitions F_FAT12_MEDIA,F_FAT16_MEDIA,F_FAT32_MEDIA
*
* RETURNS
* error code or zero if successful
*
***************************************************************************/
unsigned char fn_hardformat ( unsigned char fattype )
{
unsigned char ret;
int mdrv_ret;
F_PHY phy;
ret = _f_getvolume();
if ( ret && ( ret != F_ERR_NOTFORMATTED ) )
{
return ret;
}
gl_volume.state = F_STATE_NEEDMOUNT;
psp_memset( &phy, 0, sizeof( F_PHY ) );
mdrv_ret = mdrv->getphy( mdrv, &phy );
if ( mdrv_ret )
{
return F_ERR_ONDRIVE;
}
ret = _f_prepareformat( &phy, fattype ); /*no partition*/
if ( ret )
{
return ret;
}
return _f_postformat( &phy, fattype );
} /* fn_hardformat */
/****************************************************************************
*
* _f_readbootrecord
*
* read boot record from a volume, it detects if there is MBR on the media
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
static unsigned char _f_readbootrecord ( void )
{
unsigned char ret;
unsigned char * ptr = (unsigned char *)gl_sector;
unsigned long maxcluster, _n;
unsigned long first_sector = 0;
gl_volume.mediatype = F_UNKNOWN_MEDIA;
ret = _f_readglsector( 0 );
if ( ret )
{
return ret;
}
if ( ( ptr[0x1fe] != 0x55 ) || ( ptr[0x1ff] != 0xaa ) )
{
return F_ERR_NOTFORMATTED; /*??*/
}
if ( ( ptr[0] != 0xeb ) && ( ptr[0] != 0xe9 ) )
{
first_sector = _f_getlong( &ptr[0x08 + 0x1be] ); /*start sector for 1st partioon*/
ret = _f_readglsector( first_sector );
if ( ret )
{
return ret;
}
if ( ( ptr[0x1fe] != 0x55 ) || ( ptr[0x1ff] != 0xaa ) )
{
return F_ERR_NOTFORMATTED; /*??*/
}
if ( ( ptr[0] != 0xeb ) && ( ptr[0] != 0xe9 ) )
{
return F_ERR_NOTFORMATTED; /*??*/
}
}
ptr += 11;
if ( _f_getword( ptr ) != F_SECTOR_SIZE )
{
return F_ERR_NOTSUPPSECTORSIZE;
}
ptr += 2;
gl_volume.bootrecord.sector_per_cluster = *ptr++;
gl_volume.firstfat.sector = _f_getword( ptr );
ptr += 2;
gl_volume.bootrecord.number_of_FATs = *ptr++;
gl_volume.root.num = _f_getword( ptr );
ptr += 2;
gl_volume.root.num *= sizeof( F_DIRENTRY );
gl_volume.root.num /= F_SECTOR_SIZE;
maxcluster = _f_getword( ptr );
ptr += 2;
gl_volume.bootrecord.media_descriptor = *ptr++;
gl_volume.firstfat.num = _f_getword( ptr );
ptr += 6;
_n = _f_getlong( ptr );
ptr += 4;
if ( _n < first_sector )
{
_n = first_sector;
}
gl_volume.firstfat.sector += _n;
if ( !maxcluster )
{
maxcluster = _f_getlong( ptr );
}
ptr += 4;
if ( gl_volume.firstfat.num )
{
gl_volume.root.sector = gl_volume.firstfat.sector + ( gl_volume.firstfat.num * gl_volume.bootrecord.number_of_FATs );
gl_volume._tdata.sector = gl_volume.root.sector + gl_volume.root.num;
gl_volume._tdata.num = 0;
ptr += 3;
}
else
{
gl_volume.firstfat.num = _f_getlong( ptr );
ptr += 8;
gl_volume._tdata.sector = gl_volume.firstfat.sector;
gl_volume._tdata.sector += gl_volume.firstfat.num * gl_volume.bootrecord.number_of_FATs;
gl_volume._tdata.num = 0;
gl_volume.bootrecord.rootcluster = _f_getlong( ptr );
ptr += 23;
gl_volume.root.num = gl_volume.bootrecord.sector_per_cluster;
gl_volume.root.sector = ( ( gl_volume.bootrecord.rootcluster - 2 ) * gl_volume.root.num ) + gl_volume._tdata.sector;
}
gl_volume.bootrecord.serial_number = _f_getlong( ptr );
maxcluster -= gl_volume._tdata.sector;
maxcluster += _n;
gl_volume.maxcluster = maxcluster / gl_volume.bootrecord.sector_per_cluster;
if ( gl_volume.maxcluster < ( F_CLUSTER_RESERVED & 0xfff ) )
{
gl_volume.mediatype = F_FAT12_MEDIA;
}
else if ( gl_volume.maxcluster < ( F_CLUSTER_RESERVED & 0xffff ) )
{
gl_volume.mediatype = F_FAT16_MEDIA;
}
else
{
gl_volume.mediatype = F_FAT32_MEDIA;
}
if ( gl_volume.bootrecord.media_descriptor != 0xf8 ) /*fixdrive*/
{
if ( gl_volume.bootrecord.media_descriptor != 0xf0 ) /*removable*/
{
return F_ERR_NOTFORMATTED; /*??*/
}
}
return F_NO_ERROR;
} /* _f_readbootrecord */
/****************************************************************************
*
* _f_getvolume
*
* getting back a volume info structure of a given drive, it try to mounts
* drive if it was not mounted before
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
unsigned char _f_getvolume ( void )
{
switch ( gl_volume.state )
{
case F_STATE_NONE:
return F_ERR_ONDRIVE;
case F_STATE_WORKING:
if ( !_f_checkstatus() )
{
return F_NO_ERROR;
}
/* here we don't stop case flow, */
/* because we have to clean up this volume! */
case F_STATE_NEEDMOUNT:
{
gl_file.modified = 0;
gl_volume.modified = 0;
gl_volume.lastalloccluster = 0;
gl_volume.actsector = (unsigned long)( -1 );
gl_volume.fatsector = (unsigned long)( -1 );
gl_file.mode = F_FILE_CLOSE;
gl_volume.cwd[0] = 0; /*reset cwd*/
gl_volume.mediatype = F_UNKNOWN_MEDIA;
if ( mdrv->getstatus != NULL )
{
if ( mdrv->getstatus( mdrv ) & F_ST_MISSING )
{
gl_volume.state = F_STATE_NEEDMOUNT; /*card missing*/
return F_ERR_CARDREMOVED;
}
}
if ( !_f_readbootrecord() )
{
gl_volume.state = F_STATE_WORKING;
return F_NO_ERROR;
}
gl_volume.mediatype = F_UNKNOWN_MEDIA;
return F_ERR_NOTFORMATTED;
}
} /* switch */
return F_ERR_ONDRIVE;
} /* _f_getvolume */
/****************************************************************************
*
* fn_getfreespace
*
* get total/free/used/bad diskspace
*
* INPUTS
* pspace - pointer where to store the information
*
* RETURNS
* error code
*
***************************************************************************/
unsigned char fn_getfreespace ( F_SPACE * pspace )
{
unsigned char ret;
unsigned long a;
unsigned long clustersize;
ret = _f_getvolume();
if ( ret )
{
return ret;
}
psp_memset( pspace, 0, sizeof( F_SPACE ) );
pspace->total = gl_volume.maxcluster;
gl_volume.fatsector = (unsigned long)-1;
for ( a = 2 ; a < gl_volume.maxcluster + 2 ; a++ )
{
unsigned long value;
ret = _f_getclustervalue( a, &value );
if ( ret )
{
return ret;
}
if ( !value )
{
++( pspace->free );
}
else if ( value == F_CLUSTER_BAD )
{
++( pspace->bad );
}
else
{
++( pspace->used );
}
}
clustersize = (unsigned long)( gl_volume.bootrecord.sector_per_cluster * F_SECTOR_SIZE );
for ( a = 0 ; ( clustersize & 1 ) == 0 ; a++ )
{
clustersize >>= 1;
}
pspace->total_high = ( pspace->total ) >> ( 32 - a );
pspace->total <<= a;
pspace->free_high = ( pspace->free ) >> ( 32 - a );
pspace->free <<= a;
pspace->used_high = ( pspace->used ) >> ( 32 - a );
pspace->used <<= a;
pspace->bad_high = ( pspace->bad ) >> ( 32 - a );
pspace->bad <<= a;
return F_NO_ERROR;
} /* fn_getfreespace */
/****************************************************************************
*
* fn_getserial
*
* get serial number
*
* INPUTS
* serial - pointer where to store the serial number
*
* RETURNS
* error code
*
***************************************************************************/
unsigned char fn_getserial ( unsigned long * serial )
{
unsigned char ret;
ret = _f_getvolume();
if ( ret )
{
return ret;
}
*serial = gl_volume.bootrecord.serial_number;
return 0;
}
/*
** fn_init
**
** Initialize FAT_SL file system
**
** RETURN: F_NO_ERROR on success, other if error.
*/
unsigned char fn_init ( void )
{
return F_NO_ERROR;
} /* fn_init */
/****************************************************************************
*
* fn_initvolume
*
* initiate a volume, this function has to be called 1st to set physical
* driver function to a given volume
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
unsigned char fn_initvolume ( F_DRIVERINIT initfunc )
{
#if F_FS_THREAD_AWARE == 1
{
if( fs_lock_semaphore == NULL )
{
fs_lock_semaphore = xSemaphoreCreateMutex();
if( fs_lock_semaphore == NULL )
{
return F_ERR_OS;
}
}
}
#endif /* F_FS_THREAD_AWARE */
gl_volume.state = F_STATE_NONE;
mdrv = initfunc( 0 );
if ( mdrv == NULL )
{
return F_ERR_INITFUNC;
}
gl_volume.state = F_STATE_NEEDMOUNT;
#if F_FILE_CHANGED_EVENT
f_filechangedevent = 0;
#endif
return _f_getvolume();
} /* fn_initvolume */
/****************************************************************************
*
* fn_delvolume
*
***************************************************************************/
unsigned char fn_delvolume ( void )
{
if ( mdrv->release )
{
(void)mdrv->release( mdrv );
}
return 0;
}

View file

@ -0,0 +1,113 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef __VOLUME_H
#define __VOLUME_H
#include "config_fat_sl.h"
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
unsigned char sector_per_cluster;
unsigned char number_of_FATs;
unsigned char media_descriptor;
unsigned long rootcluster;
unsigned long sector_per_FAT;
unsigned long sector_per_FAT32;
unsigned long serial_number;
} F_BOOTRECORD;
typedef struct
{
unsigned long sector; /*start sector*/
unsigned long num; /*number of sectors*/
} F_SECTOR;
typedef struct
{
unsigned char state;
F_BOOTRECORD bootrecord;
F_SECTOR firstfat;
F_SECTOR root;
F_SECTOR _tdata;
unsigned long actsector;
unsigned long fatsector;
unsigned long lastalloccluster;
unsigned char modified;
char cwd[F_MAXPATH]; /*current working folder in this volume*/
unsigned char mediatype;
unsigned long maxcluster;
} F_VOLUME;
enum
{
/* 0 */
F_STATE_NONE,
/* 1 */ F_STATE_NEEDMOUNT,
/* 2 */ F_STATE_WORKING
};
extern F_VOLUME gl_volume;
extern F_FILE gl_file;
extern char gl_sector[F_SECTOR_SIZE]; /* actual sector */
unsigned char _f_getvolume ( void );
#ifdef __cplusplus
}
#endif
#endif /* ifndef __VOLUME_H */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,116 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef __TEST_H
#define __TEST_H
#include "../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
#error Incompatible FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
** Maximum size for seek test.
** Options: 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
*/
#define F_MAX_SEEK_TEST 16384
/*
** Defines media type for testing.
** Options: F_FAT12_MEDIA, F_FAT16_MEDIA
*/
#define F_FAT_TYPE F_FAT12_MEDIA
/*
** Start filesystem test.
** Parameter:
** 0 - run all the tests
**
** 2 - directory
** 3 - find
**
** 5* - seek 128
** 6* - seek 256
** 7* - seek 512
** 8* - seek 1024
** 9* - seek 2048
** 10*- seek 4096
** 11*- seek 8192
** 12*- seek 16384
** 13*- seek 32768
** 14 - open
** 15 - append
** 16 - write
** 17 - dots
** 18 - rit
** *Note that only seek tests allowed by F_MAX_SEEK_TEST are executed.
**
** The following defines are required for the specific test:
** 1 1 1 1 1 1 1 1 1
** 2 3 5 6 7 8 9 0 1 2 3 4 5 6 7 8
** F_CHDIR x x - - - - - - - - - - x - x -
** F_MKDIR x x - - - - - - - - - - - - x -
** F_RMDIR x x - - - - - - - - - - x - x -
** F_DELETE x x x x x x x x x x x x x x x x
** F_FILELENGTH - - x x x x x x x x x x x x - -
** F_FINDING x x - - - - - - - - - - x - - -
** F_TELL - - x x x x x x x x x x x x - x
** F_REWIND - - - - - - - - - - - x - - - -
** F_EOF - - x x x x x x x x x - - x - -
** F_SEEK - - x x x x x x x x x - x x - x
** F_WRITE - - x x x x x x x x x x x x - x
** F_WRITING x x x x x x x x x x x x x x x x
** F_DIRECTORIES x x - - - - - - - - - - x - x -
** F_CHECKNAME x - - - - - - - - - - - - - x -
*/
void f_dotest ( unsigned char );
#ifdef __cplusplus
}
#endif
#endif /* ifndef __TEST_H */

View file

@ -0,0 +1,247 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#include "../../api/api_mdriver_ram.h"
#include "config_mdriver_ram.h"
#include "../../psp/include/psp_string.h"
#include "../../version/ver_mdriver_ram.h"
#if VER_MDRIVER_RAM_MAJOR != 1 || VER_MDRIVER_RAM_MINOR != 2
#error Incompatible MDRIVER_RAM version number!
#endif
char ramdrv0[MDRIVER_RAM_VOLUME0_SIZE];
typedef struct
{
char * ramdrv;
unsigned long maxsector;
int use;
F_DRIVER * driver;
} t_RamDrv;
static F_DRIVER t_drivers[1];
static t_RamDrv RamDrv[1] =
{
{ ramdrv0, ( MDRIVER_RAM_VOLUME0_SIZE / MDRIVER_RAM_SECTOR_SIZE ), 0, &t_drivers[0] }
};
/****************************************************************************
* Read one sector
***************************************************************************/
static int ram_readsector ( F_DRIVER * driver, void * data, unsigned long sector )
{
long len;
char * d = (char *)data;
char * s;
t_RamDrv * p = (t_RamDrv *)( driver->user_ptr );
if ( sector >= p->maxsector )
{
return MDRIVER_RAM_ERR_SECTOR;
}
s = p->ramdrv;
s += sector * MDRIVER_RAM_SECTOR_SIZE;
len = MDRIVER_RAM_SECTOR_SIZE;
#if MDRIVER_MEM_LONG_ACCESS
if ( ( !( len & 3 ) ) && ( !( ( (long)d ) & 3 ) ) && ( !( ( (long)s ) & 3 ) ) )
{
long * dd = (long *)d;
long * ss = (long *)s;
len >>= 2;
while ( len-- )
{
*dd++ = *ss++;
}
return MDRIVER_RAM_NO_ERROR;
}
#endif /* if MDRIVER_MEM_LONG_ACCESS */
while ( len-- )
{
*d++ = *s++;
}
return MDRIVER_RAM_NO_ERROR;
}
/****************************************************************************
* Write one sector
***************************************************************************/
static int ram_writesector ( F_DRIVER * driver, void * data, unsigned long sector )
{
long len;
char * s = (char *)data;
char * d;
t_RamDrv * p = (t_RamDrv *)( driver->user_ptr );
if ( sector >= p->maxsector )
{
return MDRIVER_RAM_ERR_SECTOR;
}
d = p->ramdrv;
d += sector * MDRIVER_RAM_SECTOR_SIZE;
len = MDRIVER_RAM_SECTOR_SIZE;
#if MDRIVER_MEM_LONG_ACCESS
if ( ( !( len & 3 ) ) && ( !( ( (long)d ) & 3 ) ) && ( !( ( (long)s ) & 3 ) ) )
{
long * dd = (long *)d;
long * ss = (long *)s;
len >>= 2;
while ( len-- )
{
*dd++ = *ss++;
}
return MDRIVER_RAM_NO_ERROR;
}
#endif /* if MDRIVER_MEM_LONG_ACCESS */
while ( len-- )
{
*d++ = *s++;
}
return MDRIVER_RAM_NO_ERROR;
}
/****************************************************************************
*
* ram_getphy
*
* determinate ramdrive physicals
*
* INPUTS
*
* driver - driver structure
* phy - this structure has to be filled with physical information
*
* RETURNS
*
* error code or zero if successful
*
***************************************************************************/
static int ram_getphy ( F_DRIVER * driver, F_PHY * phy )
{
t_RamDrv * p = (t_RamDrv *)( driver->user_ptr );
phy->number_of_sectors = p->maxsector;
phy->bytes_per_sector = MDRIVER_RAM_SECTOR_SIZE;
return MDRIVER_RAM_NO_ERROR;
}
/****************************************************************************
*
* ram_release
*
* Releases a drive
*
* INPUTS
*
* driver_param - driver parameter
*
***************************************************************************/
static void ram_release ( F_DRIVER * driver )
{
t_RamDrv * p = (t_RamDrv *)( driver->user_ptr );
if ( p == RamDrv )
{
p->use = 0;
}
}
/****************************************************************************
*
* ram_initfunc
*
* this init function has to be passed for highlevel to initiate the
* driver functions
*
* INPUTS
*
* driver_param - driver parameter
*
* RETURNS
*
* driver structure pointer
*
***************************************************************************/
F_DRIVER * ram_initfunc ( unsigned long driver_param )
{
t_RamDrv * p;
p = RamDrv + driver_param;
if ( p != RamDrv )
{
return 0;
}
if ( p->use )
{
return 0;
}
(void)psp_memset( p->driver, 0, sizeof( F_DRIVER ) );
p->driver->readsector = ram_readsector;
p->driver->writesector = ram_writesector;
p->driver->getphy = ram_getphy;
p->driver->release = ram_release;
p->driver->user_ptr = p;
p->use = 1;
return p->driver;
} /* ram_initfunc */

View file

@ -0,0 +1,71 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _PSP_RTC_H
#define _PSP_RTC_H
#include <stdint.h>
#include "../../version/ver_psp_rtc.h"
#if VER_PSP_RTC_MAJOR != 1
#error "VER_PSP_RTC_MAJOR invalid"
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
uint8_t sec;
uint8_t min;
uint8_t hour;
uint8_t day;
uint8_t month;
uint16_t year;
} t_psp_timedate;
void psp_getcurrenttimedate ( t_psp_timedate * p_timedate );
#ifdef __cplusplus
}
#endif
#endif /* _PSP_RTC_H */

View file

@ -0,0 +1,60 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _PSP_STRING_H_
#define _PSP_STRING_H_
#include <stddef.h>
#include <string.h>
#include "../../version/ver_psp_string.h"
#if VER_PSP_STRING_MAJOR != 1 || VER_PSP_STRING_MINOR != 4
#error Incompatible PSP_STRING version number!
#endif
#define psp_memcpy( d, s, l ) memcpy( ( d ), ( s ), (size_t)( l ) )
#define psp_memmove( d, s, l ) memmove( ( d ), ( s ), (size_t)( l ) )
#define psp_memset( d, c, l ) memset( ( d ), ( c ), (size_t)( l ) )
#define psp_memcmp( s1, s2, l ) memcmp( ( s1 ), ( s2 ), (size_t)( l ) )
#define psp_strnlen( s, l ) strnlen( ( s ), ( size_t )( l ) )
#define psp_strncat( d, s, l ) strncat( ( d ), ( s ), (size_t)( l ) )
#define psp_strncpy( d, s, l ) strncpy( ( d ), ( s ), (size_t)( l ) )
#define psp_strncmp( s1, s2, l ) strncmp( ( s1 ), ( s2 ), (size_t)( l ) )
#endif /* ifndef _PSP_STRING_H_ */

View file

@ -0,0 +1,86 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#include <stdio.h>
#include "psp_test.h"
#include "config_fat_sl.h"
#include "config_mdriver_ram.h"
#include "../../../api/fat_sl.h"
#include "../../../api/api_mdriver_ram.h"
#include "../../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3
#error Incompatible FAT_SL version number!
#endif
#include "../../../version/ver_psp_fat_sl.h"
#if VER_PSP_FAT_FAT_SL_MAJOR != 1 || VER_PSP_FAT_FAT_SL_MINOR != 1
#error Incompatible PSP_FAT_FAT_SL version number!
#endif
uint8_t all_tests_passed = 1u;
/* Use to display text (printf). */
void _f_dump ( char * s )
{
printf( "%s\r\n", s );
}
/* Use to display test result (printf). */
uint8_t _f_result ( uint8_t testnum, uint32_t result )
{
(void)testnum;
if ( result == 0 )
{
printf( "Passed\r\n" );
}
else
{
printf( "FAILED! Error code: %u\r\n", result );
all_tests_passed = 0u;
}
return 0;
}
/* Use to build file system (mount). */
uint8_t _f_poweron ( void )
{
f_delvolume();
return f_initvolume( ram_initfunc );
}

View file

@ -0,0 +1,75 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _PSP_FAT_FAT_SL_H
#define _PSP_FAT_FAT_SL_H
#include <stdint.h>
#include "../../../psp/include/psp_string.h"
#include "../../../version/ver_fat_sl.h"
#if VER_FAT_SL_MAJOR != 3
#error Incompatible FAT_SL version number!
#endif
#include "../../../version/ver_psp_fat_sl.h"
#if VER_PSP_FAT_FAT_SL_MAJOR != 1 || VER_PSP_FAT_FAT_SL_MINOR != 1
#error Incompatible PSP_FAT_FAT_SL version number!
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern uint8_t all_tests_passed;
/* Use to display text (printf). */
void _f_dump ( char * s );
/* Use to display test result (printf). */
uint8_t _f_result ( uint8_t testnum, uint32_t result );
/* Use to build file system (mount). */
uint8_t _f_poweron ( void );
#ifdef __cplusplus
}
#endif
#endif /* _PSP_FAT_FAT_SL_H */

View file

@ -0,0 +1,80 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#include <stdint.h>
#include <stddef.h>
#include "../../include/psp_rtc.h"
#include "../../../version/ver_psp_rtc.h"
#if VER_PSP_RTC_MAJOR != 1
#error "VER_PSP_RTC_MAJOR invalid"
#endif
#if VER_PSP_RTC_MINOR != 0
#error "VER_PSP_RTC_MINOR invalid"
#endif
/****************************************************************************
*
* psp_getcurrenttimedate
*
* Need to be ported depending on system, it retreives the
* current time and date.
* Please take care of correct roll-over handling.
* Roll-over problem is to read a date at 23.59.59 and then reading time at
* 00:00.00.
*
* INPUT
*
* p_timedate - pointer where to store time and date
*
***************************************************************************/
void psp_getcurrenttimedate ( t_psp_timedate * p_timedate )
{
if ( p_timedate != NULL )
{
p_timedate->sec = 0;
p_timedate->min = 0;
p_timedate->hour = 12u;
p_timedate->day = 1u;
p_timedate->month = 1u;
p_timedate->year = 1980u;
}
} /* psp_getcurrenttimedate */

View file

@ -0,0 +1,46 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _VER_FAT_SL_H
#define _VER_FAT_SL_H
#define VER_FAT_SL_MAJOR 3
#define VER_FAT_SL_MINOR 2
#endif

View file

@ -0,0 +1,46 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _VER_MDRIVER_H
#define _VER_MDRIVER_H
#define VER_MDRIVER_MAJOR 1
#define VER_MDRIVER_MINOR 0
#endif

View file

@ -0,0 +1,46 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _VER_MDRIVER_RAM_H
#define _VER_MDRIVER_RAM_H
#define VER_MDRIVER_RAM_MAJOR 1
#define VER_MDRIVER_RAM_MINOR 2
#endif

View file

@ -0,0 +1,46 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _VER_PSP_FAT_FAT_SL_H
#define _VER_PSP_FAT_FAT_SL_H
#define VER_PSP_FAT_FAT_SL_MAJOR 1
#define VER_PSP_FAT_FAT_SL_MINOR 1
#endif /* _VER_PSP_FAT_FAT_SL_H */

View file

@ -0,0 +1,46 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _VER_PSP_RTC_H
#define _VER_PSP_RTC_H
#define VER_PSP_RTC_MAJOR 1
#define VER_PSP_RTC_MINOR 0
#endif

View file

@ -0,0 +1,46 @@
/*
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
*
* The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
* terms.
*
* FreeRTOS+FAT SL uses a dual license model that allows the software to be used
* under a pure GPL open source license (as opposed to the modified GPL licence
* under which FreeRTOS is distributed) or a commercial license. Details of
* both license options follow:
*
* - Open source licensing -
* FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
* distributed without charge provided the user adheres to version two of the
* GNU General Public License (GPL) and does not remove the copyright notice or
* this text. The GPL V2 text is available on the gnu.org web site, and on the
* following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
*
* - Commercial licensing -
* Businesses and individuals who for commercial or other reasons cannot comply
* with the terms of the GPL V2 license must obtain a commercial license before
* incorporating FreeRTOS+FAT SL into proprietary software for distribution in
* any form. Commercial licenses can be purchased from
* http://shop.freertos.org/fat_sl and do not require any source files to be
* changed.
*
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
* conditions and terms, be they implied, expressed, or statutory.
*
* http://www.FreeRTOS.org
* http://www.FreeRTOS.org/FreeRTOS-Plus
*
*/
#ifndef _VER_PSP_STRING_H
#define _VER_PSP_STRING_H
#define VER_PSP_STRING_MAJOR 1
#define VER_PSP_STRING_MINOR 4
#endif