SatCat5
satcat5::cfg::MultiSerial Class Referenceabstract

Detailed Description

Partial driver for the multipurpose serial peripheral.

This incomplete driver controls the "cfgbus_multiserial" block in transaction-based protocols, such as I2C and SPI. It handles core functions such as interrupt servicing, and is designed to maintain good throughput, but requires additional logic to implement specific protocols.

See also
cfg::I2c, cfg::Spi.

This driver should not be used for when "cfgbus_multiserial" is used in streaming mode.

See also
cfg::Uart.

Definition at line 24 of file cfgbus_multiserial.h.

#include <cfgbus_multiserial.h>

Inheritance diagram for satcat5::cfg::MultiSerial:
[legend]
Collaboration diagram for satcat5::cfg::MultiSerial:
[legend]

Public Member Functions

u8 get_percent_full () const
 How full is the transmit queue? (0-100%)
 
bool idle () const
 Is the queue empty and the bus idle?
 
void irq_check ()
 Check if this interrupt may need service. More...
 
void irq_enable ()
 Enable this interrupt. More...
 
void irq_disable ()
 Temporarily disable this interrupt. More...
 
void request_poll ()
 Call this method to request polling at a later time. More...
 
void request_cancel ()
 Call this method to cancel a previous request_poll().
 

Static Public Member Functions

static unsigned count_ondemand ()
 Count queued objects of this type (i.e., non-idle).
 

Protected Member Functions

 MultiSerial (satcat5::cfg::ConfigBus *cfg, unsigned devaddr, unsigned maxpkt, u8 *txbuff, unsigned txsize, u8 *rxbuff, unsigned rxsize)
 Set all parameters for this Multiserial instance. More...
 
bool write_check (unsigned ncmd, unsigned nread)
 Is there enough space in the software queue? If it returns true, write each opcode and then call write_finish().
 
unsigned write_finish ()
 Enqueue transaction after calling write_check(). More...
 
virtual void read_done (unsigned cidx)=0
 Callback when each transaction is finished. More...
 
virtual void data_unlink (satcat5::io::Readable *src)
 Unlink this EventListener from the designated source, because the designated Readable object is being destroyed. More...
 

Protected Attributes

satcat5::cfg::Register m_ctrl
 
satcat5::io::PacketBuffer m_tx
 Buffer for hardware commands.
 
satcat5::io::PacketBuffer m_rx
 Buffer for reply data.
 

Static Protected Attributes

static const unsigned REGADDR_IRQ = 0
 
static const unsigned REGADDR_CFG = 1
 
static const unsigned REGADDR_STATUS = 2
 
static const unsigned REGADDR_DATA = 3
 

Private Member Functions

void data_rcvd (satcat5::io::Readable *src) override
 The data_rcvd() callback is polled whenever data is available. More...
 
void irq_event ()
 Interrupt service routine. More...
 
void poll_demand ()
 Deferred event handler, called after request(). More...
 

Private Attributes

unsigned const m_cmd_max
 
unsigned m_cmd_cbidx
 
unsigned m_cmd_queued
 
unsigned m_new_wralloc
 
unsigned m_new_rdalloc
 
unsigned m_rdalloc
 
unsigned m_irq_wrrem
 
unsigned m_irq_rdrem
 
satcat5::cfg::ConfigBus *const m_cfg
 
satcat5::cfg::Interruptm_next
 
bool m_idle
 

Constructor & Destructor Documentation

◆ MultiSerial()

MultiSerial::MultiSerial ( satcat5::cfg::ConfigBus cfg,
unsigned  devaddr,
unsigned  maxpkt,
u8 *  txbuff,
unsigned  txsize,
u8 *  rxbuff,
unsigned  rxsize 
)
protected

Set all parameters for this Multiserial instance.

(Only children should create or destroy base class.)

Definition at line 32 of file cfgbus_multiserial.cc.

Member Function Documentation

◆ data_rcvd()

void MultiSerial::data_rcvd ( satcat5::io::Readable src)
overrideprivatevirtual

The data_rcvd() callback is polled whenever data is available.

A pointer is provided to assist handlers with multiple sources. Child objects of io::EventListener MUST override this method.

Implements satcat5::io::EventListener.

Definition at line 94 of file cfgbus_multiserial.cc.

◆ data_unlink()

virtual void satcat5::io::EventListener::data_unlink ( satcat5::io::Readable src)
inlinevirtualinherited

Unlink this EventListener from the designated source, because the designated Readable object is being destroyed.

Child objects of io::EventListener MAY override this method if action is required.

Reimplemented in satcat5::io::Override, satcat5::io::MuxUp, satcat5::io::MuxDown, satcat5::io::BufferedPackets, satcat5::io::BufferedStream, satcat5::io::BufferedCopy, satcat5::eth::SwitchLogReader, satcat5::eth::Dispatch, satcat5::ccsds_spp::Dispatch, satcat5::ccsds_aos::Dispatch, satcat5::ccsds_aos::Channel, satcat5::test::MockOffload::Port, and satcat5::freertos::MessageCopy.

Definition at line 54 of file io_readable.h.

◆ irq_check()

void Interrupt::irq_check ( )
inherited

Check if this interrupt may need service.

If the interrupt needs service, this calls irq_event.

Definition at line 46 of file cfgbus_interrupt.cc.

◆ irq_disable()

void Interrupt::irq_disable ( )
inherited

Temporarily disable this interrupt.

Interrupts are enabled by default, but some peripherals may wish to temporary toggle this setting. For use with standard "cfgbus_interrupt" only.

Definition at line 63 of file cfgbus_interrupt.cc.

◆ irq_enable()

void Interrupt::irq_enable ( )
inherited

Enable this interrupt.

Interrupts are enabled by default, but some peripherals may wish to temporary toggle this setting. For use with standard "cfgbus_interrupt" only.

Definition at line 58 of file cfgbus_interrupt.cc.

◆ irq_event()

void MultiSerial::irq_event ( )
privatevirtual

Interrupt service routine.

(Child class must override this method.)

Implements satcat5::cfg::Interrupt.

Definition at line 108 of file cfgbus_multiserial.cc.

◆ poll_demand()

void MultiSerial::poll_demand ( )
privatevirtual

Deferred event handler, called after request().

Child class MUST override this method. (Call "request_poll" to enqueue a callback to this method.)

Implements satcat5::poll::OnDemand.

Definition at line 113 of file cfgbus_multiserial.cc.

◆ read_done()

virtual void satcat5::cfg::MultiSerial::read_done ( unsigned  cidx)
protectedpure virtual

Callback when each transaction is finished.

The child object must reads N+1 bytes m_rx, where the first N bytes are reply data and the last byte is an error flag.

Parameters
cidxCommand index (for child class to retrieve metadata). (Child MUST override this method.)

Implemented in satcat5::cfg::I2c, and satcat5::cfg::Spi.

◆ request_poll()

void satcat5::poll::OnDemand::request_poll ( )
inherited

Call this method to request polling at a later time.

Safe to stack requests, but only one call to poll().

Definition at line 208 of file polling.cc.

◆ write_finish()

unsigned MultiSerial::write_finish ( )
protected

Enqueue transaction after calling write_check().

The child object must call write_check, then write each opcode to the queue (m_tx), then call write_finish.

Returns
The new command-index, to allow storage of additional metadata associated with this command.

Definition at line 74 of file cfgbus_multiserial.cc.


The documentation for this class was generated from the following files: