diff --git a/apps/settings.c b/apps/settings.c index 85bd41a55f..f8b6870863 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -158,7 +158,7 @@ static int save_config_buffer( void ) #else if(battery_level_safe() && (fat_startsector()!=0)) - return !ata_write_sectors( 61, 1, rtc_config_block); + ata_delayed_write( 61, rtc_config_block); else return -1; diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index ebe9602f01..0795eaf1f8 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -89,6 +89,9 @@ static char ata_stack[DEFAULT_STACK_SIZE]; static char ata_thread_name[] = "ata"; static struct event_queue ata_queue; static bool initialized = false; +static bool delayed_write = false; +static unsigned char delayed_sector[SECTOR_SIZE]; +static int delayed_sector_num; #ifdef USE_POWEROFF static int ata_power_on(void); @@ -215,6 +218,10 @@ int ata_read_sectors(unsigned long start, ret = -1; mutex_unlock(&ata_mtx); + + if ( delayed_write ) + ata_flush(); + return ret; } @@ -279,9 +286,30 @@ int ata_write_sectors(unsigned long start, i = wait_for_end_of_transfer(); mutex_unlock(&ata_mtx); + + if ( delayed_write ) + ata_flush(); + return i; } +extern void ata_delayed_write(unsigned long sector, void* buf) +{ + memcpy(delayed_sector, buf, SECTOR_SIZE); + delayed_sector_num = sector; + delayed_write = true; +} + +extern void ata_flush(void) +{ + if ( delayed_write ) { + delayed_write = false; + ata_write_sectors(delayed_sector_num, 1, delayed_sector); + } +} + + + static int check_registers(void) { if ( ATA_STATUS & STATUS_BSY ) diff --git a/firmware/drivers/ata.h b/firmware/drivers/ata.h index 4209fdcd1e..244ec63777 100644 --- a/firmware/drivers/ata.h +++ b/firmware/drivers/ata.h @@ -39,11 +39,9 @@ extern bool ata_disk_is_active(void); extern int ata_hard_reset(void); extern int ata_soft_reset(void); extern int ata_init(void); -extern int ata_read_sectors(unsigned long start, - int count, - void* buf); -extern int ata_write_sectors(unsigned long start, - int count, - void* buf); +extern int ata_read_sectors(unsigned long start, int count, void* buf); +extern int ata_write_sectors(unsigned long start, int count, void* buf); +extern void ata_delayed_write(unsigned long sector, void* buf); +extern void ata_flush(void); #endif diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c index aacd277cb2..22623dcb5e 100644 --- a/uisimulator/common/stubs.c +++ b/uisimulator/common/stubs.c @@ -75,3 +75,8 @@ int ata_read_sectors(unsigned long start, } return 1; } + +void ata_delayed_write(unsigned long sector, void* buf) +{ + ata_write_sectors(sector,1,buf); +}