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(())
|
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)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
enum KernelState {
|
enum KernelState {
|
||||||
Absent,
|
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<()> {
|
fn check_magic(stream: &mut TcpStream) -> io::Result<()> {
|
||||||
const MAGIC: &'static [u8] = b"ARTIQ coredev\n";
|
const MAGIC: &'static [u8] = b"ARTIQ coredev\n";
|
||||||
|
|
||||||
|
@ -226,6 +236,17 @@ fn kern_handle(waiter: Waiter,
|
||||||
kern_acknowledge()
|
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)
|
request => unexpected!("unexpected request {:?} from kernel CPU", request)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -249,12 +270,12 @@ fn handle(waiter: Waiter,
|
||||||
if session.kernel_state == KernelState::Running {
|
if session.kernel_state == KernelState::Running {
|
||||||
if session.watchdog_set.expired() {
|
if session.watchdog_set.expired() {
|
||||||
try!(host_write(stream, host::Reply::WatchdogExpired));
|
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() {
|
if !rtio_crg::check() {
|
||||||
try!(host_write(stream, host::Reply::ClockFailure));
|
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