diff --git a/Kernel.cpp b/Kernel.cpp index 2152ed5..d0b2816 100644 --- a/Kernel.cpp +++ b/Kernel.cpp @@ -9,7 +9,8 @@ struct Task *Kernel_get_task(int pid); struct Task tasks[MAX_TASKS]; int next_pid = 1; -unsigned long last_tick; +unsigned long last_tick_start; +unsigned long last_tick_duration; bool inputs[2] = {false, false}; void Kernel_panic(char* message) @@ -25,7 +26,8 @@ void Kernel_panic(char* message) void Kernel_setup() { - last_tick = millis(); + last_tick_start = millis(); + last_tick_duration = 0; //Serial.begin(115200); } @@ -158,6 +160,11 @@ bool Kernel_read_input(int input) return value; } +unsigned long Kernel_get_last_tick_duration() +{ + return last_tick_duration; +} + struct Task *Kernel_get_task(int pid) { for (int i=0; i 0) { - if (tasks[i].run_accumulator + duration > tasks[i].run_interval) + if (tasks[i].run_accumulator + last_tick_duration > tasks[i].run_interval) { // Set signal tasks[i].signal |= SIGNAL_TICK; @@ -205,7 +212,7 @@ void Kernel_tick() else { // Otherwise, accumulate time - tasks[i].run_accumulator += duration; + tasks[i].run_accumulator += last_tick_duration; } } else diff --git a/Kernel.h b/Kernel.h index 088b982..9793d3d 100644 --- a/Kernel.h +++ b/Kernel.h @@ -35,6 +35,7 @@ void Kernel_signal_mask(int pid, unsigned int signal_mask); // Get the run interval of a process unsigned long Kernel_get_run_interval(int pid); +void Kernel_set_run_interval(int pid, unsigned long interval); // Count how many tasks are running int Kernel_count_running_tasks(); @@ -46,6 +47,8 @@ int Kernel_get_exit_code(int pid); // Check if a button was pressed bool Kernel_read_input(int input); +// Get how long *actually* elapsed since the last tick since we don't provide hard guarantees +unsigned long Kernel_get_last_tick_duration(); #define SIGNAL_NONE 0x0000 #define SIGNAL_TICK 0x0001