ethercat-linux/vendor/ethercrab/src/al_control.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

78 lines
1.7 KiB
Rust

use crate::subdevice_state::SubDeviceState;
/// The AL control/status word for an individual SubDevice.
///
/// Defined in ETG1000.6 Table 9 - AL Control Description.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, ethercrab_wire::EtherCrabWireReadWrite)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[wire(bytes = 2)]
pub struct AlControl {
/// AL status.
#[wire(bits = 4)]
pub state: SubDeviceState,
/// Error flag.
#[wire(bits = 1)]
pub error: bool,
/// ID request flag.
#[wire(bits = 1, post_skip = 10)]
pub id_request: bool,
}
impl AlControl {
pub fn new(state: SubDeviceState) -> Self {
Self {
state,
error: false,
id_request: false,
}
}
pub fn reset() -> Self {
Self {
state: SubDeviceState::Init,
// Acknowledge error
error: true,
..Default::default()
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use ethercrab_wire::{EtherCrabWireRead, EtherCrabWireWriteSized};
#[test]
fn al_control() {
let value = AlControl {
state: SubDeviceState::SafeOp,
error: true,
id_request: false,
};
let packed = value.pack();
assert_eq!(packed, [0x04 | 0x10, 0x00]);
}
#[test]
fn unpack() {
let value = AlControl {
state: SubDeviceState::SafeOp,
error: true,
id_request: false,
};
let parsed = AlControl::unpack_from_slice(&[0x04 | 0x10, 0x00]).unwrap();
assert_eq!(value, parsed);
}
#[test]
fn unpack_short() {
let parsed = AlControl::unpack_from_slice(&[0x04 | 0x10]);
assert!(parsed.is_err());
}
}