From c071507ff80fa771699d0f4379a5ec5cfbb592a3 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 7 Jul 2020 16:26:33 +0800 Subject: [PATCH] RTIO: implemented exceptions --- src/runtime/src/eh_artiq.rs | 21 +++++++++++++++++++++ src/runtime/src/rtio.rs | 11 +++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/runtime/src/eh_artiq.rs b/src/runtime/src/eh_artiq.rs index 2822f26a..0acac2fa 100644 --- a/src/runtime/src/eh_artiq.rs +++ b/src/runtime/src/eh_artiq.rs @@ -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) + }); +} diff --git a/src/runtime/src/rtio.rs b/src/runtime/src/rtio.rs index ec8a0ac2..e58b3bdf 100644 --- a/src/runtime/src/rtio.rs +++ b/src/runtime/src/rtio.rs @@ -1,6 +1,7 @@ use core::ptr::{read_volatile, write_volatile}; use cslice::CSlice; use log::error; +use crate::artiq_raise; 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 {} } if status & RTIO_O_STATUS_UNDERFLOW != 0 { - error!("RTIO underflow at {0} mu, channel {1}, slack {2} mu", - timestamp, channel as i64, timestamp - get_counter()); + artiq_raise!("RTIOUnderflow", + "RTIO underflow at {0} mu, channel {1}, slack {2} mu", + timestamp, channel as i64, timestamp - get_counter()); } if status & RTIO_O_STATUS_DESTINATION_UNREACHABLE != 0 { - error!("RTIO destination unreachable, output, at {0} mu, channel {1}", - timestamp, channel as i64); + artiq_raise!("RTIODestinationUnreachable", + "RTIO destination unreachable, output, at {0} mu, channel {1}", + timestamp, channel as i64, 0); } }