From fb3cfa5a0ac1acb58c2067cd1aad0339b534f982 Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Mon, 27 Apr 2009 18:23:45 +0200 Subject: * digital/io/src (fixes #66): - add a system to enable or disable the chrono module, - call chrono update function every main loop. --- digital/io/src/chrono.c | 28 +++++++++++++++++++++++++++- digital/io/src/chrono.h | 20 ++++++++++++++++++++ digital/io/src/main.c | 2 ++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/digital/io/src/chrono.c b/digital/io/src/chrono.c index 6397f4f8..254e0e1b 100644 --- a/digital/io/src/chrono.c +++ b/digital/io/src/chrono.c @@ -64,10 +64,18 @@ */ static uint32_t chrono_ov_count_; +/** + * Status of the chrono module. + * Set to 0 if the module is disabled, otherwise set to a non 0 value. + */ +static uint8_t chrono_enabled_ = 0; + void chrono_init (void) { + /* Enable chrono. */ + chrono_enable (); /* Set the overflow counter to the maximum of overflow before the end of * the match. */ chrono_ov_count_ = CHRONO_MATCH_OVERFLOW_COUNT; @@ -77,7 +85,7 @@ void chrono_update (void) { /* Decrement overflow counter if it is possible. */ - if (chrono_ov_count_) + if (chrono_enabled_ && chrono_ov_count_) chrono_ov_count_--; } @@ -90,6 +98,24 @@ chrono_is_match_over (void) return 1; } +void +chrono_enable (void) +{ + chrono_enabled_ = 1; +} + +void +chrono_disable (void) +{ + chrono_enabled_ = 0; +} + +uint8_t +chrono_enabled (void) +{ + return chrono_enabled_; +} + uint32_t chrono_remaining_time (void) { diff --git a/digital/io/src/chrono.h b/digital/io/src/chrono.h index 5e1a378c..e2b09ac8 100644 --- a/digital/io/src/chrono.h +++ b/digital/io/src/chrono.h @@ -49,6 +49,26 @@ chrono_init (void); void chrono_update (void); +/** + * Enable chrono module. + * You should call this function when a match start. + */ +void +chrono_enable (void); + +/** + * Disable chrono module. + */ +void +chrono_disable (void); + +/** + * Is chrono module enabled? + * @return 0 if not enabled, other values otherwise. + */ +uint8_t +chrono_enabled (void); + /** * Match over? * @return diff --git a/digital/io/src/main.c b/digital/io/src/main.c index daca1b07..e2435516 100644 --- a/digital/io/src/main.c +++ b/digital/io/src/main.c @@ -182,6 +182,8 @@ main_loop (void) /* Manage UART protocol */ proto_accept (uart0_getc ()); + /* Update chrono. */ + chrono_update (); /* Is match over? */ if (chrono_is_match_over ()) { -- cgit v1.2.3