4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
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.
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.
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/>.
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
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.
31 #ifndef __SIM_CYCLE_TIMERS_H___
32 #define __SIM_CYCLE_TIMERS_H___
34 #include "sim_avr_types.h"
40 #define MAX_CYCLE_TIMERS 32
42 typedef avr_cycle_count_t (*avr_cycle_timer_t)(
44 avr_cycle_count_t when,
47 typedef struct avr_cycle_timer_slot_t {
48 avr_cycle_count_t when;
49 avr_cycle_timer_t timer;
51 } avr_cycle_timer_slot_t;
53 typedef struct avr_cycle_timer_pool_t {
54 avr_cycle_timer_slot_t timer[MAX_CYCLE_TIMERS];
56 } avr_cycle_timer_pool_t, *avr_cycle_timer_pool_p;
59 // register for calling 'timer' in 'when' cycles
61 avr_cycle_timer_register(
63 avr_cycle_count_t when,
64 avr_cycle_timer_t timer,
66 // register a timer to call in 'when' usec
68 avr_cycle_timer_register_usec(
71 avr_cycle_timer_t timer,
73 // cancel a previously set timer
75 avr_cycle_timer_cancel(
77 avr_cycle_timer_t timer,
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
84 avr_cycle_timer_status(
86 avr_cycle_timer_t timer,
90 // Private, called from the core
93 avr_cycle_timer_process(
96 avr_cycle_timer_reset(
103 #endif /* __SIM_CYCLE_TIMERS_H___ */