summaryrefslogtreecommitdiff
path: root/digital/io
diff options
context:
space:
mode:
authorJérémy Dufour2009-04-27 18:23:45 +0200
committerJérémy Dufour2009-04-27 18:23:45 +0200
commitfb3cfa5a0ac1acb58c2067cd1aad0339b534f982 (patch)
tree169d6611cce0d04d3b3d6591c8a180c238af6fa4 /digital/io
parent4f77a9904f90a3056c2ec89f497d0ffafd3f345e (diff)
* digital/io/src (fixes #66):
- add a system to enable or disable the chrono module, - call chrono update function every main loop.
Diffstat (limited to 'digital/io')
-rw-r--r--digital/io/src/chrono.c28
-rw-r--r--digital/io/src/chrono.h20
-rw-r--r--digital/io/src/main.c2
3 files changed, 49 insertions, 1 deletions
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
@@ -50,6 +50,26 @@ 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
* - 0 if the match is not finished yet.
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 ())
{