182 return 1 <<
static_cast<uint32_t
>(
Interrupt);
186 enum [[clang::flag_enum]] : uint32_t
212 enum [[clang::flag_enum]] : uint32_t
240 enum [[clang::flag_enum]] : uint32_t
258 enum [[clang::flag_enum]] : uint32_t
274 enum [[clang::flag_enum]] : uint32_t
296 static constexpr uint32_t ReceiveFifoDepth = 8;
316 const uint32_t Res = ((a - 1) / b) + 1;
317 Debug::Assert(Res <= UINT16_MAX,
318 "Division result too large to fit in uint16_t.");
319 return static_cast<uint16_t
>(Res);
334 constexpr uint32_t FieldMask =
365 const uint16_t ClockPeriod = (1000 * 1000) / SystemClockKhz;
368 uint32_t mode = (SpeedKhz > 100u) + (SpeedKhz > 400u);
371 constexpr uint16_t MinimumFallTime = 20 * 3 / 5;
374 constexpr uint16_t MinimumTimeValues[5][2][3] = {
376 {4700u, 1300u, 150u},
381 {MinimumFallTime, MinimumFallTime, MinimumFallTime},
395 {4700u, 1300u, 500u},
400 for (uint32_t i = 0; i < 5; ++i)
409 void blocking_write_byte(
const uint32_t Fmt)
volatile
423 [[nodiscard]]
bool blocking_write(
const uint8_t Addr7,
424 const uint8_t data[],
425 const uint32_t NumBytes,
426 const bool SkipStop)
volatile
433 for (uint32_t i = 0; i < NumBytes - 1; ++i)
435 blocking_write_byte(data[i]);
450 [[nodiscard]]
bool blocking_read(
const uint8_t Addr7,
452 const uint32_t NumBytes)
volatile
454 for (uint32_t idx = 0; idx < NumBytes; idx += ReceiveFifoDepth)
465 uint32_t bytesRemaining = NumBytes - idx;
466 bool lastChunk = ReceiveFifoDepth >= bytesRemaining;
467 uint8_t chunkSize = lastChunk ?
static_cast<uint8_t
>(bytesRemaining)
476 for (uint32_t chunkIdx = 0; chunkIdx < chunkSize; ++chunkIdx)
512 uint16_t receiveThreshold)
volatile
515 (formatThreshold & 0xfff) << 16 | (receiveThreshold & 0xfff);
Utility class to delete copy and move contructors.
C++ APIs for assertions, invariants, and writing formatted debug messages to a UART.
Driver for the OpenTitan's I2C block.
Interrupt
The interrupts of the OpenTitan's I2C block.
@ AcquiredFull
A target mode interrupt.
@ SclInterference
A host mode interrupt.
@ StretchTimeout
A host mode interrupt.
@ ControllerHalt
A host mode interrupt.
@ UnexpectedStop
A target mode interrupt.
@ ReceiveOverflow
A host mode interrupt.
@ ReceiveThreshold
A host mode interrupt.
@ SdaUnstable
A host mode interrupt.
@ HostTimeout
A target mode interrupt.
@ AcquiredThreshold
A target mode interrupt.
@ TransmitStretch
A target mode interrupt.
@ TransmitThreshold
A target mode interrupt.
@ CommandComplete
A host and target mode interrupt.
@ SdaInterference
A host mode interrupt.
@ FormatThreshold
A host mode interrupt.
uint32_t status
I2C Live Status Register for Host and Target modes.
uint32_t readData
I2C Read Data.
@ ControlMultiControllerMonitorEnable
Enable the bus monitor in multi-controller mode.
@ ControlAckControlEnable
Enable ACK Control Mode, which works with the targetAckControl register to allow software to control ...
@ ControlTransmitStretchEnable
If set, causes a read transfer addressed to the this target to set the corresponding bit in the targe...
@ ControlNackAddressAfterTimeout
Enable NACKing the address on a stretch timeout.
@ FormatDataNakOk
Do not signal an exception if the current byte is not ACK’d.
@ FormatDataStop
Issue a STOP condition after this operation.
@ FormatDataStart
Issue a START condition before transmitting BYTE.
@ FormatDataReadCount
Do not NACK the last byte read, let the read operation continue.
@ FormatDataReadBytes
Read BYTE bytes from I2C. (256 if BYTE==0).
uint32_t interruptState
Interrupt State Register.
uint32_t values
Oversampled Receive values.
uint32_t targetNackCount
Number of times the I2C target has NACK'ed a new transaction since the last read of this register.
void host_thresholds_set(uint16_t formatThreshold, uint16_t receiveThreshold) volatile
Sets the thresholds for the format and receive fifos.
uint32_t controllerEvents
Latched events that explain why the controller halted.
uint32_t targetAckControl
Controls for mid-transfer (N)ACK phase handling.
uint32_t targetFifoConfiguration
Target mode FIFO configuration.
uint32_t timing[5]
Detailed I2C Timings (directly corresponding to table 10 in the I2C Specification).
uint32_t formatData
I2C Host Format Data.
void interrupt_enable(Interrupt interrupt) volatile
Enables the given interrupt.
uint32_t fifoCtrl
I2C FIFO control register.
void reset_fifos() volatile
Reset all of the fifos.
uint32_t targetEvents
Latched events that can cause the target module to stretch the clock at the beginning of a read trans...
@ ControlLineLoopback
Enable I2C line loopback test If line loopback is enabled, the internal design sees ACQ and RX data a...
@ ControlEnableTarget
Enable Target I2C functionality.
@ ControlEnableHost
Enable Host I2C functionality.
uint32_t hostFifoConfiguration
Host mode FIFO configuration.
uint32_t targetFifoStatus
Target mode FIFO status register.
bool format_is_empty() volatile
Returns true when the format fifo is empty.
static constexpr bool DebugOpenTitanI2c
Flag set when we're debugging this driver.
uint32_t acquiredData
I2C target acquired data.
uint32_t targetTimeoutControl
I2C target internal stretching timeout control.
uint32_t reset_controller_events() volatile
Reset the controller Events so that the ControllerHalt interrupt will be released,...
@ FifoControlFormatReset
Format fifo reset. Write 1 to the register resets it. Read returns 0.
@ FifoControlTransmitReset
Transmit FIFO reset.
@ FifoControlReceiveReset
Receive fifo reset.
@ FifoControlAcquiredReset
Acquired FIFO reset.
static uint16_t round_up_divide(uint32_t a, uint32_t b)
Performs a 32-bit integer unsigned division, rounding up.
uint32_t timeoutControl
I2C clock stretching timeout control.
uint32_t hostFifoStatus
Host mode FIFO status register.
void interrupt_disable(Interrupt interrupt) volatile
Disables the given interrupt.
uint32_t control
I2C Control Register.
uint32_t hostTimeoutControl
I2C host clock generation timeout value (in units of input clock frequency).
uint32_t hostNackHandlerTimeout
Timeout in Host-Mode for an unhandled NACK before hardware automatically ends the transaction.
@ StatusTransmitFull
Target mode Transmit FIFO is full.
@ StatusReceiveFull
Host mode Receive FIFO is full.
@ StatusAcquiredFull
Target mode Acquired FIFO is full.
@ StatusFormatEmpty
Host mode Format FIFO is empty.
@ StatusTransmitEmpty
Target mode Transmit FIFO is empty.
@ StatusHostIdle
Host functionality is idle. No Host transaction is in progress.
@ StatusTargetIdle
Target functionality is idle. No Target transaction is in progress.
@ StatusAcquiredEmpty
Target mode Acquired FIFO is empty.
@ StatusFormatFull
Host mode Format FIFO is full.
@ SmatusReceiveEmpty
Host mode Receive FIFO is empty.
uint32_t interruptTest
Interrupt Test Register.
void speed_set(const uint32_t SpeedKhz) volatile
Set the I2C timing parameters appropriately for the given bit rate.
uint32_t alertTest
Alert Test Register (Unused in Sonata).
uint32_t transmitData
I2C target transmit data.
bool interrupt_is_asserted(Interrupt interrupt) volatile
Returns true if the given interrupt is asserted.
@ StatusAckControlStretch
Target mode stretching at (N)ACK phase due to zero count in the targetAckControl register.
void interrupt_clear(Interrupt interrupt) volatile
Clears the given interrupt.
uint32_t interruptEnable
Interrupt Enable Register.
uint32_t targetId
I2C target address and mask pairs.
void host_mode_set() volatile
Configure the I2C block to be in host mode.
ConditionalDebug< DebugOpenTitanI2c, "OpenTitan I2C"> Debug
Helper for conditional debug logs and assertions.
@ ControllerEventsArbitrationLost
Controller FSM is halted due to a Host-Mode active transaction being terminated because of lost arbit...
@ ControllerEventsBusTimeout
Controller FSM is halted due to a Host-Mode active transaction being terminated because of a bus time...
@ ControllerEventsNack
Controller FSM is halted due to receiving an unexpected NACK.
@ ControllerEventsUnhandledNackTimeout
Controller FSM is halted due to a Host-Mode active transaction being ended by the hostNackHandlerTime...
uint32_t acquireFifoNextData
The data byte pending to be written to the Acquire (ACQ) FIFO.
Miscellaneous utility functions and classes.