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

136 lines
3.9 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/// Fieldbus Memory Management Unit (FMMU).
///
/// Used to map segments of the Process Data Image (PDI) to various parts of the SubDevice memory
/// space.
///
/// ETG1000.4 Table 56 – Fieldbus memory management unit (FMMU) entity.
#[derive(Default, Copy, Clone, PartialEq, Eq, ethercrab_wire::EtherCrabWireReadWrite)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[wire(bytes = 16)]
pub struct Fmmu {
/// This parameter shall contain the start address in octets in the logical memory area of the
/// memory translation.
#[wire(bytes = 4)]
pub logical_start_address: u32,
#[wire(bytes = 2)]
pub length_bytes: u16,
#[wire(bits = 3, post_skip = 5)]
pub logical_start_bit: u8,
#[wire(bits = 3, post_skip = 5)]
pub logical_end_bit: u8,
#[wire(bytes = 2)]
pub physical_start_address: u16,
#[wire(bits = 3, post_skip = 5)]
pub physical_start_bit: u8,
#[wire(bits = 1)]
pub read_enable: bool,
#[wire(bits = 1, post_skip = 6)]
pub write_enable: bool,
// Lots of spare bytes after this one!
#[wire(bits = 1, post_skip = 31)]
pub enable: bool,
}
impl core::fmt::Debug for Fmmu {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Fmmu")
.field(
"logical_start_address",
&format_args!("{:#010x}", self.logical_start_address),
)
.field("length_bytes", &self.length_bytes)
.field("logical_start_bit", &self.logical_start_bit)
.field("logical_end_bit", &self.logical_end_bit)
.field(
"physical_start_address",
&format_args!("{:#06x}", self.physical_start_address),
)
.field("physical_start_bit", &self.physical_start_bit)
.field("read_enable", &self.read_enable)
.field("write_enable", &self.write_enable)
.field("enable", &self.enable)
.finish()
}
}
impl core::fmt::Display for Fmmu {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_fmt(format_args!(
"logical start {:#010x}:{}, size {}, logical end bit {}, physical start {:#06x}:{}, {}{}, {}",
self.logical_start_address,
self.logical_start_bit,
self.length_bytes,
self.logical_end_bit,
self.physical_start_address,
self.physical_start_bit,
if self.read_enable { "R" } else { "" },
if self.write_enable { "W" } else { "O" },
if self.enable{ "enabled" } else { "disabled" },
))
}
}
#[cfg(test)]
mod tests {
use super::*;
use core::mem;
use ethercrab_wire::{EtherCrabWireRead, EtherCrabWireSized};
#[test]
fn size() {
// Unpacked size
assert_eq!(mem::size_of::<Fmmu>(), 16);
// Packed size
assert_eq!(Fmmu::PACKED_LEN, 16);
}
#[test]
fn decode_one() {
let raw = [
// Logical start address
0x00, 0x00, 0x00, 0x00, //
// Length
0x01, 0x00, //
// Logical start bit
0x00, //
// Logical end bit
0x03, //
// Physical start address
0x00, 0x10, //
// Phyiscal start bit
0x00, //
// Read/write enable
0x01, //
// FMMU enable
0x01, //
// Padding
0x00, 0x00, 0x00,
];
let fmmu = Fmmu::unpack_from_slice(&raw).unwrap();
assert_eq!(
fmmu,
Fmmu {
logical_start_address: 0,
length_bytes: 1,
logical_start_bit: 0,
logical_end_bit: 3,
physical_start_address: 0x1000,
physical_start_bit: 0,
read_enable: true,
write_enable: false,
enable: true,
}
)
}
}