Commit ca63c862 authored by swym's avatar swym
Browse files

feat(fatfs): API to dump status of FD pool

parent f86585fa
......@@ -67,6 +67,7 @@ typedef _Bool bool;
#define API_FILE_UNLINK 0x4b
#define API_FILE_RENAME 0x4c
#define API_FILE_MKDIR 0x4d
#define API_FILE_FS_STATUS 0x4e
#define API_RTC_GET_SECONDS 0x50
#define API_RTC_SCHEDULE_ALARM 0x51
......@@ -1325,6 +1326,8 @@ API(API_FILE_RENAME, int epic_file_rename(const char *oldp, const char* newp));
*/
API(API_FILE_MKDIR, int epic_file_mkdir(const char *dirname));
API(API_FILE_FS_STATUS, int epic_file_fs_status(void));
/**
* RTC
* ===
......
......@@ -189,6 +189,33 @@ void fatfs_close_all(int coreMask)
efs_unlock_global(fs);
}
}
void efs_dump_status(EpicFileSystem *fs)
{
printf(">>> FS status\n");
for (int index = 0; index < EPIC_FAT_MAX_OPENED; ++index) {
struct FatObject *fso = &fs->pool[index];
int fd = EPIC_FAT_FD(index, fso->generation);
printf(" fd[%2d]: generation: %6d fd: 0x%08x type: ",
index,
fso->generation,
fd);
switch (fso->type) {
case EPICSTAT_NONE:
printf("%s ", "NONE");
break;
case EPICSTAT_FILE:
printf("%s ", "FILE");
break;
case EPICSTAT_DIR:
printf("%s ", "DIR");
break;
}
printf("coreMask: %02x\n", fso->coreMask);
}
printf("<<< FS status\n");
}
static const char *f_get_rc_string(FRESULT rc)
{
static const TCHAR *rcstrings =
......
......@@ -31,6 +31,7 @@ int efs_readdir(EpicFileSystem *fs, int fd, struct epic_stat *stat);
int efs_unlink(EpicFileSystem *fs, const char *path);
int efs_rename(EpicFileSystem *fs, const char *oldp, const char *newp);
int efs_mkdir(EpicFileSystem *fs, const char *dirname);
void efs_dump_status(EpicFileSystem *fs);
/**
* lock global filesystem
*
......
......@@ -23,6 +23,7 @@ int main(void)
epic_disp_print(0, 24, version_buf, 0xffff, 0x0000);
epic_disp_update();
mxc_delay(2000000);
int fd = epic_file_open("epicardium.txt", "w");
LOG_DEBUG("startup", "Initializing tasks ...");
......
......@@ -160,3 +160,14 @@ int epic_file_mkdir(const char *dirname)
}
return res;
}
int epic_file_fs_status(void)
{
EpicFileSystem *fs;
int res = efs_lock_global(&fs);
if (res == 0) {
efs_dump_status(fs);
efs_unlock_global(fs);
}
return res;
}
......@@ -98,6 +98,16 @@ static mp_obj_t mp_os_unlink(mp_obj_t py_path)
}
static MP_DEFINE_CONST_FUN_OBJ_1(unlink_obj, mp_os_unlink);
static mp_obj_t mp_os_fs_status()
{
int rc = epic_file_fs_status();
if (rc < 0) {
mp_raise_OSError(-rc);
}
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(fs_status_obj, mp_os_fs_status);
static mp_obj_t mp_os_mkdir(mp_obj_t py_path)
{
const char *path = mp_obj_str_get_str(py_path);
......@@ -141,7 +151,7 @@ static mp_obj_t mp_os_urandom(mp_obj_t size_in)
vstr_t vstr;
vstr_init_len(&vstr, size);
epic_trng_read((uint8_t*)vstr.buf, size);
epic_trng_read((uint8_t *)vstr.buf, size);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
......@@ -156,6 +166,7 @@ static const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&unlink_obj) },
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mkdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&rename_obj) },
{ MP_ROM_QSTR(MP_QSTR_fs_status), MP_ROM_PTR(&fs_status_obj) },
{ MP_ROM_QSTR(MP_QSTR_read_battery), MP_ROM_PTR(&read_battery_obj) },
{ MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&urandom_obj) },
};
......
......@@ -113,6 +113,7 @@ Q(mkdir)
Q(rename)
Q(read_battery)
Q(urandom)
Q(fs_status)
/* gpio */
Q(gpio)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment