SatCat5
port_mailmap.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 // Driver for the internal "MailMap" Ethernet port.
6 
7 #pragma once
8 
9 #include <satcat5/cfgbus_interrupt.h>
10 #include <satcat5/io_readable.h>
11 #include <satcat5/io_writeable.h>
12 #include <satcat5/ptp_interface.h>
13 
14 // Size of the memory-map defined in port_mailmap.vhd
15 #define SATCAT5_MAILMAP_BYTES 1600
16 
17 namespace satcat5 {
18  namespace port {
31  class Mailmap
32  : public satcat5::io::Readable
33  , public satcat5::io::Writeable
35  , protected satcat5::cfg::Interrupt
36  {
37  public:
39  Mailmap(satcat5::cfg::ConfigBusMmap* cfg, unsigned devaddr);
40 
41  // Writeable / Readable API
42  unsigned get_write_space() const override;
43  void write_bytes(unsigned nbytes, const void* src) override;
44  void write_abort() override;
45  bool write_finalize() override;
46  unsigned get_read_ready() const override;
47  bool read_bytes(unsigned nbytes, void* dst) override;
48  void read_finalize() override;
49 
50  // Implement the ptp::Interface API.
51  // (Requires CFG_CLK_HZ and VCONFIG to be set in the HDL.)
58 
62  { return m_clock_reg; }
63 
64  protected:
65  // Internal event-handlers.
66  void write_next(u8 data) override;
67  void write_overflow() override;
68  void read_underflow() override;
69  u8 read_next() override;
70  void irq_event() override;
71 
72  // Hardware register map:
73  struct ctrl_reg {
74  u8 rx_buff[SATCAT5_MAILMAP_BYTES]; // Reg 0-399
75  u32 rx_rsvd[106]; // Reg 400-505
76  volatile u32 rx_ptp_time[4]; // Reg 506-509
77  volatile u32 rx_irq; // Reg 510
78  volatile u32 rx_ctrl; // Reg 511
79  u8 tx_buff[SATCAT5_MAILMAP_BYTES]; // Reg 512-911
80  u32 tx_rsvd[100]; // Reg 912-1011
81  volatile u32 rt_clk_ctrl[6]; // Reg 1012-1017
82  volatile u32 tx_ptp_time[4]; // Reg 1018-1021
83  volatile u32 ptp_status; // Reg 1022
84  volatile u32 tx_ctrl; // Reg 1023
85  };
86  ctrl_reg* const m_ctrl;
87  satcat5::cfg::Register m_clock_reg;
88 
89  // Internal state.
90  unsigned m_wridx; // Current write-index in transmit buffer
91  unsigned m_wrovr; // Transmit buffer overflow?
92  unsigned m_rdidx; // Current read-index in receive buffer
93  unsigned m_rdlen; // Length of frame in receive buffer
94  unsigned m_rdovr; // Receive buffer underflow?
95  };
96 
102  public:
104  MailmapAligned(satcat5::cfg::ConfigBusMmap* cfg, unsigned devaddr);
105 
106  // Override behavior of specific API methods.
107  void write_bytes(unsigned nbytes, const void* src) override;
108  bool read_bytes(unsigned nbytes, void* dst) override;
109 
110  protected:
111  // Override behavior of specific API methods.
112  void write_next(u8 data) override;
113  u8 read_next() override;
114 
115  // Accumulator for partial writes in progress.
116  u32 m_wrtmp;
117  };
118  }
119 }
Memory-mapped local ConfigBus.
Definition: cfgbus_core.h:199
Event-handler for individual ConfigBus interrupts.
Pointer-like wrapper for one or more ConfigBus registers.
Definition: cfgbus_core.h:76
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Alternate MailMap driver using word-aligned access only.
Definition: port_mailmap.h:101
u8 read_next() override
Read the next byte from the underlying buffer or device.
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
void write_bytes(unsigned nbytes, const void *src) override
Write 0 or more bytes from a buffer.
MailmapAligned(satcat5::cfg::ConfigBusMmap *cfg, unsigned devaddr)
Constructor links this driver to a ConfigBus address.
bool read_bytes(unsigned nbytes, void *dst) override
Read 0 or more bytes into a buffer.
Driver for the internal "MailMap" Ethernet port.
Definition: port_mailmap.h:36
void write_overflow() override
Optional error handling for write overflow.
Definition: port_mailmap.cc:74
void read_underflow() override
Optional error handling for read underflow.
satcat5::io::Readable * ptp_rx_read() override
Return an object suitable for reading the next PTP frame.
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
unsigned get_read_ready() const override
How many bytes can be read without blocking?
satcat5::ptp::Time ptp_tx_start() override
Begin sending a timestamped message.
u8 read_next() override
Read the next byte from the underlying buffer or device.
satcat5::ptp::Time ptp_tx_timestamp() override
Return timestamp of the most recent outgoing message.
void irq_event() override
Interrupt service routine.
satcat5::cfg::Register ptp_clock_reg() const
Control register for creating a cfg::PtpRealtime object.
Definition: port_mailmap.h:61
void write_abort() override
If possible, abort the current partially-written packet.
Definition: port_mailmap.cc:79
bool write_finalize() override
Mark end of frame and release temporary working data.
Definition: port_mailmap.cc:85
void read_finalize() override
Consume any remaining bytes in this frame, if applicable.
satcat5::io::Writeable * ptp_tx_write() override
Return an object suitable for writing the next PTP frame.
unsigned get_write_space() const override
How many bytes can be written without blocking?
Definition: port_mailmap.cc:55
void write_bytes(unsigned nbytes, const void *src) override
Write 0 or more bytes from a buffer.
Definition: port_mailmap.cc:65
Mailmap(satcat5::cfg::ConfigBusMmap *cfg, unsigned devaddr)
Constructor links this driver to a ConfigBus address.
Definition: port_mailmap.cc:42
bool read_bytes(unsigned nbytes, void *dst) override
Read 0 or more bytes into a buffer.
satcat5::ptp::Time ptp_rx_timestamp() override
Return timestamp of the current incoming message.
satcat5::ptp::Time ptp_time_now() override
Return the best available estimate of the current time.
Generic API for network ports that support PTP.
Definition: ptp_interface.h:27
High-precision timestamp for use with PTP / IEEE1588.
Definition: ptp_time.h:41
"Readable" I/O interface core definitions
"Writeable" I/O interface core definitions