SatCat5
cfgbus_stats.cc
1 // Copyright 2021-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // ConfigBus core definitions
6 //
7 // Define a memory-mapped "ConfigBus" interface, based on a base address.
8 // All registers in this interface correspond to volatile pointers.
9 //
10 
11 #include <satcat5/cfgbus_stats.h>
12 
13 namespace cfg = satcat5::cfg;
14 
16  return u32(errct_mac)
17  + u32(errct_ovr_tx)
18  + u32(errct_ovr_rx)
19  + u32(errct_pkt)
20  + u32(errct_ptp_rx)
21  + u32(errct_ptp_tx);
22 }
23 
25  cfg::ConfigBus* cfg, unsigned devaddr)
26  : m_traffic(cfg->get_register(devaddr))
27 {
28  // Nothing else to initialize.
29 }
30 
32  // Writing to any portion of the register map reloads all counters.
33  *m_traffic = 0;
34 }
35 
37  cfg::TrafficStats stats = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
38  unsigned reg = 16 * idx; // Fixed size, 16 registers per port
39  if (reg < cfg::REGS_PER_DEVICE) {
40  // Read ConfigBus registers.
41  stats.bcast_bytes = m_traffic[reg+0];
42  stats.bcast_frames = m_traffic[reg+1];
43  stats.rcvd_bytes = m_traffic[reg+2];
44  stats.rcvd_frames = m_traffic[reg+3];
45  stats.sent_bytes = m_traffic[reg+4];
46  stats.sent_frames = m_traffic[reg+5];
47  u32 errct_word = m_traffic[reg+6];
48  u32 errct_ptp = m_traffic[reg+7];
49  u32 status_word = m_traffic[reg+8];
50  stats.delta_freq = m_traffic[reg+9];
51  // Split individual byte fields from errct_word.
52  // (This method works on both little-endian and big-endian hosts.)
53  stats.errct_mac = (u8)(errct_word >> 24);
54  stats.errct_ovr_tx = (u8)(errct_word >> 16);
55  stats.errct_ovr_rx = (u8)(errct_word >> 8);
56  stats.errct_pkt = (u8)(errct_word >> 0);
57  stats.errct_ptp_rx = (u8)(errct_ptp >> 8);
58  stats.errct_ptp_tx = (u8)(errct_ptp >> 0);
59  // Split individual fields from the status word.
60  stats.rate_mbps = (u16)(status_word >> 16);
61  stats.status = (u8)(status_word & 0xFF);
62  }
63  return stats;
64 }
const unsigned REGS_PER_DEVICE
Fixed ConfigBus gateware interface parameters.
Definition: cfgbus_core.h:45
Generic ConfigBus API.
Definition: cfgbus_core.h:124
NetworkStats(satcat5::cfg::ConfigBus *cfg, unsigned devaddr)
Construct a memory-map for the designated ConfigBus device.
Definition: cfgbus_stats.cc:24
satcat5::cfg::TrafficStats get_port(unsigned idx)
Read most recent statistics for the Nth port.
Definition: cfgbus_stats.cc:36
void refresh_now()
Immediately refresh statistics for every port.
Definition: cfgbus_stats.cc:31
Data structure for reading per-port traffic statistics.
Definition: cfgbus_stats.h:19
s32 delta_freq
Net frequency offset (see above)
Definition: cfgbus_stats.h:31
u8 errct_ovr_rx
Rx-FIFO overflow (rare)
Definition: cfgbus_stats.h:35
u32 bcast_frames
Broadcast frames received from device.
Definition: cfgbus_stats.h:26
u32 sent_frames
Total frames sent from switch to device.
Definition: cfgbus_stats.h:30
u32 bcast_bytes
Broadcast bytes received from device.
Definition: cfgbus_stats.h:25
u8 errct_ptp_tx
TX PTP packets with bad tstamps.
Definition: cfgbus_stats.h:38
u8 errct_mac
MAC/PHY errors.
Definition: cfgbus_stats.h:33
u16 rate_mbps
Link rate in Mbps.
Definition: cfgbus_stats.h:32
u32 errct_total() const
Total errors across all types.
Definition: cfgbus_stats.cc:15
u8 errct_ovr_tx
Tx-FIFO overflow (common)
Definition: cfgbus_stats.h:34
u8 errct_pkt
Packet errors (bad checksum, length, etc.)
Definition: cfgbus_stats.h:36
u32 rcvd_bytes
Total bytes received from device.
Definition: cfgbus_stats.h:27
u32 sent_bytes
Total bytes sent from switch to device.
Definition: cfgbus_stats.h:29
u8 status
Port status (Varies by port)
Definition: cfgbus_stats.h:39
u32 rcvd_frames
Total frames received from device.
Definition: cfgbus_stats.h:28
u8 errct_ptp_rx
RX PTP packets with bad tstamps.
Definition: cfgbus_stats.h:37