#![no_std]
#![no_main]
use core::fmt::Write;
use rpi_hal::{pac, timer::Timer, uart::Uart};
use rpi_kickstart::{console, logln};
use static_cell::StaticCell;
static UART: StaticCell<Uart> = StaticCell::new();
fn uptime() -> u64 {
Timer::new(unsafe { pac::Peripherals::steal() }.SYSTMR).now_micros()
}
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
let peripherals = unsafe { pac::Peripherals::steal() };
let mut uart = Uart::init(&peripherals.GPIO, peripherals.UART0);
let _ = writeln!(uart, "PANIC: {info}");
rpi_hal::halt();
}
#[unsafe(no_mangle)]
pub extern "C" fn kmain() -> ! {
logln!("discarded: there is no console yet");
let peripherals = unsafe { pac::Peripherals::steal() };
let timer = Timer::new(peripherals.SYSTMR);
let raw = timer.now_micros();
console::init(
UART.init(Uart::init(&peripherals.GPIO, peripherals.UART0)),
uptime,
);
logln!("rpi-kickstart console");
logln!("system timer read {raw}us at boot; the stamp starts from there");
logln!(
"arch: {}",
if cfg!(target_arch = "aarch64") {
"aarch64"
} else {
"aarch32"
}
);
let mut line = 0u32;
loop {
line += 1;
let pause = if line.is_multiple_of(4) { 2500 } else { 500 };
timer.delay_ms(pause);
logln!("line {line}, after a {pause}ms pause");
}
}