Skip to content

Commit

Permalink
Added API allowing user to choose settings at runtime - replacement o…
Browse files Browse the repository at this point in the history
…f PR#49 (#51)

* Adding in FF_SDDiskInitWithSettings optional initialization to support runtime initial mounting options.

* FAT-#50: Fixing duplicate definition of st_atime, st_mtime, st_ctime for linux.

* Fixing formatting with diff provided using uncrustify.

---------

Co-authored-by: Paul Helter <[email protected]>
  • Loading branch information
AniruddhaKanhere and phelter authored Aug 24, 2023
1 parent 08d0cff commit 25129e5
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 22 deletions.
6 changes: 3 additions & 3 deletions ff_stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,9 @@ int ff_stat( const char * pcName,

#if ( ffconfigTIME_SUPPORT == 1 )
{
pxStatBuffer->st_atime = prvFileTime( &( xDirEntry.xAccessedTime ) );
pxStatBuffer->st_mtime = prvFileTime( &( xDirEntry.xModifiedTime ) );
pxStatBuffer->st_ctime = prvFileTime( &( xDirEntry.xCreateTime ) );
pxStatBuffer->ff_atime = prvFileTime( &( xDirEntry.xAccessedTime ) );
pxStatBuffer->ff_mtime = prvFileTime( &( xDirEntry.xModifiedTime ) );
pxStatBuffer->ff_ctime = prvFileTime( &( xDirEntry.xCreateTime ) );
}
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions include/ff_stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@

/* Note time_t must be used here otherwise will have bugs when 2032 (uint32_t second clock rolls over) */
#if ( ffconfigTIME_SUPPORT == 1 )
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
time_t ff_atime;
time_t ff_mtime;
time_t ff_ctime;
#endif /* ffconfigTIME_SUPPORT */
} FF_Stat_t;

Expand Down
9 changes: 9 additions & 0 deletions portable/ATSAM4E/ff_sddisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ void FF_SDDiskFlush( FF_Disk_t * pxDisk )
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName,
const FFInitSettings_t * pxSettings )
{
( void ) pxSettings; /* Unused */

return FF_SDDiskInit( pcName );
}
/*-----------------------------------------------------------*/

/* Initialise the SDIO driver and mount an SD card */
FF_Disk_t * FF_SDDiskInit( const char * pcName )
{
Expand Down
9 changes: 9 additions & 0 deletions portable/ATSAM4E/ff_sddisk_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ void FF_SDDiskFlush( FF_Disk_t * pxDisk )
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName,
const FFInitSettings_t * pxSettings )
{
( void ) pxSettings; /* Unused */

return FF_SDDiskInit( pcName );
}
/*-----------------------------------------------------------*/

/* Initialise the SDIO driver and mount an SD card */
FF_Disk_t * FF_SDDiskInit( const char * pcName )
{
Expand Down
9 changes: 9 additions & 0 deletions portable/STM32F4xx/ff_sddisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,15 @@ static void vGPIO_SD_Init( SD_HandleTypeDef * xSDHandle )
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName,
const FFInitSettings_t * pxSettings )
{
( void ) pxSettings; /* Unused */

return FF_SDDiskInit( pcName );
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInit( const char * pcName )
{
FF_Error_t xFFError;
Expand Down
9 changes: 9 additions & 0 deletions portable/STM32F7xx/ff_sddisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ static void vGPIO_SD_Init( SD_HandleTypeDef * xSDHandle )
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName,
const FFInitSettings_t * pxSettings )
{
( void ) pxSettings; /* Unused */

return FF_SDDiskInit( pcName );
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInit( const char * pcName )
{
FF_Error_t xFFError;
Expand Down
27 changes: 13 additions & 14 deletions portable/Zynq.2019.3/ff_sddisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,19 @@ static CacheMemoryInfo_t * pucGetSDIOCacheMemory( BaseType_t xPartition )
}
/*-----------------------------------------------------------*/

/* Initialise the SDIO driver and mount an SD card */
BaseType_t xMountFailIgnore = 0;
FF_Disk_t * FF_SDDiskInit( const char * pcName )
{
const FFInitSettings_t defaultSettings = {};

/* _HT_ : the function FF_SDDiskInit() used to mount partition-0.
* It would be nice if it has a parameter indicating the partition
* number.
* As for now, the partion can be set with a global variable 'xDiskPartition'.
*/
BaseType_t xDiskPartition = 0;
return FF_SDDiskInitWithSettings( pcName, &defaultSettings );
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInit( const char * pcName )
/* Initialise the SDIO driver and mount an SD card */
FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName,
const FFInitSettings_t * pxSettings )
{
FF_Error_t xFFError;
BaseType_t xPartitionNumber = xDiskPartition;
FF_CreationParameters_t xParameters;
FF_Disk_t * pxDisk = NULL;
CacheMemoryInfo_t * pxCacheMem = NULL;
Expand All @@ -456,13 +455,13 @@ FF_Disk_t * FF_SDDiskInit( const char * pcName )

do
{
if( pucGetSDIOCacheMemory( xPartitionNumber ) == NULL )
if( pucGetSDIOCacheMemory( pxSettings->xDiskPartition ) == NULL )
{
FF_PRINTF( "FF_SDDiskInit: Cached memory failed\n" );
break;
}

pxCacheMem = pxCacheMemories[ xPartitionNumber ];
pxCacheMem = pxCacheMemories[ pxSettings->xDiskPartition ];

if( pxSDCardInstance == NULL )
{
Expand Down Expand Up @@ -551,14 +550,14 @@ FF_Disk_t * FF_SDDiskInit( const char * pcName )
}

pxDisk->xStatus.bIsInitialised = pdTRUE;
pxDisk->xStatus.bPartitionNumber = xPartitionNumber;
pxDisk->xStatus.bPartitionNumber = pxSettings->xDiskPartition;

if( FF_SDDiskMount( pxDisk ) == 0 )
{
/* _HT_ Suppose that the partition is not yet
* formatted, it might be desireable to have a valid
* i/o manager. */
if( xMountFailIgnore == 0 )
if( pxSettings->xMountFailIgnore == 0 )
{
FF_SDDiskDelete( pxDisk );
pxDisk = NULL;
Expand Down
9 changes: 9 additions & 0 deletions portable/Zynq/ff_sddisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ static struct xCACHE_MEMORY_INFO * pucGetSDIOCacheMemory()
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName,
const FFInitSettings_t * pxSettings )
{
( void ) pxSettings; /* Unused */

return FF_SDDiskInit( pcName );
}
/*-----------------------------------------------------------*/

/* Initialise the SDIO driver and mount an SD card */
FF_Disk_t * FF_SDDiskInit( const char * pcName )
{
Expand Down
12 changes: 11 additions & 1 deletion portable/common/ff_sddisk.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,28 @@

#define __SDDISK_H__

#include "ff_headers.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "ff_headers.h"
/* @brief Initialization settings for more granular control on init. */
typedef struct FFInitSettings_s
{
BaseType_t xMountFailIgnore; /**< Ignore failure when mounting */
BaseType_t xDiskPartition; /**< Default disk partition number */
} FFInitSettings_t;


/* Return non-zero if the SD-card is present.
* The parameter 'pxDisk' may be null, unless device locking is necessary. */
BaseType_t FF_SDDiskDetect( FF_Disk_t * pxDisk );

/* Create a RAM disk, supplying enough memory to hold N sectors of 512 bytes each */
FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName,
const FFInitSettings_t * pxSettings );

FF_Disk_t * FF_SDDiskInit( const char * pcName );

BaseType_t FF_SDDiskReinit( FF_Disk_t * pxDisk );
Expand Down
9 changes: 9 additions & 0 deletions portable/linux/ff_sddisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ void FF_SDDiskFlush( FF_Disk_t * pxDisk )
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName,
const FFInitSettings_t * pxSettings )
{
( void ) pxSettings; /* Unused */

return FF_SDDiskInit( pcName );
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInit( const char * pcName )
{
FF_Disk_t * pxDisk = NULL;
Expand Down
10 changes: 9 additions & 1 deletion portable/lpc18xx/ff_sddisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,15 @@ void FF_SDDiskFlush( FF_Disk_t * pxDisk )
}
/*-----------------------------------------------------------*/

/* Initialise the SDIO driver and mount an SD card */
FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName,
const FFInitSettings_t * pxSettings )
{
( void ) pxSettings; /* Unused */

return FF_SDDiskInit( pcName );
}
/*-----------------------------------------------------------*/

FF_Disk_t * FF_SDDiskInit( const char * pcName )
{
FF_Error_t xFFError;
Expand Down

0 comments on commit 25129e5

Please sign in to comment.