summaryrefslogtreecommitdiff
path: root/firmware/kernel/tick.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/kernel/tick.c')
-rw-r--r--firmware/kernel/tick.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/firmware/kernel/tick.c b/firmware/kernel/tick.c
new file mode 100644
index 0000000000..c524560687
--- /dev/null
+++ b/firmware/kernel/tick.c
@@ -0,0 +1,74 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "tick.h"
24#include "general.h"
25#include "panic.h"
26
27/****************************************************************************
28 * Timer tick
29 *****************************************************************************/
30
31
32/* List of tick tasks - final element always NULL for termination */
33void (*tick_funcs[MAX_NUM_TICK_TASKS+1])(void);
34
35#if !defined(CPU_PP) || !defined(BOOTLOADER) || \
36 defined(HAVE_BOOTLOADER_USB_MODE)
37volatile long current_tick SHAREDDATA_ATTR = 0;
38#endif
39
40/* - Timer initialization and interrupt handler is defined at
41 * the target level: tick_start() is implemented in the target tree */
42
43int tick_add_task(void (*f)(void))
44{
45 int oldlevel = disable_irq_save();
46 void **arr = (void **)tick_funcs;
47 void **p = find_array_ptr(arr, f);
48
49 /* Add a task if there is room */
50 if(p - arr < MAX_NUM_TICK_TASKS)
51 {
52 *p = f; /* If already in list, no problem. */
53 }
54 else
55 {
56 panicf("Error! tick_add_task(): out of tasks");
57 }
58
59 restore_irq(oldlevel);
60 return 0;
61}
62
63int tick_remove_task(void (*f)(void))
64{
65 int oldlevel = disable_irq_save();
66 int rc = remove_array_ptr((void **)tick_funcs, f);
67 restore_irq(oldlevel);
68 return rc;
69}
70
71void init_tick(void)
72{
73 tick_start(1000/HZ);
74}