aboutsummaryrefslogtreecommitdiff
path: root/kernel/heartbeat.c
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2011-03-11 01:28:00 +0000
committerDimitri Sokolyuk <demon@dim13.org>2011-03-11 01:28:00 +0000
commitb8335062ae7d19bd27e6131fadcd7d3a116c4992 (patch)
tree3bd226885fb6f2ca24ee300a44d7b51ffb8d2706 /kernel/heartbeat.c
DimOS RT
Diffstat (limited to 'kernel/heartbeat.c')
-rw-r--r--kernel/heartbeat.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/kernel/heartbeat.c b/kernel/heartbeat.c
new file mode 100644
index 0000000..6960e63
--- /dev/null
+++ b/kernel/heartbeat.c
@@ -0,0 +1,53 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2011 Dimitri Sokolyuk <demon@dim13.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <inttypes.h>
+#include <avr/io.h>
+#include "kernel.h"
+#include "tasks.h"
+
+#define PIN PB0
+
+void
+heartbeat(void *arg)
+{
+ /* 80bpm: 100ms on, 50ms off, 100ms on, 500ms off */
+ uint32_t d = deadline();
+ uint32_t r = release();
+
+ DDRB |= _BV(PIN);
+ PORTB &= ~_BV(PIN);
+
+ for (;;) {
+ PORTB ^= _BV(PIN);
+ r += MSEC(100);
+ update(r, d);
+
+ PORTB ^= _BV(PIN);
+ r += MSEC(50);
+ update(r, d);
+
+ PORTB ^= _BV(PIN);
+ r += MSEC(100);
+ update(r, d);
+
+ PORTB ^= _BV(PIN);
+ r += MSEC(500);
+ d = r + MSEC(750);
+ update(r, d);
+ }
+}