39static const char*
s_tag =
"SCI_SPI";
45typedef enum : uint32_t {
101 const uint32_t denom = divisor * baud_hz;
102 const uint32_t q = pclk_hz / denom;
195 if (reg ==
nullptr) {
222 if (reg ==
nullptr) {
239 if (reg ==
nullptr) {
243 const uint32_t saved_ccr0 = reg->
CCR0;
246 reg->
CCR0 = saved_ccr0;
262 reg->
TDR = (uint32_t)tx;
286 for (uint32_t i = 0U; i < len; i++) {
static const char * s_tag
Logging / check tag.
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_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#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_invalid_arg
Invalid function argument.
@ 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.
Bounded wait-flag primitives for RA8D2 HAL drivers.
static ra8_err_t ra8_hw_wait_flag_set32(volatile const uint32_t *reg, uint32_t mask, uint32_t budget)
Spin until (*reg & mask) != 0 or budget runs out.
@ k_ra8_hw_budget_long
RA8 hw budget long.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
Module Stop Control (MSTP) register layout for the Renesas RA8D2.
ra8_mstp_t
Packed (reg << 8) | bit module-stop identifier.
@ k_ra8_mstp_sci2
MSTPB29 SCI2.
@ k_ra8_mstp_sci4
MSTPB27 SCI4.
@ k_ra8_mstp_sci7
MSTPB24 SCI7.
@ k_ra8_mstp_sci9
MSTPB22 SCI9.
@ k_ra8_mstp_sci0
MSTPB31 SCI0.
@ k_ra8_mstp_sci5
MSTPB26 SCI5.
@ k_ra8_mstp_sci1
MSTPB30 SCI1.
@ k_ra8_mstp_sci6
MSTPB25 SCI6.
@ k_ra8_mstp_sci8
MSTPB23 SCI8.
@ k_ra8_mstp_sci3
MSTPB28 SCI3.
static const ra8_mstp_t s_mstp_table[k_ra8_sci_channel_count_val]
Channel-index -> MSTP id lookup.
SCI_B (Serial Communication Interface, B variant) register layoutfor the RA8D2.
static volatile r_sci_regs_t * ra8_sci(uint8_t channel)
Get pointer to SCI_B channel N (0..9).
@ k_ra8_sci_ccr3_mod_simple_spi
Simple SPI.
@ k_ra8_sci_ccr0_bit_re
Receive Enable.
@ k_ra8_sci_ccr0_bit_te
Transmit Enable.
@ k_ra8_sci_mddr_default
MDDR reset value (modulation disabled).
@ k_ra8_sci_cfclr_default
Clear every W1C bit at once.
@ k_ra8_sci_rdr_mask_data8
RDAT[7:0] for 8-bit reception.
@ k_ra8_sci_ccr3_bit_cpha
Clock Phase (sync only).
@ k_ra8_sci_ccr3_bit_lsbf
LSB First.
@ k_ra8_sci_ccr3_shift_chr
CHR[1:0] data-length field.
@ k_ra8_sci_ccr3_shift_mod
MOD[2:0] mode select.
@ k_ra8_sci_ccr3_bit_cpol
Clock Polarity (sync only).
@ k_ra8_sci_ccr2_shift_mddr
MDDR[7:0] field shift.
@ k_ra8_sci_ccr2_shift_cks
CKS[1:0] field shift.
@ k_ra8_sci_ccr2_shift_brr
BRR[7:0] field shift.
@ k_ra8_sci_csr_bit_rdrf
Receive Data Full.
@ k_ra8_sci_csr_bit_tdre
Transmit Data Empty.
@ k_ra8_sci_cfclr_bit_rdrfc
Clear CSR.RDRF.
@ k_ra8_sci_ccr3_chr_8bit
10 = 8-bit data (initial value).
@ k_ra8_sci_ccr2_mask_cks_field
CKS[21:20] in CCR2.
@ k_ra8_sci_ccr2_mask_brr_field
BRR[15:8] in CCR2.
ra8_err_t ra8_sci_spi_set_clock(uint8_t channel, uint32_t baud_hz, uint32_t pclk_hz)
Re-program the bit-rate without otherwise reconfiguring.
static uint32_t internal_ccr3(const ra8_sci_spi_cfg_t *cfg)
Build CCR3 for Simple-SPI controller mode.
ra8_err_t ra8_sci_spi_xfer(uint8_t channel, const uint8_t *tx, uint8_t *rx, uint32_t len)
Full-duplex multi-byte transfer.
static void internal_resolve_rate(uint32_t baud_hz, uint32_t pclk_hz, uint32_t *out_cks, uint32_t *out_brr)
Resolve CCR2.CKS + BRR for a requested Simple-SPI bit-rate.
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.
static void internal_apply_rate(volatile r_sci_regs_t *reg, uint32_t baud_hz, uint32_t pclk_hz)
Write CCR2 with the resolved CKS + BRR fields.
ra8_sci_spi_dim_t
Static dimensioning + bit-rate search constants.
@ k_ra8_sci_spi_channel_count
SCI0..SCI9.
@ k_ra8_sci_spi_brr_max
BRR is 8-bit.
@ k_ra8_sci_spi_cks_max
CKS[1:0] max (clock /64).
@ k_ra8_sci_spi_div_base
B = TCLK / (4 * 4^n * (N + 1)).
@ k_ra8_sci_spi_idle_byte
Idle fill when tx is NULL.
ra8_err_t ra8_sci_spi_xfer8(uint8_t channel, uint8_t tx, uint8_t *rx)
Full-duplex single-frame transfer.
SCI Simple-SPI controller-mode driver (polling, full-duplex).
@ k_ra8_spi_mode_1
CPOL=0, CPHA=1.
@ k_ra8_spi_mode_2
CPOL=1, CPHA=0.
Per-channel SCI_B register window.
volatile uint32_t CCR4
+0x18 Common Control 4.
volatile uint32_t CSR
+0x48 Common Status.
volatile uint32_t RDR
+0x00 Receive Data.
volatile uint32_t CCR2
+0x10 Common Control 2.
volatile uint32_t TDR
+0x04 Transmit Data.
volatile uint32_t CCR1
+0x0C Common Control 1.
volatile uint32_t CCR3
+0x14 Common Control 3.
volatile uint32_t CCR0
+0x08 Common Control 0.
volatile uint32_t CFCLR
+0x68 Common Flag Clear.
Configuration descriptor for ra8_sci_spi_init.
ra8_spi_mode_t mode
Clock polarity/phase (mode 0..3).
uint32_t baud_hz
Desired SCK bit-rate (Hz).
uint32_t pclk_hz
SCI baud-clock source (PCLKA, Hz).
bool lsb_first
true shifts LSB first.