SatCat5
temac.h
1 // Copyright 2021-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Interface wrappers for the Xilinx "Tri Mode Ethernet MAC" block (TEMAC)
6 
7 #pragma once
8 
9 #include <satcat5/interrupts.h>
10 #include <satcat5/pkt_buffer.h>
11 #include <satcat5/ptp_time.h>
12 #include <satcat5/ptp_tracking.h>
13 #include <satcat5/polling.h>
14 
15 namespace satcat5 {
16  namespace ublaze {
18  struct TemacTime {
19  TemacTime() = default;
20  TemacTime(const TemacTime& t) = default;
21  TemacTime& operator=(const TemacTime& t) = default;
22 
23  s64 sec; // Positive or negative
24  u32 nsec; // Always 0 - 999,999,999
25  };
26 
31  class Temac {
32  public:
34  explicit Temac(uintptr_t baseaddr);
35 
36  protected:
37  volatile u32* const m_regs;
38  };
39 
43  public:
45  virtual void tx_sync(const satcat5::ptp::Time& sync_egress) {}
47  virtual void tx_delay_req(const satcat5::ptp::Time& delay_req_egress) {}
48  };
49 
53  class TemacAvb
54  : public satcat5::ublaze::Temac
56  , public satcat5::irq::Handler
57  , public satcat5::poll::Always
59  {
60  public:
62  TemacAvb(uintptr_t baseaddr, int irq_idx);
63 
65  void set_tx_callback(TemacAvbTxCallback* tx_callback);
66 
69 
74  void avb_set_rate(u32 incr);
75 
78  void avb_jump_by(const satcat5::ublaze::TemacTime& delta);
79 
81  void send_frame(const u8* buf, unsigned buflen);
82 
88  const satcat5::ptp::Time& amount) override;
89  void clock_rate(s64 offset) override;
90  satcat5::ptp::Time clock_now() override;
92 
94  static constexpr double CLOCK_SCALE = 0.125 / (1u << 20);
95 
96  private:
97  void irq_event() override;
98  void poll_always() override;
99  void check_frames_waiting();
100 
101  satcat5::io::PacketBuffer m_txbuff; // TODO: Unused, but corrupts RX when removed. WHY?
102  satcat5::io::PacketBuffer m_rxbuff;
103  TemacAvbTxCallback* m_tx_callback;
104  u32 m_prev_buf_idx;
105  u8 m_frames_waiting;
106  u8 m_txrawbuff[2048]; // TODO: see above
107  u8 m_rxrawbuff[2048];
108  };
109  }
110 }
The PacketBuffer class is a wrapper for a circular buffer, with optional logic to support retention o...
Definition: pkt_buffer.h:66
Wrapper class for forwarding reads to another object.
Definition: io_readable.h:299
Parent object for receiving interrupt-handler callbacks.
An "Always" object is polled whenever service() is called.
Definition: polling.h:96
High-precision timestamp for use with PTP / IEEE1588.
Definition: ptp_time.h:41
Generic interface to a numerically-controlled reference clock.
Definition: ptp_tracking.h:52
Xilinx TEMAC with Audio-Video-Bridge (AVB) functionality.
Definition: temac.h:59
static constexpr double CLOCK_SCALE
Scaling factor for use with avb_set_rate.
Definition: temac.h:94
void irq_event() override
Method called whenever an interrupt is triggered.
Definition: temac.cc:150
void avb_set_rate(u32 incr)
Update AVB rate register.
Definition: temac.cc:106
void avb_jump_by(const satcat5::ublaze::TemacTime &delta)
One-time increment of the AVB internal timer.
Definition: temac.cc:113
satcat5::ublaze::TemacTime avb_get_time()
Read current time from the AVB internal timer.
Definition: temac.cc:96
void set_tx_callback(TemacAvbTxCallback *tx_callback)
Register callbacks for transmitted timestamps for PTP packets.
Definition: temac.cc:92
void poll_always() override
Child class MUST override this method.
Definition: temac.cc:180
satcat5::ptp::Time clock_adjust(const satcat5::ptp::Time &amount) override
Clock-adjustment API for ptp::TrackingClock.
Definition: temac.cc:121
void send_frame(const u8 *buf, unsigned buflen)
Send an arbitrary PTP frame with Ethernet header.
Definition: temac.cc:242
void clock_rate(s64 offset) override
Clock-adjustment API for ptp::TrackingClock.
Definition: temac.cc:132
satcat5::ptp::Time clock_now() override
Clock-adjustment API for ptp::TrackingClock.
Definition: temac.cc:144
TemacAvb(uintptr_t baseaddr, int irq_idx)
Initialize the core and link to specified instance.
Definition: temac.cc:70
Defines callback methods for timestamped egress times.
Definition: temac.h:42
virtual void tx_sync(const satcat5::ptp::Time &sync_egress)
Callback for PTP "Sync" messages.
Definition: temac.h:45
virtual void tx_delay_req(const satcat5::ptp::Time &delay_req_egress)
Callback for PTP "Delay request" messages.
Definition: temac.h:47
Basic Xilinx TEMAC functionality.
Definition: temac.h:31
Temac(uintptr_t baseaddr)
Initialize the core and link to specified instance.
Definition: temac.cc:62
Core event-processing loop for SatCat5 software.
High-precision "Time" object for use with PTP / IEEE1588.
Closed-loop time-tracking clocks and tracking control.
Platform-agnostic API for interrupt management.
Timestamp format used by the AVB core.
Definition: temac.h:18