diff options
| author | Melissa LeBlanc-Williams <melissa@melissagirl.com> | 2019-03-26 18:23:02 -0700 |
|---|---|---|
| committer | Melissa LeBlanc-Williams <melissa@melissagirl.com> | 2019-03-26 18:23:02 -0700 |
| commit | 5f0e71ccb48e47ea03d264a6d14e6009ac9691e1 (patch) | |
| tree | 1542be340b55cd0cea66d7aef3d60cdfaa546d58 /supervisor/shared/filesystem.c | |
| parent | a54493b4ae41210f12cb940db019be87d68253a1 (diff) | |
| parent | 3f42a49a6b9fe416b739757e6e72574abc58c4fd (diff) | |
Merge branch 'master' of https://github.com/adafruit/circuitpython into ssd1351-fix
Diffstat (limited to 'supervisor/shared/filesystem.c')
| -rw-r--r-- | supervisor/shared/filesystem.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/supervisor/shared/filesystem.c b/supervisor/shared/filesystem.c index 0ef978ef2..68c6f4749 100644 --- a/supervisor/shared/filesystem.c +++ b/supervisor/shared/filesystem.c @@ -37,6 +37,30 @@ static mp_vfs_mount_t _mp_vfs; static fs_user_mount_t _internal_vfs; +static volatile uint32_t filesystem_flush_interval_ms = CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS; +volatile bool filesystem_flush_requested = false; + +void filesystem_background(void) { + if (filesystem_flush_requested) { + filesystem_flush(); + filesystem_flush_requested = false; + } +} + +inline void filesystem_tick(void) { + if (filesystem_flush_interval_ms == 0) { + // 0 means not turned on. + return; + } + if (filesystem_flush_interval_ms == 1) { + filesystem_flush_requested = true; + filesystem_flush_interval_ms = CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS; + } else { + filesystem_flush_interval_ms--; + } +} + + static void make_empty_file(FATFS *fatfs, const char *path) { FIL fp; f_open(fatfs, &fp, path, FA_WRITE | FA_CREATE_ALWAYS); @@ -91,6 +115,8 @@ void filesystem_init(bool create_allowed, bool force_create) { } void filesystem_flush(void) { + // Reset interval before next flush. + filesystem_flush_interval_ms = CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS; supervisor_flash_flush(); } |
