misc: Point to correct simavr include dirs
[simavr] / simavr / sim / sim_cycle_timers.h
1 /*
2         sim_cycle_timers.h
3
4         Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
5
6         This file is part of simavr.
7
8         simavr is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         simavr is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 /*
23  * cycle timers are callbacks that will be called when "when" cycle is reached
24  * these timers are one shots, then get cleared if the timer function returns zero,
25  * they get reset if the callback function returns a new cycle number
26  *
27  * the implementation maintains a list of 'pending' timers, sorted by when they
28  * should run, it allows very quick comparison with the next timer to run, and
29  * quick removal of then from the pile once dispatched.
30  */
31 #ifndef __SIM_CYCLE_TIMERS_H___
32 #define __SIM_CYCLE_TIMERS_H___
33
34 #include "sim_avr_types.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 #define MAX_CYCLE_TIMERS        32
41
42 typedef avr_cycle_count_t (*avr_cycle_timer_t)(
43                 struct avr_t * avr,
44                 avr_cycle_count_t when,
45                 void * param);
46
47 typedef struct avr_cycle_timer_slot_t {
48         avr_cycle_count_t       when;
49         avr_cycle_timer_t       timer;
50         void * param;
51 } avr_cycle_timer_slot_t;
52
53 typedef struct avr_cycle_timer_pool_t {
54         avr_cycle_timer_slot_t timer[MAX_CYCLE_TIMERS];
55         uint8_t count;
56 } avr_cycle_timer_pool_t, *avr_cycle_timer_pool_p;
57
58
59 // register for calling 'timer' in 'when' cycles
60 void
61 avr_cycle_timer_register(
62                 struct avr_t * avr,
63                 avr_cycle_count_t when,
64                 avr_cycle_timer_t timer,
65                 void * param);
66 // register a timer to call in 'when' usec
67 void
68 avr_cycle_timer_register_usec(
69                 struct avr_t * avr,
70                 uint32_t when,
71                 avr_cycle_timer_t timer,
72                 void * param);
73 // cancel a previously set timer
74 void
75 avr_cycle_timer_cancel(
76                 struct avr_t * avr,
77                 avr_cycle_timer_t timer,
78                 void * param);
79 /*
80  * Check to see if a timer is present, if so, return the number (+1) of
81  * cycles left for it to fire, and if not present, return zero
82  */
83 avr_cycle_count_t
84 avr_cycle_timer_status(
85                 struct avr_t * avr,
86                 avr_cycle_timer_t timer,
87                 void * param);
88
89 //
90 // Private, called from the core
91 //
92 avr_cycle_count_t
93 avr_cycle_timer_process(
94                 struct avr_t * avr);
95 void
96 avr_cycle_timer_reset(
97                 struct avr_t * avr);
98
99 #ifdef __cplusplus
100 };
101 #endif
102
103 #endif /* __SIM_CYCLE_TIMERS_H___ */