Skip to content

PTP-P1.5: complete portable runtime and ESP control bridge - #64

Merged
masarray merged 17 commits into
mainfrom
feature/ptp-p1-5-runtime-completion
Aug 11, 2026
Merged

masarray merged 17 commits into
mainfrom
feature/ptp-p1-5-runtime-completion

Conversation

@masarray

Copy link
Copy Markdown
Owner

Summary

Completes the PTP-P1 runtime/control layer port from ARIEC61850 while preserving the stronger ESP32-P4 hardware timestamp implementation introduced in PTP-P1.

Portable runtime

  • add PtpPublisherOptions
  • add thread-safe PtpPublisherStatus
  • add per-message PtpSequenceCounters
  • add ClockIdentity parse/format and MAC-derived EUI-64 helper
  • add lifecycle: start / stop / stopped-only reconfigure
  • add monotonic Announce/Sync due scheduling
  • add portable frame preparation for Announce, Sync, Follow_Up, Pdelay_Resp and Pdelay_Resp_Follow_Up
  • add send/error accounting

Runtime validation

  • dedicated portable runtime regression suite
  • strict GCC / Clang / MSVC warnings-as-errors coverage
  • test ClockIdentity, validation, reconfigure, scheduler, sequence behavior, two-step timestamps, Pdelay t2/t3 placement and one-step policy

ESP32-P4 adapter

  • refactor the FreeRTOS PTP task into a hardware/transport adapter around the portable runtime
  • preserve EMAC HW TX timestamp -> Sync Follow_Up
  • preserve PdelayReq HW RX t2 and PdelayResp HW TX t3
  • add runtime-safe start / stop / configure / status C API for future GUI or RPC control plane
  • add lock-free live counters and TX failure count
  • harden RX/task/config concurrency
  • keep PTP on CPU0 and separate from deterministic SV hot path

Profile controls

  • complete Kconfig surface for domain, transportSpecific, optional ClockIdentity, port, VLAN/PCP, intervals, Pdelay response, priority1/2, clockClass, clockAccuracy, variance, timeSource and UTC offset
  • defaults remain conservative: class 248, unknown accuracy, 0xFFFF variance, internal oscillator

Safety boundary

  • no GPS/GM certification claim
  • no servo, BMCA, lock/holdover or absolute UTC claim
  • no smpSynch promotion; fail-safe smpSynch=0 remains unchanged

Validation before PR

  • PTP Core strict GCC/Clang/MSVC: green
  • ESP32-P4 PTP-P1.5 non-default profile: green on the control/status bridge revision
  • default ESP32-P4 SMV build: green on the control/status bridge revision

The PR-triggered full C++ CI and final ESP current-head gates are the final merge checks.

@masarray
masarray marked this pull request as ready for review August 11, 2026 13:37
@masarray
masarray merged commit 68c933f into main Aug 11, 2026
20 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5bf427aea7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +452 to +454
void finish_runtime(PtpLabContext& context) {
g_ptp_accept_rx.store(false, std::memory_order_release);
if (context.runtime.has_value()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Quiesce RX callbacks before deleting the PTP task

When ar_ptp_lab_stop() races with an incoming Pdelay request, a callback may already have passed the g_ptp_accept_rx check before this store executes; it can subsequently read context->task_handle and call xTaskNotifyGive() after finish_runtime() clears/deletes that task. The atomic gate does not wait for in-flight callbacks, so stopping or quickly restarting under Pdelay traffic can notify a stale FreeRTOS task handle or access reused context. Unregister/drain the input callback, or otherwise synchronize outstanding callbacks, before clearing the handle and deleting the task.

Useful? React with 👍 / 👎.

Comment on lines +192 to +195
if (options.vlan_id.has_value() &&
(*options.vlan_id == 0U || *options.vlan_id > 4094U)) {
error = "VLAN ID must be 1..4094";
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow priority-tagged VLAN ID 0

For deployments using IEEE 802.1Q priority tagging, VID 0 is valid and was accepted by the previous PTP configuration, but this validation now rejects it and the matching Kconfig range starts at 1. Existing vlan_id=0 profiles therefore cannot be reconfigured and are forced onto a real VLAN such as the new default 100; reject the reserved VID 4095 while preserving VID 0.

Useful? React with 👍 / 👎.

Comment on lines +127 to +130
const std::string configured_identity{CONFIG_AR_PTP_CLOCK_IDENTITY};
if (!configured_identity.empty()) {
ar::iec61850::time_sync::PtpClockIdentity parsed{};
if (try_parse_ptp_clock_identity(configured_identity, parsed)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject malformed ClockIdentity overrides

When CONFIG_AR_PTP_CLOCK_IDENTITY is nonempty but malformed, the failed parse is silently ignored, leaving clock_identity_override false and causing the firmware to transmit with a MAC-derived identity instead of reporting the configuration error. This makes a typo produce a valid but unintended on-wire clock identity; preserve the parse failure and reject the selected profile, or at minimum surface an explicit startup error.

Useful? React with 👍 / 👎.

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