|
SatCat5
|
Interface driver for the cfgbus_spi_controller block.
An SPI Controller is the device that drives the CS and SCK signals of a four-wire or three-wire SPI bus. This driver operates the controller block defined in "cfgbus_spi_controller.vhd".
The configure() method sets the baud-rate and SPI mode. This method should only be called when the bus is idle. The mode parameter is defined in the SPI specification and sets the clock-polarity (CPOL) and clock-phase (CPHA) options.
For more information on the SPI bus: https://en.wikipedia.org/wiki/Serial_Peripheral_Interface
Definition at line 41 of file cfgbus_spi.h.
#include <cfgbus_spi.h>
Public Member Functions | |
| Spi (ConfigBus *cfg, unsigned devaddr) | |
| Link driver to a specific ConfigBus address. | |
| void | configure (unsigned clkref_hz, unsigned baud_hz, unsigned mode=3) |
| Configure or reconfigure the SPI controller. | |
| bool | busy () override |
| Is the SPI controller currently busy? | |
| bool | exchange (u8 devidx, const u8 *wrdata, u8 rwbytes, satcat5::cfg::SpiEventListener *callback=0) override |
| Queue a bus transaction that reads and writes concurrently. | |
| bool | query (u8 devidx, const u8 *wrdata, u8 wrbytes, u8 rdbytes, satcat5::cfg::SpiEventListener *callback=0) override |
| Queue a bus transation that reads, then writes. 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 | |
| void | read_done (unsigned cidx) |
| 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::SpiEventListener * | m_callback [SATCAT5_SPI_MAXCMD] |
| u8 | m_txbuff [SATCAT5_SPI_TXBUFF] |
| u8 | m_rxbuff [SATCAT5_SPI_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::Interrupt * | m_next |
| bool | m_idle |
|
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.
|
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.
|
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.
|
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.
|
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.
|
privatevirtualinherited |
Interrupt service routine.
(Child class must override this method.)
Implements satcat5::cfg::Interrupt.
Definition at line 108 of file cfgbus_multiserial.cc.
|
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.
|
overridevirtual |
Queue a bus transation that reads, then writes.
Note that read-length or write-length may be zero.
Implements satcat5::cfg::SpiGeneric.
Definition at line 69 of file cfgbus_spi.cc.
|
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.
| cidx | Command index (for child class to retrieve metadata). (Child MUST override this method.) |
Implements satcat5::cfg::MultiSerial.
Definition at line 93 of file cfgbus_spi.cc.
|
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.
|
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.
Definition at line 74 of file cfgbus_multiserial.cc.