Skip to content

Add IGMP Multicast Joiner and PTP Slave Core (IEEE 1588v2, Layer 3).#199

Merged
enjoy-digital merged 11 commits intomasterfrom
ptp
Apr 2, 2026
Merged

Add IGMP Multicast Joiner and PTP Slave Core (IEEE 1588v2, Layer 3).#199
enjoy-digital merged 11 commits intomasterfrom
ptp

Conversation

@enjoy-digital
Copy link
Copy Markdown
Owner

This pull request adds PTP (IEEE 1588v2) Slave support to LiteEth, along with IGMP multicast group management required for switch compatibility. It introduces an LiteEthIGMPJoiner module for multicast group registration and a complete LiteEthPTP Slave core with TSU, clock servo, protocol FSM, and monitoring — all operating over Layer 3 (UDP/IPv4) transport. This enables microsecond-level clock synchronization over standard Ethernet infrastructure using software timestamping on the master side.

All changes are fully backward compatible — IGMP and PTP are disabled by default and existing designs are unaffected.


Summary of Features

1. IGMP Multicast Group Joiner (core/igmp)

  • LiteEthIGMPJoiner
    Periodically sends IGMPv2 Membership Reports for configured multicast groups via the IP crossbar. Allows switches with IGMP snooping to forward PTP (or other) multicast traffic to the FPGA port.

  • Core Integration

    • Integrated as optional parameters (with_igmp, igmp_groups, igmp_interval) in LiteEthIPCore, LiteEthUDPIPCore, and add_etherbone.
    • Runs inside the ethcore clock domain, avoiding external CDC complexity.

2. PTP Slave Core (core/ptp)

  • TSU (Time Stamping Unit)
    48-bit seconds / 32-bit nanoseconds timestamp counter with addend-based tick accumulation. Supports offset correction (phase/seconds adjust) and coarse step for initial lock.

  • TX/RX Packet Handling
    Packetizer for Delay_Req/Pdelay_Req transmission with TSU TX latch on first byte. Depacketizer with PTP header/body extraction, version/domain validation, and timeout-based deadlock recovery.

  • Clock Servo

    • Pipelined 7-stage computation of phase offset and path delay from E2E/P2P timestamps.
    • Phase correction via TSU offset and frequency trim via addend update.
    • Outlier detection for second-boundary artifacts.
    • Seconds adjustment via ±1e9 offset with fractional accumulator preservation.
    • Addend clamping (nominal ±1) with fractional bits preserved.
    • Shadow addend register for continuous TSU restoration against transient corruption.
  • Protocol Control FSM
    Manages the full E2E/P2P exchange sequence (WAIT_SYNC → WAIT_FUP → SEND_DELAY_REQ → WAIT_DELAY_RESP → SERVE → LOCKED). Handles master IP learning, sequence ID tracking, peer/requester validation, stale Sync skip, and announce timeout.

  • Snapshot-based Monitor
    Coherent CSR snapshots of PTP state (phase, delay, addend, timestamps, servo flags) for Etherbone reads. Common and debug CSR variants.

  • Delay Mechanisms
    End-to-End (E2E) and Peer-to-Peer (P2P) delay measurement supported, selectable at runtime.

3. Bench Design and Test Utility

  • bench/arty_ptp.py
    Minimal Etherbone + PTP Slave design for Arty A7 with IGMP, dedicated sys_eth clock domain for PTP isolation, and ptp4l master configuration instructions in the file header.

  • bench/test_ptp.py
    RemoteClient-based PTP monitor with:

    • Table-style colored output with periodic column headers.
    • Debug mode for timestamps, offsets, and frequency step.
    • Summary statistics (min/max/avg phase and delay).
    • CSV export and matplotlib plotting.

Validation

Validated on Arty A7 with ptp4l master (software timestamping, E2E, UDP/IPv4). Steady-state phase error ±200–900ns (limited by host-side software timestamp jitter).

Unit test coverage (120 tests total):

  • test/test_igmp.py — 4 tests: checksum verification, FSM hang-free operation (single/multi-group), end-to-end IGMP packet content at PHY output.
  • test/test_ptp.py — 27 HDL simulation tests: TSU (counting, rollover, offset, addend), RX (depacketization, field extraction, rejection, timeout), TX (packetization, P2P mode), top-level integration (E2E exchange lock, timeout, domain filtering, error counting).
  • test/test_ptp_servo.py — 89 pure-Python tests: signed delta computation, outlier detection, coarse step, frequency trim, exchange validity, queued Sync skip, seconds adjustment, addend clamping, shadow addend, TSU tick/offset race, servo convergence.

Add LiteEthIGMPJoiner that periodically sends IGMPv2 Membership Reports
for configured multicast groups via the IP crossbar. This allows switches
with IGMP snooping to forward multicast traffic (e.g. PTP) to this port.

The joiner uses a simple 3-state FSM (WAIT/SEND/GAP) with pre-computed
payloads via combinational Case lookup.
Test checksum computation, FSM hang-free operation (single and multi-group),
and end-to-end IGMP packet content verification at PHY output level.
Add with_igmp, igmp_groups and igmp_interval parameters to LiteEthIPCore
and LiteEthUDPIPCore, following the same pattern as ICMP. When enabled,
the IGMP joiner is instantiated inside the core, running in the same clock
domain as the IP crossbar and avoiding external CDC complexity.
Add LiteEthPTP, a complete PTP Slave implementation for Layer 3
(UDP/IPv4) with:
- TSU with 48-bit seconds / 32-bit nanoseconds and addend-based tick
  accumulation
- TX/RX packetization with depacketizer and timeout recovery
- Pipelined clock servo with phase correction and frequency trim
- E2E and P2P delay mechanisms
- Outlier detection and seconds-boundary correction
- Snapshot-based monitoring with common and debug CSR variants
test_ptp.py (27 tests): HDL simulation tests covering TSU (counting,
rollover, offset, addend), RX (depacketization, field extraction,
rejection, timeout), TX (packetization, P2P mode), and top-level
integration (E2E exchange lock, timeout, domain filtering, error
counting).

test_ptp_servo.py (89 tests): pure-Python mirrors of the servo
algorithms covering signed delta computation, outlier detection, coarse
step, frequency trim, exchange validity classification, queued Sync
skip logic, seconds adjustment, addend clamping, shadow addend, TSU
tick/offset race, and servo convergence.
Minimal SoC with Etherbone, PTP slave, and IGMP multicast support.
Provides a self-contained bench for testing PTP on the Arty without
the full digilent_arty target complexity.

Usage:
  python3 bench/arty_ptp.py --build --load
  python3 bench/arty_ptp.py --build --load --ptp-debug
  python3 bench/arty_ptp.py --build --load --p2p
RemoteClient-based PTP monitor with:
- Table-style output with periodic column headers
- Color-coded phase error, lock status, and servo flags
- Optional debug fields (timestamps, offsets, frequency step)
- Summary statistics (min/max/avg phase and delay)
- CSV export and matplotlib plotting

Usage:
  python3 bench/test_ptp.py --count 100
  python3 bench/test_ptp.py --count 100 --debug
  python3 bench/test_ptp.py --count 100 --plot --csv-out data.csv
Document how to configure and run ptp4l as a PTP master for testing
the bench design, including the required config file and monitor commands.
Use a dedicated sys_eth PLL output (same frequency as sys) for the PTP
core and UDP ports. This avoids crossing from sys to eth_rx through the
async FIFO on every packet, reducing Delay_Req/Resp latency to match
the original digilent_arty design.
@enjoy-digital enjoy-digital merged commit a2102c6 into master Apr 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant