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

SCI Simple-SPI backend for the ra8_io SPI-bus facade – thin shim over ra8_sci_spi. More...

#include "ra8_io_spi_bus_sci_spi.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_sci_regs.h"
#include "ra8_sci_spi.h"
#include "ra8_spi.h"
Include dependency graph for ra8_io_spi_bus_sci_spi.c:

Go to the source code of this file.

Functions

static ra8_err_t internal_sci_spi_xfer8 (void *ctx, uint8_t tx, uint8_t *rx)
 SCI backend: full-duplex single-byte exchange.
static ra8_err_t internal_sci_spi_write_read (void *ctx, const void *tx, void *rx, uint32_t len, ra8_spi_bit_width_t width)
 SCI backend: full-duplex multi-byte transfer (8-bit frames only).
static ra8_err_t internal_sci_spi_set_clock (void *ctx, uint32_t baud_hz, uint32_t pclk_hz)
 SCI backend: re-program the CCR2 bit-rate divider.
ra8_err_t ra8_io_spi_bus_bind_sci_spi (ra8_io_spi_bus_t *bus, uint8_t channel)
 Bind bus to SCI Simple-SPI channel channel.

Variables

static const char *const s_tag = "ra8_io_spi_bus_sci_spi"
 Module log tag.
static const ra8_io_spi_bus_iface_t s_sci_spi_iface
 SCI Simple-SPI backend vtable – every row forwards to ra8_sci_spi_*.

Detailed Description

SCI Simple-SPI backend for the ra8_io SPI-bus facade – thin shim over ra8_sci_spi.

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

Implements ra8_io_spi_bus_iface by forwarding to the SCI Simple-SPI driver (ra8_sci_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. The SCI block clocks 8-bit frames only, so the multi-frame row rejects wider widths with k_ra8_err_not_supported instead of silently mis-framing. No raw MMIO is touched here; the driver carries every HUM citation.

Definition in file ra8_io_spi_bus_sci_spi.c.

Function Documentation

◆ internal_sci_spi_set_clock()

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

SCI backend: re-program the CCR2 bit-rate divider.

Forwards to ra8_sci_spi_set_clock, which validates the arguments and picks the smallest CKS keeping BRR in range.

Parameters
[in]ctxBound channel index, encoded as (void*)(uintptr_t).
[in]baud_hzTarget bit-rate in Hz.
[in]pclk_hzSCI baud-clock source (PCLKA) in Hz.
Returns
ra8_err_t Error code.
Return values
k_ra8_okDivider reprogrammed.
k_ra8_err_invalid_argChannel out of range or baud_hz zero.
Precondition
The channel was initialised via ra8_sci_spi_init.
ctx carries a channel index bound by ra8_io_spi_bus_bind_sci_spi.
Postcondition
On success CCR2.CKS/BRR reflect 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 139 of file ra8_io_spi_bus_sci_spi.c.

References ra8_sci_spi_set_clock().

◆ internal_sci_spi_write_read()

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

SCI backend: full-duplex multi-byte transfer (8-bit frames only).

The SCI Simple-SPI data register clocks one byte per frame, so any width other than k_ra8_spi_width_8 is rejected up-front with k_ra8_err_not_supported. Valid requests forward to ra8_sci_spi_xfer, which treats a NULL tx as idle (0xFF) fill and a NULL rx as discard.

Parameters
[in]ctxBound channel index, encoded as (void*)(uintptr_t).
[in]txSource bytes or NULL for idle fill.
[out]rxDestination bytes or NULL to discard.
[in]lenNumber of bytes.
[in]widthPer-frame bit width; only k_ra8_spi_width_8.
Returns
ra8_err_t Error code.
Return values
k_ra8_okEvery byte exchanged.
k_ra8_err_not_supportedwidth is not 8-bit.
k_ra8_err_invalid_argChannel out of range.
k_ra8_err_hw_timeoutA per-frame poll expired.
Precondition
The channel was initialised via ra8_sci_spi_init.
ctx carries a channel index bound by ra8_io_spi_bus_bind_sci_spi.
Postcondition
On success len frames were clocked.
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 101 of file ra8_io_spi_bus_sci_spi.c.

References k_ra8_err_not_supported, k_ra8_spi_width_8, RA8_INTERNAL, and ra8_sci_spi_xfer().

◆ internal_sci_spi_xfer8()

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

SCI backend: full-duplex single-byte exchange.

Decodes the channel from the handle context and forwards to ra8_sci_spi_xfer8, which validates the channel and owns the CSR 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_timeoutThe TX-empty or RX-full poll expired.
Precondition
The channel was initialised via ra8_sci_spi_init.
ctx carries a channel index bound by ra8_io_spi_bus_bind_sci_spi.
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 65 of file ra8_io_spi_bus_sci_spi.c.

References RA8_INTERNAL, and ra8_sci_spi_xfer8().

◆ ra8_io_spi_bus_bind_sci_spi()

ra8_err_t ra8_io_spi_bus_bind_sci_spi ( ra8_io_spi_bus_t * bus,
uint8_t channel )
nodiscard

Bind bus to SCI Simple-SPI channel channel.

Installs the SCI Simple-SPI trampoline vtable and records the channel in the handle context. No hardware is touched: initialise the channel with ra8_sci_spi_init(channel, ...) (before or after binding) and own the chip-select as a GPIO yourself.

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

Definition at line 151 of file ra8_io_spi_bus_sci_spi.c.

References ra8_io_spi_bus_t::ctx, ra8_io_spi_bus_t::iface, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_sci_channel_count, RA8_CHECK_NULL_PTR, s_sci_spi_iface, and s_tag.

Referenced by priv_ra8_esp_hosted_spi_open().

Variable Documentation

◆ s_sci_spi_iface

const ra8_io_spi_bus_iface_t s_sci_spi_iface
static
Initial value:
= {
}
static ra8_err_t internal_sci_spi_xfer8(void *ctx, uint8_t tx, uint8_t *rx)
SCI backend: full-duplex single-byte exchange.
static ra8_err_t internal_sci_spi_write_read(void *ctx, const void *tx, void *rx, uint32_t len, ra8_spi_bit_width_t width)
SCI backend: full-duplex multi-byte transfer (8-bit frames only).
static ra8_err_t internal_sci_spi_set_clock(void *ctx, uint32_t baud_hz, uint32_t pclk_hz)
SCI backend: re-program the CCR2 bit-rate divider.

SCI Simple-SPI backend vtable – every row forwards to ra8_sci_spi_*.

Definition at line 145 of file ra8_io_spi_bus_sci_spi.c.

Referenced by ra8_io_spi_bus_bind_sci_spi().

◆ s_tag

const char* const s_tag = "ra8_io_spi_bus_sci_spi"
static

Module log tag.

Definition at line 36 of file ra8_io_spi_bus_sci_spi.c.