Module Name: src
Committed By: pooka
Date: Sun Jan 31 03:11:55 UTC 2010
Added Files:
src/share/examples/rump/swwdog_arm: Makefile swwdog_arm.c
Log Message:
Add an example on how to use sysmon watchdogs in rump.
To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/share/examples/rump/swwdog_arm/Makefile \
src/share/examples/rump/swwdog_arm/swwdog_arm.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Added files:
Index: src/share/examples/rump/swwdog_arm/Makefile
diff -u /dev/null src/share/examples/rump/swwdog_arm/Makefile:1.1
--- /dev/null Sun Jan 31 03:11:55 2010
+++ src/share/examples/rump/swwdog_arm/Makefile Sun Jan 31 03:11:55 2010
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 2010/01/31 03:11:55 pooka Exp $
+#
+
+PROG= swwdog_arm
+
+LDADD+= -lrumpdev_sysmon -lrumpdev
+LDADD+= -lrumpvfs -lrump
+LDADD+= -lrumpuser -lpthread
+
+DBG= -g
+NOMAN=
+WARNS= 4
+
+.include <bsd.prog.mk>
Index: src/share/examples/rump/swwdog_arm/swwdog_arm.c
diff -u /dev/null src/share/examples/rump/swwdog_arm/swwdog_arm.c:1.1
--- /dev/null Sun Jan 31 03:11:55 2010
+++ src/share/examples/rump/swwdog_arm/swwdog_arm.c Sun Jan 31 03:11:55 2010
@@ -0,0 +1,91 @@
+/* $NetBSD: swwdog_arm.c,v 1.1 2010/01/31 03:11:55 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 Antti Kantee. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/wdog.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main(void)
+{
+ char wname[WDOG_NAMESIZE];
+ struct wdog_conf wc;
+ struct wdog_mode wm;
+ int fd;
+ extern int rumpns_swwdog_reboot;
+
+ rumpns_swwdog_reboot = 1;
+ rump_init();
+
+ fd = rump_sys_open("/dev/watchdog", O_RDWR);
+ if (fd == -1)
+ err(1, "open watchdog");
+
+ wc.wc_count = 1;
+ wc.wc_names = wname;
+
+ if (rump_sys_ioctl(fd, WDOGIOC_GWDOGS, &wc) == -1)
+ err(1, "can't fetch watchdog names");
+
+ if (wc.wc_count) {
+ assert(wc.wc_count == 1);
+ printf("watchdog available: %s\n", wc.wc_names);
+
+ printf("enabling watchdog with 2s period\n");
+ strlcpy(wm.wm_name, wc.wc_names, sizeof(wm.wm_name));
+ wm.wm_mode = WDOG_MODE_ETICKLE;
+ wm.wm_period = 2;
+ if (rump_sys_ioctl(fd, WDOGIOC_SMODE, &wm) == -1)
+ err(1, "failed to set tickle\n");
+
+ printf("sleep 1s, then tickle tickle\n");
+ sleep(1);
+ rump_sys_ioctl(fd, WDOGIOC_TICKLE);
+
+ printf("sleep 1s, then tickle tickle\n");
+ sleep(1);
+ rump_sys_ioctl(fd, WDOGIOC_TICKLE);
+
+ printf("now, \"forgetting\" to tickle the doggie\n");
+ sleep(3);
+ } else {
+ printf("no puppies\n");
+ }
+
+ return 0;
+}