SatCat5
cfgbus_remote.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 // Controller for a remote ConfigBus, connected over network
6 
7 #pragma once
8 
9 #include <satcat5/cfgbus_core.h>
10 #include <satcat5/eth_dispatch.h>
11 #include <satcat5/net_core.h>
12 #include <satcat5/polling.h>
13 #include <satcat5/udp_core.h>
14 
15 namespace satcat5 {
16  namespace cfg {
37  , public satcat5::net::Protocol
38  , public satcat5::poll::Timer
39  {
40  public:
43  satcat5::cfg::IoStatus read(unsigned regaddr, u32& rdval) override;
44  satcat5::cfg::IoStatus write(unsigned regaddr, u32 wrval) override;
46 
49  unsigned regaddr, unsigned count, u32* result) override;
52  unsigned regaddr, unsigned count, u32* result) override;
55  unsigned regaddr, unsigned count, const u32* data) override;
58  unsigned regaddr, unsigned count, const u32* data) override;
59 
61  void set_timeout_rd(unsigned usec) {m_timeout_rd = usec;}
63  void set_timeout_wr(unsigned usec) {m_timeout_wr = usec;}
64 
66  void set_irq_polling(unsigned msec) {timer_every(msec);}
67 
68  protected:
72  satcat5::net::Address* dst, // Remote iface + address
73  const satcat5::net::Type& ack); // Ack type parameter
74  ~ConfigBusRemote() SATCAT5_OPTIONAL_DTOR;
75 
76  // Callback for incoming reply frames.
77  void frame_rcvd(satcat5::io::LimitedRead& src) override;
78 
79  // Callback for timer events.
80  void timer_event() override;
81 
83  satcat5::cfg::IoStatus send_and_wait(
84  u8 opcode, unsigned addr,
85  unsigned len, const u32* ptr, unsigned timeout);
86 
88  bool send_command(
89  u8 opcode, unsigned addr,
90  unsigned len, const u32* ptr);
91 
93  satcat5::cfg::IoStatus wait_response(unsigned timeout);
94 
96  satcat5::net::Address* const m_dst;
97 
98  // Timer for measuring timeouts.
99  unsigned m_timeout_rd;
100  unsigned m_timeout_wr;
101 
102  // Stored state for pending responses.
103  u32 m_status;
104  u8 m_sequence;
105  u8 m_response_opcode;
106  u32* m_response_ptr;
107  unsigned m_response_len;
108  satcat5::cfg::IoStatus m_response_status;
109  };
110  }
111 
112  namespace eth {
113  // Remote ConfigBus operation over Ethernet.
114  class ConfigBus final
117  {
118  public:
119  ConfigBus(satcat5::eth::Dispatch* iface); // Network interface
120 
121  void connect(const satcat5::eth::MacAddr& dst);
122 
123  inline void close() {m_addr.close();}
124  inline bool ready() const {return m_addr.ready();}
125  };
126  }
127 
128  namespace udp {
129  // Remote ConfigBus operation over UDP.
130  class ConfigBus final
133  {
134  public:
135  explicit ConfigBus(
136  satcat5::udp::Dispatch* udp); // UDP interface
137 
138  void connect(
139  const satcat5::ip::Addr& dstaddr); // Remote address
140 
141  inline void close() {m_addr.close();}
142  inline bool ready() const {return m_addr.ready();}
143  };
144  }
145 }
ConfigBus core definitions.
IoStatus
Status codes for ConfigBus read/write operations.
Definition: cfgbus_core.h:99
Generic ConfigBus API.
Definition: cfgbus_core.h:124
Controller for a remote ConfigBus, connected over network.
Definition: cfgbus_remote.h:39
satcat5::cfg::IoStatus read_array(unsigned regaddr, unsigned count, u32 *result) override
Bulk read from consecutive registers.
satcat5::cfg::IoStatus write_repeat(unsigned regaddr, unsigned count, const u32 *data) override
Repeated write to the same register.
void set_timeout_rd(unsigned usec)
Adjust read timeout (0 = Non-blocking).
Definition: cfgbus_remote.h:61
satcat5::net::Address *const m_dst
MAC address for the remote interface.
Definition: cfgbus_remote.h:96
satcat5::cfg::IoStatus wait_response(unsigned timeout)
Busywait until response is received.
void timer_event() override
Child class MUST override this method.
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
void set_irq_polling(unsigned msec)
Adjust polling rate for interrupt status (0 = None).
Definition: cfgbus_remote.h:66
void set_timeout_wr(unsigned usec)
Adjust write timeout (0 = Non-blocking).
Definition: cfgbus_remote.h:63
bool send_command(u8 opcode, unsigned addr, unsigned len, const u32 *ptr)
Send the specified opcode.
satcat5::cfg::IoStatus read_repeat(unsigned regaddr, unsigned count, u32 *result) override
Repeated read from the same register.
satcat5::cfg::IoStatus send_and_wait(u8 opcode, unsigned addr, unsigned len, const u32 *ptr, unsigned timeout)
Send, then wait if requested.
ConfigBusRemote(satcat5::net::Address *dst, const satcat5::net::Type &ack)
Create a link to the designated remote address, with commands and replies routed through the designat...
satcat5::cfg::IoStatus write(unsigned regaddr, u32 wrval) override
Basic read and write operations (ConfigBus API).
satcat5::cfg::IoStatus write_array(unsigned regaddr, unsigned count, const u32 *data) override
Bulk write to consecutive registers.
satcat5::cfg::IoStatus read(unsigned regaddr, u32 &rdval) override
Basic read and write operations (ConfigBus API).
Inheritable container for a eth::Address.
Definition: eth_address.h:60
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
Defines a generic API for sending data to a specific destination, such as a MAC address,...
Definition: net_address.h:30
A net::Protocol is the counterpart to net::Dispatch that handles a particular data stream,...
Definition: net_protocol.h:28
Timer objects are polled after a fixed delay or at a regular interval.
Definition: polling.h:213
void timer_every(unsigned msec)
Configure a repeating notification every X milliseconds.
Definition: polling.cc:321
Inheritable container for a udp::Address.
Definition: udp_core.h:149
Dispatcher sorts incoming UDP messages by port index.
Definition: udp_dispatch.h:20
Generic network Dispatch API.
Core event-processing loop for SatCat5 software.
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15
Multipurpose filter for matching fields in network packets.
Definition: net_type.h:38