summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src
diff options
context:
space:
mode:
Diffstat (limited to 'digital/io/src')
-rw-r--r--digital/io/src/main.c18
-rw-r--r--digital/io/src/main_timer.avr.h6
-rw-r--r--digital/io/src/simu.host.c3
-rw-r--r--digital/io/src/simu.host.h2
4 files changed, 25 insertions, 4 deletions
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
@@ -99,6 +99,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.
*/
#define MAIN_SHARP_UPDATE_FREQ 5
@@ -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. */