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

SPI_B backend for the ra8_io SPI-bus facade – thin shim over ra8_spi. More...

#include "ra8_io_spi_bus_spi_b.h"
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_io_spi_bus.h"
#include "ra8_io_spi_bus_internal.h"
#include "ra8_spi.h"
#include "ra8_spi_regs.h"
Include dependency graph for ra8_io_spi_bus_spi_b.c:

Go to the source code of this file.

Functions

static ra8_err_t internal_spi_b_xfer8 (void *ctx, uint8_t tx, uint8_t *rx)
 SPI_B backend: full-duplex single-byte exchange.
static ra8_err_t internal_spi_b_write_read (void *ctx, const void *tx, void *rx, uint32_t len, ra8_spi_bit_width_t width)
 SPI_B backend: full-duplex multi-frame transfer.
static ra8_err_t internal_spi_b_set_clock (void *ctx, uint32_t baud_hz, uint32_t pclk_hz)
 SPI_B backend: re-program the SPBR bit-rate divider.
ra8_err_t ra8_io_spi_bus_bind_spi_b (ra8_io_spi_bus_t *bus, uint8_t channel)
 Bind bus to SPI_B channel channel.

Variables

static const char *const s_tag = "ra8_io_spi_bus_spi_b"
 Module log tag.
static const ra8_io_spi_bus_iface_t s_spi_b_iface
 SPI_B backend vtable – every row forwards to ra8_spi_*.

Detailed Description

SPI_B backend for the ra8_io SPI-bus facade – thin shim over ra8_spi.

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

Implements ra8_io_spi_bus_iface by forwarding to the SPI_B driver (ra8_spi.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, divider limits) stays with the wrapped driver, which also carries every HUM citation – no raw MMIO is touched here.

Definition in file ra8_io_spi_bus_spi_b.c.

Function Documentation

◆ internal_spi_b_set_clock()

ra8_err_t internal_spi_b_set_clock ( void * ctx,
uint32_t baud_hz,
uint32_t pclk_hz )
static

SPI_B backend: re-program the SPBR bit-rate divider.

Forwards to ra8_spi_set_clock, which validates the channel and clock arguments and reprograms SPCR3.SPBR without tearing the channel down.

Parameters
[in]ctxBound channel index, encoded as (void*)(uintptr_t).
[in]baud_hzTarget bit-rate in Hz.
[in]pclk_hzCurrent PCLKA frequency in Hz.
Returns
ra8_err_t Error code.
Return values
k_ra8_okDivider reprogrammed.
k_ra8_err_invalid_argChannel or clock arguments invalid.
Precondition
The channel was initialised via ra8_spi_init.
ctx carries a channel index bound by ra8_io_spi_bus_bind_spi_b.
Postcondition
On success the channel's divider reflects the new rate.
On failure the divider is unchanged.
Note
Not thread-safe with respect to the same channel.
Since
0.1.0

Definition at line 131 of file ra8_io_spi_bus_spi_b.c.

References ra8_spi_set_clock().

◆ internal_spi_b_write_read()

ra8_err_t internal_spi_b_write_read ( void * ctx,
const void * tx,
void * rx,
uint32_t len,
ra8_spi_bit_width_t width )
static

SPI_B backend: full-duplex multi-frame transfer.

Forwards straight to ra8_spi_write_read, which supports 8/16/32-bit frames, treats a single NULL buffer as write-only / read-with-idle-fill, and rejects both buffers NULL.

Parameters
[in]ctxBound channel index, encoded as (void*)(uintptr_t).
[in]txSource buffer or NULL.
[out]rxDestination buffer or NULL.
[in]lenNumber of frames.
[in]widthPer-frame bit width.
Returns
ra8_err_t Error code.
Return values
k_ra8_okEvery frame exchanged.
k_ra8_err_null_ptrBoth buffers NULL with len > 0.
k_ra8_err_invalid_argChannel or width invalid.
k_ra8_err_hw_timeoutSPSR polling expired.
Precondition
The channel was initialised via ra8_spi_init.
Buffer alignment matches width.
Postcondition
On success len frames were clocked in both directions.
On failure the channel is left as the driver leaves it.
Note
Not thread-safe with respect to the same channel.
Since
0.1.0

Definition at line 96 of file ra8_io_spi_bus_spi_b.c.

References RA8_INTERNAL, and ra8_spi_write_read().

◆ internal_spi_b_xfer8()

ra8_err_t internal_spi_b_xfer8 ( void * ctx,
uint8_t tx,
uint8_t * rx )
static

SPI_B backend: full-duplex single-byte exchange.

Decodes the channel from the handle context and forwards to ra8_spi_xfer8, which validates the channel and owns the SPSR polling.

Parameters
[in]ctxBound channel index, encoded as (void*)(uintptr_t).
[in]txByte to transmit.
[out]rxReceive slot; may be NULL to discard.
Returns
ra8_err_t Error code.
Return values
k_ra8_okFrame exchanged.
k_ra8_err_null_ptrChannel out of range (driver reports it).
k_ra8_err_hw_timeoutSPSR.SPTEF / SPSR.SPRF never asserted.
Precondition
The channel was initialised via ra8_spi_init.
ctx carries a channel index bound by ra8_io_spi_bus_bind_spi_b.
Postcondition
On success one frame was clocked in both directions.
On failure the channel is left as the driver leaves it.
Note
Not thread-safe with respect to the same channel.
Since
0.1.0

Definition at line 61 of file ra8_io_spi_bus_spi_b.c.

References RA8_INTERNAL, and ra8_spi_xfer8().

◆ ra8_io_spi_bus_bind_spi_b()

ra8_err_t ra8_io_spi_bus_bind_spi_b ( ra8_io_spi_bus_t * bus,
uint8_t channel )
nodiscard

Bind bus to SPI_B channel channel.

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

Parameters
[in,out]busCaller-owned handle to bind (non-NULL).
[in]channelSPI_B channel index (0 or 1).
Returns
ra8_err_t Error code.
Return values
k_ra8_okbus now dispatches to ra8_spi_*.
k_ra8_err_null_ptrbus was NULL.
k_ra8_err_invalid_argchannel is out of range.
Precondition
bus points to writable storage.
channel < 2 (the RA8D2 has SPI0 and SPI1).
Postcondition
On success bus->iface is non-NULL and every ra8_io_spi_bus_* call forwards to SPI_B channel channel.
On failure bus is left unmodified.
Note
Thread-safe (writes only the caller's handle).
See also
ra8_io_spi_bus_bind_sci_spi The SCI Simple-SPI twin.
Since
0.1.0

Definition at line 143 of file ra8_io_spi_bus_spi_b.c.

References ra8_io_spi_bus_t::ctx, ra8_io_spi_bus_t::iface, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_spi_b_channel_count, RA8_CHECK_NULL_PTR, s_spi_b_iface, and s_tag.

Referenced by ep_bringup_panel_bus().

Variable Documentation

◆ s_spi_b_iface

const ra8_io_spi_bus_iface_t s_spi_b_iface
static
Initial value:
= {
}
static ra8_err_t internal_spi_b_xfer8(void *ctx, uint8_t tx, uint8_t *rx)
SPI_B backend: full-duplex single-byte exchange.
static ra8_err_t internal_spi_b_write_read(void *ctx, const void *tx, void *rx, uint32_t len, ra8_spi_bit_width_t width)
SPI_B backend: full-duplex multi-frame transfer.
static ra8_err_t internal_spi_b_set_clock(void *ctx, uint32_t baud_hz, uint32_t pclk_hz)
SPI_B backend: re-program the SPBR bit-rate divider.

SPI_B backend vtable – every row forwards to ra8_spi_*.

Definition at line 137 of file ra8_io_spi_bus_spi_b.c.

Referenced by ra8_io_spi_bus_bind_spi_b().

◆ s_tag

const char* const s_tag = "ra8_io_spi_bus_spi_b"
static

Module log tag.

Definition at line 33 of file ra8_io_spi_bus_spi_b.c.