The first version that was demonstrated to get an IPv6 address
[firmerware] / include / 0cpm / timer.h
1 /* Timer drivers
2  *
3  * This file is part of 0cpm Firmerware.
4  *
5  * 0cpm Firmerware is Copyright (c)2011 Rick van Rein, OpenFortress.
6  *
7  * 0cpm Firmerware is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation, version 3.
10  *
11  * 0cpm Firmerware is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with 0cpm Firmerware.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #ifndef HEADER_TIMER
22 #define HEADER_TIMER
23
24 #include <0cpm/irq.h>
25
26
27 /* The bottom defines a few useful things:
28  *   typedef uint..._t timing_t;
29  *   #define TIME_MSEC(x) ...
30  *   #define TIME_SEC(x) ...
31  *   #define TIME_BEOFRE(x,y) ...
32  *   #define TIME_BEFOREQ(x,y) ...
33  * The former can be used as a parameter without pointers;
34  * the TIME_xxx define such periods in terms of that time.
35  */
36
37
38 /* Timer drivers are split in a top half and a bottom half.  The top half is generic, the
39  * bottom half is device-specific.  The bottom half routines start with bottom_irqtimer_
40  * while the top half functions start with irqtimer_
41  *
42  * The bottom system is only aware of the time of the next hardware-raised interrupt.
43  * The top system maintains a timeout-ordered queue of interrupts to raise.
44  */
45
46 typedef struct irqtimer_type irqtimer_t;
47 struct irqtimer_type {
48         irq_t tmr_irq;
49         irqtimer_t *tmr_next;
50         timing_t tmr_expiry;
51 };
52
53
54 /* Managing functions for kernel-defined timers */
55 void irqtimer_start   (irqtimer_t *tmr, timing_t delay, irq_handler_t hdl, priority_t prio);
56 void irqtimer_restart (irqtimer_t *tmr, timing_t intval);
57 void irqtimer_stop    (irqtimer_t *tmr);
58
59
60 /* Top-half operations to manipulate timers; return the desired
61  * new timer setting to follow up after the expiration has
62  * taken place */
63 timing_t top_timer_expiration (timing_t exptime);
64
65
66 /* Bottom-half operations to manipulate the next timer interrupt */
67 timing_t bottom_time (void);
68 timing_t bottom_timer_set (timing_t nextirq);
69
70
71 #endif