implement timer

This commit is contained in:
2025-05-20 12:29:16 +02:00
parent aff0259643
commit 5e8180ceaf
3 changed files with 25 additions and 10 deletions

View File

@@ -5,8 +5,10 @@
use core::{arch::asm, panic::PanicInfo};
use gpio::{gpio_high, gpio_low, set_gpio_state};
use timer::{delay_nops, sleep};
mod gpio;
mod timer;
mod uart;
#[panic_handler]
@@ -31,20 +33,13 @@ extern "C" fn main() {
}
// Delay so clock speed can stabilize
unsafe { delay(50000) }
unsafe { delay_nops(50000) }
uart::print("Hello World!\n");
loop {
let _ = gpio_high(29);
unsafe { delay(1_000_000) }
unsafe { sleep(500_000) } // 0.5s
let _ = gpio_low(29);
unsafe { delay(1_000_000) }
}
}
unsafe fn delay(count: u32) {
for _ in 0..count {
// Prevent compiler optimizing away the loop
core::arch::asm!("nop");
unsafe { sleep(500_000) } // 0.5s
}
}