diff --git a/Kernel.cpp b/Kernel.cpp index b59187c..01e725f 100644 --- a/Kernel.cpp +++ b/Kernel.cpp @@ -113,12 +113,16 @@ void Kernel_tick() last_tick = millis(); unsigned long next_tick_due = ULONG_MAX; + int running_tasks = 0; + int last_exit_code = 0; for (int i=0; i tasks[i].run_interval) @@ -149,19 +153,29 @@ void Kernel_tick() tasks[i].running = false; // Store the exit code tasks[i].exit_code = task_return; + // Actually it's not running... + running_tasks--; + last_exit_code = task_return; } } // Check each task to see if it's the one scheduled to run on the next closest tick, and track it // so we can put the processor to sleep until then. - if (tasks[i].run_interval - tasks[i].run_accumulator < next_tick_due) + if (tasks[i].running && tasks[i].run_interval - tasks[i].run_accumulator < next_tick_due) { next_tick_due = tasks[i].run_interval - tasks[i].run_accumulator; } } } + if (running_tasks == 0) + { + char panic_msg[255]; + sprintf(panic_msg, "All processes exited! Last exit code: %d", last_exit_code); + Kernel_panic(panic_msg); + } + // Put processor to sleep until the next scheduled run of a task // Leave the home button enabled to force a wake-up before then esp_sleep_enable_timer_wakeup(next_tick_due * 1000);