#![no_std] #![no_main] mod blink; mod led; mod log; use gd32vf103xx_hal::{ afio::AfioExt, eclic::{self, EclicExt}, gpio::GpioExt, pac::{self, Peripherals}, rcu::RcuExt, serial::Serial, time::Hertz, timer::Timer, }; use riscv::asm::wfi; use riscv_rt::entry; use led::LED; // global_asm!(include_str!("boot.S")); #[derive(PartialEq)] pub enum PollResult { Ok, WouldBlock, } #[entry] fn main(_hartid: usize) -> ! { let p = Peripherals::take().expect("couldn't take peripherals"); pac::ECLIC::set_threshold_level(eclic::Level::L0); pac::ECLIC::set_level_priority_bits(eclic::LevelPriorityBits::L3P1); let mut rcu = p.RCU.configure().freeze(); let mut afio = p.AFIO.constrain(&mut rcu); let timer = Timer::::timer6(p.TIMER6, Hertz(1), &mut rcu); let gpioa = p.GPIOA.split(&mut rcu); let led = LED::new(gpioa.pa7); let mut blink = blink::Task::new(timer, Hertz(5), led); // TODO: figure out how to use the usb serial on the start board. // // this version has to be wired up physically. let serial = Serial::new( p.USART1, (gpioa.pa2, gpioa.pa3), Default::default(), &mut afio, &mut rcu, ); let (tx, _rx) = serial.split(); unsafe { log::new(tx) }; loop { let mut can_sleep = true; can_sleep &= blink.poll() == PollResult::WouldBlock; unsafe { log::log("hi\r\n") }; if can_sleep { unsafe { wfi() }; } } } #[export_name="ExceptionHandler"] fn exception_handler(_frame: &riscv_rt::TrapFrame) -> ! { loop { unsafe { wfi() } }; } #[export_name="DefaultHandler"] fn default_handler() -> ! { loop { unsafe { wfi() } }; } #[export_name="MachineTimer"] fn machine_timer() { loop { unsafe { wfi() } }; } #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { if let Some(loc) = info.location() { let _file = loc.file(); let _line = loc.line(); if let Some(_msg) = info.payload().downcast_ref::<&str>() { loop {} } loop {} } loop {} }