RTIO: implemented exceptions

This commit is contained in:
pca006132 2020-07-07 16:26:33 +08:00
parent f1750cf8cd
commit c071507ff8
2 changed files with 28 additions and 4 deletions

View File

@ -237,3 +237,24 @@ pub unsafe extern fn reraise() -> ! {
} }
} }
#[macro_export]
macro_rules! artiq_raise {
($name:expr, $message:expr, $param0:expr, $param1:expr, $param2:expr) => ({
use cslice::AsCSlice;
let exn = $crate::eh_artiq::Exception {
name: concat!("0:artiq.coredevice.exceptions.", $name).as_c_slice(),
file: file!().as_c_slice(),
line: line!(),
column: column!(),
// https://github.com/rust-lang/rfcs/pull/1719
function: "(Rust function)".as_c_slice(),
message: $message.as_c_slice(),
param: [$param0, $param1, $param2]
};
#[allow(unused_unsafe)]
unsafe { $crate::eh_artiq::raise(&exn) }
});
($name:expr, $message:expr) => ({
artiq_raise!($name, $message, 0, 0, 0)
});
}

View File

@ -1,6 +1,7 @@
use core::ptr::{read_volatile, write_volatile}; use core::ptr::{read_volatile, write_volatile};
use cslice::CSlice; use cslice::CSlice;
use log::error; use log::error;
use crate::artiq_raise;
use crate::pl::csr; use crate::pl::csr;
@ -75,12 +76,14 @@ unsafe fn process_exceptional_status(channel: i32, status: u8) {
while csr::rtio::o_status_read() & RTIO_O_STATUS_WAIT != 0 {} while csr::rtio::o_status_read() & RTIO_O_STATUS_WAIT != 0 {}
} }
if status & RTIO_O_STATUS_UNDERFLOW != 0 { if status & RTIO_O_STATUS_UNDERFLOW != 0 {
error!("RTIO underflow at {0} mu, channel {1}, slack {2} mu", artiq_raise!("RTIOUnderflow",
"RTIO underflow at {0} mu, channel {1}, slack {2} mu",
timestamp, channel as i64, timestamp - get_counter()); timestamp, channel as i64, timestamp - get_counter());
} }
if status & RTIO_O_STATUS_DESTINATION_UNREACHABLE != 0 { if status & RTIO_O_STATUS_DESTINATION_UNREACHABLE != 0 {
error!("RTIO destination unreachable, output, at {0} mu, channel {1}", artiq_raise!("RTIODestinationUnreachable",
timestamp, channel as i64); "RTIO destination unreachable, output, at {0} mu, channel {1}",
timestamp, channel as i64, 0);
} }
} }