netutils/ptpd: Add egress latency compensation for TX timestamps.

The frame leaves the MAC later than the moment its hardware transmit
timestamp is latched, because of the clock domain crossing and the PHY.
This fixed delay is the egressLatency port parameter of IEEE 1588.

Add the configured latency to every hardware transmit timestamp
obtained through MSG_ERRQUEUE, the counterpart of the ingress
compensation.

- Add CONFIG_NETUTILS_PTPD_EGRESS_LATENCY_NS (default 0, which applies
  no compensation).
- Add the -O option to override it at run time.
- Add egress_latency_ns to struct ptpd_config_s.

Software timestamps are not affected.

Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
This commit is contained in:
Daniel P. Carvalho 2026-09-19 15:45:39 -03:00 • committed by Xiang Xiao
parent dd35d76edd
commit c78e4d69ea
4 changed files with 38 additions and 1 deletions

View file

@ -165,6 +165,7 @@ static void usage(FAR const char *progname)
" -i [dev] interface device to use, for example 'eth0'\n"
" -p [dev] clock device to use\n"
" -I [ns] hardware RX timestamp latency to compensate\n"
" -O [ns] hardware TX timestamp latency to compensate\n"
" -t [pid] look the status of ptp daemon\n"
" -d [pid] stop ptp daemon\n",
progname);
@ -197,8 +198,13 @@ int main(int argc, FAR char *argv[])
config.bmca = false;
config.af = AF_INET;
config.ingress_latency_ns = CONFIG_NETUTILS_PTPD_INGRESS_LATENCY_NS;
#ifdef CONFIG_NET_TIMESTAMP
config.egress_latency_ns = CONFIG_NETUTILS_PTPD_EGRESS_LATENCY_NS;
#else
config.egress_latency_ns = 0;
#endif
while ((option = getopt(argc, argv, "p:i:t:d:I:rs246BEHSP")) != ERROR)
while ((option = getopt(argc, argv, "p:i:t:d:I:O:rs246BEHSP")) != ERROR)
{
switch (option)
{
@ -256,6 +262,9 @@ int main(int argc, FAR char *argv[])
case 'I':
config.ingress_latency_ns = atoi(optarg);
break;
case 'O':
config.egress_latency_ns = atoi(optarg);
break;
case 'r':
config.clock = "realtime";
break;