Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
watchdog.c
Go to the documentation of this file.
1
36#define _DEFAULT_SOURCE
37
38#include <unistd.h>
39
40#include "os/watchdog.h"
41#include "os/os.h"
42
43
47static int watchdog_ticks = 0;
48
50static void* watchdog_thread(void* arg)
51{
52 while (1)
53 {
54 usleep(((useconds_t)1000) * watchdog_period_msec);
55 if (++watchdog_ticks > 1)
56 {
57#ifdef __FreeRTOS__
59#else
60 abort();
61#endif
62 }
63 }
64 return NULL;
65}
66
67void start_watchdog(int period_msec)
68{
69 watchdog_period_msec = period_msec;
71#ifdef __FreeRTOS__
72 const int kStackSize = 256;
73#else
74 const int kStackSize = 2048;
75#endif
76 os_thread_create(NULL, "watchdog", 0, kStackSize,
77 &watchdog_thread, NULL);
78}
79
81{
83}
84
85#if 0
86static long long watchdog_reset_timer(void* unused1, void* unused2)
87{
89 return OS_TIMER_RESTART;
90}
91#endif
92
93void add_watchdog_reset_timer(int period_msec)
94{
95 //os_timer_start(os_timer_create(&watchdog_reset_timer, NULL, NULL),
96 // MSEC_TO_NSEC(period_msec));
97}
void diewith(uint32_t pattern)
Sets a blinking pattern and never returns.
#define BLINK_DIE_WATCHDOG
Watchdog timeout.
Definition blinker.h:73
int os_thread_create(os_thread_t *thread, const char *name, int priority, size_t stack_size, void *(*start_routine)(void *), void *arg)
Create a thread.
Definition os.c:450
void reset_watchdog(void)
Resets the watchdog.
Definition watchdog.c:80
static int watchdog_ticks
How many times have we seen the watchdog tick without being fed.
Definition watchdog.c:47
static void * watchdog_thread(void *arg)
Thread running a watchdog.
Definition watchdog.c:50
void start_watchdog(int period_msec)
Starts a watchdog thread that must be reset more often than period_msec.
Definition watchdog.c:67
static int watchdog_period_msec
What is the timeout of the watchdog in milliseconds.
Definition watchdog.c:45
void add_watchdog_reset_timer(int period_msec)
Inserts a timer that will periodically reset the watchdog, thereby practically making the watchdog wa...
Definition watchdog.c:93