better tick interface

main
Clyne 3 months ago
parent f4bf565897
commit 0491a3f6af
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

@ -20,12 +20,8 @@ pub fn main() void {
gpioc.set_mode(13, .input);
while (true) {
//asm volatile("svc 0");
gpioa.toggle(5);
const next = tick.ticks() + 1000;
while (tick.ticks() < next) {
asm volatile("nop");
}
asm volatile("svc 0");
tick.delay(500);
}
}

@ -33,10 +33,15 @@ const driver = struct {
self.lld.initialize(freq);
}
pub fn ticks(self: driver) u32 {
pub fn count(self: driver) u32 {
_ = self;
return @atomicLoad(u32, &ticks_raw, .acquire);
}
pub fn delay(self: driver, ticks: u32) void {
const now = self.count();
while (self.count() - now < ticks) {}
}
};
pub const systick = driver { .lld = @ptrFromInt(0xE000E010) };

Loading…
Cancel
Save