Add a thread to power down the NAND after inactivity on the iPod Nano 2G

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23106 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sparmann 2009-10-11 12:45:27 +00:00
parent a79dc87761
commit 264d877889

View file

@ -37,6 +37,8 @@ long last_disk_activity = -1;
/** static, private data **/ /** static, private data **/
static bool initialized = false; static bool initialized = false;
static long nand_stack[20];
/* API Functions */ /* API Functions */
void nand_led(bool onoff) void nand_led(bool onoff)
@ -47,13 +49,17 @@ void nand_led(bool onoff)
int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int incount, int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
void* inbuf) void* inbuf)
{ {
return ftl_read(start, incount, inbuf); int rc = ftl_read(start, incount, inbuf);
last_disk_activity = current_tick;
return rc;
} }
int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count, int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
const void* outbuf) const void* outbuf)
{ {
return ftl_write(start, count, outbuf); int rc = ftl_write(start, count, outbuf);
last_disk_activity = current_tick;
return rc;
} }
void nand_spindown(int seconds) void nand_spindown(int seconds)
@ -73,6 +79,7 @@ void nand_sleepnow(void)
void nand_spin(void) void nand_spin(void)
{ {
last_disk_activity = current_tick;
nand_power_up(); nand_power_up();
} }
@ -88,20 +95,38 @@ void nand_get_info(IF_MD2(int drive,) struct storage_info *info)
long nand_last_disk_activity(void) long nand_last_disk_activity(void)
{ {
return 0; return last_disk_activity;
} }
#ifdef HAVE_STORAGE_FLUSH #ifdef HAVE_STORAGE_FLUSH
int nand_flush(void) int nand_flush(void)
{ {
last_disk_activity = current_tick;
return ftl_sync(); return ftl_sync();
} }
#endif #endif
static void nand_thread(void)
{
while (1)
{
if (TIME_AFTER(current_tick, last_disk_activity + HZ / 5))
nand_power_down();
sleep(HZ / 10);
}
}
int nand_init(void) int nand_init(void)
{ {
if (ftl_init()) return 1; if (ftl_init()) return 1;
last_disk_activity = current_tick;
create_thread(nand_thread, nand_stack,
sizeof(nand_stack), 0, "nand"
IF_PRIO(, PRIORITY_USER_INTERFACE)
IF_COP(, CPU));
initialized = true; initialized = true;
return 0; return 0;
} }