78 return (len != 0U) && (buf ==
nullptr);
98 return (mask != 0U) && (cb !=
nullptr);
108typedef enum : uint32_t {
163 if ((bus_hz == 0U) || (pclka_hz == 0U)) {
167 k_ra8_i3c_i2c_period_split = 2U,
168 k_ra8_i3c_i2c_max_field = 0xFFU,
170 const uint32_t total = pclka_hz / bus_hz;
171 const uint32_t half = total / k_ra8_i3c_i2c_period_split;
175 uint32_t value = half - 1U;
176 if (value > k_ra8_i3c_i2c_max_field) {
177 value = k_ra8_i3c_i2c_max_field;
179 return (uint8_t)value;
205#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
207 if (ra8_fake_mmio_poll(®->
NTST, i, (reg->
NTST & mask) != 0U)) {
210 if ((reg->
NTST & mask) != 0U) {
250#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
252 const bool observed = ra8_fake_mmio_poll(®->
RSTCTL, i, reset_clear);
254 const bool observed = reset_clear;
356 reg->
BST = reg->
BST & ~k_ra8_i3c_i2c_bst_clear_mask;
389 reg->
NTDTBP0 = (uint32_t)address_byte;
570 if (reg ==
nullptr) {
591 if (reg ==
nullptr) {
609 if (reg ==
nullptr) {
612 if ((bus_hz == 0U) || (pclka_hz == 0U)) {
677 for (uint32_t i = 0U; i < len; i++) {
686 reg->
NTDTBP0 = (uint32_t)data[i];
715 if ((err !=
k_ra8_ok) || !restart) {
771 const uint8_t address_byte =
820 for (uint32_t i = 0U; i < len; i++) {
821 if (i == (len - 1U)) {
875ra8_i3c_i2c_read(uint8_t channel, uint8_t target_7b, uint8_t* buf, uint32_t len,
bool restart)
893 const uint8_t address_byte =
926 if ((tx_len == 0U) && (rx_len == 0U)) {
929 if ((tx_len != 0U) && (tx ==
nullptr)) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_busy
Resource busy – blocking operation cannot proceed.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
@ k_ra8_err_nack
Peer responded with NACK (negative acknowledgement).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Bounded wait-flag primitives for RA8D2 HAL drivers.
ra8_err_t ra8_i3c_i2c_init(uint8_t channel, const ra8_i3c_i2c_cfg_t *cfg)
Initialise the IIC_B channel and bring the bus up.
static void internal_i3c_i2c_open_phase(volatile r_i3c_i2c_regs_t *reg, bool bus_held)
Issue START or RESTART based on whether the bus is currently held by a previous restart=true call.
static ra8_err_t internal_i3c_i2c_drain_tx(volatile r_i3c_i2c_regs_t *reg, const uint8_t *data, uint32_t len)
Push len bytes from data into NTDTBP0.
ra8_err_t ra8_i3c_i2c_read(uint8_t channel, uint8_t target_7b, uint8_t *buf, uint32_t len, bool restart)
Polling read of len bytes from a 7-bit target.
void priv_i3c_i2c_start(volatile r_i3c_i2c_regs_t *reg)
Issue a START condition.
ra8_err_t ra8_i3c_i2c_transfer(uint8_t channel, uint8_t target_7b, const uint8_t *tx, uint32_t tx_len, uint8_t *rx, uint32_t rx_len)
Combined write-then-RESTART-then-read in a single bus transaction.
static ra8_err_t internal_i3c_i2c_wait_ntst(volatile r_i3c_i2c_regs_t *reg, uint32_t mask)
Wait for a flag in NTST to set.
bool priv_i3c_i2c_should_dispatch(uint8_t mask, const void *cb)
Pure dispatch-callback predicate – see header for full contract.
ra8_i3c_i2c_state_t s_iic_b_state[k_ra8_i3c_i2c_channel_count]
Per-channel state table indexed by channel.
ra8_err_t ra8_i3c_i2c_deinit(uint8_t channel)
Tear down the IIC_B channel.
static ra8_err_t internal_i3c_i2c_reset(volatile r_i3c_i2c_regs_t *reg)
Pulse-reset the I3C peripheral via RSTCTL.RI3CRST.
static ra8_err_t internal_i3c_i2c_status_from_bst(uint32_t bst)
Map the latched BST error bits to a high-level status code.
static ra8_err_t internal_i3c_i2c_busy_gate(volatile const r_i3c_i2c_regs_t *reg, bool bus_held)
Bus-busy gate: rejects new transactions while BCST.BFREF is clear, unless the channel is in a held-bu...
ra8_err_t ra8_i3c_i2c_set_clock(uint8_t channel, uint32_t bus_hz, uint32_t pclka_hz)
Update the bus clock without tearing the channel down.
static ra8_err_t internal_i3c_i2c_drain_rx(volatile r_i3c_i2c_regs_t *reg, uint8_t *out, uint32_t len)
Drain len bytes from NTDTBP0 into out.
static void internal_i3c_i2c_apply_init_regs(volatile r_i3c_i2c_regs_t *reg, const ra8_i3c_i2c_cfg_t *cfg)
Apply the post-reset register defaults for an IIC_B channel.
void priv_i3c_i2c_clear_bst(volatile r_i3c_i2c_regs_t *reg)
Clear all latched bus-status flags ahead of a new transaction.
bool priv_i3c_i2c_len_buf_invalid(uint32_t len, const void *buf)
Pure len/buf reject predicate – see header for full contract.
static bool internal_i3c_i2c_bus_free(volatile const r_i3c_i2c_regs_t *reg)
True when the bus is free as reported by BCST.BFREF.
ra8_err_t priv_i3c_i2c_send_address(volatile r_i3c_i2c_regs_t *reg, uint8_t address_byte)
Send a single address byte and wait for TDBEF0 to be ready for the next slot.
static void internal_i3c_i2c_finalize(volatile r_i3c_i2c_regs_t *reg, uint8_t channel, ra8_err_t err, bool restart)
Decide STOP vs hold and update channel state accordingly.
void priv_i3c_i2c_stop(volatile r_i3c_i2c_regs_t *reg)
Issue a STOP condition.
ra8_err_t ra8_i3c_i2c_write(uint8_t channel, uint8_t target_7b, const uint8_t *data, uint32_t len, bool restart)
Polling write of len bytes to a 7-bit target address.
static ra8_err_t internal_i3c_i2c_rx_phase(volatile r_i3c_i2c_regs_t *reg, uint8_t *buf, uint32_t len)
Run the data phase of an RX transaction (dummy-read + drain).
static void internal_i3c_i2c_restart(volatile r_i3c_i2c_regs_t *reg)
Issue a repeated-START (Sr) condition.
static uint8_t internal_i3c_i2c_half_period(uint32_t bus_hz, uint32_t pclka_hz)
Compute STDBR.SBRLO / SBRHO half-period count from PCLKA.
internal_i3c_i2c_t
Implementation constants – spin budgets, addressing helpers.
@ k_ra8_i3c_i2c_addr_rw_write
R/W bit value for a write transaction (0 in LSB).
@ k_ra8_i3c_i2c_addr_rw_read
R/W bit value for a read transaction (1 in LSB).
@ k_ra8_i3c_i2c_poll_limit
Generic spin budget for status-flag polls.
@ k_ra8_i3c_i2c_byte_mask
8-bit byte mask for narrowing 32-bit reads from NTDTBP0.
@ k_ra8_i3c_i2c_addr_shift
Shift count to convert a 7-bit address into the on-the-wire byte.
static ra8_err_t internal_i3c_i2c_block_bringup(volatile r_i3c_i2c_regs_t *reg)
Bring the IIC_B block up: MSTP release, CECTL clock, reset, and switch the I3C IP into I2C single-buf...
IIC_B (I3C unified IP, I2C-only mode) controller driver.
@ k_ra8_i3c_i2c_speed_fast_plus
1 MHz Fm+.
Test-access surface for ra8_i3c_i2c internal helpers (MC/DC).
IIC_B (I3C-based I2C) register layout for the Renesas RA8D2.
@ k_ra8_i3c_i2c_channel_count
HUM Ch 40.1.1, p 2445.
static volatile r_i3c_i2c_regs_t * i3c_i2c_regs(uint8_t channel)
Get a pointer to the IIC_B / I3C channel channel.
@ k_ra8_i3c_i2c_msk_ackctl_ackt
HUM 40.2 ACKCTL.ACKT, p 2468.
@ k_ra8_i3c_i2c_msk_bst_nackdf
HUM 40.2 BST.NACKDF, p 2482.
@ k_ra8_i3c_i2c_msk_bfctl_nale
HUM 40.2 BFCTL.NALE, p 2461.
@ k_ra8_i3c_i2c_msk_rstctl_ri3crst
HUM 40.2 RSTCTL.RI3CRST, p 2456.
@ k_ra8_i3c_i2c_msk_bfctl_scsyne
HUM 40.2 BFCTL.SCSYNE, p 2461.
@ k_ra8_i3c_i2c_msk_cndctl_spcnd
HUM 40.2 CNDCTL.SPCND, p 2473.
@ k_ra8_i3c_i2c_msk_prts_prtmd
HUM 40.2.1 PRTS.PRTMD, p 2449.
@ k_ra8_i3c_i2c_msk_bst_spcnddf
HUM 40.2 BST.SPCNDDF, p 2482.
@ k_ra8_i3c_i2c_msk_bst_stcnddf
HUM 40.2 BST.STCNDDF, p 2482.
@ k_ra8_i3c_i2c_msk_bcst_bfref
HUM 40.2 BCST.BFREF, p 2491.
@ k_ra8_i3c_i2c_msk_cndctl_stcnd
HUM 40.2 CNDCTL.STCND, p 2473.
@ k_ra8_i3c_i2c_msk_bst_tendf
HUM 40.2 BST.TENDF, p 2482.
@ k_ra8_i3c_i2c_msk_ntst_tdbef0
HUM 40.2 NTST.TDBEF0, p 2486.
@ k_ra8_i3c_i2c_msk_bst_alf
HUM 40.2 BST.ALF, p 2482.
@ k_ra8_i3c_i2c_msk_bst_todf
HUM 40.2 BST.TODF, p 2482.
@ k_ra8_i3c_i2c_msk_bctl_buse
HUM 40.2 BCTL.BUSE, p 2454.
@ k_ra8_i3c_i2c_msk_bfctl_fmpe
HUM 40.2 BFCTL.FMPE, p 2461.
@ k_ra8_i3c_i2c_msk_cectl_clke
HUM 40.2 CECTL.CLKE, p 2453.
@ k_ra8_i3c_i2c_msk_ntst_rdbff0
HUM 40.2 NTST.RDBFF0, p 2486.
@ k_ra8_i3c_i2c_msk_bfctl_male
HUM 40.2 BFCTL.MALE, p 2461.
@ k_ra8_i3c_i2c_msk_ackctl_acktwp
HUM 40.2 ACKCTL.ACKTWP,p 2468.
@ k_ra8_i3c_i2c_msk_cndctl_srcnd
HUM 40.2 CNDCTL.SRCND, p 2473.
@ k_ra8_i3c_i2c_stdbr_sbrlo_pos
HUM 40.2 STDBR.SBRLO, p 2462.
@ k_ra8_i3c_i2c_stdbr_sbrho_pos
HUM 40.2 STDBR.SBRHO, p 2462.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
@ k_ra8_mstp_iic0
MSTPB9 IIC0.
@ k_ra8_mstp_i3c
MSTPB4 I3C.
Memory-mapped register block for one IIC_B / I3C channel.
volatile uint32_t NTST
+0x1E0 Normal Transfer Status (HUM 40.2, p 2486).
volatile uint32_t REFCKCTL
+0x070 Reference Clock Control (HUM 40.2, p 2462).
volatile uint32_t BCST
+0x210 Bus Condition Status (HUM 40.2, p 2491).
volatile uint32_t CECTL
+0x010 Clock Enable Control (HUM 40.2, p 2453).
volatile uint32_t STDBR
+0x074 Standard Bit Rate (HUM 40.2, p 2462).
volatile uint32_t BST
+0x1D0 Bus Status (HUM 40.2, p 2482).
volatile uint32_t BCTL
+0x014 Bus Control (HUM 40.2, p 2454).
volatile uint32_t PRTS
+0x000 Protocol Selection (HUM 40.2, p 2452).
volatile uint32_t SCSTRCTL
+0x0A4 SCL Stretch Control (HUM 40.2, p 2469).
volatile uint32_t ACKCTL
+0x0A0 Acknowledge Control (HUM 40.2, p 2468).
volatile uint32_t RSTCTL
+0x020 Reset Control (HUM 40.2, p 2456).
volatile uint32_t NTDTBP0
+0x158 Normal Tx/Rx Data Buffer 0 (HUM 40.2, p 2476).
volatile uint32_t BFCTL
+0x060 Bus Function Control (HUM 40.2, p 2461).
volatile uint32_t CNDCTL
+0x140 Condition Control (HUM 40.2, p 2473).
Configuration descriptor for ra8_i3c_i2c_init.
uint32_t bus_hz
Target I2C clock rate in Hz.
uint32_t pclka_hz
Current PCLKA / I3CCLK frequency for STDBR calc.
Per-channel dispatch state shared across the driver's TUs.