Skip to content
Snippets Groups Projects
Commit f86585fa authored by swym's avatar swym
Browse files

feat(fatfs): remember by which core an FD was opened, allow to close all FDs by a certain core

parent 76acf664
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include "epicardium.h" #include "epicardium.h"
#include "card10.h" #include "card10.h"
#include "modules/log.h" #include "modules/log.h"
#include "modules/modules.h"
#include "api/common.h"
#define SSLOG_DEBUG(...) LOG_DEBUG("fatfs", __VA_ARGS__) #define SSLOG_DEBUG(...) LOG_DEBUG("fatfs", __VA_ARGS__)
#define SSLOG_INFO(...) LOG_INFO("fatfs", __VA_ARGS__) #define SSLOG_INFO(...) LOG_INFO("fatfs", __VA_ARGS__)
...@@ -44,6 +46,7 @@ ...@@ -44,6 +46,7 @@
struct FatObject { struct FatObject {
uint32_t generation; uint32_t generation;
int coreMask;
enum epic_stat_type type; enum epic_stat_type type;
union { union {
FIL file; FIL file;
...@@ -56,6 +59,7 @@ struct EpicFileSystem { ...@@ -56,6 +59,7 @@ struct EpicFileSystem {
uint32_t generationCount; uint32_t generationCount;
bool initialized; bool initialized;
FATFS FatFs; FATFS FatFs;
int lockCoreMask;
}; };
// this table converts from FRESULT to POSIX errno // this table converts from FRESULT to POSIX errno
...@@ -64,7 +68,7 @@ static const int s_libffToErrno[20]; ...@@ -64,7 +68,7 @@ static const int s_libffToErrno[20];
static const char *f_get_rc_string(FRESULT rc); static const char *f_get_rc_string(FRESULT rc);
static bool globalLockAccquire(); static bool globalLockAccquire();
static void globalLockRelease(); static void globalLockRelease();
static void efs_close_all(EpicFileSystem *fs); static void efs_close_all(EpicFileSystem *fs, int coreMask);
/** /**
* if EPICSTAT_NONE is passed to `expected`, the type is not checked. * if EPICSTAT_NONE is passed to `expected`, the type is not checked.
...@@ -159,7 +163,7 @@ void fatfs_detach() ...@@ -159,7 +163,7 @@ void fatfs_detach()
FRESULT ff_res; FRESULT ff_res;
EpicFileSystem *fs; EpicFileSystem *fs;
if (efs_lock_global(&fs) == 0) { if (efs_lock_global(&fs) == 0) {
efs_close_all(fs); efs_close_all(fs, EPICARDIUM_COREMASK_BOTH);
//unmount by passing NULL as fs object, will destroy our sync object via ff_del_syncobj //unmount by passing NULL as fs object, will destroy our sync object via ff_del_syncobj
ff_res = f_mount(NULL, "/", 0); ff_res = f_mount(NULL, "/", 0);
...@@ -177,6 +181,14 @@ void fatfs_detach() ...@@ -177,6 +181,14 @@ void fatfs_detach()
} }
} }
void fatfs_close_all(int coreMask)
{
EpicFileSystem *fs;
if (efs_lock_global(&fs) == 0) {
efs_close_all(fs, coreMask);
efs_unlock_global(fs);
}
}
static const char *f_get_rc_string(FRESULT rc) static const char *f_get_rc_string(FRESULT rc)
{ {
static const TCHAR *rcstrings = static const TCHAR *rcstrings =
...@@ -216,6 +228,11 @@ int efs_lock_global(EpicFileSystem **fs) ...@@ -216,6 +228,11 @@ int efs_lock_global(EpicFileSystem **fs)
return -ENODEV; return -ENODEV;
} }
*fs = &s_globalFileSystem; *fs = &s_globalFileSystem;
if (xTaskGetCurrentTaskHandle() == dispatcher_task_id) {
s_globalFileSystem.lockCoreMask = EPICARDIUM_COREMASK_1;
} else {
s_globalFileSystem.lockCoreMask = EPICARDIUM_COREMASK_0;
}
return 0; return 0;
} }
...@@ -292,6 +309,7 @@ static int efs_obj_init( ...@@ -292,6 +309,7 @@ static int efs_obj_init(
} }
obj->type = type; obj->type = type;
obj->generation = generation; obj->generation = generation;
obj->coreMask = fs->lockCoreMask;
return EPIC_FAT_FD(index, generation); return EPIC_FAT_FD(index, generation);
} }
...@@ -300,6 +318,7 @@ static void efs_obj_deinit(EpicFileSystem *fs, struct FatObject *obj) ...@@ -300,6 +318,7 @@ static void efs_obj_deinit(EpicFileSystem *fs, struct FatObject *obj)
{ {
obj->type = EPICSTAT_NONE; obj->type = EPICSTAT_NONE;
obj->generation = 0; obj->generation = 0;
obj->coreMask = 0;
} }
/* here we're trying to mirror glibc's behaviour: /* here we're trying to mirror glibc's behaviour:
...@@ -392,9 +411,13 @@ int efs_close(EpicFileSystem *fs, int fd) ...@@ -392,9 +411,13 @@ int efs_close(EpicFileSystem *fs, int fd)
return res; return res;
} }
void efs_close_all(EpicFileSystem *fs) void efs_close_all(EpicFileSystem *fs, int coreMask)
{ {
assert(coreMask != 0);
for (int i = 0; i < EPIC_FAT_MAX_OPENED; ++i) { for (int i = 0; i < EPIC_FAT_MAX_OPENED; ++i) {
if (!(fs->pool[i].coreMask & coreMask)) {
continue;
}
switch (fs->pool[i].type) { switch (fs->pool[i].type) {
case EPICSTAT_FILE: case EPICSTAT_FILE:
f_close(&fs->pool[i].file); f_close(&fs->pool[i].file);
......
...@@ -22,4 +22,13 @@ int fatfs_attach(void); ...@@ -22,4 +22,13 @@ int fatfs_attach(void);
/** close all opened FDs, sync and deinitialize FLASH layer */ /** close all opened FDs, sync and deinitialize FLASH layer */
void fatfs_detach(void); void fatfs_detach(void);
/** close all onpened FDs
* TODO: add ability to close FDs opened by core0/core1 only
*/
#define EPICARDIUM_COREMASK_0 0x01
#define EPICARDIUM_COREMASK_1 0x02
#define EPICARDIUM_COREMASK_BOTH 0x03
void fatfs_close_all(int coreMask);
#endif//EPICARDIUM_MODULE_FILESYSTEM_INCLUDED #endif//EPICARDIUM_MODULE_FILESYSTEM_INCLUDED
...@@ -206,6 +206,11 @@ int hardware_reset(void) ...@@ -206,6 +206,11 @@ int hardware_reset(void)
api_interrupt_init(); api_interrupt_init();
api_dispatcher_init(); api_dispatcher_init();
/*
* close all FDs currently owned by core1
*/
fatfs_close_all(EPICARDIUM_COREMASK_1);
/* Personal State */ /* Personal State */
const int personal_state_is_persistent = const int personal_state_is_persistent =
epic_personal_state_is_persistent(); epic_personal_state_is_persistent();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment