runtime: interrogate ethmac error counters and display changes.

This commit is contained in:
whitequark 2017-10-30 07:46:23 +00:00
parent 978c0d98aa
commit cdf63c5ea0
2 changed files with 52 additions and 2 deletions

View File

@ -1,8 +1,9 @@
use core::slice; use core::{slice, fmt};
use board::{csr, mem};
use smoltcp::Error; use smoltcp::Error;
use smoltcp::phy::{DeviceCapabilities, Device}; use smoltcp::phy::{DeviceCapabilities, Device};
use board::{csr, mem};
const RX_SLOTS: usize = csr::ETHMAC_RX_SLOTS as usize; const RX_SLOTS: usize = csr::ETHMAC_RX_SLOTS as usize;
const TX_SLOTS: usize = csr::ETHMAC_TX_SLOTS as usize; const TX_SLOTS: usize = csr::ETHMAC_TX_SLOTS as usize;
const SLOT_SIZE: usize = csr::ETHMAC_SLOT_SIZE as usize; const SLOT_SIZE: usize = csr::ETHMAC_SLOT_SIZE as usize;
@ -84,3 +85,47 @@ impl Drop for TxBuffer {
unsafe { csr::ethmac::sram_reader_start_write(1) } unsafe { csr::ethmac::sram_reader_start_write(1) }
} }
} }
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct EthernetStatistics {
rx_errors: u32,
rx_dropped: u32,
}
impl EthernetStatistics {
pub fn new() -> Self {
unsafe {
EthernetStatistics {
rx_errors: csr::ethmac::crc_errors_read(),
rx_dropped: csr::ethmac::sram_writer_errors_read(),
}
}
}
pub fn update(&mut self) -> Option<Self> {
let old = self.clone();
*self = Self::new();
let diff = EthernetStatistics {
rx_errors: self.rx_errors.wrapping_sub(old.rx_errors),
rx_dropped: self.rx_dropped.wrapping_sub(old.rx_dropped),
};
if diff == EthernetStatistics::default() {
None
} else {
Some(diff)
}
}
}
impl fmt::Display for EthernetStatistics {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.rx_errors > 0 {
write!(f, " rx crc errors: {}", self.rx_errors)?
}
if self.rx_dropped > 0 {
write!(f, " rx dropped: {}", self.rx_dropped)?
}
Ok(())
}
}

View File

@ -153,6 +153,7 @@ fn startup() {
} }
} }
let mut net_stats = ethmac::EthernetStatistics::new();
loop { loop {
scheduler.run(); scheduler.run();
@ -162,6 +163,10 @@ fn startup() {
Err(smoltcp::Error::Unrecognized) => (), Err(smoltcp::Error::Unrecognized) => (),
Err(err) => warn!("network error: {}", err) Err(err) => warn!("network error: {}", err)
} }
if let Some(net_stats_diff) = net_stats.update() {
warn!("ethernet mac:{}", net_stats_diff); // mac:{} (sic)
}
} }
} }