8000 flush flash filesystem once a second by dhalbert · Pull Request #1672 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

flush flash filesystem once a second #1672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ports/atmel-samd/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "audio_dma.h"
#include "tick.h"
#include "supervisor/filesystem.h"
#include "supervisor/usb.h"

#include "py/runtime.h"
Expand All @@ -53,6 +54,7 @@ void run_background_tasks(void) {
#if CIRCUITPY_NETWORK
network_module_background();
#endif
filesystem_background();
usb_background();
assert_heap_ok();

Expand Down
2 changes: 2 additions & 0 deletions ports/nrf/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include "py/runtime.h"
#include "supervisor/filesystem.h"
#include "supervisor/usb.h"
#include "supervisor/shared/stack.h"

Expand All @@ -33,6 +34,7 @@
#endif

void run_background_tasks(void) {
filesystem_background();
usb_background();

#ifdef CIRCUITPY_DISPLAYIO
Expand Down
14 changes: 9 additions & 5 deletions ports/nrf/tick.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "tick.h"

#include "supervisor/shared/autoreload.h"
#include "supervisor/filesystem.h"
#include "shared-module/gamepad/__init__.h"
#include "shared-bindings/microcontroller/Processor.h"
#include "nrf.h"
Expand All @@ -39,14 +40,17 @@ void SysTick_Handler(void) {
// (every millisecond).
ticks_ms += 1;

#ifdef CIRCUITPY_AUTORELOAD_DELAY_MS
autoreload_tick();
#endif
#ifdef CIRCUITPY_GAMEPAD_TICKS
#if CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS > 0
filesystem_tick();
#endif
#ifdef CIRCUITPY_AUTORELOAD_DELAY_MS
autoreload_tick();
#endif
#ifdef CIRCUITPY_GAMEPAD_TICKS
if (!(ticks_ms & CIRCUITPY_GAMEPAD_TICKS)) {
gamepad_tick();
}
#endif
#endif
}

void tick_init() {
Expand Down
1 change: 1 addition & 0 deletions py/circuitpy_mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ void run_background_tasks(void);
#define MICROPY_VM_HOOK_RETURN run_background_tasks();

#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
#define CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS 1000
#define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt"

#endif // __INCLUDED_MPCONFIG_CIRCUITPY_H
4 changes: 4 additions & 0 deletions supervisor/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions supervisor/shared/autoreload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
26 changes: 26 additions & 0 deletions supervisor/shared/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down
0