aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 2740d2528f49447d3cb3b724e62ca988d524a137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![no_std]
#![no_main]

mod blink;
mod led;

use gd32vf103xx_hal::{
    eclic::{self, EclicExt},
    pac::{self, Peripherals},
    rcu::RcuExt,
    time::Hertz,
    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 = unsafe { Peripherals::steal() };

    pac::ECLIC::set_threshold_level(eclic::Level::L0);
    pac::ECLIC::set_level_priority_bits(eclic::LevelPriorityBits::L3P1);

    let t6 = p.TIMER6;
    let mut rcu = p.RCU.configure().freeze();
    let timer = timer::Timer::<pac::TIMER6>::timer6(t6, Hertz(1), &mut rcu);

    let led = LED::new();
    let mut blink = blink::Task::new(timer, Hertz(5), led);
    loop {
        if blink.poll() == PollResult::WouldBlock {
            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 {}
}