From 91a0fa0e186fa382fb0631d9b0378fee0f5b1206 Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Thu, 1 May 2008 07:09:53 +0200 Subject: * digital/io/src - add a command to get the stats of main timer. --- digital/io/src/main.c | 18 +++++++++++++++++- digital/io/src/main_timer.avr.h | 6 +++++- digital/io/src/simu.host.c | 3 ++- digital/io/src/simu.host.h | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) (limited to 'digital/io/src') diff --git a/digital/io/src/main.c b/digital/io/src/main.c index 7d323ea6..7a372e80 100644 --- a/digital/io/src/main.c +++ b/digital/io/src/main.c @@ -98,6 +98,11 @@ uint8_t main_stats_sharps_interpreted_, main_stats_sharps_interpreted_cpt_; */ static uint8_t main_stats_asserv_, main_stats_asserv_cpt_; +/** + * Main timer stats. + */ +static uint8_t main_stats_timer_; + /** * Update frequency of sharps. */ @@ -158,7 +163,11 @@ main_loop (void) while (1) { /* Wait for an overflow of the main timer (4.444ms) */ - main_timer_wait (); + { + uint8_t timer_count = main_timer_wait (); + if (main_stats_timer_) + proto_send1b('M', timer_count); + } /* Get the data from the UART */ while (uart0_poll ()) @@ -417,6 +426,13 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) main_stats_sharps_cpt = main_stats_sharps = args[0]; break; + case c ('M', 1): + /* Main stats timer. + * - 1b: 1 to enable, 0 to disable. + */ + main_stats_timer_ = args[0]; + break; + case c ('I', 1): /* Print interpreted stats for sharps. * - 1b: frequency of sharp stats. diff --git a/digital/io/src/main_timer.avr.h b/digital/io/src/main_timer.avr.h index 528c8e4d..39cf70b5 100644 --- a/digital/io/src/main_timer.avr.h +++ b/digital/io/src/main_timer.avr.h @@ -49,14 +49,18 @@ main_timer_init (void) /** * Wait until the main timer overflows. */ -static inline void +static inline uint8_t main_timer_wait (void) { + uint8_t count_before_ov = 0; /* Loop until an overflow of the timer occurs */ while (!(TIFR & _BV (TOV0))) + count_before_ov++; ; /* Write 1 to clear */ TIFR = _BV (TOV0); + + return count_before_ov; } #endif /* main_timer_avr_h */ diff --git a/digital/io/src/simu.host.c b/digital/io/src/simu.host.c index 09e4610e..1eb18a39 100644 --- a/digital/io/src/simu.host.c +++ b/digital/io/src/simu.host.c @@ -174,11 +174,12 @@ main_timer_init (void) simu_init (); } -void +uint8_t main_timer_wait (void) { mex_node_wait_date (mex_node_date () + 4); simu_step (); + return 0; } void diff --git a/digital/io/src/simu.host.h b/digital/io/src/simu.host.h index 91203fce..4f27f389 100644 --- a/digital/io/src/simu.host.h +++ b/digital/io/src/simu.host.h @@ -32,7 +32,7 @@ void main_timer_init (void); /** Hooked, as before, wait for the next iteration. */ -void +uint8_t main_timer_wait (void); /** Hooked, do nothing. */ -- cgit v1.2.3