The unified diff between revisions [d0420ebd..] and [24d5b9f4..] 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 [24d5b9f4dff9135787b198fe1127d9c1e3326b9c]
#
# add_file "watchdog.c"
#  content [8398952deb37d8242fc858143c5e201321343c27]
#
============================================================
--- /dev/null	
+++ watchdog.c	8398952deb37d8242fc858143c5e201321343c27
@@ -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 * TIMER_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;
+	}
+}