SatCat5
cfgbus_hdlc.h
1 // Copyright 2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Interface driver for the cfgbus_hdlc block
6 
7 #pragma once
8 
9 #include <satcat5/cfgbus_interrupt.h>
10 #include <satcat5/io_buffer.h>
11 
12 // Default size parameters
13 #ifndef SATCAT5_HDLC_BUFFSIZE
14 #define SATCAT5_HDLC_BUFFSIZE 256
15 #endif
16 
17 #ifndef SATCAT5_HDLC_MAXPKT
18 #define SATCAT5_HDLC_MAXPKT 16 // Each queue up to N packets
19 #endif
20 
21 namespace satcat5 {
22  namespace cfg {
26  class Hdlc
28  , protected satcat5::cfg::Interrupt
29  , protected satcat5::poll::Timer
30  {
31  public:
33  Hdlc(ConfigBus* cfg, unsigned devaddr);
34 
44  void configure(unsigned clkref_hz,
45  unsigned baud_hz,
46  unsigned frame_bytes = 0);
47 
48  private:
49  // Event handlers.
51  void irq_event();
52  void timer_event();
53 
54  // Control registers
56 
57  // Pending end-of-packet marker?
58  bool m_tx_eof;
59 
60  // Raw Tx/Rx working buffers are NOT publicly accessible.
61  u8 m_txbuff[SATCAT5_HDLC_BUFFSIZE];
62  u8 m_rxbuff[SATCAT5_HDLC_BUFFSIZE];
63  };
64  }
65 }
Generic ConfigBus API.
Definition: cfgbus_core.h:124
Interface driver for the cfgbus_hdlc block.
Definition: cfgbus_hdlc.h:30
void irq_event()
Interrupt service routine.
Definition: cfgbus_hdlc.cc:69
void configure(unsigned clkref_hz, unsigned baud_hz, unsigned frame_bytes=0)
Configure the HDLC driver.
Definition: cfgbus_hdlc.cc:37
Hdlc(ConfigBus *cfg, unsigned devaddr)
Initialize this HDLC and link to a specific register bank.
Definition: cfgbus_hdlc.cc:27
void timer_event()
Child class MUST override this method.
Definition: cfgbus_hdlc.cc:88
void data_rcvd(satcat5::io::Readable *src)
The data_rcvd() callback is polled whenever data is available.
Definition: cfgbus_hdlc.cc:47
Event-handler for individual ConfigBus interrupts.
Pointer-like wrapper for one or more ConfigBus registers.
Definition: cfgbus_core.h:76
Extensible transmit and receive buffer.
Definition: io_buffer.h:42
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Timer objects are polled after a fixed delay or at a regular interval.
Definition: polling.h:213
Buffered I/O wrappers for PacketBuffer.