-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwatchdog.c
74 lines (63 loc) · 1.7 KB
/
watchdog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "ch.h"
#include "hal.h"
#include "debug.h"
//#include "portab.h"
#ifndef DISABLE_HW_WATCHDOG
// Hardware Watchdog configuration
static const WDGConfig wdgcfg = {
.pr = STM32_IWDG_PR_256,
.rlr = STM32_IWDG_RL(10000)
};
#endif
static void flash_led(void) {
palSetLine(LINE_LED_GREEN);
chThdSleep(TIME_MS2I(50));
palClearLine(LINE_LED_GREEN);
}
THD_FUNCTION(wdgThread, arg) {
(void)arg;
// Setup LED
palSetLineMode(LINE_LED_GREEN, PAL_MODE_OUTPUT_PUSHPULL);
uint8_t counter = 0;
while(true)
{
chThdSleep(TIME_MS2I(500));
bool healthy = true;
// FIXME: Watchdog without functionality at the moment
/*for(uint8_t i=0; i<threads_cnt; i++) {
if(registered_threads[i]->wdg_timeout < chVTGetSystemTime())
{
TRACE_ERROR("WDG > Thread %s not healty", registered_threads[i]->name);
healthy = false; // Threads reached timeout
}
}*/
if(healthy)
#ifndef DISABLE_HW_WATCHDOG
wdgReset(&WDGD1); // Reset hardware watchdog at no error
#endif
// Switch LEDs
if(counter++ % (4*healthy) == 0)
{
flash_led();
}
}
}
void init_watchdog(void)
{
#ifndef DISABLE_HW_WATCHDOG
// Initialize Watchdog
TRACE_INFO("WDG > Initialize Watchdog");
wdgStart(&WDGD1, &wdgcfg);
wdgReset(&WDGD1);
#else
#warning "Hardware Watchdog is disabled"
TRACE_INFO("WDG > Watchdog disabled");
#endif
flash_led();
TRACE_INFO("WDG > Startup Watchdog thread");
thread_t *th = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(256), "WDG", NORMALPRIO, wdgThread, NULL);
if(!th) {
// Print startup error, do not start watchdog for this thread
TRACE_ERROR("TRAC > Could not startup thread (not enough memory available)");
}
}