22 uint32_t interruptEnable;
23 uint32_t interruptTest;
68 ConfigurationMSBFirst = 1u << 29,
76 ConfigurationClockPhase = 1u << 30,
82 ConfigurationClockPolarity = 1u << 31,
89 ControlTransmitClear = 1 << 0,
91 ControlReceiveClear = 1 << 1,
97 ControlTransmitEnable = 1 << 2,
102 ControlReceiveEnable = 1 << 3,
107 ControlTransmitWatermarkMask = 0xf << 4,
112 ControlReceiveWatermarkMask = 0xf << 8,
163 void init(
const bool ClockPolarity,
164 const bool ClockPhase,
166 const uint16_t HalfClockPeriod)
volatile
168 configuration = (ClockPolarity ? ConfigurationClockPolarity : 0) |
169 (ClockPhase ? ConfigurationClockPhase : 0) |
170 (MsbFirst ? ConfigurationMSBFirst : 0) |
187 Debug::Assert(len <= 0x7ff,
188 "You can't transfer more than 0x7ff bytes at a time.");
195 uint32_t transmitAvailable = 0;
196 for (uint32_t i = 0; i < len; ++i)
198 if (transmitAvailable == 0)
200 while (transmitAvailable < 64)
219 void blocking_read(uint8_t data[], uint16_t len)
volatile
221 Debug::Assert(len <= 0x7ff,
222 "You can't receive more than 0x7ff bytes at a time.");
223 len &= StartByteCountMask;
225 control = ControlReceiveEnable;
228 for (uint32_t i = 0; i < len; ++i)
231 while ((status & StatusRxFifoLevel) == 0) {}
232 data[i] =
static_cast<uint8_t
>(receiveFifo);
C++ APIs for assertions, invariants, and writing formatted debug messages to a UART.
A Simple Driver for the Sonata's SPI.
@ StartByteCountMask
Number of bytes to receive/transmit in the SPI operation.
static constexpr bool DebugSonataSpi
Flag set when we're debugging this driver.
uint32_t configuration
Configuration register.
uint32_t receiveFifo
Data from the receive FIFO.
@ StatusTxFifoLevel
Number of items in the transmit FIFO.
@ StatusRxFifoEmpty
When set the receive FIFO is empty and any data read from it will be undefined.
@ StatusRxFifoLevel
Number of items in the receive FIFO.
@ StatusIdle
When set the SPI block is idle and can accept a new start command.
@ StatusTxFifoFull
When set the transmit FIFO is full and any data written to it will be ignored.
void init(const bool ClockPolarity, const bool ClockPhase, const bool MsbFirst, const uint16_t HalfClockPeriod) volatile
Initialises the SPI block.
@ ControlTransmitEnable
When set bytes from the transmit FIFO are sent.
void wait_idle() volatile
Waits for the SPI device to become idle.
uint32_t status
Status information about the SPI block.
uint32_t transmitFifo
Bytes written here are pushed to the transmit FIFO.
@ ConfigurationHalfClockPeriodMask
The length of a half period (i.e.
uint32_t interruptState
The Sonata SPI block doesn't currently have support for interrupts.
void blocking_write(const uint8_t data[], uint16_t len) volatile
Sends len bytes from the given data buffer, where len is at most 0x7ff.
ConditionalDebug< DebugSonataSpi, "Sonata SPI"> Debug
Helper for conditional debug logs and assertions.
uint32_t start
Writes to this begin an SPI operation.
uint32_t control
Controls the operation of the SPI block.