xref: /haiku/headers/private/kernel/timer.h (revision 2880b9ff657559b9ce1ab62881b6b4a024822157)
1 #ifndef _KERNEL_TIMER_H
2 #define _KERNEL_TIMER_H
3 
4 /**
5  * @file kernel/timer.h
6  * @brief Timer structures and definitions
7  */
8 
9 #include <stage2.h>
10 
11 /**
12  * @defgroup Timer Timer structures (not architecture specific)
13  * @ingroup OpenBeOS_Kernel
14  * @{
15  */
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
20 
21 typedef struct timer timer;
22 typedef struct qent	qent;
23 typedef	int32 (*timer_hook)(timer *);
24 
25 /**
26  * qent structure
27  */
28 /**
29  * The BeOS qent structure is probably part of a general double linked list
30  * interface used all over the kernel; a struct is required to have a qent
31  * entry struct as first element, so it can be linked to other elements
32  * easily. The key field is probably just an id, eventually used to order
33  * the list.
34  * Since we don't use this kind of interface, but we have to provide it
35  * to keep compatibility, we can use the qent struct for other purposes...
36  */
37 struct qent {
38 	int64		key;			/* We use this as the sched time */
39 	qent		*next;			/* This is used as a pointer to next timer */
40 	qent		*prev;			/* This can be used for callback args */
41 };
42 
43 /**
44  * Timer event data structure
45  */
46 struct timer {
47 	/** qent entry for this timer event */
48 	qent			entry;
49 	/** This just holds the timer operating mode (relative/absolute/periodic) */
50 	uint16			flags;
51 	/** Number of the CPU associated to this timer event */
52 	uint16			cpu;
53 	/** Hook function to be called on timer expiration */
54 	timer_hook		hook;
55 	/** Expiration time in microseconds */
56 	bigtime_t		period;
57 };
58 
59 /** @defgroup timermodes Timer operating modes
60  *  @ingroup Timer
61  *  @{
62  */
63 /** @def B_ONE_SHOT_ABSOLUTE_TIMER the timer will fire once at the system
64  *  time specified by period
65  */
66 /** @def B_ONE_SHOT_RELATIVE_TIMER the timer will fire once in approximately
67  *  period microseconds
68  */
69 /** @def B_PERIODIC_TIMER the timer will fire every period microseconds,
70  *  starting in period microseconds
71  */
72 #define		B_ONE_SHOT_ABSOLUTE_TIMER		1
73 #define		B_ONE_SHOT_RELATIVE_TIMER		2
74 #define		B_PERIODIC_TIMER				3
75 /** @} */
76 
77 status_t  add_timer(timer *event, timer_hook hook, bigtime_t period, int32 flags);
78 bool      cancel_timer(timer *event);
79 void      spin(bigtime_t microseconds);
80 
81 /** kernel functions */
82 int  timer_init(kernel_args *);
83 int  timer_interrupt(void);
84 
85 /** these two are only to be used by the scheduler */
86 int local_timer_cancel_event(timer *event);
87 int _local_timer_cancel_event(int curr_cpu, timer *event);
88 
89 /** @} */
90 
91 #endif /* _KERNEL_TIMER_H */
92 
93