#![no_std]
#![no_main]

extern crate panic_halt;

use core::{arch::asm, ptr::write};

use riscv_rt::entry;

// use `main` as the entry point of this application
// `main` is not allowed to return
#[entry]
fn main() -> ! {
    // do something here
    loop {
        unsafe {
            write(0x01002000 as *mut u32, 0);
            busy_wait(10_000_000);
            write(0x01002000 as *mut u32, 1);
            busy_wait(10_000_000);
        }
    }
}

fn busy_wait(num_nops: u32) {
    for _ in 0..num_nops {
        unsafe { asm!("nop"); }
    }
}

fn write_led(val: u32) {
    unsafe { write(0x01002000 as *mut u32, val); }
}