78static const char*
s_tag =
"SCI";
157 if ((baud == 0U) || (pclk_hz == 0U)) {
161 const uint32_t n = pclk_hz / divisor;
165 return (uint8_t)(n - 1U);
414 if (reg ==
nullptr) {
446 if (reg ==
nullptr) {
479 if (reg ==
nullptr) {
492 reg->
TDR = (uint32_t)
byte;
500 if (reg ==
nullptr) {
518 if ((data ==
nullptr) && (len != 0U)) {
522 if (reg ==
nullptr) {
525 for (uint32_t i = 0U; i < len; ++i) {
546 if (reg ==
nullptr) {
561 if (reg ==
nullptr) {
586 if (reg ==
nullptr) {
613 if (reg ==
nullptr) {
619 const uint32_t csr = reg->
CSR;
636 if (reg ==
nullptr) {
651 if (reg ==
nullptr) {
667 uint32_t v = reg->
CCR2;
680 if (reg ==
nullptr) {
709typedef enum : uint16_t {
721 if ((baud == 0U) || (pclk_hz == 0U)) {
732 const uint64_t denom = divisor * (uint64_t)baud;
733 const uint64_t quotient = (uint64_t)pclk_hz / denom;
735 const uint64_t candidate = quotient - 1U;
737 *brr_out = (uint16_t)candidate;
749 if ((data ==
nullptr) && (len != 0U)) {
753 if (reg ==
nullptr) {
783 if ((buf ==
nullptr) && (len != 0U)) {
787 if (reg ==
nullptr) {
818 if (reg ==
nullptr) {
854 if (reg ==
nullptr) {
868 *remaining = pending;
881 if (reg ==
nullptr) {
900 if (reg ==
nullptr) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_HW_REGISTER_ACCESS
Mark an MMIO accessor function (returns volatile register pointer).
#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.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_init_failed
Hardware peripheral failed to initialise.
@ k_ra8_err_busy
Resource busy – blocking operation cannot proceed.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
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_medium
RA8 hw budget medium.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
#define ra8_log_error_val(tag, message, value)
RA8 log error val.
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.
IRQ-masked read-modify-write helper for shared registers.
static void ra8_register_guard_exit(const ra8_register_guard_t *guard)
Exit a critical section: restore PRIMASK.
static void ra8_register_guard_enter(ra8_register_guard_t *guard)
Enter a critical section: save PRIMASK, mask interrupts.
ra8_err_t ra8_sci_exit_stop(uint8_t channel)
Exit MSTP-gated stop state; the channel must be re-init'd.
ra8_err_t ra8_sci_write_polling(uint8_t channel, const uint8_t *data, uint32_t len)
Send len bytes by polling (convenience wrapper).
ra8_err_t ra8_sci_attach_rx_handler(uint8_t channel, ra8_sci_rx_fn_t fn, void *ctx)
Install the RX interrupt callback + context.
static volatile r_sci_regs_t * internal_reg(uint8_t channel)
Validate channel and return the register pointer.
ra8_err_t ra8_sci_set_baud(uint8_t channel, uint32_t baud, uint32_t pclk_hz)
Change the baud rate without tearing down the channel.
static uint32_t internal_ccr3(const ra8_sci_cfg_t *cfg)
Build the CCR3 value for an async-UART config descriptor.
ra8_err_t ra8_sci_baud_calculate(uint32_t baud, uint32_t pclk_hz, uint16_t *brr_out, uint8_t *clk_div_out)
Pure-math conversion from a target baud rate to BRR + clock divider settings.
ra8_err_t ra8_sci_abort(uint8_t channel, ra8_sci_dir_t direction)
Cancel an in-flight async TX or RX.
static void internal_clear_csr_flags(volatile r_sci_regs_t *reg)
Clear every stale CSR / FFCLR latch on a freshly-opened channel.
static uint8_t internal_brr(uint32_t pclk_hz, uint32_t baud)
Compute the 8-bit BRR value from a target baud and PCLKB.
ra8_err_t ra8_sci_clear_errors(uint8_t channel)
Clear the SSR error flags via write-zero.
ra8_err_t ra8_sci_read(uint8_t channel, uint8_t *buf, uint32_t len)
Arm an interrupt-driven RX of len bytes into buf.
ra8_err_t ra8_sci_init(uint8_t channel, const ra8_sci_cfg_t *cfg)
Initialise an SCI channel using the descriptor.
ra8_err_t ra8_sci_enter_stop(uint8_t channel)
Put the channel into MSTP-gated stop state.
static const ra8_mstp_t s_mstp_table[k_ra8_sci_channel_count_val]
Channel-index -> MSTP id lookup.
ra8_err_t ra8_sci_attach_tx_handler(uint8_t channel, ra8_sci_tx_fn_t fn, void *ctx)
Install the TX interrupt callback + context.
ra8_err_t ra8_sci_getc_polling(uint8_t channel, uint8_t *out_byte)
Poll-receive one byte (blocking, bounded spin).
static ra8_err_t internal_wait_tx_end(volatile r_sci_regs_t *reg)
Spin until CSR.TEND = 1 or the bounded budget runs out.
static uint32_t internal_ccr2(const ra8_sci_cfg_t *cfg)
Build the CCR2 value with BRR programmed.
ra8_err_t ra8_sci_receive_resume(uint8_t channel)
Resume reception by setting CCR0.RE.
ra8_err_t ra8_sci_receive_suspend(uint8_t channel)
Suspend reception by clearing CCR0.RE.
ra8_err_t ra8_sci_putc_polling(uint8_t channel, uint8_t byte)
Poll-send one byte (blocking, bounded by ra8_hw_err spin budget).
ra8_err_t ra8_sci_read_stop(uint8_t channel, uint32_t *remaining)
Stop an in-flight RX and report how many bytes were not yet consumed.
static void internal_program_ccr_bank(volatile r_sci_regs_t *reg, const ra8_sci_cfg_t *cfg)
Program CCR0..CCR4 + FCR for the requested UART config.
ra8_sci_state_t s_sci_state[k_ra8_sci_channel_count_val]
Per-channel allocation + dispatch table.
static uint32_t internal_ccr1(const ra8_sci_cfg_t *cfg)
Build the CCR1 value for an async-UART config descriptor.
ra8_err_t ra8_sci_write(uint8_t channel, const uint8_t *data, uint32_t len)
Arm an interrupt-driven TX of len bytes from data.
ra8_err_t ra8_sci_flush(uint8_t channel)
Block until the channel's transmit shift register is empty.
ra8_sci_baud_calc_const_t
Constants used by ra8_sci_baud_calculate.
@ k_ra8_sci_baud_cks_max
CKS field is 2 bits.
@ k_ra8_sci_baud_n0_divisor
32 * 2^(2*0).
@ k_ra8_sci_baud_div_step
Multiplier per CKS step.
@ k_ra8_sci_baud_brr_max
BRR is 8 bits wide.
ra8_err_t ra8_sci_deinit(uint8_t channel)
Tear down a channel – disable TX/RX, release MSTP.
ra8_err_t ra8_sci_get_errors(uint8_t channel, uint8_t *out_mask)
Read the SSR error bits (ORER, FER, PER).
Full-featured Serial Communications Interface driver.
bool(* ra8_sci_tx_fn_t)(void *ctx, uint8_t *byte)
TX-empty interrupt callback signature.
@ k_ra8_sci_stop_2
RA8 SCI stop 2.
@ k_ra8_sci_err_overrun
ORER set.
@ k_ra8_sci_err_parity
PER set.
@ k_ra8_sci_err_framing
FER set.
@ k_ra8_sci_err_none
RA8 SCI error none.
void(* ra8_sci_rx_fn_t)(void *ctx, uint8_t byte)
RX interrupt callback signature.
@ k_ra8_sci_parity_odd
RA8 SCI parity odd.
@ k_ra8_sci_parity_none
RA8 SCI parity none.
@ k_ra8_sci_data_7
RA8 SCI data 7.
ra8_sci_dir_t
Direction selector for ra8_sci_abort.
@ k_ra8_sci_dir_tx
Cancel an in-flight TX.
@ k_ra8_sci_dir_both
Cancel both directions.
@ k_ra8_sci_dir_rx
Cancel an in-flight RX.
src/-local shared surface for the ra8_sci driver TUs.
@ k_ra8_sci_channel_count_val
Total channels tracked.
@ k_ra8_sci_channel_max_index
SCI0..SCI9.
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_ccr0_bit_re
Receive Enable.
@ k_ra8_sci_ccr0_bit_tie
Transmit Interrupt Enable.
@ k_ra8_sci_ccr0_bit_rie
Receive Interrupt Enable.
@ k_ra8_sci_ccr0_bit_teie
Transmit End Interrupt 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_lsbf
LSB First.
@ k_ra8_sci_ccr3_bit_bpen
Synchronizer Bypass Enable.
@ k_ra8_sci_ccr3_bit_stp
Stop Bit Length (0=1, 1=2).
@ k_ra8_sci_ccr3_shift_chr
CHR[1:0] data-length field.
@ k_ra8_sci_ccr1_bit_pm
Parity Mode (0=even, 1=odd).
@ k_ra8_sci_ccr1_bit_pe
Parity Enable.
@ k_ra8_sci_ccr1_bit_spb2dt
Serial Port Break Data Select.
@ k_ra8_sci_ccr1_bit_spb2io
Serial Port Break I/O.
@ k_ra8_sci_ccr2_shift_mddr
MDDR[7:0] field shift.
@ k_ra8_sci_ccr2_shift_brr
BRR[7:0] field shift.
@ k_ra8_sci_csr_bit_tend
Transmit End.
@ k_ra8_sci_csr_bit_rdrf
Receive Data Full.
@ k_ra8_sci_csr_bit_tdre
Transmit Data Empty.
@ k_ra8_sci_csr_bit_fer
Framing Error.
@ k_ra8_sci_csr_bit_orer
Overrun Error.
@ k_ra8_sci_csr_bit_per
Parity Error.
@ k_ra8_sci_ffclr_default
Clear FRSR.DR latch.
@ k_ra8_sci_brr_async_divisor
64 * 2^(2*0 - 1) for n = 0.
@ k_ra8_sci_cfclr_bit_perc
Clear CSR.PER.
@ k_ra8_sci_cfclr_bit_ferc
Clear CSR.FER.
@ k_ra8_sci_cfclr_bit_orerc
Clear CSR.ORER.
@ k_ra8_sci_ccr3_chr_8bit
10 = 8-bit data (initial value).
@ k_ra8_sci_ccr3_chr_7bit
11 = 7-bit data.
@ k_ra8_sci_ccr2_mask_brr_field
BRR[15:8] in CCR2.
Per-channel SCI_B register window.
volatile uint32_t CCR4
+0x18 Common Control 4.
volatile uint32_t FCR
+0x24 FIFO Control.
volatile uint32_t FFCLR
+0x70 FIFO Flag Clear.
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.
Opaque save-restore handle for IRQ masking.
Configuration descriptor for ra8_sci_init.
uint32_t pclk_hz
PCLKB frequency in Hz (used for BRR calculation).
ra8_sci_parity_t parity
Parity mode.
ra8_sci_stop_bits_t stop_bits
1 or 2 stop bits.
uint32_t baud
Target baud rate in bps.
ra8_sci_data_bits_t data_bits
7 or 8 data bits.
Per-channel dispatch state.