main: measure read intervals

This commit is contained in:
Astro 2019-09-08 02:43:01 +02:00
parent 25dc3fb70c
commit 4e518e88ee
2 changed files with 6 additions and 2 deletions

View File

@ -7,7 +7,7 @@ use bare_metal::CriticalSection;
static mut TIME: Mutex<RefCell<u64>> = Mutex::new(RefCell::new(0)); static mut TIME: Mutex<RefCell<u64>> = Mutex::new(RefCell::new(0));
/// In HZ /// In HZ
const RATE: u32 = 10; const RATE: u32 = 10;
/// Period between to interrupts in ns /// Period between two interrupts in ns
const INTERVAL: u64 = 1_000_000 / RATE as u64; const INTERVAL: u64 = 1_000_000 / RATE as u64;
fn syst() -> &'static mut SYST { fn syst() -> &'static mut SYST {

View File

@ -177,6 +177,7 @@ fn main() -> ! {
tcp_handle7, tcp_handle7,
]; ];
let mut read_times = [0, 0];
let mut data = None; let mut data = None;
// if a socket has sent the latest data // if a socket has sent the latest data
let mut socket_pending = [false; 8]; let mut socket_pending = [false; 8];
@ -186,6 +187,8 @@ fn main() -> ! {
channel.map(|channel| channel.map(|channel|
adc.read_data().map(|new_data| { adc.read_data().map(|new_data| {
let now = get_time(); let now = get_time();
read_times[0] = read_times[1];
read_times[1] = now;
data = Some((now, Ok((channel, new_data)))); data = Some((now, Ok((channel, new_data))));
for p in socket_pending.iter_mut() { for p in socket_pending.iter_mut() {
*p = true; *p = true;
@ -209,7 +212,8 @@ fn main() -> ! {
if socket.may_send() && *pending { if socket.may_send() && *pending {
match &data { match &data {
Some((time, Ok((channel, input)))) => { Some((time, Ok((channel, input)))) => {
let _ = writeln!(socket, "t={} channel={} input={}\r", time, channel, input); let interval = read_times[1] - read_times[0];
let _ = writeln!(socket, "t={}-{} channel={} input={}\r", time, interval, channel, input);
} }
Some((time, Err(ad7172::AdcError::ChecksumMismatch(Some(expected), Some(input))))) => { Some((time, Err(ad7172::AdcError::ChecksumMismatch(Some(expected), Some(input))))) => {
let _ = writeln!(socket, "t={} checksum_expected={:02X} checksum_input={:02X}\r", time, expected, input); let _ = writeln!(socket, "t={} checksum_expected={:02X} checksum_input={:02X}\r", time, expected, input);