diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-07-20 00:02:43 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-09-20 12:55:28 -0400 |
commit | d851882278644b959d9175d6b303631ddc8cd2c6 (patch) | |
tree | 786412ef59997a3c885c4ee15cf28d2597fa2d77 /src/linux/watchdog.c | |
parent | 3ccecc568dbfd505fe3bdc46b4d16bf7a4528996 (diff) | |
download | kutter-d851882278644b959d9175d6b303631ddc8cd2c6.tar.gz kutter-d851882278644b959d9175d6b303631ddc8cd2c6.tar.xz kutter-d851882278644b959d9175d6b303631ddc8cd2c6.zip |
linux: Initial support for running Klipper in a Linux real-time process
Add support for compiling the Klipper micro-controller code as a
real-time process capable of running on standard Linux systems.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/linux/watchdog.c')
-rw-r--r-- | src/linux/watchdog.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/linux/watchdog.c b/src/linux/watchdog.c new file mode 100644 index 00000000..d89fcd29 --- /dev/null +++ b/src/linux/watchdog.c @@ -0,0 +1,36 @@ +// Support for Linux watchdog +// +// Copyright (C) 2017 Kevin O'Connor <kevin@koconnor.net> +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include <fcntl.h> // open +#include <unistd.h> // write +#include "internal.h" // report_errno +#include "sched.h" // DECL_TASK + +static int watchdog_fd = -1; + +int +watchdog_setup(void) +{ + int ret = open("/dev/watchdog", O_RDWR|O_CLOEXEC); + if (ret < 0) { + report_errno("watchdog open", ret); + return -1; + } + watchdog_fd = ret; + return set_non_blocking(watchdog_fd); +} + +void +watchdog_task(void) +{ + static struct timespec next_watchdog_time; + if (watchdog_fd < 0 || !timer_check_periodic(&next_watchdog_time)) + return; + int ret = write(watchdog_fd, ".", 1); + if (ret <= 0) + report_errno("watchdog write", ret); +} +DECL_TASK(watchdog_task); |