43typedef enum : uint32_t {
116 *total = *total >> 1U;
149 uint32_t field = half - 1U;
153 return (uint8_t)field;
198 uint32_t total = pclkb_hz / bus_hz;
318 if (reg ==
nullptr) {
341 if (reg ==
nullptr) {
355 if (reg ==
nullptr) {
385 if (reg ==
nullptr) {
396 if (reg ==
nullptr) {
400 k_ra8_i2c_err_clear_mask =
402 (uint8_t)(1U << (uint8_t)
406 reg->
ICSR2 = (uint8_t)(reg->
ICSR2 & (uint8_t)~(uint8_t)k_ra8_i2c_err_clear_mask);
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_invalid_arg
Invalid function argument.
@ 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.
bool priv_ra8_i2c_internal_clk_invalid(uint32_t bus_hz, uint32_t pclkb_hz)
Pure predicate: either clock argument is zero.
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_speed_fast_plus
1 MHz Fast-mode Plus (Fm+).
@ k_ra8_i2c_err_none
No latched error.
@ k_ra8_i2c_err_arb_lost
ICSR2.AL set (arbitration lost).
@ k_ra8_i2c_err_nack
ICSR2.NACKF set (NACK received).
@ k_ra8_i2c_err_timeout
ICSR2.TMOF set (bus timeout).
static ra8_err_t internal_i2c_bitrate(uint32_t bus_hz, uint32_t pclkb_hz, uint8_t *out_cks, uint8_t *out_brh, uint8_t *out_brl)
Compute the CKS divider and ICBRH/ICBRL half-period counts.
static ra8_mstp_t internal_i2c_mstp_id(uint8_t channel)
Map a channel index to its MSTP gate id.
static uint8_t internal_i2c_decode_errors(uint8_t icsr2)
Decode latched ICSR2 error bits into a k_ra8_i2c_err_* mask.
ra8_err_t ra8_i2c_deinit(uint8_t channel)
Tear down an IIC channel.
static uint8_t internal_i2c_clamp_half(uint32_t total)
Clamp one SCL half-period count to the 5-bit BR field.
ra8_err_t ra8_i2c_init(uint8_t channel, const ra8_i2c_cfg_t *cfg)
Initialise an IIC channel as a controller and bring the bus up.
ra8_err_t ra8_i2c_get_errors(uint8_t channel, uint8_t *out_mask)
Read latched error flags from ICSR2 (AL / NACKF / TMOF).
ra8_err_t ra8_i2c_clear_errors(uint8_t channel)
Clear latched error flags in ICSR2.
static uint8_t internal_i2c_pick_cks(uint32_t *total)
Pick the smallest CKS divider and divide *total to match.
ra8_i2c_brate_t
Bit-rate divider field limits (HUM Ch 39.2.15 / 39.2.16).
@ k_ra8_i2c_br_reserved_hi
Upper 3 reserved bits of ICBRL / ICBRH read as 1.
@ k_ra8_i2c_cks_max
CKS divider exponent ceiling (CKS[2:0] selects PCLKB / 2^CKS).
@ k_ra8_i2c_br_field_max
ICBRL / ICBRH counter fields are 5 bits ([4:0]).
@ k_ra8_i2c_period_split
Period split between SCL high and low halves.
ra8_err_t ra8_i2c_set_clock(uint8_t channel, uint32_t bus_hz, uint32_t pclkb_hz)
Update the bus clock without tearing the channel down.
static void internal_i2c_apply_init_regs(volatile r_i2c_regs_t *reg, uint8_t cks, uint8_t brh, uint8_t brl, bool fast_plus)
Apply the bring-up register sequence for an IIC channel.
Test-access surface for ra8_i2c internal helpers (MC/DC).
I2C Bus Interface (IIC) register layout for the Renesas RA8D2.
@ k_ra8_i2c_icmr1_cks_pos
Internal reference clock select [6:4].
@ k_ra8_i2c_msk_icsr2_al
HUM 39.2.10 ICSR2.AL, p 2384.
@ k_ra8_i2c_msk_icfer_fmpe
HUM 39.2.6 ICFER.FMPE, p 2378.
@ k_ra8_i2c_msk_icfer_nacke
HUM 39.2.6 ICFER.NACKE, p 2378.
@ k_ra8_i2c_msk_icsr2_nackf
HUM 39.2.10 ICSR2.NACKF, p 2384.
@ k_ra8_i2c_msk_iccr1_iicrst
HUM 39.2.1 ICCR1.IICRST, p 2369.
@ k_ra8_i2c_msk_iccr1_ice
HUM 39.2.1 ICCR1.ICE, p 2369.
@ k_ra8_i2c_msk_icfer_scle
HUM 39.2.6 ICFER.SCLE, p 2378.
@ k_ra8_i2c_msk_icfer_male
HUM 39.2.6 ICFER.MALE, p 2378.
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_tmof_pos
Timeout detection flag.
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.
ra8_mstp_t
Packed (reg << 8) | bit module-stop identifier.
@ k_ra8_mstp_iic2
MSTPB7 IIC2.
@ k_ra8_mstp_iic0
MSTPB9 IIC0.
@ k_ra8_mstp_iic1
MSTPB8 IIC1.
Memory-mapped register block for one IIC channel.
volatile uint8_t ICMR1
+0x02 Bus Mode Register 1 (HUM 39.2.3, p 2374).
volatile uint8_t ICBRL
+0x10 Bit Rate Low-Level (HUM 39.2.15, p 2391).
volatile uint8_t ICFER
+0x05 Bus Function Enable (HUM 39.2.6, p 2378).
volatile uint8_t ICCR1
+0x00 Bus Control Register 1 (HUM 39.2.1, p 2369).
volatile uint8_t ICBRH
+0x11 Bit Rate High-Level (HUM 39.2.16, p 2392).
volatile uint8_t ICSR2
+0x09 Bus Status Register 2 (HUM 39.2.10, p 2384).
Configuration descriptor for ra8_i2c_init.
uint32_t bus_hz
Target I2C clock rate in Hz.
uint32_t pclkb_hz
Current PCLKB frequency in Hz for bit-rate calc.