|
|
@ -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<MAX_TASKS; i++) |
|
|
|
{ |
|
|
|
// If the task is initialized (non-zero PID) and is marked as running
|
|
|
|
if (tasks[i].pid != 0 && tasks[i].running == true) |
|
|
|
{ |
|
|
|
// Make sure we found at least one active process, because if not we dead.
|
|
|
|
running_tasks++; |
|
|
|
|
|
|
|
// Check if this tick's duration will push us over the run interval and if so set the TICK signal
|
|
|
|
if (tasks[i].run_accumulator + duration > 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); |
|
|
|