From: Clyne Sullivan Date: Sun, 6 Oct 2024 20:20:14 +0000 (-0400) Subject: better tick interface X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=0491a3f6af9e318b9e3774c34fe4923a67376829;p=clyne%2Fzig-stm32l476.git better tick interface --- diff --git a/src/main.zig b/src/main.zig index 99cb451..346ca56 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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); } } diff --git a/src/timer.zig b/src/timer.zig index b30cfcf..00fd6ba 100644 --- a/src/timer.zig +++ b/src/timer.zig @@ -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) };