From f184152c0501a80e95ad871927d766fdee50281b Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Wed, 8 Nov 2006 01:55:26 +0000 Subject: * changes to ata.c - idle callbacks are called after 2 sec of real idle, and shutdown and usb (it makes sense here). ata_sleep doesnt get broken by callbacks. * allow ata_sleep() at the end of buffering again * config block uses ata_idle instead of delayed sector when saving * remove delayed sector code from ata_mmc.c (idle callbacks are not yet implemented for ata_mmc.c tho) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11461 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/ata.c | 65 ++++++++++++++-------------------------------- firmware/drivers/ata_mmc.c | 31 ---------------------- 2 files changed, 20 insertions(+), 76 deletions(-) (limited to 'firmware/drivers') diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index 0a03fd2a25..9e20bfb87d 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -239,9 +239,6 @@ static long ata_stack[DEFAULT_STACK_SIZE/sizeof(long)]; static const 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; static long last_user_activity = -1; long last_disk_activity = -1; @@ -804,10 +801,6 @@ int ata_read_sectors(IF_MV2(int drive,) mutex_unlock(&ata_mtx); - /* only flush if reading went ok */ - if ( (ret == 0) && delayed_write ) - ata_flush(); - return ret; } @@ -1229,34 +1222,9 @@ int ata_write_sectors(IF_MV2(int drive,) mutex_unlock(&ata_mtx); - /* only flush if writing went ok */ - if ( (ret == 0) && delayed_write ) - ata_flush(); - return ret; } -/* schedule a single sector write, executed with the the next spinup - (volume 0 only, used for config sector) */ -extern void ata_delayed_write(unsigned long sector, const void* buf) -{ - memcpy(delayed_sector, buf, SECTOR_SIZE); - delayed_sector_num = sector; - delayed_write = true; -} - -/* write the delayed sector to volume 0 */ -extern void ata_flush(void) -{ - if ( delayed_write ) { - DEBUGF("ata_flush()\n"); - delayed_write = false; - ata_write_sectors(IF_MV2(0,) delayed_sector_num, 1, delayed_sector); - } -} - - - static int check_registers(void) { #if (CONFIG_CPU == PP5002) @@ -1364,28 +1332,31 @@ static void ata_thread(void) { static long last_sleep = 0; struct event ev; - static long last_callback_run = 0; + static long last_seen_mtx_unlock = 0; while (1) { while ( queue_empty( &ata_queue ) ) { if (!spinup && !sleeping) { + if (!ata_mtx.locked) + { + if (!last_seen_mtx_unlock) + last_seen_mtx_unlock = current_tick; + if (TIME_AFTER(current_tick, last_seen_mtx_unlock+(HZ*2))) + { + call_ata_idle_notifys(false); + last_seen_mtx_unlock = 0; + } + } if ( sleep_timeout && TIME_AFTER( current_tick, last_user_activity + sleep_timeout ) && TIME_AFTER( current_tick, last_disk_activity + sleep_timeout ) ) { - if (!call_ata_idle_notifys()) - { - ata_perform_sleep(); - last_sleep = current_tick; - } - } - else if (TIME_AFTER(current_tick, last_callback_run+(HZ*5))) - { - last_callback_run = current_tick; - call_ata_idle_notifys(); + call_ata_idle_notifys(false); + ata_perform_sleep(); + last_sleep = current_tick; } } #ifdef HAVE_ATA_POWER_OFF @@ -1403,8 +1374,10 @@ static void ata_thread(void) } queue_wait(&ata_queue, &ev); switch ( ev.id ) { -#ifndef USB_NONE + case SYS_POWEROFF: case SYS_USB_CONNECTED: + call_ata_idle_notifys(false); +#ifndef USB_NONE if (poweroff) { mutex_lock(&ata_mtx); ata_led(true); @@ -1419,11 +1392,13 @@ static void ata_thread(void) /* Wait until the USB cable is extracted again */ usb_wait_for_disconnect(&ata_queue); - break; #endif + break; case Q_SLEEP: + call_ata_idle_notifys(true); last_disk_activity = current_tick - sleep_timeout + (HZ/2); break; + } } } diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c index 6303ca2851..64a7ba4bfd 100644 --- a/firmware/drivers/ata_mmc.c +++ b/firmware/drivers/ata_mmc.c @@ -98,9 +98,6 @@ static bool mmc_monitor_enabled = true; #endif static bool initialized = false; static bool new_mmc_circuit; -static bool delayed_write = false; -static unsigned char delayed_sector[SECTOR_SIZE]; -static int delayed_sector_num; static enum { MMC_UNKNOWN, @@ -805,10 +802,6 @@ int ata_read_sectors(IF_MV2(int drive,) deselect_card(); - /* only flush if reading went ok */ - if ( (rc == 0) && delayed_write ) - ata_flush(); - return rc; } @@ -960,33 +953,9 @@ int ata_write_sectors(IF_MV2(int drive,) deselect_card(); - /* only flush if writing went ok */ - if ( (rc == 0) && delayed_write ) - ata_flush(); - return rc; } -/* While there is no spinup, the delayed write is still here to avoid - wearing the flash unnecessarily */ -extern void ata_delayed_write(unsigned long sector, const void* buf) -{ - memcpy(delayed_sector, buf, SECTOR_SIZE); - delayed_sector_num = sector; - delayed_write = true; -} - -/* write the delayed sector to volume 0 */ -extern void ata_flush(void) -{ - if ( delayed_write ) - { - DEBUGF("ata_flush()\n"); - delayed_write = false; - ata_write_sectors(IF_MV2(0,) delayed_sector_num, 1, delayed_sector); - } -} - void ata_spindown(int seconds) { (void)seconds; -- cgit v1.2.3