Compare commits

..

No commits in common. "a005afaa139ab6f059efac788a5037608dc3e754" and "2cd4847a576d45fb32ecef097a922807cbf2e9f0" have entirely different histories.

10 changed files with 825 additions and 1108 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,208 +1,170 @@
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* A Sample Code of User Provided OS Dependent Functions for FatFs */ /* Sample Code of OS Dependent Functions for FatFs */
/* (C)ChaN, 2018 */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#include <fatfs/ff.h> #include <fatfs/ff.h>
#if FF_USE_LFN == 3 /* Use dynamic memory allocation */ #if FF_USE_LFN == 3 /* Dynamic memory allocation */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Allocate/Free a Memory Block */ /* Allocate a memory block */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#include <stdlib.h> /* with POSIX API */
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */ UINT msize /* Number of bytes to allocate */
) )
{ {
return malloc((size_t)msize); /* Allocate a new memory block */ return malloc(msize); /* Allocate a new memory block with POSIX API */
} }
/*------------------------------------------------------------------------*/
/* Free a memory block */
/*------------------------------------------------------------------------*/
void ff_memfree ( void ff_memfree (
void* mblock /* Pointer to the memory block to free (no effect if null) */ void* mblock /* Pointer to the memory block to free (nothing to do if null) */
) )
{ {
free(mblock); /* Free the memory block */ free(mblock); /* Free the memory block with POSIX API */
} }
#endif #endif
#if FF_FS_REENTRANT /* Mutal exclusion */ #if FF_FS_REENTRANT /* Mutal exclusion */
/*------------------------------------------------------------------------*/
/* Definitions of Mutex */
/*------------------------------------------------------------------------*/
#define OS_TYPE 0 /* 0:Win32, 1:uITRON4.0, 2:uC/OS-II, 3:FreeRTOS, 4:CMSIS-RTOS */
#if OS_TYPE == 0 /* Win32 */
#include <windows.h>
static HANDLE Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
#elif OS_TYPE == 1 /* uITRON */
#include "itron.h"
#include "kernel.h"
static mtxid Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
#elif OS_TYPE == 2 /* uc/OS-II */
#include "includes.h"
static OS_EVENT *Mutex[FF_VOLUMES + 1]; /* Table of mutex pinter */
#elif OS_TYPE == 3 /* FreeRTOS */
#include "FreeRTOS.h"
#include "semphr.h"
static SemaphoreHandle_t Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
#elif OS_TYPE == 4 /* CMSIS-RTOS */
#include "cmsis_os.h"
static osMutexId Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
#endif
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Create a Mutex */ /* Create a Synchronization Object */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This function is called in f_mount function to create a new mutex /* This function is called in f_mount() function to create a new
/ or semaphore for the volume. When a 0 is returned, the f_mount function / synchronization object for the volume, such as semaphore and mutex.
/ fails with FR_INT_ERR. / When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
*/ */
int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */ //const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
BYTE vol, /* Corresponding volume (logical drive number) */
FF_SYNC_t* sobj /* Pointer to return the created sync object */
) )
{ {
#if OS_TYPE == 0 /* Win32 */ /* Win32 */
Mutex[vol] = CreateMutex(NULL, FALSE, NULL); *sobj = CreateMutex(NULL, FALSE, NULL);
return (int)(Mutex[vol] != INVALID_HANDLE_VALUE); return (int)(*sobj != INVALID_HANDLE_VALUE);
#elif OS_TYPE == 1 /* uITRON */ /* uITRON */
T_CMTX cmtx = {TA_TPRI,1}; // T_CSEM csem = {TA_TPRI,1,1};
// *sobj = acre_sem(&csem);
// return (int)(*sobj > 0);
Mutex[vol] = acre_mtx(&cmtx); /* uC/OS-II */
return (int)(Mutex[vol] > 0); // OS_ERR err;
// *sobj = OSMutexCreate(0, &err);
// return (int)(err == OS_NO_ERR);
#elif OS_TYPE == 2 /* uC/OS-II */ /* FreeRTOS */
OS_ERR err; // *sobj = xSemaphoreCreateMutex();
// return (int)(*sobj != NULL);
Mutex[vol] = OSMutexCreate(0, &err); /* CMSIS-RTOS */
return (int)(err == OS_NO_ERR); // *sobj = osMutexCreate(&Mutex[vol]);
// return (int)(*sobj != NULL);
#elif OS_TYPE == 3 /* FreeRTOS */
Mutex[vol] = xSemaphoreCreateMutex();
return (int)(Mutex[vol] != NULL);
#elif OS_TYPE == 4 /* CMSIS-RTOS */
osMutexDef(cmsis_os_mutex);
Mutex[vol] = osMutexCreate(osMutex(cmsis_os_mutex));
return (int)(Mutex[vol] != NULL);
#endif
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Delete a Mutex */ /* Delete a Synchronization Object */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This function is called in f_mount function to delete a mutex or /* This function is called in f_mount() function to delete a synchronization
/ semaphore of the volume created with ff_mutex_create function. / object that created with ff_cre_syncobj() function. When a 0 is returned,
/ the f_mount() function fails with FR_INT_ERR.
*/ */
void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */ int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
) )
{ {
#if OS_TYPE == 0 /* Win32 */ /* Win32 */
CloseHandle(Mutex[vol]); return (int)CloseHandle(sobj);
#elif OS_TYPE == 1 /* uITRON */ /* uITRON */
del_mtx(Mutex[vol]); // return (int)(del_sem(sobj) == E_OK);
#elif OS_TYPE == 2 /* uC/OS-II */ /* uC/OS-II */
OS_ERR err; // OS_ERR err;
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
// return (int)(err == OS_NO_ERR);
OSMutexDel(Mutex[vol], OS_DEL_ALWAYS, &err); /* FreeRTOS */
// vSemaphoreDelete(sobj);
// return 1;
#elif OS_TYPE == 3 /* FreeRTOS */ /* CMSIS-RTOS */
vSemaphoreDelete(Mutex[vol]); // return (int)(osMutexDelete(sobj) == osOK);
#elif OS_TYPE == 4 /* CMSIS-RTOS */
osMutexDelete(Mutex[vol]);
#endif
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Request a Grant to Access the Volume */ /* Request Grant to Access the Volume */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This function is called on enter file functions to lock the volume. /* This function is called on entering file functions to lock the volume.
/ When a 0 is returned, the file function fails with FR_TIMEOUT. / When a 0 is returned, the file function fails with FR_TIMEOUT.
*/ */
int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */ int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ FF_SYNC_t sobj /* Sync object to wait */
) )
{ {
#if OS_TYPE == 0 /* Win32 */ /* Win32 */
return (int)(WaitForSingleObject(Mutex[vol], FF_FS_TIMEOUT) == WAIT_OBJECT_0); return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
#elif OS_TYPE == 1 /* uITRON */ /* uITRON */
return (int)(tloc_mtx(Mutex[vol], FF_FS_TIMEOUT) == E_OK); // return (int)(wai_sem(sobj) == E_OK);
#elif OS_TYPE == 2 /* uC/OS-II */ /* uC/OS-II */
OS_ERR err; // OS_ERR err;
// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
// return (int)(err == OS_NO_ERR);
OSMutexPend(Mutex[vol], FF_FS_TIMEOUT, &err)); /* FreeRTOS */
return (int)(err == OS_NO_ERR); // return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
#elif OS_TYPE == 3 /* FreeRTOS */ /* CMSIS-RTOS */
return (int)(xSemaphoreTake(Mutex[vol], FF_FS_TIMEOUT) == pdTRUE); // return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
#elif OS_TYPE == 4 /* CMSIS-RTOS */
return (int)(osMutexWait(Mutex[vol], FF_FS_TIMEOUT) == osOK);
#endif
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Release a Grant to Access the Volume */ /* Release Grant to Access the Volume */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This function is called on leave file functions to unlock the volume. /* This function is called on leaving file functions to unlock the volume.
*/ */
void ff_mutex_give ( void ff_rel_grant (
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ FF_SYNC_t sobj /* Sync object to be signaled */
) )
{ {
#if OS_TYPE == 0 /* Win32 */ /* Win32 */
ReleaseMutex(Mutex[vol]); ReleaseMutex(sobj);
#elif OS_TYPE == 1 /* uITRON */ /* uITRON */
unl_mtx(Mutex[vol]); // sig_sem(sobj);
#elif OS_TYPE == 2 /* uC/OS-II */ /* uC/OS-II */
OSMutexPost(Mutex[vol]); // OSMutexPost(sobj);
#elif OS_TYPE == 3 /* FreeRTOS */ /* FreeRTOS */
xSemaphoreGive(Mutex[vol]); // xSemaphoreGive(sobj);
#elif OS_TYPE == 4 /* CMSIS-RTOS */ /* CMSIS-RTOS */
osMutexRelease(Mutex[vol]); // osMutexRelease(sobj);
#endif
} }
#endif /* FF_FS_REENTRANT */ #endif

View File

@ -1,13 +1,13 @@
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Unicode Handling Functions for FatFs R0.13 and Later */ /* Unicode handling functions for FatFs R0.13+ */
/*------------------------------------------------------------------------*/
/* This module will occupy a huge memory in the .rodata section when the */
/* FatFs is configured for LFN with DBCS. If the system has a Unicode */
/* library for the code conversion, this module should be modified to use */
/* it to avoid silly memory consumption. */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This module will occupy a huge memory in the .const section when the /
/ FatFs is configured for LFN with DBCS. If the system has any Unicode /
/ utilitiy for the code conversion, this module should be modified to use /
/ that function to avoid silly memory consumption. /
/-------------------------------------------------------------------------*/
/* /*
/ Copyright (C) 2022, ChaN, all right reserved. / Copyright (C) 2014, ChaN, all right reserved.
/ /
/ FatFs module is an open source software. Redistribution and use of FatFs in / FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided / source and binary forms, with or without modification, are permitted provided
@ -25,7 +25,7 @@
#include <fatfs/ff.h> #include <fatfs/ff.h>
#if FF_USE_LFN != 0 /* This module will be blanked if in non-LFN configuration */ #if FF_USE_LFN /* This module will be blanked if non-LFN configuration */
#define MERGE2(a, b) a ## b #define MERGE2(a, b) a ## b
#define CVTBL(tbl, cp) MERGE2(tbl, cp) #define CVTBL(tbl, cp) MERGE2(tbl, cp)
@ -15214,8 +15214,8 @@ static const WCHAR uc869[] = { /* CP869(Greek 2) to Unicode conversion table */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* OEM <==> Unicode Conversions for Static Code Page Configuration with */ /* OEM <==> Unicode conversions for static code page configuration */
/* SBCS Fixed Code Page */ /* SBCS fixed code page */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#if FF_CODE_PAGE != 0 && FF_CODE_PAGE < 900 #if FF_CODE_PAGE != 0 && FF_CODE_PAGE < 900
@ -15267,8 +15267,8 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* OEM <==> Unicode Conversions for Static Code Page Configuration with */ /* OEM <==> Unicode conversions for static code page configuration */
/* DBCS Fixed Code Page */ /* DBCS fixed code page */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#if FF_CODE_PAGE >= 900 #if FF_CODE_PAGE >= 900
@ -15346,7 +15346,7 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* OEM <==> Unicode Conversions for Dynamic Code Page Configuration */ /* OEM <==> Unicode conversions for dynamic code page configuration */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#if FF_CODE_PAGE == 0 #if FF_CODE_PAGE == 0
@ -15458,7 +15458,7 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Unicode Up-case Conversion */ /* Unicode up-case conversion */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
DWORD ff_wtoupper ( /* Returns up-converted code point */ DWORD ff_wtoupper ( /* Returns up-converted code point */
@ -15590,4 +15590,4 @@ DWORD ff_wtoupper ( /* Returns up-converted code point */
} }
#endif /* #if FF_USE_LFN != 0 */ #endif /* #if FF_USE_LFN */

View File

@ -1,8 +1,8 @@
/*----------------------------------------------------------------------------/ /*----------------------------------------------------------------------------/
/ FatFs - Generic FAT Filesystem module R0.15 / / FatFs - Generic FAT Filesystem module R0.14b /
/-----------------------------------------------------------------------------/ /-----------------------------------------------------------------------------/
/ /
/ Copyright (C) 2022, ChaN, all right reserved. / Copyright (C) 2021, ChaN, all right reserved.
/ /
/ FatFs module is an open source software. Redistribution and use of FatFs in / FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided / source and binary forms, with or without modification, are permitted provided
@ -20,7 +20,7 @@
#ifndef FF_DEFINED #ifndef FF_DEFINED
#define FF_DEFINED 80286 /* Revision ID */ #define FF_DEFINED 86631 /* Revision ID */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -131,11 +131,10 @@ extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
typedef struct { typedef struct {
BYTE fs_type; /* Filesystem type (0:not mounted) */ BYTE fs_type; /* Filesystem type (0:not mounted) */
BYTE pdrv; /* Volume hosting physical drive */ BYTE pdrv; /* Associated physical drive */
BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */
BYTE n_fats; /* Number of FATs (1 or 2) */ BYTE n_fats; /* Number of FATs (1 or 2) */
BYTE wflag; /* win[] status (b0:dirty) */ BYTE wflag; /* win[] flag (b0:dirty) */
BYTE fsi_flag; /* FSINFO status (b7:disabled, b0:dirty) */ BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
WORD id; /* Volume mount ID */ WORD id; /* Volume mount ID */
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
WORD csize; /* Cluster size [sectors] */ WORD csize; /* Cluster size [sectors] */
@ -148,6 +147,9 @@ typedef struct {
#if FF_FS_EXFAT #if FF_FS_EXFAT
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */ BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
#endif #endif
#if FF_FS_REENTRANT
FF_SYNC_t sobj; /* Identifier of sync object */
#endif
#if !FF_FS_READONLY #if !FF_FS_READONLY
DWORD last_clst; /* Last allocated cluster */ DWORD last_clst; /* Last allocated cluster */
DWORD free_clst; /* Number of free clusters */ DWORD free_clst; /* Number of free clusters */
@ -161,10 +163,10 @@ typedef struct {
#endif #endif
#endif #endif
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */ DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
DWORD fsize; /* Number of sectors per FAT */ DWORD fsize; /* Size of an FAT [sectors] */
LBA_t volbase; /* Volume base sector */ LBA_t volbase; /* Volume base sector */
LBA_t fatbase; /* FAT base sector */ LBA_t fatbase; /* FAT base sector */
LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */ LBA_t dirbase; /* Root directory base sector/cluster */
LBA_t database; /* Data base sector */ LBA_t database; /* Data base sector */
#if FF_FS_EXFAT #if FF_FS_EXFAT
LBA_t bitbase; /* Allocation bitmap base sector */ LBA_t bitbase; /* Allocation bitmap base sector */
@ -179,7 +181,7 @@ typedef struct {
typedef struct { typedef struct {
FATFS* fs; /* Pointer to the hosting volume of this object */ FATFS* fs; /* Pointer to the hosting volume of this object */
WORD id; /* Hosting volume's mount ID */ WORD id; /* Hosting volume mount ID */
BYTE attr; /* Object attribute */ BYTE attr; /* Object attribute */
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */ BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */ DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
@ -248,7 +250,7 @@ typedef struct {
WORD ftime; /* Modified time */ WORD ftime; /* Modified time */
BYTE fattrib; /* File attribute */ BYTE fattrib; /* File attribute */
#if FF_USE_LFN #if FF_USE_LFN
TCHAR altname[FF_SFN_BUF + 1];/* Alternative file name */ TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */ TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
#else #else
TCHAR fname[12 + 1]; /* File name */ TCHAR fname[12 + 1]; /* File name */
@ -296,10 +298,8 @@ typedef enum {
/*--------------------------------------------------------------*/
/* FatFs Module Application Interface */
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* FatFs module application interface */
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */ FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
FRESULT f_close (FIL* fp); /* Close an open file object */ FRESULT f_close (FIL* fp); /* Close an open file object */
@ -336,8 +336,6 @@ int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */ int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
/* Some API fucntions are implemented as macro */
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize)) #define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
#define f_error(fp) ((fp)->err) #define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr) #define f_tell(fp) ((fp)->fptr)
@ -351,43 +349,38 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the fil
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* Additional Functions */ /* Additional user defined functions */
/*--------------------------------------------------------------*/
/* RTC function (provided by user) */ /* RTC function */
#if !FF_FS_READONLY && !FF_FS_NORTC #if !FF_FS_READONLY && !FF_FS_NORTC
DWORD get_fattime (void); /* Get current time */ DWORD get_fattime (void);
#endif #endif
/* LFN support functions */
/* LFN support functions (defined in ffunicode.c) */ #if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
#if FF_USE_LFN >= 1
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */ WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */ WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */ DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
#endif #endif
/* O/S dependent functions (samples available in ffsystem.c) */
#if FF_USE_LFN == 3 /* Dynamic memory allocation */ #if FF_USE_LFN == 3 /* Dynamic memory allocation */
void* ff_memalloc (UINT msize); /* Allocate memory block */ void* ff_memalloc (UINT msize); /* Allocate memory block */
void ff_memfree (void* mblock); /* Free memory block */ void ff_memfree (void* mblock); /* Free memory block */
#endif #endif
#if FF_FS_REENTRANT /* Sync functions */
int ff_mutex_create (int vol); /* Create a sync object */ /* Sync functions */
void ff_mutex_delete (int vol); /* Delete a sync object */ #if FF_FS_REENTRANT
int ff_mutex_take (int vol); /* Lock sync object */ int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
void ff_mutex_give (int vol); /* Unlock sync object */ int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
#endif #endif
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* Flags and Offset Address */ /* Flags and offset address */
/*--------------------------------------------------------------*/
/* File access mode and open method flags (3rd argument of f_open) */ /* File access mode and open method flags (3rd argument of f_open) */
#define FA_READ 0x01 #define FA_READ 0x01

View File

@ -1,8 +1,8 @@
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ Configurations of FatFs Module / FatFs Functional Configurations
/---------------------------------------------------------------------------*/ /---------------------------------------------------------------------------*/
#define FFCONF_DEF 80286 /* Revision ID */ #define FFCONF_DEF 86631 /* Revision ID */
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ Function Configurations / Function Configurations
@ -68,7 +68,7 @@
/ 2: Enable with LF-CRLF conversion. / 2: Enable with LF-CRLF conversion.
/ /
/ FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2 / FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
/ makes f_printf() support floating point argument. These features want C99 or later. makes f_printf() support floating point argument. These features want C99 or later.
/ When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character / When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
/ encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE / encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
/ to be read/written via those functions. / to be read/written via those functions.
@ -178,7 +178,7 @@
/ logical drives. Number of items must not be less than FF_VOLUMES. Valid / logical drives. Number of items must not be less than FF_VOLUMES. Valid
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are / characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is / compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
/ not defined, a user defined volume string table is needed as: / not defined, a user defined volume string table needs to be defined as:
/ /
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... / const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
*/ */
@ -190,7 +190,7 @@
/ number and only an FAT volume found on the physical drive will be mounted. / number and only an FAT volume found on the physical drive will be mounted.
/ When this function is enabled (1), each logical drive number can be bound to / When this function is enabled (1), each logical drive number can be bound to
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() / arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
/ function will be available. */ / funciton will be available. */
#define FF_MIN_SS 512 #define FF_MIN_SS 512
@ -240,10 +240,10 @@
#define FF_FS_NORTC 0 #define FF_FS_NORTC 0
#define FF_NORTC_MON 1 #define FF_NORTC_MON 1
#define FF_NORTC_MDAY 1 #define FF_NORTC_MDAY 1
#define FF_NORTC_YEAR 2022 #define FF_NORTC_YEAR 2020
/* The option FF_FS_NORTC switches timestamp feature. If the system does not have /* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
/ an RTC or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable the / any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
/ timestamp feature. Every object modified by FatFs will have a fixed timestamp / the timestamp function. Every object modified by FatFs will have a fixed timestamp
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. / defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be / To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
/ added to the project to read current time form real-time clock. FF_NORTC_MON, / added to the project to read current time form real-time clock. FF_NORTC_MON,
@ -253,7 +253,7 @@
#define FF_FS_NOFSINFO 0 #define FF_FS_NOFSINFO 0
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this /* If you need to know correct free space on the FAT32 volume, set bit 0 of this
/ option, and f_getfree() function at the first time after volume mount will force / option, and f_getfree() function at first time after volume mount will force
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. / a full FAT scan. Bit 1 controls the use of last allocated cluster number.
/ /
/ bit0=0: Use free cluster count in the FSINFO if available. / bit0=0: Use free cluster count in the FSINFO if available.
@ -275,21 +275,26 @@
/ lock control is independent of re-entrancy. */ / lock control is independent of re-entrancy. */
/* #include <somertos.h> // O/S definitions */
#define FF_FS_REENTRANT 0 #define FF_FS_REENTRANT 0
#define FF_FS_TIMEOUT 1000 #define FF_FS_TIMEOUT 1000
#define FF_SYNC_t HANDLE
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs /* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different / module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() / volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
/ and f_fdisk() function, are always not re-entrant. Only file/directory access / and f_fdisk() function, are always not re-entrant. Only file/directory access
/ to the same volume is under control of this featuer. / to the same volume is under control of this function.
/ /
/ 0: Disable re-entrancy. FF_FS_TIMEOUT have no effect. / 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers, / 1: Enable re-entrancy. Also user provided synchronization handlers,
/ ff_mutex_create(), ff_mutex_delete(), ff_mutex_take() and ff_mutex_give() / ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
/ function, must be added to the project. Samples are available in ffsystem.c. / function, must be added to the project. Samples are available in
/ option/syscall.c.
/ /
/ The FF_FS_TIMEOUT defines timeout period in unit of O/S time tick. / The FF_FS_TIMEOUT defines timeout period in unit of time tick.
*/ / The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
/ included somewhere in the scope of ff.h. */

File diff suppressed because it is too large Load Diff

View File

@ -1,208 +1,170 @@
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* A Sample Code of User Provided OS Dependent Functions for FatFs */ /* Sample Code of OS Dependent Functions for FatFs */
/* (C)ChaN, 2018 */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#include <fatfs/ff.h> #include <fatfs/ff.h>
#if FF_USE_LFN == 3 /* Use dynamic memory allocation */ #if FF_USE_LFN == 3 /* Dynamic memory allocation */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Allocate/Free a Memory Block */ /* Allocate a memory block */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#include <stdlib.h> /* with POSIX API */
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */ UINT msize /* Number of bytes to allocate */
) )
{ {
return malloc((size_t)msize); /* Allocate a new memory block */ return malloc(msize); /* Allocate a new memory block with POSIX API */
} }
/*------------------------------------------------------------------------*/
/* Free a memory block */
/*------------------------------------------------------------------------*/
void ff_memfree ( void ff_memfree (
void* mblock /* Pointer to the memory block to free (no effect if null) */ void* mblock /* Pointer to the memory block to free (nothing to do if null) */
) )
{ {
free(mblock); /* Free the memory block */ free(mblock); /* Free the memory block with POSIX API */
} }
#endif #endif
#if FF_FS_REENTRANT /* Mutal exclusion */ #if FF_FS_REENTRANT /* Mutal exclusion */
/*------------------------------------------------------------------------*/
/* Definitions of Mutex */
/*------------------------------------------------------------------------*/
#define OS_TYPE 0 /* 0:Win32, 1:uITRON4.0, 2:uC/OS-II, 3:FreeRTOS, 4:CMSIS-RTOS */
#if OS_TYPE == 0 /* Win32 */
#include <windows.h>
static HANDLE Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
#elif OS_TYPE == 1 /* uITRON */
#include "itron.h"
#include "kernel.h"
static mtxid Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
#elif OS_TYPE == 2 /* uc/OS-II */
#include "includes.h"
static OS_EVENT *Mutex[FF_VOLUMES + 1]; /* Table of mutex pinter */
#elif OS_TYPE == 3 /* FreeRTOS */
#include "FreeRTOS.h"
#include "semphr.h"
static SemaphoreHandle_t Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
#elif OS_TYPE == 4 /* CMSIS-RTOS */
#include "cmsis_os.h"
static osMutexId Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
#endif
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Create a Mutex */ /* Create a Synchronization Object */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This function is called in f_mount function to create a new mutex /* This function is called in f_mount() function to create a new
/ or semaphore for the volume. When a 0 is returned, the f_mount function / synchronization object for the volume, such as semaphore and mutex.
/ fails with FR_INT_ERR. / When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
*/ */
int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */ //const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
BYTE vol, /* Corresponding volume (logical drive number) */
FF_SYNC_t* sobj /* Pointer to return the created sync object */
) )
{ {
#if OS_TYPE == 0 /* Win32 */ /* Win32 */
Mutex[vol] = CreateMutex(NULL, FALSE, NULL); *sobj = CreateMutex(NULL, FALSE, NULL);
return (int)(Mutex[vol] != INVALID_HANDLE_VALUE); return (int)(*sobj != INVALID_HANDLE_VALUE);
#elif OS_TYPE == 1 /* uITRON */ /* uITRON */
T_CMTX cmtx = {TA_TPRI,1}; // T_CSEM csem = {TA_TPRI,1,1};
// *sobj = acre_sem(&csem);
// return (int)(*sobj > 0);
Mutex[vol] = acre_mtx(&cmtx); /* uC/OS-II */
return (int)(Mutex[vol] > 0); // OS_ERR err;
// *sobj = OSMutexCreate(0, &err);
// return (int)(err == OS_NO_ERR);
#elif OS_TYPE == 2 /* uC/OS-II */ /* FreeRTOS */
OS_ERR err; // *sobj = xSemaphoreCreateMutex();
// return (int)(*sobj != NULL);
Mutex[vol] = OSMutexCreate(0, &err); /* CMSIS-RTOS */
return (int)(err == OS_NO_ERR); // *sobj = osMutexCreate(&Mutex[vol]);
// return (int)(*sobj != NULL);
#elif OS_TYPE == 3 /* FreeRTOS */
Mutex[vol] = xSemaphoreCreateMutex();
return (int)(Mutex[vol] != NULL);
#elif OS_TYPE == 4 /* CMSIS-RTOS */
osMutexDef(cmsis_os_mutex);
Mutex[vol] = osMutexCreate(osMutex(cmsis_os_mutex));
return (int)(Mutex[vol] != NULL);
#endif
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Delete a Mutex */ /* Delete a Synchronization Object */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This function is called in f_mount function to delete a mutex or /* This function is called in f_mount() function to delete a synchronization
/ semaphore of the volume created with ff_mutex_create function. / object that created with ff_cre_syncobj() function. When a 0 is returned,
/ the f_mount() function fails with FR_INT_ERR.
*/ */
void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */ int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
) )
{ {
#if OS_TYPE == 0 /* Win32 */ /* Win32 */
CloseHandle(Mutex[vol]); return (int)CloseHandle(sobj);
#elif OS_TYPE == 1 /* uITRON */ /* uITRON */
del_mtx(Mutex[vol]); // return (int)(del_sem(sobj) == E_OK);
#elif OS_TYPE == 2 /* uC/OS-II */ /* uC/OS-II */
OS_ERR err; // OS_ERR err;
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
// return (int)(err == OS_NO_ERR);
OSMutexDel(Mutex[vol], OS_DEL_ALWAYS, &err); /* FreeRTOS */
// vSemaphoreDelete(sobj);
// return 1;
#elif OS_TYPE == 3 /* FreeRTOS */ /* CMSIS-RTOS */
vSemaphoreDelete(Mutex[vol]); // return (int)(osMutexDelete(sobj) == osOK);
#elif OS_TYPE == 4 /* CMSIS-RTOS */
osMutexDelete(Mutex[vol]);
#endif
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Request a Grant to Access the Volume */ /* Request Grant to Access the Volume */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This function is called on enter file functions to lock the volume. /* This function is called on entering file functions to lock the volume.
/ When a 0 is returned, the file function fails with FR_TIMEOUT. / When a 0 is returned, the file function fails with FR_TIMEOUT.
*/ */
int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */ int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ FF_SYNC_t sobj /* Sync object to wait */
) )
{ {
#if OS_TYPE == 0 /* Win32 */ /* Win32 */
return (int)(WaitForSingleObject(Mutex[vol], FF_FS_TIMEOUT) == WAIT_OBJECT_0); return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
#elif OS_TYPE == 1 /* uITRON */ /* uITRON */
return (int)(tloc_mtx(Mutex[vol], FF_FS_TIMEOUT) == E_OK); // return (int)(wai_sem(sobj) == E_OK);
#elif OS_TYPE == 2 /* uC/OS-II */ /* uC/OS-II */
OS_ERR err; // OS_ERR err;
// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
// return (int)(err == OS_NO_ERR);
OSMutexPend(Mutex[vol], FF_FS_TIMEOUT, &err)); /* FreeRTOS */
return (int)(err == OS_NO_ERR); // return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
#elif OS_TYPE == 3 /* FreeRTOS */ /* CMSIS-RTOS */
return (int)(xSemaphoreTake(Mutex[vol], FF_FS_TIMEOUT) == pdTRUE); // return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
#elif OS_TYPE == 4 /* CMSIS-RTOS */
return (int)(osMutexWait(Mutex[vol], FF_FS_TIMEOUT) == osOK);
#endif
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Release a Grant to Access the Volume */ /* Release Grant to Access the Volume */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This function is called on leave file functions to unlock the volume. /* This function is called on leaving file functions to unlock the volume.
*/ */
void ff_mutex_give ( void ff_rel_grant (
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ FF_SYNC_t sobj /* Sync object to be signaled */
) )
{ {
#if OS_TYPE == 0 /* Win32 */ /* Win32 */
ReleaseMutex(Mutex[vol]); ReleaseMutex(sobj);
#elif OS_TYPE == 1 /* uITRON */ /* uITRON */
unl_mtx(Mutex[vol]); // sig_sem(sobj);
#elif OS_TYPE == 2 /* uC/OS-II */ /* uC/OS-II */
OSMutexPost(Mutex[vol]); // OSMutexPost(sobj);
#elif OS_TYPE == 3 /* FreeRTOS */ /* FreeRTOS */
xSemaphoreGive(Mutex[vol]); // xSemaphoreGive(sobj);
#elif OS_TYPE == 4 /* CMSIS-RTOS */ /* CMSIS-RTOS */
osMutexRelease(Mutex[vol]); // osMutexRelease(sobj);
#endif
} }
#endif /* FF_FS_REENTRANT */ #endif

View File

@ -1,13 +1,13 @@
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Unicode Handling Functions for FatFs R0.13 and Later */ /* Unicode handling functions for FatFs R0.13+ */
/*------------------------------------------------------------------------*/
/* This module will occupy a huge memory in the .rodata section when the */
/* FatFs is configured for LFN with DBCS. If the system has a Unicode */
/* library for the code conversion, this module should be modified to use */
/* it to avoid silly memory consumption. */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* This module will occupy a huge memory in the .const section when the /
/ FatFs is configured for LFN with DBCS. If the system has any Unicode /
/ utilitiy for the code conversion, this module should be modified to use /
/ that function to avoid silly memory consumption. /
/-------------------------------------------------------------------------*/
/* /*
/ Copyright (C) 2022, ChaN, all right reserved. / Copyright (C) 2014, ChaN, all right reserved.
/ /
/ FatFs module is an open source software. Redistribution and use of FatFs in / FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided / source and binary forms, with or without modification, are permitted provided
@ -22,9 +22,10 @@
/ by use of this software. / by use of this software.
*/ */
#include <fatfs/ff.h> #include <fatfs/ff.h>
#if FF_USE_LFN != 0 /* This module will be blanked if in non-LFN configuration */ #if FF_USE_LFN /* This module will be blanked if non-LFN configuration */
#define MERGE2(a, b) a ## b #define MERGE2(a, b) a ## b
#define CVTBL(tbl, cp) MERGE2(tbl, cp) #define CVTBL(tbl, cp) MERGE2(tbl, cp)
@ -15213,8 +15214,8 @@ static const WCHAR uc869[] = { /* CP869(Greek 2) to Unicode conversion table */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* OEM <==> Unicode Conversions for Static Code Page Configuration with */ /* OEM <==> Unicode conversions for static code page configuration */
/* SBCS Fixed Code Page */ /* SBCS fixed code page */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#if FF_CODE_PAGE != 0 && FF_CODE_PAGE < 900 #if FF_CODE_PAGE != 0 && FF_CODE_PAGE < 900
@ -15266,8 +15267,8 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* OEM <==> Unicode Conversions for Static Code Page Configuration with */ /* OEM <==> Unicode conversions for static code page configuration */
/* DBCS Fixed Code Page */ /* DBCS fixed code page */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#if FF_CODE_PAGE >= 900 #if FF_CODE_PAGE >= 900
@ -15345,7 +15346,7 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* OEM <==> Unicode Conversions for Dynamic Code Page Configuration */ /* OEM <==> Unicode conversions for dynamic code page configuration */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#if FF_CODE_PAGE == 0 #if FF_CODE_PAGE == 0
@ -15457,7 +15458,7 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Unicode Up-case Conversion */ /* Unicode up-case conversion */
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
DWORD ff_wtoupper ( /* Returns up-converted code point */ DWORD ff_wtoupper ( /* Returns up-converted code point */
@ -15589,4 +15590,4 @@ DWORD ff_wtoupper ( /* Returns up-converted code point */
} }
#endif /* #if FF_USE_LFN != 0 */ #endif /* #if FF_USE_LFN */

View File

@ -1,8 +1,8 @@
/*----------------------------------------------------------------------------/ /*----------------------------------------------------------------------------/
/ FatFs - Generic FAT Filesystem module R0.15 / / FatFs - Generic FAT Filesystem module R0.14b /
/-----------------------------------------------------------------------------/ /-----------------------------------------------------------------------------/
/ /
/ Copyright (C) 2022, ChaN, all right reserved. / Copyright (C) 2021, ChaN, all right reserved.
/ /
/ FatFs module is an open source software. Redistribution and use of FatFs in / FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided / source and binary forms, with or without modification, are permitted provided
@ -20,7 +20,7 @@
#ifndef FF_DEFINED #ifndef FF_DEFINED
#define FF_DEFINED 80286 /* Revision ID */ #define FF_DEFINED 86631 /* Revision ID */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -131,11 +131,10 @@ extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
typedef struct { typedef struct {
BYTE fs_type; /* Filesystem type (0:not mounted) */ BYTE fs_type; /* Filesystem type (0:not mounted) */
BYTE pdrv; /* Volume hosting physical drive */ BYTE pdrv; /* Associated physical drive */
BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */
BYTE n_fats; /* Number of FATs (1 or 2) */ BYTE n_fats; /* Number of FATs (1 or 2) */
BYTE wflag; /* win[] status (b0:dirty) */ BYTE wflag; /* win[] flag (b0:dirty) */
BYTE fsi_flag; /* FSINFO status (b7:disabled, b0:dirty) */ BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
WORD id; /* Volume mount ID */ WORD id; /* Volume mount ID */
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
WORD csize; /* Cluster size [sectors] */ WORD csize; /* Cluster size [sectors] */
@ -148,6 +147,9 @@ typedef struct {
#if FF_FS_EXFAT #if FF_FS_EXFAT
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */ BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
#endif #endif
#if FF_FS_REENTRANT
FF_SYNC_t sobj; /* Identifier of sync object */
#endif
#if !FF_FS_READONLY #if !FF_FS_READONLY
DWORD last_clst; /* Last allocated cluster */ DWORD last_clst; /* Last allocated cluster */
DWORD free_clst; /* Number of free clusters */ DWORD free_clst; /* Number of free clusters */
@ -161,10 +163,10 @@ typedef struct {
#endif #endif
#endif #endif
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */ DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
DWORD fsize; /* Number of sectors per FAT */ DWORD fsize; /* Size of an FAT [sectors] */
LBA_t volbase; /* Volume base sector */ LBA_t volbase; /* Volume base sector */
LBA_t fatbase; /* FAT base sector */ LBA_t fatbase; /* FAT base sector */
LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */ LBA_t dirbase; /* Root directory base sector/cluster */
LBA_t database; /* Data base sector */ LBA_t database; /* Data base sector */
#if FF_FS_EXFAT #if FF_FS_EXFAT
LBA_t bitbase; /* Allocation bitmap base sector */ LBA_t bitbase; /* Allocation bitmap base sector */
@ -179,7 +181,7 @@ typedef struct {
typedef struct { typedef struct {
FATFS* fs; /* Pointer to the hosting volume of this object */ FATFS* fs; /* Pointer to the hosting volume of this object */
WORD id; /* Hosting volume's mount ID */ WORD id; /* Hosting volume mount ID */
BYTE attr; /* Object attribute */ BYTE attr; /* Object attribute */
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */ BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */ DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
@ -248,7 +250,7 @@ typedef struct {
WORD ftime; /* Modified time */ WORD ftime; /* Modified time */
BYTE fattrib; /* File attribute */ BYTE fattrib; /* File attribute */
#if FF_USE_LFN #if FF_USE_LFN
TCHAR altname[FF_SFN_BUF + 1];/* Alternative file name */ TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */ TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
#else #else
TCHAR fname[12 + 1]; /* File name */ TCHAR fname[12 + 1]; /* File name */
@ -296,10 +298,8 @@ typedef enum {
/*--------------------------------------------------------------*/
/* FatFs Module Application Interface */
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* FatFs module application interface */
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */ FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
FRESULT f_close (FIL* fp); /* Close an open file object */ FRESULT f_close (FIL* fp); /* Close an open file object */
@ -336,8 +336,6 @@ int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */ int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
/* Some API fucntions are implemented as macro */
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize)) #define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
#define f_error(fp) ((fp)->err) #define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr) #define f_tell(fp) ((fp)->fptr)
@ -351,43 +349,38 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the fil
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* Additional Functions */ /* Additional user defined functions */
/*--------------------------------------------------------------*/
/* RTC function (provided by user) */ /* RTC function */
#if !FF_FS_READONLY && !FF_FS_NORTC #if !FF_FS_READONLY && !FF_FS_NORTC
DWORD get_fattime (void); /* Get current time */ DWORD get_fattime (void);
#endif #endif
/* LFN support functions */
/* LFN support functions (defined in ffunicode.c) */ #if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
#if FF_USE_LFN >= 1
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */ WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */ WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */ DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
#endif #endif
/* O/S dependent functions (samples available in ffsystem.c) */
#if FF_USE_LFN == 3 /* Dynamic memory allocation */ #if FF_USE_LFN == 3 /* Dynamic memory allocation */
void* ff_memalloc (UINT msize); /* Allocate memory block */ void* ff_memalloc (UINT msize); /* Allocate memory block */
void ff_memfree (void* mblock); /* Free memory block */ void ff_memfree (void* mblock); /* Free memory block */
#endif #endif
#if FF_FS_REENTRANT /* Sync functions */
int ff_mutex_create (int vol); /* Create a sync object */ /* Sync functions */
void ff_mutex_delete (int vol); /* Delete a sync object */ #if FF_FS_REENTRANT
int ff_mutex_take (int vol); /* Lock sync object */ int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
void ff_mutex_give (int vol); /* Unlock sync object */ int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
#endif #endif
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* Flags and Offset Address */ /* Flags and offset address */
/*--------------------------------------------------------------*/
/* File access mode and open method flags (3rd argument of f_open) */ /* File access mode and open method flags (3rd argument of f_open) */
#define FA_READ 0x01 #define FA_READ 0x01

View File

@ -1,8 +1,8 @@
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ Configurations of FatFs Module / FatFs Functional Configurations
/---------------------------------------------------------------------------*/ /---------------------------------------------------------------------------*/
#define FFCONF_DEF 80286 /* Revision ID */ #define FFCONF_DEF 86631 /* Revision ID */
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ Function Configurations / Function Configurations
@ -68,7 +68,7 @@
/ 2: Enable with LF-CRLF conversion. / 2: Enable with LF-CRLF conversion.
/ /
/ FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2 / FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
/ makes f_printf() support floating point argument. These features want C99 or later. makes f_printf() support floating point argument. These features want C99 or later.
/ When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character / When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
/ encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE / encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
/ to be read/written via those functions. / to be read/written via those functions.
@ -178,7 +178,7 @@
/ logical drives. Number of items must not be less than FF_VOLUMES. Valid / logical drives. Number of items must not be less than FF_VOLUMES. Valid
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are / characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is / compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
/ not defined, a user defined volume string table is needed as: / not defined, a user defined volume string table needs to be defined as:
/ /
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... / const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
*/ */
@ -190,7 +190,7 @@
/ number and only an FAT volume found on the physical drive will be mounted. / number and only an FAT volume found on the physical drive will be mounted.
/ When this function is enabled (1), each logical drive number can be bound to / When this function is enabled (1), each logical drive number can be bound to
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() / arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
/ function will be available. */ / funciton will be available. */
#define FF_MIN_SS 512 #define FF_MIN_SS 512
@ -240,10 +240,10 @@
#define FF_FS_NORTC 0 #define FF_FS_NORTC 0
#define FF_NORTC_MON 1 #define FF_NORTC_MON 1
#define FF_NORTC_MDAY 1 #define FF_NORTC_MDAY 1
#define FF_NORTC_YEAR 2022 #define FF_NORTC_YEAR 2020
/* The option FF_FS_NORTC switches timestamp feature. If the system does not have /* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
/ an RTC or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable the / any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
/ timestamp feature. Every object modified by FatFs will have a fixed timestamp / the timestamp function. Every object modified by FatFs will have a fixed timestamp
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. / defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be / To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
/ added to the project to read current time form real-time clock. FF_NORTC_MON, / added to the project to read current time form real-time clock. FF_NORTC_MON,
@ -253,7 +253,7 @@
#define FF_FS_NOFSINFO 0 #define FF_FS_NOFSINFO 0
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this /* If you need to know correct free space on the FAT32 volume, set bit 0 of this
/ option, and f_getfree() function at the first time after volume mount will force / option, and f_getfree() function at first time after volume mount will force
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. / a full FAT scan. Bit 1 controls the use of last allocated cluster number.
/ /
/ bit0=0: Use free cluster count in the FSINFO if available. / bit0=0: Use free cluster count in the FSINFO if available.
@ -275,21 +275,26 @@
/ lock control is independent of re-entrancy. */ / lock control is independent of re-entrancy. */
/* #include <somertos.h> // O/S definitions */
#define FF_FS_REENTRANT 0 #define FF_FS_REENTRANT 0
#define FF_FS_TIMEOUT 1000 #define FF_FS_TIMEOUT 1000
#define FF_SYNC_t HANDLE
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs /* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different / module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() / volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
/ and f_fdisk() function, are always not re-entrant. Only file/directory access / and f_fdisk() function, are always not re-entrant. Only file/directory access
/ to the same volume is under control of this featuer. / to the same volume is under control of this function.
/ /
/ 0: Disable re-entrancy. FF_FS_TIMEOUT have no effect. / 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers, / 1: Enable re-entrancy. Also user provided synchronization handlers,
/ ff_mutex_create(), ff_mutex_delete(), ff_mutex_take() and ff_mutex_give() / ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
/ function, must be added to the project. Samples are available in ffsystem.c. / function, must be added to the project. Samples are available in
/ option/syscall.c.
/ /
/ The FF_FS_TIMEOUT defines timeout period in unit of O/S time tick. / The FF_FS_TIMEOUT defines timeout period in unit of time tick.
*/ / The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
/ included somewhere in the scope of ff.h. */