SatCat5
satcat5::cfg::I2c Class Reference

Detailed Description

Interace driver for "cfgbus_i2c_controller".

This driver is designed for high-throughput, for example writing large blocks of data to I2C-controlled OLED displays. As such, it has a relatively large transmit queue, to ensure throughput can be maintained without buffer underruns.

Definition at line 33 of file cfgbus_i2c.h.

#include <cfgbus_i2c.h>

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

Public Member Functions

 I2c (satcat5::cfg::ConfigBus *cfg, unsigned devaddr)
 Constructor links to specified ConfigBus address.
 
void configure (unsigned refclk_hz, unsigned baud_hz, bool clock_stretch=true)
 Configure the I2C controller.
 
bool busy () override
 Is the I2C controller currently busy?
 
bool read (const satcat5::util::I2cAddr &devaddr, u8 regbytes, u32 regaddr, u8 nread, satcat5::cfg::I2cEventListener *callback=0) override
 Add a read operation to the queue. More...
 
bool write (const satcat5::util::I2cAddr &devaddr, u8 regbytes, u32 regaddr, u8 nwrite, const u8 *data, satcat5::cfg::I2cEventListener *callback=0) override
 Add a write operation to the queue. More...
 
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

bool enqueue_cmd (const satcat5::util::I2cAddr &devaddr, u8 regbytes, u32 regaddr, u8 nwrite, const u8 *data, u8 nread, satcat5::cfg::I2cEventListener *callback=0)
 
void read_done (unsigned idx)
 Callback when each transaction is finished. 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 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::I2cEventListenerm_callback [SATCAT5_I2C_MAXCMD]
 
u16 m_devaddr [SATCAT5_I2C_MAXCMD]
 
u32 m_regaddr [SATCAT5_I2C_MAXCMD]
 
u8 m_txbuff [SATCAT5_I2C_TXBUFF]
 
u8 m_rxbuff [SATCAT5_I2C_RXBUFF]
 
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
 

Member Function Documentation

◆ data_rcvd()

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

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 ( )
privatevirtualinherited

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 ( )
privatevirtualinherited

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()

bool satcat5::cfg::I2c::read ( const satcat5::util::I2cAddr devaddr,
u8  regbytes,
u32  regaddr,
u8  nread,
satcat5::cfg::I2cEventListener callback = 0 
)
overridevirtual

Add a read operation to the queue.

Returns
True if successful.

Implements satcat5::cfg::I2cGeneric.

Definition at line 53 of file cfgbus_i2c.cc.

◆ read_done()

void satcat5::cfg::I2c::read_done ( unsigned  cidx)
protectedvirtual

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.)

Implements satcat5::cfg::MultiSerial.

Definition at line 146 of file cfgbus_i2c.cc.

◆ 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()

bool satcat5::cfg::I2c::write ( const satcat5::util::I2cAddr devaddr,
u8  regbytes,
u32  regaddr,
u8  nwrite,
const u8 *  data,
satcat5::cfg::I2cEventListener callback = 0 
)
overridevirtual

Add a write operation to the queue.

Returns
True if successful.

Implements satcat5::cfg::I2cGeneric.

Definition at line 66 of file cfgbus_i2c.cc.

◆ write_finish()

unsigned MultiSerial::write_finish ( )
protectedinherited

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: