71typedef enum : uint32_t {
90typedef enum : uint32_t {
116 return (bus_hz == 0U) || (pclkb_hz == 0U);
160#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
162 if (ra8_fake_mmio_poll(®->
ICSR2, i, (reg->
ICSR2 & mask) != 0U)) {
165 if ((reg->
ICSR2 & mask) != 0U) {
225 k_ra8_i2c_status_clear_mask =
231 reg->
ICSR2 = (uint8_t)(reg->
ICSR2 & (uint8_t)~(uint8_t)k_ra8_i2c_status_clear_mask);
285#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
287 const bool observed = ra8_fake_mmio_poll(®->
ICCR2, i, restart_complete);
289 const bool observed = restart_complete;
482 uint8_t address_byte)
491 reg->
ICDRT = address_byte;
521 for (uint32_t i = 0U; i < len; i++) {
532 reg->
ICDRT = data[i];
569 if ((err !=
k_ra8_ok) || send_stop) {
580 uint8_t peripheral_7b,
589 const bool bus_held =
s_i2c_state[channel].bus_held;
598 const uint8_t address_byte =
660 for (uint32_t loaded = 0U; loaded < len; loaded++) {
665 const uint32_t remain = len - loaded;
677 out[loaded] = reg->
ICDRR;
697 const bool bus_held =
s_i2c_state[channel].bus_held;
706 const uint8_t address_byte =
727 uint8_t peripheral_7b,
736 if ((wr_len == 0U) && (rd_len == 0U)) {
739 if ((wr_len != 0U) && (wr ==
nullptr)) {
742 if ((rd_len != 0U) && (rd ==
nullptr)) {
749 ra8_i2c_write(channel, peripheral_7b, wr, wr_len, (rd_len == 0U));
757 return ra8_i2c_read(channel, peripheral_7b, rd, rd_len);
777 const uint8_t address_byte =
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_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.
static void internal_i2c_stop_request(volatile r_i2c_regs_t *reg)
Request a STOP condition without waiting for it to complete.
ra8_err_t ra8_i2c_scan(uint8_t channel, uint8_t peripheral_7b, bool *out_acked)
Probe whether a 7-bit peripheral address ACKs.
static void internal_i2c_restart(volatile r_i2c_regs_t *reg)
Issue a repeated-START condition (HUM Ch 39.11 p 2434).
ra8_i2c_state_t s_i2c_state[k_ra8_i2c_channel_count]
Per-channel state table indexed by channel.
ra8_err_t ra8_i2c_write(uint8_t channel, uint8_t peripheral_7b, const uint8_t *data, uint32_t len, bool send_stop)
Polling write of len bytes to a 7-bit peripheral address.
static void internal_i2c_wait_bus_free(volatile const r_i2c_regs_t *reg)
Spin (bounded) until the bus is free (ICCR2.BBSY clears).
static void internal_i2c_stop(volatile r_i2c_regs_t *reg)
Issue a STOP condition and wait for the bus to be released.
static void internal_i2c_clear_status(volatile r_i2c_regs_t *reg)
Clear the START / STOP / NACK status flags ahead of a transfer.
static ra8_err_t internal_i2c_busy_gate(volatile const r_i2c_regs_t *reg, bool bus_held)
Bus-busy gate: reject a fresh transaction while BBSY is set, unless the channel currently holds the b...
static ra8_err_t internal_i2c_wait_icsr2(volatile const r_i2c_regs_t *reg, uint8_t mask)
Wait for a flag in ICSR2 to set, with a bounded spin budget.
ra8_err_t ra8_i2c_read(uint8_t channel, uint8_t peripheral_7b, uint8_t *data, uint32_t len)
Polling read of len bytes from a 7-bit peripheral.
ra8_i2c_rx_phase_t
Controller-receive end-of-frame boundaries (HUM Ch 39.3.4 p 2400).
@ k_ra8_i2c_rx_remain_wait
bytes-remaining == this: arm WAIT.
@ k_ra8_i2c_rx_remain_nack
bytes-remaining == this: NACK final byte.
@ k_ra8_i2c_rx_remain_stop
bytes-remaining == this: request STOP.
@ k_ra8_i2c_rx_short_len
len <= this: arm WAIT in the dummy phase.
@ k_ra8_i2c_rx_single_len
len == this: NACK in the dummy phase.
ra8_i2c_internal_t
Implementation constants – spin budgets and addressing helpers.
@ k_ra8_i2c_addr_rw_write
R/W bit value for a write transaction (0 in LSB).
@ k_ra8_i2c_addr_rw_read
R/W bit value for a read transaction (1 in LSB).
@ k_ra8_i2c_poll_limit
Generic spin budget for status-flag polls.
@ k_ra8_i2c_addr_shift
Shift count to convert a 7-bit address into the on-the-wire byte.
bool priv_ra8_i2c_internal_clk_invalid(uint32_t bus_hz, uint32_t pclkb_hz)
Pure predicate: either clock argument is zero.
static ra8_err_t internal_i2c_drain_rx(volatile r_i2c_regs_t *reg, uint8_t *out, uint32_t len)
Drain len bytes from ICDRR into out (controller receive).
static void internal_i2c_open_phase(volatile r_i2c_regs_t *reg, bool bus_held)
Issue START or RESTART based on whether the bus is held.
static void internal_i2c_start(volatile r_i2c_regs_t *reg)
Issue a START condition (HUM Ch 39.3.3 step 2 p 2396).
ra8_err_t ra8_i2c_transfer(uint8_t channel, uint8_t peripheral_7b, const uint8_t *wr, uint32_t wr_len, uint8_t *rd, uint32_t rd_len)
Combined write-then-RESTART-then-read in one bus transaction.
static ra8_err_t internal_i2c_status_from_icsr2(uint8_t icsr2)
Map latched ICSR2 error bits to a high-level status code.
static ra8_err_t internal_i2c_drain_tx(volatile r_i2c_regs_t *reg, const uint8_t *data, uint32_t len)
Push len bytes from data into ICDRT.
const char *const g_i2c_tag
Log tag for this driver, shared with ra8_i2c_config.c.
static ra8_err_t internal_i2c_finish_tx(volatile r_i2c_regs_t *reg, uint8_t channel, ra8_err_t err, bool send_stop)
Finish a write: wait for TEND, then STOP or hold the bus.
static void internal_i2c_set_nack(volatile r_i2c_regs_t *reg)
Set ICMR3.ACKBT (transmit NACK) under ACKWP write-enable.
static ra8_err_t internal_i2c_send_address(volatile r_i2c_regs_t *reg, uint8_t address_byte)
Transmit one address byte (HUM Ch 39.3.3 step 3 p 2396).
I2C Bus Interface (IIC) controller driver – polling mode.
Test-access surface for ra8_i2c internal helpers (MC/DC).
I2C Bus Interface (IIC) register layout for the Renesas RA8D2.
@ k_ra8_i2c_msk_icsr2_al
HUM 39.2.10 ICSR2.AL, p 2384.
@ k_ra8_i2c_msk_iccr2_rs
HUM 39.2.2 ICCR2.RS, p 2371.
@ k_ra8_i2c_msk_iccr2_st
HUM 39.2.2 ICCR2.ST, p 2371.
@ k_ra8_i2c_msk_icsr2_nackf
HUM 39.2.10 ICSR2.NACKF, p 2384.
@ k_ra8_i2c_msk_iccr2_sp
HUM 39.2.2 ICCR2.SP, p 2371.
@ k_ra8_i2c_msk_icsr2_tdre
HUM 39.2.10 ICSR2.TDRE, p 2384.
@ k_ra8_i2c_msk_icmr3_wait
HUM 39.2.5 ICMR3.WAIT, p 2376.
@ k_ra8_i2c_msk_iccr2_bbsy
HUM 39.2.2 ICCR2.BBSY, p 2371.
@ k_ra8_i2c_msk_icsr2_stop
HUM 39.2.10 ICSR2.STOP, p 2384.
@ k_ra8_i2c_msk_icmr3_ackbt
HUM 39.2.5 ICMR3.ACKBT, p 2376.
@ k_ra8_i2c_msk_icsr2_tend
HUM 39.2.10 ICSR2.TEND, p 2384.
@ k_ra8_i2c_msk_icmr3_ackwp
HUM 39.2.5 ICMR3.ACKWP, p 2376.
@ k_ra8_i2c_msk_icsr2_rdrf
HUM 39.2.10 ICSR2.RDRF, p 2384.
@ k_ra8_i2c_channel_count
HUM Ch 39.1, p 2367 (3 channels).
static volatile r_i2c_regs_t * ra8_i2c_regs(uint8_t channel)
Get a pointer to the IIC channel channel register block.
@ k_ra8_i2c_icsr2_start_pos
Start condition detection flag.
Memory-mapped register block for one IIC channel.
volatile uint8_t ICCR2
+0x01 Bus Control Register 2 (HUM 39.2.2, p 2371).
volatile uint8_t ICDRT
+0x12 Transmit Data Register (HUM 39.2.17, p 2393).
volatile uint8_t ICDRR
+0x13 Receive Data Register (HUM 39.2.18, p 2393).
volatile uint8_t ICMR3
+0x04 Bus Mode Register 3 (HUM 39.2.5, p 2376).
volatile uint8_t ICSR2
+0x09 Bus Status Register 2 (HUM 39.2.10, p 2384).
Per-channel driver state shared by both I2C translation units.