From d5ae5b14aa5d204ae6ebdc077e65c00a3eaaeaa0 Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Sun, 27 Nov 2022 14:48:22 +0100 Subject: [PATCH] [SC64][SW] Disable save writeback on SD card removal or write error --- sw/controller/src/writeback.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sw/controller/src/writeback.c b/sw/controller/src/writeback.c index c21cf84..40f0351 100644 --- a/sw/controller/src/writeback.c +++ b/sw/controller/src/writeback.c @@ -2,7 +2,6 @@ #include "sd.h" #include "timer.h" #include "writeback.h" -#include "led.h" #define SAVE_MAX_SECTOR_COUNT (256) @@ -33,6 +32,7 @@ static void writeback_save_to_sd (void) { break; } if (sd_write_sectors(save_address, sector, 1)) { + p.enabled = false; break; } save_address += SD_SECTOR_SIZE; @@ -66,11 +66,15 @@ void writeback_init (void) { void writeback_process (void) { if (p.enabled) { - uint16_t save_count = fpga_reg_get(REG_SAVE_COUNT); - if (save_count != p.last_save_count) { - p.pending = true; - timer_set(TIMER_ID_WRITEBACK, WRITEBACK_DELAY_TICKS); - p.last_save_count = save_count; + if (fpga_reg_get(REG_SD_SCR) & SD_SCR_CARD_INSERTED) { + uint16_t save_count = fpga_reg_get(REG_SAVE_COUNT); + if (save_count != p.last_save_count) { + p.pending = true; + timer_set(TIMER_ID_WRITEBACK, WRITEBACK_DELAY_TICKS); + p.last_save_count = save_count; + } + } else { + writeback_init(); } } if (p.pending) {