ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_io_i2c_bus_riic.c File Reference

RIIC backend for the ra8_io I2C-bus facade – thin shim over ra8_i2c. More...

#include "ra8_io_i2c_bus_riic.h"
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_i2c.h"
#include "ra8_i2c_regs.h"
#include "ra8_io_i2c_bus.h"
#include "ra8_io_i2c_bus_internal.h"
Include dependency graph for ra8_io_i2c_bus_riic.c:

Go to the source code of this file.

Functions

static ra8_err_t internal_riic_write (void *ctx, uint8_t addr, const uint8_t *data, uint32_t len, bool send_stop)
 RIIC backend: controller write.
static ra8_err_t internal_riic_read (void *ctx, uint8_t addr, uint8_t *data, uint32_t len)
 RIIC backend: controller read.
static ra8_err_t internal_riic_transfer (void *ctx, uint8_t addr, const uint8_t *wr, uint32_t wr_len, uint8_t *rd, uint32_t rd_len)
 RIIC backend: write-then-RESTART-then-read.
ra8_err_t ra8_io_i2c_bus_bind_riic (ra8_io_i2c_bus_t *bus, uint8_t channel)
 Bind bus to RIIC channel channel.

Variables

static const char *const s_tag = "ra8_io_i2c_bus_riic"
 Module log tag.
static const ra8_io_i2c_bus_iface_t s_riic_iface
 RIIC backend vtable – every row forwards to ra8_i2c_*.

Detailed Description

RIIC backend for the ra8_io I2C-bus facade – thin shim over ra8_i2c.

Tag
[Ring 4 / PAL] {World: NS}

Implements ra8_io_i2c_bus_iface by forwarding to the classic RIIC polling driver (ra8_i2c.h), unmodified. The bound channel index travels in the handle context ((void*)(uintptr_t)channel), so the backend keeps no static state and multiple bound buses coexist. Argument validation (channel range, NULL buffers, zero lengths) stays with the wrapped driver, which also carries every HUM citation – no raw MMIO is touched here.

Definition in file ra8_io_i2c_bus_riic.c.

Function Documentation

◆ internal_riic_read()

ra8_err_t internal_riic_read ( void * ctx,
uint8_t addr,
uint8_t * data,
uint32_t len )
static

RIIC backend: controller read.

Decodes the channel from the handle context and forwards to ra8_i2c_read, which always ends the transaction with STOP.

Parameters
[in]ctxBound channel index, encoded as (void*)(uintptr_t).
[in]addr7-bit peripheral address.
[out]dataDestination buffer.
[in]lenByte count.
Returns
ra8_err_t Error code.
Return values
k_ra8_okBytes received.
k_ra8_err_null_ptrdata NULL or bad channel.
k_ra8_err_invalid_arglen is zero.
k_ra8_err_nackPeripheral NACKed the address byte.
Precondition
The channel was initialised via ra8_i2c_init.
ctx carries a channel index bound by ra8_io_i2c_bus_bind_riic.
Postcondition
On success data holds the received bytes.
STOP was issued and the bus released.
Note
Not thread-safe with respect to the same channel.
Since
0.1.0

Definition at line 101 of file ra8_io_i2c_bus_riic.c.

References ra8_i2c_read().

◆ internal_riic_transfer()

ra8_err_t internal_riic_transfer ( void * ctx,
uint8_t addr,
const uint8_t * wr,
uint32_t wr_len,
uint8_t * rd,
uint32_t rd_len )
static

RIIC backend: write-then-RESTART-then-read.

Decodes the channel from the handle context and forwards to ra8_i2c_transfer, which owns the repeated-START framing.

Parameters
[in]ctxBound channel index, encoded as (void*)(uintptr_t).
[in]addr7-bit peripheral address.
[in]wrBytes to send first.
[in]wr_lenNumber of bytes to send.
[out]rdDestination buffer.
[in]rd_lenNumber of bytes to read.
Returns
ra8_err_t Error code.
Return values
k_ra8_okBoth phases completed; STOP issued.
k_ra8_err_null_ptrA required buffer was NULL or bad channel.
k_ra8_err_invalid_argBoth lengths zero.
k_ra8_err_nackPeripheral NACKed.
Precondition
The channel was initialised via ra8_i2c_init.
ctx carries a channel index bound by ra8_io_i2c_bus_bind_riic.
Postcondition
On success both phases completed and STOP was issued.
The bus is released regardless of outcome.
Note
Not thread-safe with respect to the same channel.
Since
0.1.0

Definition at line 136 of file ra8_io_i2c_bus_riic.c.

References ra8_i2c_transfer(), and RA8_INTERNAL.

◆ internal_riic_write()

ra8_err_t internal_riic_write ( void * ctx,
uint8_t addr,
const uint8_t * data,
uint32_t len,
bool send_stop )
static

RIIC backend: controller write.

Decodes the channel from the handle context and forwards to ra8_i2c_write, whose send_stop flag matches the facade contract directly.

Parameters
[in]ctxBound channel index, encoded as (void*)(uintptr_t).
[in]addr7-bit peripheral address.
[in]dataBytes to send.
[in]lenByte count.
[in]send_stoptrue = STOP after payload; false = hold the bus.
Returns
ra8_err_t Error code.
Return values
k_ra8_okPayload transmitted.
k_ra8_err_null_ptrdata NULL with len > 0 or bad channel.
k_ra8_err_nackPeripheral NACKed.
k_ra8_err_hw_timeoutTDRE / TEND poll timed out.
Precondition
The channel was initialised via ra8_i2c_init.
ctx carries a channel index bound by ra8_io_i2c_bus_bind_riic.
Postcondition
On success the payload was transmitted per send_stop.
On failure the bus is released where the driver allows.
Note
Not thread-safe with respect to the same channel.
Since
0.1.0

Definition at line 67 of file ra8_io_i2c_bus_riic.c.

References ra8_i2c_write().

◆ ra8_io_i2c_bus_bind_riic()

ra8_err_t ra8_io_i2c_bus_bind_riic ( ra8_io_i2c_bus_t * bus,
uint8_t channel )
nodiscard

Bind bus to RIIC channel channel.

Installs the RIIC trampoline vtable and records the channel in the handle context. No hardware is touched: initialise the channel with ra8_i2c_init(channel, ...) (before or after binding) and route the SCL/SDA pins yourself.

Parameters
[in,out]busCaller-owned handle to bind (non-NULL).
[in]channelRIIC channel index (0, 1 or 2).
Returns
ra8_err_t Error code.
Return values
k_ra8_okbus now dispatches to ra8_i2c_*.
k_ra8_err_null_ptrbus was NULL.
k_ra8_err_invalid_argchannel is out of range.
Precondition
bus points to writable storage.
channel < 3 (the RA8D2 has IIC0..IIC2).
Postcondition
On success bus->iface is non-NULL and every ra8_io_i2c_bus_* call forwards to RIIC channel channel.
On failure bus is left unmodified.
Note
Thread-safe (writes only the caller's handle).
See also
ra8_io_i2c_bus_bind_i3c_compat The I3C I2C-compatibility twin.
Since
0.1.0

Definition at line 153 of file ra8_io_i2c_bus_riic.c.

References ra8_io_i2c_bus_t::ctx, ra8_io_i2c_bus_t::iface, k_ra8_err_invalid_arg, k_ra8_i2c_channel_count, k_ra8_ok, RA8_CHECK_NULL_PTR, s_riic_iface, and s_tag.

Variable Documentation

◆ s_riic_iface

const ra8_io_i2c_bus_iface_t s_riic_iface
static
Initial value:
= {
}
static ra8_err_t internal_riic_read(void *ctx, uint8_t addr, uint8_t *data, uint32_t len)
RIIC backend: controller read.
static ra8_err_t internal_riic_transfer(void *ctx, uint8_t addr, const uint8_t *wr, uint32_t wr_len, uint8_t *rd, uint32_t rd_len)
RIIC backend: write-then-RESTART-then-read.
static ra8_err_t internal_riic_write(void *ctx, uint8_t addr, const uint8_t *data, uint32_t len, bool send_stop)
RIIC backend: controller write.

RIIC backend vtable – every row forwards to ra8_i2c_*.

Definition at line 147 of file ra8_io_i2c_bus_riic.c.

Referenced by ra8_io_i2c_bus_bind_riic().

◆ s_tag

const char* const s_tag = "ra8_io_i2c_bus_riic"
static

Module log tag.

Definition at line 34 of file ra8_io_i2c_bus_riic.c.