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

IIC_B peripheral driver implementation. More...

#include "ra8_i3c_i2c_peripheral.h"
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_i3c_i2c_regs.h"
#include "ra8_log.h"
#include "ra8_mstp.h"
#include "ra8_mstp_regs.h"
Include dependency graph for ra8_i3c_i2c_peripheral.c:

Go to the source code of this file.

Enumerations

enum  ra8_i3c_i2c_peripheral_internal_t : uint32_t {
  k_ra8_i3c_i2c_peripheral_spin_budget = 50000U ,
  k_ra8_i3c_i2c_peripheral_max_addr_7b = 0x7FU
}
 Internal tunables. More...
enum  ra8_i3c_i2c_peripheral_bits_t : uint32_t {
  k_ra8_i3c_i2c_peripheral_msk_ntst_tdbef0 = (uint32_t)(1U << 0U) ,
  k_ra8_i3c_i2c_peripheral_msk_ntst_rdbff0 = (uint32_t)(1U << 1U) ,
  k_ra8_i3c_i2c_peripheral_msk_svctl_gcae = (uint32_t)(1U << 0U) ,
  k_ra8_i3c_i2c_peripheral_msdvad_shift_dvad = 1U ,
  k_ra8_i3c_i2c_peripheral_byte_mask = 0xFFU
}
 Local register-bit positions / masks used by this driver. More...

Functions

static ra8_err_t internal_wait_ntst (volatile const r_i3c_i2c_regs_t *reg, uint32_t mask)
 Bounded wait until mask bits set in NTST.
ra8_err_t ra8_i3c_i2c_peripheral_open (uint8_t channel, const ra8_i3c_i2c_peripheral_cfg_t *cfg)
 Open a channel as an IIC_B peripheral.
ra8_err_t ra8_i3c_i2c_peripheral_close (uint8_t channel)
 Close the peripheral channel.
ra8_err_t ra8_i3c_i2c_peripheral_send (uint8_t channel, const uint8_t *data, uint32_t len)
 Push len bytes into NTDTBP0 in response to a controller-read.
ra8_err_t ra8_i3c_i2c_peripheral_receive (uint8_t channel, uint8_t *buf, uint32_t len)
 Drain len bytes from NTDTBP0 after a controller-write.
ra8_err_t ra8_i3c_i2c_peripheral_status (uint8_t channel, uint8_t *out_mask)
 Read latched peripheral-side status mask.

Variables

static const char * s_tag = "IICBP"

Detailed Description

IIC_B peripheral driver implementation.

Tag
[Ring 3 / HAL] {World: NS}

Polling-mode peripheral companion to ra8_i3c_i2c. Mirrors FSP r_iic_b_peripheral.c:

  • ra8_i3c_i2c_peripheral_open clears the channel (RSTCTL.RI3CRST), programmes MSDVAD with the 7-bit own address, switches the bus interface enable bit BCTL.BUSE on, and (optionally) enables the general-call response via SVCTL.GCAE.
  • _send pushes len bytes into NTDTBP0 once NTST.TDBEF0 asserts.
  • _receive drains len bytes from NTDTBP0 once NTST.RDBFF0 asserts.
  • _status snapshots NTST + BST and translates the latched bits into k_ra8_i3c_i2c_peripheral_status_*.

Citations: HUM Ch 40.2 "I3C / IIC_B Register Reference", pages 2452..2491 (chapter map row 40).

Definition in file ra8_i3c_i2c_peripheral.c.

Enumeration Type Documentation

◆ ra8_i3c_i2c_peripheral_bits_t

Local register-bit positions / masks used by this driver.

Enumerator
k_ra8_i3c_i2c_peripheral_msk_ntst_tdbef0 

NTST.TDBEF0.

k_ra8_i3c_i2c_peripheral_msk_ntst_rdbff0 

NTST.RDBFF0.

k_ra8_i3c_i2c_peripheral_msk_svctl_gcae 

SVCTL.GCAE.

k_ra8_i3c_i2c_peripheral_msdvad_shift_dvad 

Address shifted left 1.

k_ra8_i3c_i2c_peripheral_byte_mask 

NTDTBP0 low-byte mask.

Definition at line 57 of file ra8_i3c_i2c_peripheral.c.

◆ ra8_i3c_i2c_peripheral_internal_t

Internal tunables.

Enumerator
k_ra8_i3c_i2c_peripheral_spin_budget 

Bounded poll iterations.

k_ra8_i3c_i2c_peripheral_max_addr_7b 

7-bit address ceiling.

Definition at line 48 of file ra8_i3c_i2c_peripheral.c.

Function Documentation

◆ internal_wait_ntst()

ra8_err_t internal_wait_ntst ( volatile const r_i3c_i2c_regs_t * reg,
uint32_t mask )
static

Bounded wait until mask bits set in NTST.

See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.

Parameters
[in]regSee header declaration for direction and constraints.
[in]maskSee header declaration for direction and constraints.
Returns
ra8_err_t error code (or void if the signature returns void).
Return values
k_ra8_okSuccess path.
k_ra8_err_invalid_argCaller violated a precondition.
Precondition
Driver state has been initialized by the matching *_init.
Caller has validated all pointer parameters.
Postcondition
Side effects are limited to those documented in the header.
No global state is modified on the error path.
Note
Thread safety: see the header declaration.
Since
0.1.0

Definition at line 83 of file ra8_i3c_i2c_peripheral.c.

References k_ra8_err_hw_timeout, k_ra8_i3c_i2c_peripheral_spin_budget, k_ra8_ok, r_i3c_i2c_regs_t::NTST, and RA8_INTERNAL.

Referenced by ra8_i3c_i2c_peripheral_receive(), and ra8_i3c_i2c_peripheral_send().

◆ ra8_i3c_i2c_peripheral_close()

ra8_err_t ra8_i3c_i2c_peripheral_close ( uint8_t channel)
nodiscard

Close the peripheral channel.

Parameters
[in]channelChannel index.
Returns
ra8_err_t.
Return values
k_ra8_okChannel torn down.
k_ra8_err_invalid_argChannel out of range.
Since
0.1.0

Definition at line 124 of file ra8_i3c_i2c_peripheral.c.

References r_i3c_i2c_regs_t::BCTL, i3c_i2c_regs(), k_ra8_err_invalid_arg, k_ra8_mstp_i3c, r_i3c_i2c_regs_t::MSDVAD, ra8_mstp_disable(), and r_i3c_i2c_regs_t::SVCTL.

Referenced by ra8_i3c_peripheral_close().

◆ ra8_i3c_i2c_peripheral_open()

ra8_err_t ra8_i3c_i2c_peripheral_open ( uint8_t channel,
const ra8_i3c_i2c_peripheral_cfg_t * cfg )
nodiscard

◆ ra8_i3c_i2c_peripheral_receive()

ra8_err_t ra8_i3c_i2c_peripheral_receive ( uint8_t channel,
uint8_t * buf,
uint32_t len )
nodiscard

Drain len bytes from NTDTBP0 after a controller-write.

Parameters
[in]channelChannel index.
[out]bufDestination buffer (non-NULL when len > 0).
[in]lenByte count.
Returns
ra8_err_t.
Return values
k_ra8_okAll bytes consumed.
k_ra8_err_null_ptrbuf is NULL with non-zero len.
k_ra8_err_invalid_argChannel out of range.
k_ra8_err_hw_timeoutRDBFF0 wait exhausted spin budget.
Since
0.1.0

Definition at line 157 of file ra8_i3c_i2c_peripheral.c.

References i3c_i2c_regs(), internal_wait_ntst(), k_ra8_err_invalid_arg, k_ra8_err_null_ptr, k_ra8_i3c_i2c_peripheral_byte_mask, k_ra8_i3c_i2c_peripheral_msk_ntst_rdbff0, k_ra8_ok, r_i3c_i2c_regs_t::NTDTBP0, ra8_log_error, RA8_RETURN_ON_ERROR, and s_tag.

Referenced by ra8_i3c_peripheral_receive().

◆ ra8_i3c_i2c_peripheral_send()

ra8_err_t ra8_i3c_i2c_peripheral_send ( uint8_t channel,
const uint8_t * data,
uint32_t len )
nodiscard

Push len bytes into NTDTBP0 in response to a controller-read.

Parameters
[in]channelChannel index.
[in]dataBuffer (non-NULL when len > 0).
[in]lenByte count.
Returns
ra8_err_t.
Return values
k_ra8_okAll bytes loaded.
k_ra8_err_null_ptrdata is NULL with non-zero len.
k_ra8_err_invalid_argChannel out of range.
k_ra8_err_hw_timeoutTDBEF0 wait exhausted spin budget.
Since
0.1.0

Definition at line 138 of file ra8_i3c_i2c_peripheral.c.

References i3c_i2c_regs(), internal_wait_ntst(), k_ra8_err_invalid_arg, k_ra8_err_null_ptr, k_ra8_i3c_i2c_peripheral_msk_ntst_tdbef0, k_ra8_ok, r_i3c_i2c_regs_t::NTDTBP0, ra8_log_error, RA8_RETURN_ON_ERROR, and s_tag.

Referenced by ra8_i3c_peripheral_send().

◆ ra8_i3c_i2c_peripheral_status()

ra8_err_t ra8_i3c_i2c_peripheral_status ( uint8_t channel,
uint8_t * out_mask )
nodiscard

Variable Documentation

◆ s_tag

const char* s_tag = "IICBP"
static

Definition at line 42 of file ra8_i3c_i2c_peripheral.c.