forked from M-Labs/artiq
Rust: implement watchdogs.
This commit is contained in:
parent
5701b2095b
commit
d825393e81
|
@ -58,7 +58,6 @@ impl WatchdogSet {
|
|||
}
|
||||
}
|
||||
|
||||
warn!("cannot add watchdog; all {} watchdogs used", MAX_WATCHDOGS);
|
||||
Err(())
|
||||
}
|
||||
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue