systick driver
parent
64df2e9f31
commit
294cf13209
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue