1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
22 #include "ata_idle_notify.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;
32 bool register_ata_idle_func(ata_idle_notify function
)
34 #if USING_ATA_CALLBACK
36 if (ata_callback_count
>= MAX_ATA_CALLBACKS
)
38 for (i
=0; i
<MAX_ATA_CALLBACKS
; i
++)
40 if (ata_idle_notify_funcs
[i
] == NULL
)
42 ata_idle_notify_funcs
[i
] = function
;
46 else if (ata_idle_notify_funcs
[i
] == function
)
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 */
59 #if USING_ATA_CALLBACK
60 void unregister_ata_idle_func(ata_idle_notify func
, bool run
)
63 for (i
=0; i
<MAX_ATA_CALLBACKS
; i
++)
65 if (ata_idle_notify_funcs
[i
] == func
)
67 ata_idle_notify_funcs
[i
] = NULL
;
75 bool call_ata_idle_notifys(bool force
)
78 static int lock_until
= 0;
79 ata_idle_notify function
;
82 if (TIME_BEFORE(current_tick
,lock_until
) )
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
;
100 void ata_idle_notify_init(void)
102 ata_callback_count
= 0;
103 memset(ata_idle_notify_funcs
, 0, sizeof(ata_idle_notify_funcs
));