[SC64][SW] Disable save writeback on SD card removal or write error

This commit is contained in:
Mateusz Faderewski 2022-11-27 14:48:22 +01:00
parent ed25ef16e9
commit d5ae5b14aa

View File

@ -2,7 +2,6 @@
#include "sd.h" #include "sd.h"
#include "timer.h" #include "timer.h"
#include "writeback.h" #include "writeback.h"
#include "led.h"
#define SAVE_MAX_SECTOR_COUNT (256) #define SAVE_MAX_SECTOR_COUNT (256)
@ -33,6 +32,7 @@ static void writeback_save_to_sd (void) {
break; break;
} }
if (sd_write_sectors(save_address, sector, 1)) { if (sd_write_sectors(save_address, sector, 1)) {
p.enabled = false;
break; break;
} }
save_address += SD_SECTOR_SIZE; save_address += SD_SECTOR_SIZE;
@ -66,11 +66,15 @@ void writeback_init (void) {
void writeback_process (void) { void writeback_process (void) {
if (p.enabled) { if (p.enabled) {
uint16_t save_count = fpga_reg_get(REG_SAVE_COUNT); if (fpga_reg_get(REG_SD_SCR) & SD_SCR_CARD_INSERTED) {
if (save_count != p.last_save_count) { uint16_t save_count = fpga_reg_get(REG_SAVE_COUNT);
p.pending = true; if (save_count != p.last_save_count) {
timer_set(TIMER_ID_WRITEBACK, WRITEBACK_DELAY_TICKS); p.pending = true;
p.last_save_count = save_count; timer_set(TIMER_ID_WRITEBACK, WRITEBACK_DELAY_TICKS);
p.last_save_count = save_count;
}
} else {
writeback_init();
} }
} }
if (p.pending) { if (p.pending) {