The unified diff between revisions [d0420ebd..] and [9142f333..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'watchdog.c'

#
# old_revision [d0420ebd87c820e33a32b29727989516e15980a8]
# new_revision [9142f3330490a5aa00c1686475633b620c2ef5e7]
#
# add_file "watchdog.c"
#  content [d26ee7fc5e47c24a05fdd00cb771f966b4a87102]
#
============================================================
--- /dev/null	
+++ watchdog.c	d26ee7fc5e47c24a05fdd00cb771f966b4a87102
@@ -0,0 +1,50 @@
+/* watchdog.c */
+
+#include "watchdog.h"
+#include "panic.h"
+#include "timer.h"
+
+/* There are two watchdogs to worry about. The hardware one, and watchdogs
+   to make sure that critical parts of the software are running.
+ */
+
+/*
+ * This is about 10 times round the main loop. If we haven't had a kick by
+ * now, something's gone horribly wrong.
+ */
+
+#define WATCHDOG_TIMEOUT (100 * TIMER0_MS)
+
+static unsigned int watchdog_last_seen[WATCHDOG_MODULES];
+
+void watchdog_kick(unsigned int module)
+{
+	if (module >= WATCHDOG_MODULES)
+		return;
+	watchdog_last_seen[module] = timer_read();
+}
+
+void watchdog_check(void)
+{
+	unsigned int time = timer_read();
+	int i;
+
+	/* XXX not yet */
+	return;
+	for (i = 0; i < WATCHDOG_MODULES; i++) {
+		if ((signed int)(watchdog_last_seen[i] + WATCHDOG_TIMEOUT
+					- time) < 0) {
+			panic(PANIC_WATCHDOG_TIMEOUT + i);
+		}
+	}
+}
+
+void init_watchdog(void)
+{
+	unsigned int time = timer_read();
+	int i;
+
+	for (i = 0; i < WATCHDOG_MODULES; i++) {
+		watchdog_last_seen[i] = time;
+	}
+}