SatCat5
sim_router2_offload.h
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Simulate the router2::Offload port's ConfigBus interface.
6 
7 #pragma once
8 
9 #include <hal_test/sim_utils.h>
10 #include <vector>
11 
12 namespace satcat5 {
13  namespace test {
18  public:
20  explicit MockOffload(unsigned devaddr);
21  ~MockOffload();
22 
24  void add_port(
27 
29  void port_shdn(u32 mask_shdn);
30 
31  private:
32  // Helper class representing a single port.
33  class Port final : public satcat5::io::EventListener {
34  public:
35  Port(unsigned index, MockOffload* parent,
38  ~Port();
39 
40  void data_rcvd(satcat5::io::Readable* src) override;
41  void data_unlink(satcat5::io::Readable* src) override;
42  inline u32 port_mask() const {return 1u << m_index;}
43 
44  const unsigned m_index;
45  MockOffload* const m_parent;
46  satcat5::io::Writeable* const m_dst;
47  satcat5::io::Readable* m_src;
48  };
49 
50  // Copy data from the hardware buffer to the designated port(s).
51  void poll_always() override;
52 
53  // If the hardware receive buffer is empty, copy incoming data.
54  bool copy_to_hwbuf(unsigned idx, satcat5::io::Readable* src);
55 
56  friend Port;
57  u32* const m_dev;
58  std::vector<Port*> m_ports;
59  };
60  }
61 }
Event-handler interface for newly received data.
Definition: io_readable.h:43
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
An "Always" object is polled whenever service() is called.
Definition: polling.h:96
Mockup for a memory-mapped ConfigBus.
Definition: sim_utils.h:238
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
Simulate the router2::Offload port's ConfigBus interface.
MockOffload(unsigned devaddr)
Create the mock interface and set ConfigBus device address.
void poll_always() override
Child class MUST override this method.
void add_port(satcat5::io::Writeable *dst, satcat5::io::Readable *src)
Link the next hardware port to a destination and source.
void port_shdn(u32 mask_shdn)
Update the reported port-status flags.
Miscellaneous simulation and test helper functions.