From 56afeb17c86b8297cab06a8fb958fe26b7582786 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sun, 17 Oct 2021 17:07:25 -0700 Subject: [PATCH] Fix simulator (#3360) * fix simulator * print out halt reason * option to close simulator after time * workflow calls it * test with the bug still present * ...and fix the bug --- .github/workflows/build-simulator.yaml | 4 ++++ .../system/timer/signal_executor_sleep.cpp | 2 ++ simulator/chconf.h | 2 +- simulator/main.c | 13 ++++++++++++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-simulator.yaml b/.github/workflows/build-simulator.yaml index b6e8eff724..af1470df35 100644 --- a/.github/workflows/build-simulator.yaml +++ b/.github/workflows/build-simulator.yaml @@ -31,6 +31,10 @@ jobs: working-directory: ./simulator/ run: bash compile.sh + - name: Run Simulator (10 seconds) + working-directory: ./simulator/ + run: ./build/rusefi_simulator 10 + - name: Upload built simulator uses: actions/upload-artifact@v2 with: diff --git a/firmware/controllers/system/timer/signal_executor_sleep.cpp b/firmware/controllers/system/timer/signal_executor_sleep.cpp index 522f442a60..69f29567b3 100644 --- a/firmware/controllers/system/timer/signal_executor_sleep.cpp +++ b/firmware/controllers/system/timer/signal_executor_sleep.cpp @@ -92,6 +92,8 @@ void SleepExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, acti } void SleepExecutor::cancel(scheduling_s* s) { + chibios_rt::CriticalSectionLocker csl; + if (chVTIsArmedI(&s->timer)) { chVTResetI(&s->timer); } diff --git a/simulator/chconf.h b/simulator/chconf.h index c29aca8d4e..1482cc4b25 100644 --- a/simulator/chconf.h +++ b/simulator/chconf.h @@ -727,7 +727,7 @@ * the system is halted. */ #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ - printf("chSysHalt\r\n"); \ + printf("chSysHalt: %s\r\n", reason); \ exit(-1); \ } diff --git a/simulator/main.c b/simulator/main.c index bdb39f84e8..a4a960acac 100644 --- a/simulator/main.c +++ b/simulator/main.c @@ -129,10 +129,12 @@ static evhandler_t fhandlers[] = { termination_handler, sd1_handler, sd2_handler bool verboseMode = true; +static virtual_timer_t exitTimer; + /*------------------------------------------------------------------------* * Simulator main. * *------------------------------------------------------------------------*/ -int main(void) { +int main(int argc, char** argv) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers @@ -143,6 +145,15 @@ int main(void) { halInit(); chSysInit(); + if (argc == 2) { + int timeoutSeconds = atoi(argv[1]); + printf("Running rusEFI simulator for %d seconds, then exiting.\n\n", timeoutSeconds); + + chSysLock(); + chVTSetI(&exitTimer, MY_US2ST(timeoutSeconds * 1e6), &exit, 0); + chSysUnlock(); + } + /* * Console thread started. */