SatCat5
cfgbus_mdio.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 // ConfigBus MDIO interface
6 
7 #pragma once
8 
9 #include <satcat5/cfgbus_core.h>
10 #include <satcat5/polling.h>
11 #include <satcat5/types.h>
12 
13 // Set default buffer size
14 #ifndef SATCAT5_MDIO_BUFFSIZE
15 #define SATCAT5_MDIO_BUFFSIZE 8
16 #endif
17 
18 namespace satcat5 {
19  namespace cfg {
23  public:
24  virtual void mdio_done(u16 regaddr, u16 regval) = 0;
25  protected:
26  ~MdioEventListener() {}
27  };
28 
31  void mdio_done(u16 regaddr, u16 regval) override;
32  };
33 
38  class Mdio final : public satcat5::poll::Always {
39  public:
41  Mdio(satcat5::cfg::ConfigBus* cfg, unsigned devaddr,
42  unsigned regaddr = satcat5::cfg::REGADDR_ANY);
43  ~Mdio() {}
44 
47  inline bool can_read() const
48  {return m_addr_rdcount < SATCAT5_MDIO_BUFFSIZE;}
49 
52  bool direct_write(unsigned phy, unsigned reg, unsigned data);
53 
58  bool direct_read(unsigned phy, unsigned reg, unsigned ref,
60 
61  protected:
62  // Poll hardware status.
63  void poll_always();
64 
65  // Internal accessors.
66  u32 hw_rd_status();
67  bool hw_wr_command(u32 cmd);
68 
69  // Control register address.
70  satcat5::cfg::Register m_ctrl_reg;
71 
72  // Queue for read callbacks and associated metadata.
73  unsigned m_addr_rdcount;
74  unsigned m_addr_rdidx;
75  u16 m_addr_buff[SATCAT5_MDIO_BUFFSIZE];
76  satcat5::cfg::MdioEventListener* m_callback[SATCAT5_MDIO_BUFFSIZE];
77  };
78 
83  class MdioWrapper {
84  public:
86  MdioWrapper(satcat5::cfg::Mdio* mdio, unsigned phyaddr)
87  : m_mdio(mdio), m_phy(phyaddr) {}
88 
91  virtual bool write(unsigned reg, unsigned data) = 0;
92  virtual bool read(unsigned reg, satcat5::cfg::MdioEventListener* callback) = 0;
94 
95  protected:
96  // Restricted access avoids need for virtual destructor.
97  ~MdioWrapper() {}
98 
99  // Parameters for the wrapped interface.
100  satcat5::cfg::Mdio* const m_mdio;
101  const unsigned m_phy;
102  };
103 
106  public:
108  bool write(unsigned reg, unsigned data) override;
109  bool read(unsigned reg, satcat5::cfg::MdioEventListener* callback) override;
110  };
111 
113  class MdioMarvell final : public satcat5::cfg::MdioWrapper {
114  public:
116  bool write(unsigned reg, unsigned data) override;
117  bool read(unsigned reg, satcat5::cfg::MdioEventListener* callback) override;
118  };
119  }
120 }
ConfigBus core definitions.
const unsigned REGADDR_ANY
Shortcut for don't-care register address.
Definition: cfgbus_core.h:51
Generic ConfigBus API.
Definition: cfgbus_core.h:124
Prototype for the cfg::Mdio callback interface.
Definition: cfgbus_mdio.h:22
MMD standard (e.g., Atheros AR8031, Texas Instruments DP83867).
Definition: cfgbus_mdio.h:105
bool write(unsigned reg, unsigned data) override
Read and write methods allow indirect access.
Definition: cfgbus_mdio.cc:119
bool read(unsigned reg, satcat5::cfg::MdioEventListener *callback) override
Read and write methods allow indirect access.
Definition: cfgbus_mdio.cc:131
Interface object for a "cfgbus_mdio" block (direct registers only).
Definition: cfgbus_mdio.h:38
bool can_read() const
Is there space in the callback queue? (Note: Reads may still fail if hardware queue is full....
Definition: cfgbus_mdio.h:47
bool direct_write(unsigned phy, unsigned reg, unsigned data)
Direct write to designated MDIO register.
Definition: cfgbus_mdio.cc:49
Mdio(satcat5::cfg::ConfigBus *cfg, unsigned devaddr, unsigned regaddr=satcat5::cfg::REGADDR_ANY)
Constructor ties this driver to a ConfigBus address.
Definition: cfgbus_mdio.cc:34
bool direct_read(unsigned phy, unsigned reg, unsigned ref, satcat5::cfg::MdioEventListener *callback)
Direct read from designated MDIO register.
Definition: cfgbus_mdio.cc:55
void poll_always()
Child class MUST override this method.
Definition: cfgbus_mdio.cc:43
Example MdioEventListener that writes to the system log.
Definition: cfgbus_mdio.h:30
Marvell Alaska 88E1111 or 88E151x.
Definition: cfgbus_mdio.h:113
bool write(unsigned reg, unsigned data) override
Read and write methods allow indirect access.
Definition: cfgbus_mdio.cc:144
bool read(unsigned reg, satcat5::cfg::MdioEventListener *callback) override
Read and write methods allow indirect access.
Definition: cfgbus_mdio.cc:151
Helper class for indirect access register access.
Definition: cfgbus_mdio.h:83
virtual bool read(unsigned reg, satcat5::cfg::MdioEventListener *callback)=0
Read and write methods allow indirect access.
MdioWrapper(satcat5::cfg::Mdio *mdio, unsigned phyaddr)
Public constructor so we can inherit cleanly.
Definition: cfgbus_mdio.h:86
virtual bool write(unsigned reg, unsigned data)=0
Read and write methods allow indirect access.
Pointer-like wrapper for one or more ConfigBus registers.
Definition: cfgbus_core.h:76
An "Always" object is polled whenever service() is called.
Definition: polling.h:96
Core event-processing loop for SatCat5 software.
Basic type aliases and prototypes used throughout SatCat5.