aboutsummaryrefslogtreecommitdiffstats
path: root/src/timer.zig
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2024-10-06 11:30:25 -0400
committerClyne Sullivan <clyne@bitgloo.com>2024-10-06 11:30:25 -0400
commit294cf1320986f12efad7885836c31ef6a56f94dc (patch)
treeb1b46602d260e773ee987f1be048e76d423f6983 /src/timer.zig
parent64df2e9f313ca8b22310f839ab50f7ec2628ec25 (diff)
systick driver
Diffstat (limited to 'src/timer.zig')
-rw-r--r--src/timer.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/timer.zig b/src/timer.zig
new file mode 100644
index 0000000..21151c7
--- /dev/null
+++ b/src/timer.zig
@@ -0,0 +1,31 @@
+const interrupt = @import("interrupt.zig");
+
+const sys_tick_type = packed struct {
+ enable: u1,
+ tickint: u1,
+ unused: u30,
+
+ rvr: u32,
+ cvr: u32,
+ calib: u32,
+};
+
+var sys_tick: *volatile sys_tick_type = @ptrFromInt(0xE000E010);
+
+pub var ticks_raw: u32 = 0;
+
+pub fn initialize(freq: u32) void {
+ interrupt.register(.SysTick, tick);
+ sys_tick.rvr = 4000000 / 8 / freq;
+ sys_tick.tickint = 1;
+ sys_tick.enable = 1;
+}
+
+fn tick() void {
+ ticks_raw += 1;
+}
+
+pub fn ticks() u32 {
+ return @atomicLoad(u32, &ticks_raw, .acquire);
+}
+