5bd1a20e43
- As TimeReceiver in ptp.mode hybrid: Delay_Req unicast to the GM (IP
from its Announce, MAC recorded by the RX hook from its Sync frames),
unicastFlag set.
- As TimeTransmitter: a Delay_Req with the unicastFlag gets a unicast
Delay_Resp; multicast requests get multicast replies.
- EMAC timestamps every received frame (en_ts4all): its PTP filter left
unicast Delay_Req unstamped ("no HW RX timestamp").
- A unicast Delay_Resp's logMessageInterval 0x7F is ignored (use
ptp.log_delay_req); log_us() clamps to -7..6 (the shift was undefined).
- Verified vs ptp4l --hybrid_e2e 1: board hybrid TimeReceiver 18
Delay_Req in 20 s, all answered, locked; board TimeTransmitter
(p1 100): tcpdump shows Sync/Follow_Up/Announce to 224.0.1.129,
Delay_Req 192.168.192.233 -> .244 [unicast] and Delay_Resp .244 ->
.233 [unicast] within 0.4 ms; ptp4l s2.
- Docs: TimeTransmitter/hybrid notes; step 6 ticked.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.6 KiB
C
34 lines
1.6 KiB
C
// EMAC IEEE 1588 clock and hardware timestamps for PTP over UDP/IPv4.
|
|
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#include "esp_eth_driver.h"
|
|
#include "esp_eth_mac.h"
|
|
#include "esp_netif.h"
|
|
|
|
#define PTP_MSG_SYNC 0x0
|
|
#define PTP_MSG_DELAY_REQ 0x1
|
|
#define PTP_MSG_FOLLOW_UP 0x8
|
|
#define PTP_MSG_DELAY_RESP 0x9
|
|
#define PTP_MSG_ANNOUNCE 0xB
|
|
|
|
// Start the EMAC PTP clock, enable IPv4/UDP timestamping and hook the RX path.
|
|
esp_err_t ptp_hw_init(esp_eth_handle_t eth, esp_netif_t *netif);
|
|
// Hardware RX timestamp of an event message (UDP port 319), looked up by type,
|
|
// sequence ID and sourcePortIdentity (10 bytes). Each record is returned once.
|
|
bool ptp_hw_rx_ts(uint8_t msg_type, uint16_t seq, const uint8_t *src_port_id, eth_mac_time_t *ts);
|
|
// Same, also returning the sender's Ethernet MAC (for unicast replies as raw frames). src_mac may be NULL.
|
|
bool ptp_hw_rx_ts_mac(uint8_t msg_type, uint16_t seq, const uint8_t *src_port_id, eth_mac_time_t *ts,
|
|
uint8_t src_mac[6]);
|
|
esp_err_t ptp_hw_get_time(eth_mac_time_t *t);
|
|
// Frequency correction relative to the nominal rate, in ppb (positive = faster).
|
|
esp_err_t ptp_hw_adj_freq(double ppb);
|
|
// Step the clock back by offset_ns (offset = local - GM), via read + write.
|
|
esp_err_t ptp_hw_step(int64_t offset_ns);
|
|
// Send a PTP event message as a raw Ethernet/IPv4/UDP frame (port 319 -> 319) and return its
|
|
// hardware TX timestamp. dst_ip/dst_mac: 224.0.1.129 / 01:00:5e:00:01:81 or the GM unicast.
|
|
esp_err_t ptp_hw_send_event(const uint8_t dst_mac[6], uint32_t dst_ip, uint8_t dscp,
|
|
const uint8_t *msg, size_t len, eth_mac_time_t *tx_ts);
|