fuzev2: prevent button light flickering when accessing µSD
[kugel-rb.git] / firmware / ata_idle_notify.c
blob35d192bee0d90b17e151f62b045fc8f81ca87b39
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include <stdbool.h>
22 #include "system.h"
23 #include "ata.h"
24 #include "ata_idle_notify.h"
25 #include "kernel.h"
26 #include "string.h"
28 void register_storage_idle_func(void (*function)(void *data))
30 #if USING_STORAGE_CALLBACK
31 add_event(DISK_EVENT_SPINUP, true, function);
32 #else
33 function(NULL); /* just call the function now */
34 /* this _may_ cause problems later if the calling function
35 sets a variable expecting the callback to unset it, because
36 the callback will be run before this function exits, so before the var is set */
37 #endif
40 #if USING_STORAGE_CALLBACK
41 void unregister_storage_idle_func(void (*func)(void *data), bool run)
43 remove_event(DISK_EVENT_SPINUP, func);
45 if (run)
46 func(NULL);
49 bool call_storage_idle_notifys(bool force)
51 static int lock_until = 0;
53 if (!force)
55 if (TIME_BEFORE(current_tick,lock_until) )
56 return false;
58 lock_until = current_tick + 30*HZ;
60 send_event(DISK_EVENT_SPINUP, NULL);
62 return true;
64 #endif