Skip to content

Commit

Permalink
Rust: implement watchdogs.
Browse files Browse the repository at this point in the history
whitequark committed Oct 1, 2016
1 parent 5701b20 commit d825393
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 0 additions & 1 deletion artiq/runtime.rs/src/clock.rs
Original file line number Diff line number Diff line change
@@ -58,7 +58,6 @@ impl WatchdogSet {
}
}

warn!("cannot add watchdog; all {} watchdogs used", MAX_WATCHDOGS);
Err(())
}

25 changes: 23 additions & 2 deletions artiq/runtime.rs/src/session.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,10 @@ macro_rules! unexpected {
};
}

fn io_error(msg: &str) -> io::Error {
io::Error::new(io::ErrorKind::Other, msg)
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum KernelState {
Absent,
@@ -49,6 +53,12 @@ impl Session {
}
}

impl Drop for Session {
fn drop(&mut self) {
kernel::stop()
}
}

fn check_magic(stream: &mut TcpStream) -> io::Result<()> {
const MAGIC: &'static [u8] = b"ARTIQ coredev\n";

@@ -226,6 +236,17 @@ fn kern_handle(waiter: Waiter,
kern_acknowledge()
}

kern::WatchdogSetRequest { ms } => {
let id = try!(session.watchdog_set.set_ms(ms)
.map_err(|()| io_error("out of watchdogs")));
kern_send(waiter, kern::WatchdogSetReply { id: id })
}

kern::WatchdogClear { id } => {
session.watchdog_set.clear(id);
kern_acknowledge()
}

request => unexpected!("unexpected request {:?} from kernel CPU", request)
}
})
@@ -249,12 +270,12 @@ fn handle(waiter: Waiter,
if session.kernel_state == KernelState::Running {
if session.watchdog_set.expired() {
try!(host_write(stream, host::Reply::WatchdogExpired));
return Err(io::Error::new(io::ErrorKind::Other, "watchdog expired"))
return Err(io_error("watchdog expired"))
}

if !rtio_crg::check() {
try!(host_write(stream, host::Reply::ClockFailure));
return Err(io::Error::new(io::ErrorKind::Other, "RTIO clock failure"))
return Err(io_error("RTIO clock failure"))
}
}

0 comments on commit d825393

Please sign in to comment.