60#include "transport_drv.h"
71static const char*
const s_tag =
"eh_spi";
96typedef enum : uint16_t {
102 "the co-processor image is built CONFIG_ESP_SPI_MODE=3");
113 "the port's frame bound must be the one the vendored SPI driver clocks");
237 return (
s_bus.iface !=
nullptr) ? &
s_bus :
nullptr;
318 if ((pclk_hz == 0U) || (sck_hz == 0U) ||
448 if (bus_handle ==
nullptr) {
451 if (bus_handle != (
void*)&
s_bus) {
494 struct hosted_transport_context_t* ctx = (
struct hosted_transport_context_t*)transfer_context;
495 if (ctx ==
nullptr) {
498 if ((ctx->tx_buf ==
nullptr) || (ctx->rx_buf ==
nullptr)) {
505 if (bus ==
nullptr) {
const ra8_pin_interface_t g_ra8_gpio_pin_interface
esp-hosted port header: RTOS handle types, return codes and budgets.
#define RET_FAIL
Operation failed for an unspecified reason.
#define RET_INVALID
A parameter was out of contract (null handle, bad size).
#define RET_OK
Operation completed.
#define MAX_TRANSPORT_BUFFER_SIZE
Bytes moved in one SDIO block transfer.
esp-hosted port header: full-duplex SPI transport buffer size.
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Board-identity, LEDs, switches, display, audio, Arduino, Pmod, and MikroBUS portion of the EK-RA8D2 v...
@ k_ra8_board_pmod1_sci_channel
Pmod1 (J26) Simple-SPI is SCI2.
@ k_ra8_board_pmod1_spi_copi
Pmod1.2 COPI (MOSI2/TXD2 per UM),P801.
@ k_ra8_board_pmod1_spi_sck
Pmod1.4 SCK (SCK2), P803.
@ k_ra8_board_pmod1_spi_cipo
Pmod1.3 CIPO (MISO2/RXD2 per UM),P802.
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.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_spi_error
SPI transfer failed (bus fault, mode fault, overrun, ...).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
static const ra8_pin_interface_t * s_pin_if
The pin driver every level read and write goes through.
THE single point of change for the RA8 <-> ESP32-C6 harness map.
@ k_ra8_esp_hosted_pin_chip_select
Chip select, RA8 output.
static ra8_err_t internal_route_data_pins(void)
Route the three Pmod1 SPI data pins to the SCI peripheral.
static const ra8_io_spi_bus_t * s_injected_bus
Test-injected replacement for s_bus, or null in production.
static void internal_release_pins(void)
Hand every pin the transport claimed back to the pin validator.
ra8_err_t priv_ra8_esp_hosted_spi_close(void)
Close the SCI Simple-SPI channel and release every pin it took.
void priv_ra8_esp_hosted_spi_set_bus(const ra8_io_spi_bus_t *bus)
Replace the SPI bus the transfer slot clocks frames through.
static bool s_open
True between a successful open and its matching close.
ra8_err_t priv_ra8_esp_hosted_spi_bind(hosted_osi_funcs_t *out)
Populate the three transport slots of the OS-abstraction vtable.
bool priv_ra8_esp_hosted_spi_is_open(void)
Report whether the SCI Simple-SPI channel is currently open.
ra8_esp_hosted_spi_frame_t
The frame bound this port supplies, as a named constant.
@ k_ra8_esp_hosted_spi_frame_bytes
Bytes clocked in one full-duplex transaction, from the port header.
void priv_ra8_esp_hosted_spi_set_pin_interface(const ra8_pin_interface_t *iface)
Replace the pin driver the transfer slot drives chip select with.
static ra8_io_spi_bus_t s_bus
Bus handle bound to the SCI Simple-SPI channel by the open.
ra8_err_t priv_ra8_esp_hosted_spi_open(uint8_t sci_channel, uint32_t pclk_hz, uint32_t sck_hz)
Route the Pmod1 SPI pins and open the SCI Simple-SPI channel.
static uint8_t s_channel
SCI channel the open brought up, meaningful only while s_open.
static int internal_do_bus_transfer(void *transfer_context)
_h_do_bus_transfer: clock one full-duplex esp-hosted frame.
static const ra8_io_spi_bus_t * internal_bus(void)
Report the bus the transfer slot should clock through.
static int internal_bus_deinit(void *bus_handle)
_h_bus_deinit: close the channel behind an opaque bus handle.
static const ra8_pin_interface_t * internal_pin_if(void)
Report the pin driver the chip select is driven through.
static void * internal_bus_init(void)
_h_bus_init: hand the vendored transport its opaque bus handle.
Module-private surface of the esp-hosted full-duplex SPI transport.
@ k_ra8_esp_hosted_spi_mode
Clock polarity/phase both high: the C6 image's CONFIG_ESP_SPI_MODE.
PSEL codes for peripheral pin routing on the RA8D2.
@ k_ra8_psel_sci_async
00100b: SCI async serial (UART).
ra8_io SPI-bus facade – one controller-transfer vtable over thechip's two SPI implementations.
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.
SCI Simple-SPI backend binder for the ra8_io SPI-bus facade.
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.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_warn(tag, message)
RA8 log warn.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
#define ra8_log_error_val(tag, message, value)
RA8 log error val.
Abstract pin-driver interface for dependency injection.
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
@ k_ra8_level_high
Drive or read 1.
@ k_ra8_level_low
Drive or read 0.
High-level GPIO helpers on top of the PORT + PFS register layer.
ra8_err_t ra8_gpio_release(ra8_port_pin_t pin)
Release a GPIO pin claim.
ra8_err_t ra8_pfs_route_peripheral(ra8_port_pin_t pin, ra8_psel_t psel, const char *owner)
Route a pin to a non-IRQ peripheral function via PFS.PSEL.
SCI Simple-SPI controller-mode driver (polling, full-duplex).
ra8_err_t ra8_sci_spi_init(uint8_t channel, const ra8_sci_spi_cfg_t *cfg)
Bring an SCI channel up as a Simple-SPI controller.
ra8_err_t ra8_sci_spi_deinit(uint8_t channel)
Disable the channel and release its MSTP gate.
SPI_B controller driver (RA8D2 Type-B SPI peripheral).
@ k_ra8_spi_width_8
8-bit frame -> SPCMDn.SPB = 0b00111.
ra8_spi_mode_t
CPOL / CPHA combinations.
@ k_ra8_spi_mode_3
CPOL=1, CPHA=1.
Caller-allocated SPI-bus handle binding a backend to its context.
ra8_err_t(* output_init)(void *ctx, ra8_port_pin_t pin, ra8_level_t init_level)
Configure a pin as an output at an initial level.
void * ctx
Opaque context handed to every call.
ra8_err_t(* write)(void *ctx, ra8_port_pin_t pin, ra8_level_t level)
Drive a pin.
Configuration descriptor for ra8_sci_spi_init.