forked from M-Labs/nac3
1
0
Fork 0

moninj: implement monitoring

This commit is contained in:
Sebastien Bourdeauducq 2020-04-25 20:45:25 +08:00
parent 5df4a0a2f8
commit cc5c679b31
2 changed files with 22 additions and 3 deletions

View File

@ -1,6 +1,6 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#![recursion_limit="512"] // for futures_util::select! #![recursion_limit="1024"] // for futures_util::select!
extern crate alloc; extern crate alloc;
extern crate log; extern crate log;

View File

@ -54,7 +54,7 @@ enum DeviceMessage {
InjectionStatus = 1 InjectionStatus = 1
} }
fn read_probe(channel: i32, probe: u8) -> i32 { fn read_probe(channel: i32, probe: i8) -> i32 {
unsafe { unsafe {
csr::rtio_moninj::mon_chan_sel_write(channel as _); csr::rtio_moninj::mon_chan_sel_write(channel as _);
csr::rtio_moninj::mon_probe_sel_write(probe as _); csr::rtio_moninj::mon_probe_sel_write(probe as _);
@ -149,7 +149,26 @@ async fn handle_connection(stream: &TcpStream, timer: GlobalTimer) -> Result<()>
} }
}, },
_ = timeout_f => { _ = timeout_f => {
warn!("tick"); for (&(channel, probe), previous) in probe_watch_list.iter_mut() {
let current = read_probe(channel, probe);
if previous.is_none() || previous.unwrap() != current {
write_i8(&stream, DeviceMessage::MonitorStatus.to_i8().unwrap()).await?;
write_i32(&stream, channel).await?;
write_i8(&stream, probe).await?;
write_i32(&stream, current).await?;
*previous = Some(current);
}
}
for (&(channel, overrd), previous) in inject_watch_list.iter_mut() {
let current = read_injection_status(channel, overrd);
if previous.is_none() || previous.unwrap() != current {
write_i8(&stream, DeviceMessage::InjectionStatus.to_i8().unwrap()).await?;
write_i32(&stream, channel).await?;
write_i8(&stream, overrd).await?;
write_i8(&stream, current).await?;
*previous = Some(current);
}
}
next_check = next_check + Milliseconds(200); next_check = next_check + Milliseconds(200);
} }
} }