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.
117 lines
3.7 KiB
Rust
117 lines
3.7 KiB
Rust
//! Dump the EEPROM of a given sub device to stdout.
|
|
|
|
use env_logger::Env;
|
|
use ethercrab::{
|
|
MainDevice, MainDeviceConfig, PduStorage, Timeouts, error::Error, std::ethercat_now,
|
|
};
|
|
use std::io::Write;
|
|
|
|
/// Maximum number of SubDevices that can be stored. This must be a power of 2 greater than 1.
|
|
const MAX_SUBDEVICES: usize = 16;
|
|
/// Maximum PDU data payload size - set this to the max PDI size or higher.
|
|
const MAX_PDU_DATA: usize = PduStorage::element_size(1100);
|
|
/// Maximum number of EtherCAT frames that can be in flight at any one time.
|
|
const MAX_FRAMES: usize = 16;
|
|
/// Maximum total PDI length.
|
|
const PDI_LEN: usize = 64;
|
|
|
|
static PDU_STORAGE: PduStorage<MAX_FRAMES, MAX_PDU_DATA> = PduStorage::new();
|
|
|
|
fn main() -> Result<(), Error> {
|
|
smol::block_on(async {
|
|
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
|
|
|
let interface = std::env::args()
|
|
.nth(1)
|
|
.expect("Provide network interface as first argument.");
|
|
|
|
let index: u16 = std::env::args()
|
|
.nth(2)
|
|
.expect("Provide device index (starting from zero) as second argument.")
|
|
.parse()
|
|
.expect("Invalid index: must be a number");
|
|
|
|
log::info!(
|
|
"Starting EEPROM dump tool, interface {}, device index {}",
|
|
interface,
|
|
index
|
|
);
|
|
|
|
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,
|
|
..MainDeviceConfig::default()
|
|
},
|
|
);
|
|
|
|
#[cfg(target_os = "windows")]
|
|
std::thread::spawn(move || {
|
|
ethercrab::std::tx_rx_task_blocking(
|
|
&interface,
|
|
tx,
|
|
rx,
|
|
ethercrab::std::TxRxTaskConfig { spinloop: false },
|
|
)
|
|
.expect("TX/RX task")
|
|
});
|
|
#[cfg(not(target_os = "windows"))]
|
|
smol::spawn(ethercrab::std::tx_rx_task(&interface, tx, rx).expect("spawn TX/RX task"))
|
|
.detach();
|
|
|
|
let group = maindevice
|
|
.init_single_group::<MAX_SUBDEVICES, PDI_LEN>(ethercat_now)
|
|
.await
|
|
.expect("Init");
|
|
|
|
log::info!("Discovered {} SubDevices", group.len());
|
|
|
|
for subdevice in group.iter(&maindevice) {
|
|
log::info!(
|
|
"--> SubDevices {:#06x} {} {}",
|
|
subdevice.configured_address(),
|
|
subdevice.name(),
|
|
subdevice.identity()
|
|
);
|
|
}
|
|
|
|
let subdevice = group
|
|
.subdevice(&maindevice, usize::from(index))
|
|
.expect("Could not find device for given index");
|
|
|
|
log::info!(
|
|
"Dumping EEPROM for device index {}: {:#06x} {} {} {}...",
|
|
index,
|
|
subdevice.configured_address(),
|
|
subdevice.name(),
|
|
subdevice
|
|
.description()
|
|
.await?
|
|
.map(|d| d.as_str().to_string())
|
|
.unwrap_or(String::new()),
|
|
subdevice.identity()
|
|
);
|
|
|
|
let eeprom_len = subdevice
|
|
.eeprom_size(&maindevice)
|
|
.await
|
|
.expect("Could not read EEPROM len");
|
|
|
|
log::info!("--> Device EEPROM is {} bytes long", eeprom_len);
|
|
|
|
let mut buf = vec![0u8; eeprom_len];
|
|
|
|
// Read entire EEPROM into buffer
|
|
subdevice.eeprom_read_raw(&maindevice, 0, &mut buf).await?;
|
|
|
|
std::io::stdout().write_all(&buf[..]).expect("Stdout write");
|
|
|
|
log::info!("Done, wrote {} bytes to stdout", buf.len());
|
|
|
|
Ok(())
|
|
})
|
|
}
|