From 968403610e6f99cbbc5ec5d945056215bd1604d7 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Fri, 14 Jan 2011 10:18:40 +0000 Subject: [PATCH] cycle timers: Added avr_cycle_timer_status() Allows verification wether a timer is running, and until when it is. Signed-off-by: Michel Pollet --- simavr/sim/sim_cycle_timers.c | 20 ++++++++++++++++++++ simavr/sim/sim_cycle_timers.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/simavr/sim/sim_cycle_timers.c b/simavr/sim/sim_cycle_timers.c index f2161d9..fed6b6c 100644 --- a/simavr/sim/sim_cycle_timers.c +++ b/simavr/sim/sim_cycle_timers.c @@ -63,6 +63,26 @@ void avr_cycle_timer_cancel(avr_t * avr, avr_cycle_timer_t timer, void * param) } } +/* + * Check to see if a timer is present, if so, return the number (+1) of + * cycles left for it to fire, and if not present, return zero + */ +avr_cycle_count_t +avr_cycle_timer_status(avr_t * avr, avr_cycle_timer_t timer, void * param) +{ + if (!avr->cycle_timer_map) + return 0; + + for (int i = 0; i < 32; i++) + if ((avr->cycle_timer_map & (1 << i)) && + avr->cycle_timer[i].timer == timer && + avr->cycle_timer[i].param == param) { + return 1 + (avr->cycle_timer[i].when - avr->cycle); + } + + return 0; +} + /* * run thru all the timers, call the ones that needs it, * clear the ones that wants it, and calculate the next diff --git a/simavr/sim/sim_cycle_timers.h b/simavr/sim/sim_cycle_timers.h index 49a9851..a7c9d41 100644 --- a/simavr/sim/sim_cycle_timers.h +++ b/simavr/sim/sim_cycle_timers.h @@ -53,6 +53,12 @@ void avr_cycle_timer_register(avr_t * avr, avr_cycle_count_t when, avr_cycle_tim void avr_cycle_timer_register_usec(avr_t * avr, uint32_t when, avr_cycle_timer_t timer, void * param); // cancel a previously set timer void avr_cycle_timer_cancel(avr_t * avr, avr_cycle_timer_t timer, void * param); +/* + * Check to see if a timer is present, if so, return the number (+1) of + * cycles left for it to fire, and if not present, return zero + */ +avr_cycle_count_t +avr_cycle_timer_status(avr_t * avr, avr_cycle_timer_t timer, void * param); // -- 2.39.5