Battery blinks if >BATTERY_LEVEL_DANGEROUS
[kugel-rb.git] / firmware / kernel.h
blobef287e5689d525c5d0dccb693d9bfff5ced37316
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Björn Stenberg
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 #ifndef _KERNEL_H_
20 #define _KERNEL_H_
22 #include <stdbool.h>
24 /* wrap-safe macros for tick comparison */
25 #define TIME_AFTER(a,b) ((long)(b) - (long)(a) < 0)
26 #define TIME_BEFORE(a,b) TIME_AFTER(b,a)
28 #define HZ 100 /* number of ticks per second */
30 #define MAX_NUM_TICK_TASKS 4
32 #define QUEUE_LENGTH 16 /* MUST be a power of 2 */
33 #define QUEUE_LENGTH_MASK (QUEUE_LENGTH - 1)
35 /* System defined message ID's */
36 #define SYS_USB_CONNECTED -1
37 #define SYS_USB_CONNECTED_ACK -2
38 #define SYS_USB_DISCONNECTED -3
39 #define SYS_USB_DISCONNECTED_ACK -4
41 struct event
43 int id;
44 void *data;
47 struct event_queue
49 struct event events[QUEUE_LENGTH];
50 unsigned int read;
51 unsigned int write;
54 struct mutex
56 bool locked;
59 /* global tick variable */
60 extern long current_tick;
62 /* kernel functions */
63 extern void kernel_init(void);
64 extern void yield(void);
65 extern void sleep(int ticks);
66 int set_irq_level(int level);
67 int tick_add_task(void (*f)(void));
68 int tick_remove_task(void (*f)(void));
70 extern void queue_init(struct event_queue *q);
71 extern void queue_wait(struct event_queue *q, struct event *ev);
72 extern void queue_post(struct event_queue *q, int id, void *data);
73 extern bool queue_empty(struct event_queue* q);
74 extern int queue_broadcast(int id, void *data);
76 extern void mutex_init(struct mutex *m);
77 extern void mutex_lock(struct mutex *m);
78 extern void mutex_unlock(struct mutex *m);
80 #endif