summaryrefslogtreecommitdiff
path: root/supervisor
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-03-20 12:21:36 -0400
committerDan Halbert <halbert@halwitz.org>2019-03-20 12:21:36 -0400
commit2459eabd66169d18f3f223c942cc73152ce6de68 (patch)
tree855da308cc8795b2a238b5e90a6b8e4712686f8b /supervisor
parent8543695f9d6117d758d0cece4a921ce9396d3948 (diff)
flush flash filesystem once a second
Diffstat (limited to 'supervisor')
-rw-r--r--supervisor/filesystem.h4
-rw-r--r--supervisor/shared/autoreload.c5
-rw-r--r--supervisor/shared/filesystem.c24
3 files changed, 31 insertions, 2 deletions
diff --git a/supervisor/filesystem.h b/supervisor/filesystem.h
index 76f235f47..c7c951a5e 100644
--- a/supervisor/filesystem.h
+++ b/supervisor/filesystem.h
@@ -31,6 +31,10 @@
#include "extmod/vfs_fat.h"
+extern volatile bool filesystem_flush_requested;
+
+void filesystem_background(void);
+void filesystem_tick(void);
void filesystem_init(bool create_allowed, bool force_create);
void filesystem_flush(void);
bool filesystem_present(void);
diff --git a/supervisor/shared/autoreload.c b/supervisor/shared/autoreload.c
index 2a7fd1e9d..14b21902c 100644
--- a/supervisor/shared/autoreload.c
+++ b/supervisor/shared/autoreload.c
@@ -29,9 +29,10 @@
#include "py/mphal.h"
#include "py/reload.h"
-volatile uint32_t autoreload_delay_ms = 0;
-bool autoreload_enabled = false;
+static volatile uint32_t autoreload_delay_ms = 0;
+static bool autoreload_enabled = false;
static bool autoreload_suspended = false;
+
volatile bool reload_requested = false;
inline void autoreload_tick() {
diff --git a/supervisor/shared/filesystem.c b/supervisor/shared/filesystem.c
index 0ef978ef2..dc061fa41 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);