ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_io_spi_bus.c
Go to the documentation of this file.
1
19
20#include "ra8_io_spi_bus.h"
21
22#include <stdint.h>
23
24#include "ra8_attributes.h"
25#include "ra8_check.h"
26#include "ra8_err.h"
28#include "ra8_spi.h"
29#include "ra8_spi_bus_ops.h"
30
32static const char* const s_tag = "ra8_io_spi_bus";
33
34/* =============================================================================
35 * Internal helpers
36 * =============================================================================
37 */
38
64{
65 if (bus == nullptr) {
66 return k_ra8_err_null_ptr;
67 }
68 if (bus->iface == nullptr) {
70 }
71 return k_ra8_ok;
72}
73
74/* =============================================================================
75 * Public API -- dispatch through the bound backend
76 * =============================================================================
77 */
78
79ra8_err_t ra8_io_spi_bus_xfer8(const ra8_io_spi_bus_t* bus, uint8_t tx, uint8_t* rx)
80{
81 const ra8_err_t v = internal_validate(bus);
82 if (v != k_ra8_ok) {
83 return v;
84 }
85 RA8_CHECK_NULL_PTR(bus->iface->xfer8, s_tag, "backend xfer8 op missing");
86 return bus->iface->xfer8(bus->ctx, tx, rx);
87}
88
90 const void* tx,
91 void* rx,
92 uint32_t len,
94{
95 const ra8_err_t v = internal_validate(bus);
96 if (v != k_ra8_ok) {
97 return v;
98 }
99 RA8_CHECK_NULL_PTR(bus->iface->write_read, s_tag, "backend write_read op missing");
100 return bus->iface->write_read(bus->ctx, tx, rx, len, width);
101}
102
103ra8_err_t ra8_io_spi_bus_set_clock(const ra8_io_spi_bus_t* bus, uint32_t baud_hz, uint32_t pclk_hz)
104{
105 const ra8_err_t v = internal_validate(bus);
106 if (v != k_ra8_ok) {
107 return v;
108 }
109 RA8_CHECK_NULL_PTR(bus->iface->set_clock, s_tag, "backend set_clock op missing");
110 return bus->iface->set_clock(bus->ctx, baud_hz, pclk_hz);
111}
112
113/* =============================================================================
114 * ra8_spi_bus_ops_t bridge (Ring-3 seam)
115 * =============================================================================
116 */
117
144static ra8_err_t internal_ops_xfer8(void* ctx, uint8_t tx, uint8_t* rx)
145{
146 RA8_CHECK_NULL_PTR(ctx, s_tag, "ctx (spi bus) must not be nullptr");
147 return ra8_io_spi_bus_xfer8((const ra8_io_spi_bus_t*)ctx, tx, rx);
148}
149
151{
152 const ra8_err_t v = internal_validate(bus);
153 if (v != k_ra8_ok) {
154 return v;
155 }
156 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
158 out->ctx = (void*)(uintptr_t)bus;
159 return k_ra8_ok;
160}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
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_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
ra8_err_t ra8_io_spi_bus_xfer8(const ra8_io_spi_bus_t *bus, uint8_t tx, uint8_t *rx)
Full-duplex single-byte exchange on the bound bus.
ra8_err_t ra8_io_spi_bus_write_read(const ra8_io_spi_bus_t *bus, const void *tx, void *rx, uint32_t len, ra8_spi_bit_width_t width)
Full-duplex multi-frame transfer on the bound bus.
static ra8_err_t internal_validate(const ra8_io_spi_bus_t *bus)
Reject a handle that is NULL or has no backend bound.
static ra8_err_t internal_ops_xfer8(void *ctx, uint8_t tx, uint8_t *rx)
Seam trampoline – forward an xfer8 into the bound bus.
ra8_err_t ra8_io_spi_bus_set_clock(const ra8_io_spi_bus_t *bus, uint32_t baud_hz, uint32_t pclk_hz)
Re-program the bound bus bit-rate without reconfiguring.
ra8_err_t ra8_io_spi_bus_as_ops(const ra8_io_spi_bus_t *bus, ra8_spi_bus_ops_t *out)
Expose a bound bus through the Ring-3 seam ra8_spi_bus_ops_t.
ra8_io SPI-bus facade – one controller-transfer vtable over thechip's two SPI implementations.
Internal vtable type for the ra8_io SPI-bus facade.
SPI_B controller driver (RA8D2 Type-B SPI peripheral).
ra8_spi_bit_width_t
Per-frame bit width for multi-byte transfers.
Definition ra8_spi.h:84
Injected SPI-bus seam consumed by Ring-3 SPI device drivers.
ra8_err_t(* set_clock)(void *ctx, uint32_t baud_hz, uint32_t pclk_hz)
Re-program the bit-rate divider from baud_hz / pclk_hz.
ra8_err_t(* xfer8)(void *ctx, uint8_t tx, uint8_t *rx)
Full-duplex single-byte exchange (rx may be NULL).
ra8_err_t(* write_read)(void *ctx, const void *tx, void *rx, uint32_t len, ra8_spi_bit_width_t width)
Full-duplex multi-frame transfer (either buffer may be NULL).
Caller-allocated SPI-bus handle binding a backend to its context.
void * ctx
Backend-private context (private).
const ra8_io_spi_bus_iface_t * iface
Bound backend vtable (private).
Caller-filled SPI transfer seam: one full-duplex byte exchange.
void * ctx
Opaque cookie handed to xfer8 (binder-owned).
ra8_err_t(* xfer8)(void *ctx, uint8_t tx, uint8_t *rx)
Full-duplex single-byte exchange on the bound bus.