ethercat-linux/vendor/ethercrab/tests/replay-issue-255.rs
Tony Cao 21b2d3bf99 J1900 <-> TwinCAT 1 kHz verification over EL6695 bridge
Re-implementation of rustbootd's ecat_el6695_* examples as a single binary
with fixes found in review and on hardware:

- DC-follow PLL hardened against period-2 hunting: slew-limited anchor
  (+/-50us/cycle), bistable-trap snap re-anchor, re-prime on stale deadline
- drift-free absolute-grid ticker mode; probe mode for timestamp forensics
- bounded-memory online stats (histograms), graceful SIGINT/SIGTERM shutdown
  with full report, error-streak abort
- timestamp plausibility filter comparing against the previous raw sample
  (avoids the deadlock after a startup outlier)
- XFC scope waveform options: --el2202 (with --el2202-dual), --el2262,
  --el1252 latch timestamp readback with per-channel edge statistics
- register access unified in regs.rs: named bit constants everywhere,
  read-modify-write for enable/activation bytes
- vendored patched ethercrab 0.7.1 (sdo_write_complete, send_raw_coe)

Verified on J1900 (PREEMPT_RT 6.6.135): 600k cycles/600s exact 1 kHz,
tx/rx zero errors, phase_err p50=164us std=5us; EL2202<->EL1252 loopback
edge interval mean 2000.24us std=24.65us.
2026-07-22 08:55:41 +08:00

81 lines
2.0 KiB
Rust

//! Capture network traffic for `issue-255.rs`
//!
//! Required hardware:
//!
//! - EK1100
//! - EL2828
mod util;
use env_logger::Env;
use ethercrab::{MainDevice, MainDeviceConfig, PduStorage, Timeouts, error::Error};
use std::{hint::black_box, path::PathBuf, time::Duration};
use tokio::time::MissedTickBehavior;
const MAX_SUBDEVICES: usize = 16;
const MAX_PDU_DATA: usize = PduStorage::element_size(1100);
const MAX_FRAMES: usize = 128;
const MAX_PDI: usize = 128;
#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn replay_issue_255() -> Result<(), Error> {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
static PDU_STORAGE: PduStorage<MAX_FRAMES, MAX_PDU_DATA> = PduStorage::new();
let (tx, rx, pdu_loop) = PDU_STORAGE.try_split().expect("can only split once");
let maindevice = MainDevice::new(
pdu_loop,
Timeouts::default(),
MainDeviceConfig {
dc_static_sync_iterations: 0,
..Default::default()
},
);
let test_name = PathBuf::from(file!())
.file_stem()
.unwrap()
.to_string_lossy()
.to_string();
util::spawn_tx_rx(&format!("tests/{test_name}.pcapng"), tx, rx);
// Read configurations from SubDevice EEPROMs and configure devices.
let group = maindevice
.init_single_group::<MAX_SUBDEVICES, MAX_PDI>(time_zero)
.await
.expect("Init");
let group = group.into_op(&maindevice).await.expect("Slow into OP");
let mut cycle_time = tokio::time::interval(Duration::from_millis(2));
cycle_time.set_missed_tick_behavior(MissedTickBehavior::Skip);
// Animate slow pattern for 8 ticks
for _ in 0..64 {
group.tx_rx(&maindevice).await.expect("TX/RX");
let el2889 = group.subdevice(&maindevice, 1).unwrap();
let mut o = el2889.outputs_raw_mut();
do_stuff(black_box(&mut o));
cycle_time.tick().await;
}
Ok(())
}
fn time_zero() -> u64 {
0
}
fn do_stuff(slice: &mut [u8]) {
slice[0] += 1;
slice[0] -= 1;
}