-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2172 from lf-lang/watchdog
Add watchdogs to environment struct
- Loading branch information
Showing
12 changed files
with
305 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule reactor-c
updated
13 files
+1 −0 | core/CMakeLists.txt | |
+7 −0 | core/environment.c | |
+7 −1 | core/platform/lf_zephyr_support.c | |
+8 −7 | core/reactor_common.c | |
+3 −2 | core/threaded/reactor_threaded.c | |
+112 −38 | core/threaded/watchdog.c | |
+4 −0 | include/core/environment.h | |
+3 −1 | include/core/reactor.h | |
+0 −1 | include/core/reactor_common.h | |
+4 −2 | include/core/threaded/watchdog.h | |
+22 −1 | include/core/utils/util.h | |
+1 −1 | lingua-franca-ref.txt | |
+1 −1 | test/src_gen_stub.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Test watchdog. This test starts a watchdog timer of 1500ms every 1s. Half the time, it then | ||
* sleeps after starting the watchdog so that the watchdog expires. There should be a total of two | ||
* watchdog expirations. | ||
* @author Benjamin Asch | ||
* @author Edward A. Lee | ||
*/ | ||
target C { | ||
timeout: 11000 ms | ||
} | ||
|
||
reactor Watcher(timeout: time = 1500 ms) { | ||
// Offset ameliorates startup time. | ||
timer t(1 s, 1 s) | ||
// Period has to be smaller than watchdog timeout. Produced if the watchdog triggers. | ||
output d: int | ||
state count: int = 0 | ||
|
||
watchdog poodle(timeout) {= | ||
instant_t p = lf_time_physical_elapsed(); | ||
lf_print("******** Watchdog timed out at elapsed physical time: " PRINTF_TIME, p); | ||
self->count++; | ||
=} | ||
|
||
reaction(t) -> poodle, d {= | ||
lf_watchdog_start(poodle, 0); | ||
lf_print("Watchdog started at physical time " PRINTF_TIME, lf_time_physical_elapsed()); | ||
lf_print("Will expire at " PRINTF_TIME, lf_time_logical_elapsed() + self->timeout); | ||
lf_set(d, 42); | ||
=} | ||
|
||
reaction(poodle) -> d {= | ||
lf_print("Reaction poodle was called."); | ||
lf_set(d, 1); | ||
=} | ||
|
||
reaction(shutdown) -> poodle {= | ||
lf_watchdog_stop(poodle); | ||
// Watchdog may expire in tests even without the sleep, but it should at least expire twice. | ||
if (self->count < 2) { | ||
lf_print_error_and_exit("Watchdog expired %d times. Expected at least 2.", self->count); | ||
} | ||
=} | ||
} | ||
|
||
main reactor { | ||
logical action a | ||
state count: int = 0 | ||
|
||
w = new Watcher() | ||
|
||
reaction(startup) {= | ||
if (NUMBER_OF_WATCHDOGS != 1) { | ||
lf_print_error_and_exit("NUMBER_OF_WATCHDOGS was %d", NUMBER_OF_WATCHDOGS); | ||
} | ||
=} | ||
|
||
reaction(w.d) {= | ||
lf_print("Watcher reactor produced an output. %d", self->count % 2); | ||
self->count++; | ||
if (self->count % 4 == 0) { | ||
lf_print(">>>>>> Taking a long time to process that output!"); | ||
lf_sleep(MSEC(1600)); | ||
} | ||
=} | ||
|
||
reaction(shutdown) {= | ||
if (self->count < 12) { | ||
lf_print_error_and_exit("Watchdog produced output %d times. Expected at least 12.", self->count); | ||
} | ||
=} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* This tests that the order of reactions triggered when a watchdog expires is as expected. | ||
* @author Erling Rennemo Jellum | ||
*/ | ||
target C | ||
|
||
reactor WithWatchdog { | ||
state cnt: int = 0 | ||
|
||
watchdog watch(10 msec) {= =} | ||
|
||
reaction(startup) -> watch {= | ||
lf_watchdog_start(watch, 0); | ||
=} | ||
|
||
reaction(watch) {= | ||
self->cnt++; | ||
if (lf_time_logical_elapsed() != MSEC(10)) { | ||
lf_print_error_and_exit("Watchdog handler triggered at wrong tag."); | ||
} | ||
=} | ||
|
||
reaction(shutdown) {= | ||
if (self->cnt != 1) { | ||
lf_print_error_and_exit("Watchdog did not timeout"); | ||
} | ||
=} | ||
} | ||
|
||
main reactor { | ||
w1 = new WithWatchdog() | ||
w2 = new WithWatchdog() | ||
timer t(2 sec) | ||
|
||
reaction(startup) {= | ||
if (NUMBER_OF_WATCHDOGS != 2) { | ||
lf_print_error_and_exit("NUMBER_OF_WATCHDOGS was %d", NUMBER_OF_WATCHDOGS); | ||
} | ||
=} | ||
|
||
reaction(t) {= =} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* This tests that the order of reactions triggered when a watchdog expires is as expected. | ||
* @author Erling Rennemo Jellum | ||
*/ | ||
target C | ||
|
||
preamble {= | ||
typedef enum { | ||
INVALID = 0, | ||
STARTUP_DONE=1, | ||
WATCHDOG_HANDLE_DONE = 2, | ||
WATCHDOG_TRIGGERED_REACTION_DONE = 3, | ||
} state_t; | ||
=} | ||
|
||
main reactor { | ||
state test: state_t = {= INVALID =} | ||
timer t(1 sec) | ||
|
||
watchdog watch(1 msec) {= | ||
lf_print("Watchdog handler"); | ||
if(self->test != STARTUP_DONE) { | ||
lf_print_error_and_exit("Startup reaction not done"); | ||
} | ||
self->test = WATCHDOG_HANDLE_DONE; | ||
=} | ||
|
||
reaction(startup) -> watch {= | ||
if (NUMBER_OF_WATCHDOGS != 1) { | ||
lf_print_error_and_exit("NUMBER_OF_WATCHDOGS was %d", NUMBER_OF_WATCHDOGS); | ||
} | ||
|
||
lf_watchdog_start(watch, 0); | ||
if(self->test != 0) { | ||
lf_print_error_and_exit("Startup reaction interrupted"); | ||
} | ||
lf_sleep(MSEC(100)); | ||
if(self->test != 0) { | ||
lf_print_error_and_exit("Startup reaction interrupted"); | ||
} | ||
self->test = STARTUP_DONE; | ||
=} | ||
|
||
reaction(watch) {= | ||
lf_print("Watchdog trigger"); | ||
if(self->test != WATCHDOG_HANDLE_DONE) { | ||
lf_print_error_and_exit("Watchdog handle not finished"); | ||
} | ||
self->test = WATCHDOG_TRIGGERED_REACTION_DONE; | ||
=} | ||
|
||
reaction(t) {= | ||
if(self->test != WATCHDOG_TRIGGERED_REACTION_DONE) { | ||
lf_print_error_and_exit("Watchdog did not expire"); | ||
} | ||
=} | ||
} |
Oops, something went wrong.