summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-02-11 07:42:11 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-02-11 07:42:11 +0000
commit9811fc9abf6c3b2bb9500a99c14a64ee29641b09 (patch)
treeabb1962b88f85ea13688a3d68169300fba93075a /firmware
parent523f88e192e60184a08e7dfa3de8d398a697148d (diff)
Some misc. ATA stuff: Increase threads' priority (important for idle callbacks to get done faster). Use a simpler loop for ata thread. Add a balancing mutex_lock call to ata_init (oops).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16278 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/ata.c70
-rw-r--r--firmware/target/arm/sandisk/ata-c200_e200.c3
2 files changed, 39 insertions, 34 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index cacf4583ae..ee322be667 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -816,45 +816,46 @@ static void ata_thread(void)
static long last_seen_mtx_unlock = 0;
while (1) {
- while ( queue_empty( &ata_queue ) ) {
- if (!spinup && !sleeping)
- {
- if (!ata_mtx.locked)
+ queue_wait_w_tmo(&ata_queue, &ev, HZ/2);
+
+ switch ( ev.id ) {
+ case SYS_TIMEOUT:
+ if (!spinup && !sleeping)
{
- if (!last_seen_mtx_unlock)
- last_seen_mtx_unlock = current_tick;
- if (TIME_AFTER(current_tick, last_seen_mtx_unlock+(HZ*2)))
+ 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 ) )
{
- call_ata_idle_notifys(false);
- last_seen_mtx_unlock = 0;
+ call_ata_idle_notifys(true);
+ ata_perform_sleep();
+ last_sleep = current_tick;
}
}
- if ( sleep_timeout &&
- TIME_AFTER( current_tick,
- last_user_activity + sleep_timeout ) &&
- TIME_AFTER( current_tick,
- last_disk_activity + sleep_timeout ) )
+
+#ifdef HAVE_ATA_POWER_OFF
+ if ( !spinup && sleeping && !poweroff &&
+ TIME_AFTER( current_tick, last_sleep + ATA_POWER_OFF_TIMEOUT ))
{
- call_ata_idle_notifys(true);
- ata_perform_sleep();
- last_sleep = current_tick;
+ mutex_lock(&ata_mtx);
+ ide_power_enable(false);
+ mutex_unlock(&ata_mtx);
+ poweroff = true;
}
- }
-#ifdef HAVE_ATA_POWER_OFF
- if ( !spinup && sleeping && !poweroff &&
- TIME_AFTER( current_tick, last_sleep + ATA_POWER_OFF_TIMEOUT ))
- {
- mutex_lock(&ata_mtx);
- ide_power_enable(false);
- mutex_unlock(&ata_mtx);
- poweroff = true;
- }
#endif
+ break;
- sleep(HZ/4);
- }
- queue_wait(&ata_queue, &ev);
- switch ( ev.id ) {
#ifndef USB_NONE
case SYS_USB_CONNECTED:
if (poweroff) {
@@ -1149,7 +1150,8 @@ int ata_init(void)
#endif
if ( !initialized ) {
- /* First call won't have multiple thread contention */
+ /* First call won't have multiple thread contention - this
+ * may return at any point without having to unlock */
mutex_unlock(&ata_mtx);
if (!ide_powered()) /* somebody has switched it off */
@@ -1211,10 +1213,12 @@ int ata_init(void)
if (rc)
return -60 + rc;
+ mutex_lock(&ata_mtx); /* Balance unlock below */
+
last_disk_activity = current_tick;
create_thread(ata_thread, ata_stack,
sizeof(ata_stack), 0, ata_thread_name
- IF_PRIO(, PRIORITY_SYSTEM)
+ IF_PRIO(, PRIORITY_USER_INTERFACE)
IF_COP(, CPU));
initialized = true;
diff --git a/firmware/target/arm/sandisk/ata-c200_e200.c b/firmware/target/arm/sandisk/ata-c200_e200.c
index f32c000543..8714b1e055 100644
--- a/firmware/target/arm/sandisk/ata-c200_e200.c
+++ b/firmware/target/arm/sandisk/ata-c200_e200.c
@@ -1190,7 +1190,8 @@ int ata_init(void)
queue_init(&sd_queue, true);
create_thread(sd_thread, sd_stack, sizeof(sd_stack), 0,
- sd_thread_name IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU));
+ sd_thread_name IF_PRIO(, PRIORITY_USER_INTERFACE)
+ IF_COP(, CPU));
/* enable interupt for the mSD card */
sleep(HZ/10);