summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)
816 static long last_seen_mtx_unlock = 0; 816 static long last_seen_mtx_unlock = 0;
817 817
818 while (1) { 818 while (1) {
819 while ( queue_empty( &ata_queue ) ) { 819 queue_wait_w_tmo(&ata_queue, &ev, HZ/2);
820 if (!spinup && !sleeping) 820
821 { 821 switch ( ev.id ) {
822 if (!ata_mtx.locked) 822 case SYS_TIMEOUT:
823 if (!spinup && !sleeping)
823 { 824 {
824 if (!last_seen_mtx_unlock) 825 if (!ata_mtx.locked)
825 last_seen_mtx_unlock = current_tick; 826 {
826 if (TIME_AFTER(current_tick, last_seen_mtx_unlock+(HZ*2))) 827 if (!last_seen_mtx_unlock)
828 last_seen_mtx_unlock = current_tick;
829 if (TIME_AFTER(current_tick, last_seen_mtx_unlock+(HZ*2)))
830 {
831 call_ata_idle_notifys(false);
832 last_seen_mtx_unlock = 0;
833 }
834 }
835 if ( sleep_timeout &&
836 TIME_AFTER( current_tick,
837 last_user_activity + sleep_timeout ) &&
838 TIME_AFTER( current_tick,
839 last_disk_activity + sleep_timeout ) )
827 { 840 {
828 call_ata_idle_notifys(false); 841 call_ata_idle_notifys(true);
829 last_seen_mtx_unlock = 0; 842 ata_perform_sleep();
843 last_sleep = current_tick;
830 } 844 }
831 } 845 }
832 if ( sleep_timeout && 846
833 TIME_AFTER( current_tick, 847#ifdef HAVE_ATA_POWER_OFF
834 last_user_activity + sleep_timeout ) && 848 if ( !spinup && sleeping && !poweroff &&
835 TIME_AFTER( current_tick, 849 TIME_AFTER( current_tick, last_sleep + ATA_POWER_OFF_TIMEOUT ))
836 last_disk_activity + sleep_timeout ) )
837 { 850 {
838 call_ata_idle_notifys(true); 851 mutex_lock(&ata_mtx);
839 ata_perform_sleep(); 852 ide_power_enable(false);
840 last_sleep = current_tick; 853 mutex_unlock(&ata_mtx);
854 poweroff = true;
841 } 855 }
842 }
843#ifdef HAVE_ATA_POWER_OFF
844 if ( !spinup && sleeping && !poweroff &&
845 TIME_AFTER( current_tick, last_sleep + ATA_POWER_OFF_TIMEOUT ))
846 {
847 mutex_lock(&ata_mtx);
848 ide_power_enable(false);
849 mutex_unlock(&ata_mtx);
850 poweroff = true;
851 }
852#endif 856#endif
857 break;
853 858
854 sleep(HZ/4);
855 }
856 queue_wait(&ata_queue, &ev);
857 switch ( ev.id ) {
858#ifndef USB_NONE 859#ifndef USB_NONE
859 case SYS_USB_CONNECTED: 860 case SYS_USB_CONNECTED:
860 if (poweroff) { 861 if (poweroff) {
@@ -1149,7 +1150,8 @@ int ata_init(void)
1149#endif 1150#endif
1150 1151
1151 if ( !initialized ) { 1152 if ( !initialized ) {
1152 /* First call won't have multiple thread contention */ 1153 /* First call won't have multiple thread contention - this
1154 * may return at any point without having to unlock */
1153 mutex_unlock(&ata_mtx); 1155 mutex_unlock(&ata_mtx);
1154 1156
1155 if (!ide_powered()) /* somebody has switched it off */ 1157 if (!ide_powered()) /* somebody has switched it off */
@@ -1211,10 +1213,12 @@ int ata_init(void)
1211 if (rc) 1213 if (rc)
1212 return -60 + rc; 1214 return -60 + rc;
1213 1215
1216 mutex_lock(&ata_mtx); /* Balance unlock below */
1217
1214 last_disk_activity = current_tick; 1218 last_disk_activity = current_tick;
1215 create_thread(ata_thread, ata_stack, 1219 create_thread(ata_thread, ata_stack,
1216 sizeof(ata_stack), 0, ata_thread_name 1220 sizeof(ata_stack), 0, ata_thread_name
1217 IF_PRIO(, PRIORITY_SYSTEM) 1221 IF_PRIO(, PRIORITY_USER_INTERFACE)
1218 IF_COP(, CPU)); 1222 IF_COP(, CPU));
1219 initialized = true; 1223 initialized = true;
1220 1224
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)
1190 1190
1191 queue_init(&sd_queue, true); 1191 queue_init(&sd_queue, true);
1192 create_thread(sd_thread, sd_stack, sizeof(sd_stack), 0, 1192 create_thread(sd_thread, sd_stack, sizeof(sd_stack), 0,
1193 sd_thread_name IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU)); 1193 sd_thread_name IF_PRIO(, PRIORITY_USER_INTERFACE)
1194 IF_COP(, CPU));
1194 1195
1195 /* enable interupt for the mSD card */ 1196 /* enable interupt for the mSD card */
1196 sleep(HZ/10); 1197 sleep(HZ/10);