aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/main.rs33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 7fd2ba3..707feed 100755
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,7 +15,10 @@ use gd32vf103xx_hal::{
time::Hertz,
timer::Timer,
};
-use riscv::asm::wfi;
+use riscv::{
+ asm::wfi,
+ interrupt,
+};
use riscv_rt::entry;
use led::LED;
@@ -71,28 +74,34 @@ fn main(_hartid: usize) -> ! {
#[export_name="ExceptionHandler"]
fn exception_handler(_frame: &riscv_rt::TrapFrame) -> ! {
- loop { unsafe { wfi() } };
+ spin();
}
#[export_name="DefaultHandler"]
fn default_handler() -> ! {
- loop { unsafe { wfi() } };
+ spin();
}
#[export_name="MachineTimer"]
fn machine_timer() {
- loop { unsafe { wfi() } };
+ spin();
}
#[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 {}
+ interrupt::free(|_cs| {
+ log!("!!! panic ");
+ if let Some(loc) = info.location() {
+ log!("in {}:{} ", loc.file(), loc.line());
}
- loop {}
- }
- loop {}
+ if let Some(msg) = info.payload().downcast_ref::<&str>() {
+ log!("⇒ {} ", msg);
+ }
+ logln!("!!!");
+ });
+ spin();
+}
+
+fn spin() -> ! {
+ loop { unsafe { wfi() } };
}