Move a few #defines to target specific config files
[kugel-rb.git] / firmware / ata_idle_notify.c
blob1fc6605ac6b66629ad9a5cf4241f3f9cf58d3c68
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Jonathan Gordon
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include <stdbool.h>
20 #include "system.h"
21 #include "ata.h"
22 #include "ata_idle_notify.h"
23 #include "kernel.h"
24 #include "string.h"
26 #if USING_ATA_CALLBACK
27 static ata_idle_notify ata_idle_notify_funcs[MAX_ATA_CALLBACKS];
28 static int ata_callback_count = 0;
29 #endif
32 bool register_ata_idle_func(ata_idle_notify function)
34 #if USING_ATA_CALLBACK
35 int i;
36 if (ata_callback_count >= MAX_ATA_CALLBACKS)
37 return false;
38 for (i=0; i<MAX_ATA_CALLBACKS; i++)
40 if (ata_idle_notify_funcs[i] == NULL)
42 ata_idle_notify_funcs[i] = function;
43 ata_callback_count++;
44 return true;
46 else if (ata_idle_notify_funcs[i] == function)
47 return true;
49 return false;
50 #else
51 function(); /* just call the function now */
52 /* this _may_ cause problems later if the calling function
53 sets a variable expecting the callback to unset it, because
54 the callback will be run before this function exits, so before the var is set */
55 return true;
56 #endif
59 #if USING_ATA_CALLBACK
60 void unregister_ata_idle_func(ata_idle_notify func, bool run)
62 int i;
63 for (i=0; i<MAX_ATA_CALLBACKS; i++)
65 if (ata_idle_notify_funcs[i] == func)
67 ata_idle_notify_funcs[i] = NULL;
68 ata_callback_count--;
69 if (run) func();
72 return;
75 bool call_ata_idle_notifys(bool force)
77 int i;
78 static int lock_until = 0;
79 ata_idle_notify function;
80 if (!force)
82 if (TIME_BEFORE(current_tick,lock_until) )
83 return false;
85 lock_until = current_tick + 30*HZ;
87 for (i = 0; i < MAX_ATA_CALLBACKS; i++)
89 if (ata_idle_notify_funcs[i])
91 function = ata_idle_notify_funcs[i];
92 ata_idle_notify_funcs[i] = NULL;
93 function();
94 ata_callback_count--;
97 return true;
100 void ata_idle_notify_init(void)
102 ata_callback_count = 0;
103 memset(ata_idle_notify_funcs, 0, sizeof(ata_idle_notify_funcs));
105 #endif