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>
This commit is contained in:
Kevin O'Connor
2017-07-20 00:02:43 -04:00
parent 3ccecc568d
commit d851882278
10 changed files with 622 additions and 2 deletions

36
src/linux/watchdog.c Normal file
View File

@@ -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);