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. */