]> code.bitgloo.com Git - clyne/zig-stm32l476.git/commitdiff
better tick interface
authorClyne Sullivan <clyne@bitgloo.com>
Sun, 6 Oct 2024 20:20:14 +0000 (16:20 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sun, 6 Oct 2024 20:20:14 +0000 (16:20 -0400)
src/main.zig
src/timer.zig

index 99cb451ac677c7ebcaf1a097bd746147b944dbba..346ca5651b479abe88eda10a8e45737f944f75aa 100644 (file)
@@ -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);
     }
 }
 
index b30cfcf2ed417728f2b3de4e71f2766abbafb181..00fd6bae44fb422cfc7973ca3c7336dda75e0382 100644 (file)
@@ -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) };