70typedef enum : uint32_t {
80typedef enum : uint8_t {
190 if ((reg->
ICSR2 & mask) != 0U) {
281 for (uint32_t i = 0U; i <= capacity; i++) {
289 const uint8_t icsr2 = reg->
ICSR2;
294 buf[count] = reg->
ICDRR;
301 buf[count] = reg->
ICDRR;
338 for (uint32_t i = 0U; i <= len; i++) {
345 const uint8_t icsr2 = reg->
ICSR2;
350 reg->
ICDRT = data[sent];
415 const uint8_t slot = (uint8_t)cfg->
slot;
438 if (reg ==
nullptr) {
466 const uint8_t icsr1 = reg->
ICSR1;
468 const uint8_t icsr2 = reg->
ICSR2;
475 const uint8_t icsr1 = reg->
ICSR1;
477 const uint8_t iccr2 = reg->
ICCR2;
490 if (capacity == 0U) {
514 *out_received = count;
515 return (count == 0U) ? err :
k_ra8_ok;
608 if (reg ==
nullptr) {
620 const uint8_t icsr1 = reg->
ICSR1;
622 const uint8_t icsr2 = reg->
ICSR2;
624 const uint8_t iccr2 = reg->
ICCR2;
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#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_invalid_arg
Invalid function argument.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
ra8_i2c_state_t s_i2c_state[k_ra8_i2c_channel_count]
Per-channel state table indexed by channel.
const char *const g_i2c_tag
Log tag for this driver, shared with ra8_i2c_config.c.
I2C Bus Interface (IIC) controller driver – polling mode.
@ k_ra8_i2c_peripheral_slot_0
Own-address slot 0 (SARL0/SARU0).
@ k_ra8_i2c_peripheral_slot_1
Own-address slot 1 (SARL1/SARU1).
void(* ra8_i2c_peripheral_event_fn_t)(void *ctx, ra8_i2c_peripheral_event_t event)
Address-match callback fired by ra8_i2c_peripheral_dispatch.
ra8_i2c_peripheral_event_t
Outcome of ra8_i2c_peripheral_poll / ra8_i2c_peripheral_dispatch.
@ k_ra8_i2c_peripheral_event_none
No own-address match observed.
@ k_ra8_i2c_peripheral_event_write
Controller WRITE: call receive next.
@ k_ra8_i2c_peripheral_event_read
Controller READ: call transmit next.
@ k_ra8_i2c_peripheral_event_stop
STOP ended the transaction (idle).
Test-access surface for ra8_i2c internal helpers (MC/DC).
static ra8_i2c_peripheral_event_t internal_i2c_dispatch_event(uint8_t icsr1, uint8_t icsr2, uint8_t iccr2)
Classify an own-address / STOP status snapshot into a dispatch event.
static uint8_t internal_i2c_target_icser_mask(uint8_t slot, bool general_call)
Build the ICSER enable mask for one own-address slot.
ra8_err_t ra8_i2c_peripheral_transmit(uint8_t channel, const uint8_t *data, uint32_t len, uint32_t *out_sent)
Answer a controller-read transaction from data (target transmit).
ra8_err_t ra8_i2c_peripheral_init(uint8_t channel, const ra8_i2c_peripheral_cfg_t *cfg)
Arm an IIC channel to answer as an I2C target (peripheral).
static void internal_i2c_target_fill_tx(volatile r_i2c_regs_t *reg, const uint8_t *data, uint32_t len, uint32_t *out_sent)
Push controller-read data bytes from data into ICDRT.
static ra8_err_t internal_i2c_target_wait(volatile const r_i2c_regs_t *reg, uint8_t mask)
Wait (bounded) for a flag in ICSR2 to set.
bool priv_ra8_i2c_internal_peripheral_tx_continue(uint8_t icsr2, uint32_t sent, uint32_t len)
Transmit-loop predicate: keep sending while no NACK and data remains.
static ra8_i2c_peripheral_event_t internal_i2c_target_classify(uint8_t icsr1, uint8_t iccr2)
Classify a latched address-match snapshot into a poll event.
bool priv_ra8_i2c_internal_peripheral_poll_done(uint8_t icsr1, uint8_t icsr2)
Poll-exit predicate: an own-address match or a STOP was observed.
bool priv_ra8_i2c_internal_peripheral_rx_continue(uint8_t icsr2, uint32_t received, uint32_t capacity)
Receive-loop predicate: keep draining while no STOP and room remains.
static bool internal_i2c_target_finish_tx(volatile r_i2c_regs_t *reg)
Close a target-transmit frame: wait for end, release SCL, clear flags.
ra8_err_t ra8_i2c_peripheral_poll(uint8_t channel, ra8_i2c_peripheral_event_t *out_event)
Wait (bounded) for a controller to address this target.
ra8_err_t priv_ra8_i2c_internal_target_drain_rx(volatile r_i2c_regs_t *reg, uint8_t *buf, uint32_t capacity, uint32_t *out_count)
Implementation of priv_ra8_i2c_internal_target_drain_rx() – trailing-byte ICDRR drain.
static void internal_i2c_target_set_addr(volatile r_i2c_regs_t *reg, uint8_t slot, uint8_t addr_7b)
Programme a 7-bit own address into the SARLy/SARUy pair for a slot.
bool priv_ra8_i2c_internal_peripheral_tx_done(uint8_t icsr2)
Transmit-completion predicate: the controller ended the read.
ra8_err_t ra8_i2c_peripheral_deinit(uint8_t channel)
Disarm own-address matching, returning the channel to controller use.
void ra8_i2c_peripheral_dispatch(uint8_t channel)
Snapshot the latched target status and fire the attached callback.
ra8_i2c_peripheral_limits_t
Spin budgets and validation bounds for the target plane.
@ k_ra8_i2c_peripheral_poll_limit
Generic spin budget for status-flag polls, matching the controller plane: ~200k iterations keeps the ...
ra8_err_t ra8_i2c_peripheral_receive(uint8_t channel, uint8_t *buf, uint32_t capacity, uint32_t *out_received)
Drain a controller-write transaction into buf (target receive).
ra8_i2c_peripheral_const_t
Addressing constants for the target plane.
@ k_ra8_i2c_peripheral_addr_7b_max
Largest valid 7-bit own address.
@ k_ra8_i2c_peripheral_slot_max
Highest own-address comparator slot.
@ k_ra8_i2c_peripheral_saru_7bit
SARUy value for the 7-bit address format (FS = 0, SVA[1:0] = 0).
@ k_ra8_i2c_peripheral_icier_arm
ICIER target-interrupt arm mask: RIE (RXI, bit 5) | TIE (TXI, bit 7) | SPIE (STOP,...
@ k_ra8_i2c_peripheral_addr_shift
Shift to place a 7-bit own address into SARLy.SVA[6:0] (bits [7:1]).
ra8_err_t ra8_i2c_peripheral_attach_handler(uint8_t channel, ra8_i2c_peripheral_event_fn_t fn, void *ctx)
Attach (or detach) the address-match callback for a channel.
I2C Bus Interface (IIC) register layout for the Renesas RA8D2.
@ k_ra8_i2c_sarl_sva_pos
7-bit own address / 10-bit low SVA[6:0].
@ k_ra8_i2c_msk_iccr2_trs
HUM 39.2.2 ICCR2.TRS, p 2371.
@ k_ra8_i2c_msk_icsr2_nackf
HUM 39.2.10 ICSR2.NACKF, p 2384.
@ 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_icsr2_stop
HUM 39.2.10 ICSR2.STOP, p 2384.
@ k_ra8_i2c_msk_icsr2_tend
HUM 39.2.10 ICSR2.TEND, p 2384.
@ 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).
@ k_ra8_i2c_icier_rie_pos
Receive data full interrupt enable.
@ k_ra8_i2c_icier_spie_pos
Stop condition interrupt enable.
@ k_ra8_i2c_icier_tie_pos
Transmit data empty interrupt enable.
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_msk_icser_gcae
HUM 39.2.7 ICSER.GCAE, p 2380.
@ k_ra8_i2c_msk_icsr1_match
Union AAS0|AAS1|AAS2|GCA: any own-address/general-call match.
@ k_ra8_i2c_msk_icser_sar0e
HUM 39.2.7 ICSER.SAR0E, p 2380.
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 ICIER
+0x07 Bus Interrupt Enable (HUM 39.2.8, p 2381).
volatile uint8_t SARU0
+0x0B Peripheral Address U0 (HUM 39.2.14, p 2391).
volatile uint8_t ICSER
+0x06 Bus Status Enable (HUM 39.2.7, p 2380).
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 ICSR1
+0x08 Bus Status Register 1 (HUM 39.2.9, p 2382).
volatile uint8_t SARL2
+0x0E Peripheral Address L2 (HUM 39.2.13, p 2390).
volatile uint8_t SARL1
+0x0C Peripheral Address L1 (HUM 39.2.13, p 2390).
volatile uint8_t SARU1
+0x0D Peripheral Address U1 (HUM 39.2.14, p 2391).
volatile uint8_t SARU2
+0x0F Peripheral Address U2 (HUM 39.2.14, p 2391).
volatile uint8_t SARL0
+0x0A Peripheral Address L0 (HUM 39.2.13, p 2390).
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).
Configuration descriptor for ra8_i2c_peripheral_init.
ra8_i2c_peripheral_slot_t slot
Own-address comparator slot.
uint8_t own_addr_7b
7-bit own address to answer on.
bool general_call
Also answer the general-call addr.
bool irq_enable
Arm ICIER RIE / TIE / SPIE.
bool clock_stretch
Arm ICMR3.WAIT clock stretching.