summaryrefslogtreecommitdiff
path: root/firmware/ata_idle_notify.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/ata_idle_notify.c')
-rw-r--r--firmware/ata_idle_notify.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/firmware/ata_idle_notify.c b/firmware/ata_idle_notify.c
index c51c3800ce..17adbc1192 100644
--- a/firmware/ata_idle_notify.c
+++ b/firmware/ata_idle_notify.c
@@ -20,7 +20,7 @@
20#include "system.h" 20#include "system.h"
21#include "ata.h" 21#include "ata.h"
22#include "ata_idle_notify.h" 22#include "ata_idle_notify.h"
23#include "logf.h" 23#include "kernel.h"
24#include "string.h" 24#include "string.h"
25 25
26#if USING_ATA_CALLBACK 26#if USING_ATA_CALLBACK
@@ -28,10 +28,13 @@ static ata_idle_notify ata_idle_notify_funcs[MAX_ATA_CALLBACKS];
28static int ata_callback_count = 0; 28static int ata_callback_count = 0;
29#endif 29#endif
30 30
31
31bool register_ata_idle_func(ata_idle_notify function) 32bool register_ata_idle_func(ata_idle_notify function)
32{ 33{
33#if USING_ATA_CALLBACK 34#if USING_ATA_CALLBACK
34 int i; 35 int i;
36 if (ata_callback_count >= MAX_ATA_CALLBACKS)
37 return false;
35 for (i=0; i<MAX_ATA_CALLBACKS; i++) 38 for (i=0; i<MAX_ATA_CALLBACKS; i++)
36 { 39 {
37 if (ata_idle_notify_funcs[i] == NULL) 40 if (ata_idle_notify_funcs[i] == NULL)
@@ -69,13 +72,15 @@ void unregister_ata_idle_func(ata_idle_notify func, bool run)
69 return; 72 return;
70} 73}
71 74
72bool call_ata_idle_notifys(bool sleep_after) 75bool call_ata_idle_notifys(bool force)
73{ 76{
74 int i; 77 int i;
78 static int lock_until = 0;
75 ata_idle_notify function; 79 ata_idle_notify function;
76 if (ata_callback_count == 0) 80 if (!force && TIME_BEFORE(current_tick,lock_until) )
77 return false; 81 return false;
78 ata_callback_count = 0; /* so we dont re-enter every time the callbacks read/write */ 82 lock_until = current_tick + 30*HZ;
83
79 for (i = 0; i < MAX_ATA_CALLBACKS; i++) 84 for (i = 0; i < MAX_ATA_CALLBACKS; i++)
80 { 85 {
81 if (ata_idle_notify_funcs[i]) 86 if (ata_idle_notify_funcs[i])
@@ -83,10 +88,9 @@ bool call_ata_idle_notifys(bool sleep_after)
83 function = ata_idle_notify_funcs[i]; 88 function = ata_idle_notify_funcs[i];
84 ata_idle_notify_funcs[i] = NULL; 89 ata_idle_notify_funcs[i] = NULL;
85 function(); 90 function();
91 ata_callback_count--;
86 } 92 }
87 } 93 }
88 if (sleep_after)
89 ata_sleep();
90 return true; 94 return true;
91} 95}
92 96