Nucleus
Barry Multitasking support db9a0c1 (3 years, 3 months ago)
diff --git a/task/time.c b/task/time.c
new file mode 100644
index 0000000..39675e4
--- /dev/null
+++ b/task/time.c
@@ -0,0 +1,30 @@
+/*
+ * This file controls the system clock and contains the functions related to
+ * getting and setting the time from various sources. It keeps a monotonic
+ * clock internally, but can also make use of the tasks' clocks, and the RTC.
+ */
+
+#include <stdint.h>
+#include <nucleus/cpu.h>
+#include <nucleus/task.h>
+
+uint32_t monotonic = 0;
+uint8_t slice[MAX_CPUS] = {0};
+
+/* Timer interrupt */
+void
+timer_handler(struct InterruptFrame *frame)
+{
+ monotonic++;
+
+ /* Account timeslices */
+ slice[CPUID]++;
+ if (!current)
+ return;
+
+ /* Call scheduler */
+ if (slice[CPUID] < current->priority)
+ return;
+ slice[CPUID] = 0;
+ schedule();
+}