46static const char*
s_tag =
"LIN";
61typedef enum : uint8_t {
76typedef enum : uint8_t {
88typedef enum : uint16_t {
134 uint32_t ccr3 = reg->
CCR3;
224 sum = (uint16_t)(low + high);
258 for (uint8_t i = 0U; i < len; ++i) {
294 for (uint8_t i = 0U; i < len; ++i) {
375 *out_detected = ((reg->
XSR0 & mask) != 0U);
418 uint8_t checksum = 0U;
458 const uint8_t p0 = (uint8_t)(b0 ^ b1 ^ b2 ^ b4);
469 uint8_t* out_checksum)
472 if (data ==
nullptr) {
487 for (uint8_t i = 0U; i < len; ++i) {
488 sum = (uint16_t)(sum + (uint16_t)data[i]);
505 *out_valid = sync_ok && pid_ok;
520 uint8_t expected = 0U;
524 *out_valid = (expected == received);
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.
@ 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_long
RA8 hw budget long.
static ra8_err_t ra8_hw_wait_flag_clear32(volatile const uint32_t *reg, uint32_t mask, uint32_t budget)
Spin until (*reg & mask) == 0 or budget runs out.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Full-featured Serial Communications Interface driver.
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_getc_polling(uint8_t channel, uint8_t *out_byte)
Poll-receive one byte (blocking, bounded spin).
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).
uint8_t ra8_sci_lin_pid(uint8_t id)
Compute the LIN protected identifier (PID) from a frame id.
static uint8_t internal_lin_fold_complement(uint16_t sum)
Fold a LIN checksum accumulator and return its one's complement.
ra8_err_t ra8_sci_lin_read_response(uint8_t channel, uint8_t *out_data, uint8_t len, uint8_t *out_checksum)
Read a LIN response: len data bytes plus one checksum byte.
ra8_err_t ra8_sci_lin_clear_status(uint8_t channel)
Clear the Simple-LIN status latches (XSR0) via XFCLR.
ra8_err_t ra8_sci_lin_wait_break(uint8_t channel)
Block until the responder detects a break field (XSR0.BFDF set).
static ra8_err_t internal_lin_wait_break_done(volatile const r_sci_regs_t *reg)
Spin until the break-field timer (XCR1.TCST) self-clears.
ra8_err_t ra8_sci_lin_init(uint8_t channel, const ra8_sci_lin_cfg_t *cfg)
Configure an SCI_B channel for a LIN role (commander or responder).
static ra8_err_t internal_lin_rx_buf(uint8_t channel, uint8_t *buf, uint8_t len)
Poll-receive len bytes of a LIN response data field.
ra8_sci_lin_pid_shift_t
Bit positions used when packing / unpacking a LIN PID.
@ k_ra8_sci_lin_id_bit2
Frame-id bit 2 position.
@ k_ra8_sci_lin_pid_p0_shift
PID parity bit P0 position.
@ k_ra8_sci_lin_id_bit0
Frame-id bit 0 position.
@ k_ra8_sci_lin_id_bit3
Frame-id bit 3 position.
@ k_ra8_sci_lin_pid_p1_shift
PID parity bit P1 position.
@ k_ra8_sci_lin_id_bit1
Frame-id bit 1 position.
@ k_ra8_sci_lin_id_bit4
Frame-id bit 4 position.
@ k_ra8_sci_lin_id_bit5
Frame-id bit 5 position.
static ra8_err_t internal_lin_tx_buf(uint8_t channel, const uint8_t *data, uint8_t len)
Poll-transmit len bytes of a LIN response data field.
ra8_err_t ra8_sci_lin_checksum(ra8_sci_lin_checksum_mode_t mode, uint8_t pid, const uint8_t *data, uint8_t len, uint8_t *out_checksum)
Compute a classic or enhanced LIN checksum over a data field.
ra8_err_t ra8_sci_lin_check_response(ra8_sci_lin_checksum_mode_t mode, uint8_t pid, const uint8_t *data, uint8_t len, uint8_t received, bool *out_valid)
Verify a received LIN response checksum against the data field.
ra8_err_t ra8_sci_lin_check_header(uint8_t sync, uint8_t pid, uint8_t *out_id, bool *out_valid)
Validate a received LIN header: SYNC byte + protected identifier.
ra8_err_t ra8_sci_lin_send_header(uint8_t channel, uint8_t id)
Transmit a full LIN header: break + SYNC (0x55) + PID.
ra8_sci_lin_const_t
Byte-level masks and protocol constants for the LIN math.
@ k_ra8_sci_lin_id_mask
6-bit LIN frame-id mask.
@ k_ra8_sci_lin_bit_mask
Single-bit extract / invert.
@ k_ra8_sci_lin_fold_passes
Carry-fold passes for checksum.
@ k_ra8_sci_lin_data_max
Max LIN response data bytes.
@ k_ra8_sci_lin_sync_byte
LIN SYNC field byte (0x55).
ra8_err_t ra8_sci_lin_break_detected(uint8_t channel, bool *out_detected)
Report whether the responder's break-field detector has fired.
ra8_err_t ra8_sci_lin_send_response(uint8_t channel, ra8_sci_lin_checksum_mode_t mode, uint8_t pid, const uint8_t *data, uint8_t len)
Publish a LIN response: data bytes followed by the checksum.
ra8_err_t ra8_sci_lin_send_break(uint8_t channel)
Emit a LIN break field on the channel's TXD line.
static void internal_lin_program_mode(volatile r_sci_regs_t *reg, ra8_sci_lin_role_t role, uint32_t tcss, uint16_t break_len)
Program the SCI_B mode + break-field timer/detector for a LIN role.
ra8_sci_lin_fold_const_t
16-bit masks used while folding the LIN checksum carry.
@ k_ra8_sci_lin_byte_bits
Bits per byte (carry shift).
@ k_ra8_sci_lin_byte_mask
Low-byte mask.
LIN (Local Interconnect Network) commander + responder driver on SCI_B.
@ k_ra8_sci_lin_id_max
Highest legal 6-bit LIN frame id.
ra8_sci_lin_role_t
Selects whether the channel drives (commander) or detects (responder) the LIN frame header.
@ k_ra8_sci_lin_role_responder
Detect the header (subordinate node).
ra8_sci_lin_checksum_mode_t
Selector for the classic vs.
@ k_ra8_sci_lin_checksum_enhanced
LIN 2.x: sum of PID + data bytes.
@ k_ra8_sci_lin_clk_div4
Break timer clock = TCLK / 4.
@ k_ra8_sci_lin_clk_div64
Break timer clock = TCLK / 64.
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_lin
Simple LIN.
@ k_ra8_sci_ccr0_bit_re
Receive Enable.
@ k_ra8_sci_ccr0_bit_te
Transmit Enable.
@ k_ra8_sci_xcr2_shift_bflw
BFLW[15:0] Break Field length.
@ k_ra8_sci_xcr2_bflw_max
Highest legal BFLW (0xFFFF banned).
@ k_ra8_sci_ccr3_shift_mod
MOD[2:0] mode select.
@ k_ra8_sci_ccr3_mask_mod
MOD[18:16] in CCR3.
@ k_ra8_sci_xsr0_bit_bfdf
Break Field Detection Flag (1 = seen).
@ k_ra8_sci_xfclr_default
Clear every LIN W1C latch at once.
@ k_ra8_sci_xcr0_shift_tcss
TCSS[1:0] timer count clock source.
@ k_ra8_sci_xcr0_bit_bfe
Break Field Enable.
@ k_ra8_sci_xcr1_bit_bmen
Bit Rate Measurement Enable.
@ k_ra8_sci_xcr1_bit_sdst
Start Frame Detection Enable.
@ k_ra8_sci_xcr1_bit_tcst
Break Field Output Timer Count Start.
Per-channel SCI_B register window.
volatile uint32_t XCR1
+0x38 Simple LIN Control 1.
volatile uint32_t XFCLR
+0x78 Simple LIN Flag Clear.
volatile uint32_t XSR0
+0x5C Simple LIN Status 0.
volatile uint32_t CCR3
+0x14 Common Control 3.
volatile uint32_t CCR0
+0x08 Common Control 0.
volatile uint32_t XCR0
+0x34 Simple LIN Control 0.
volatile uint32_t XCR2
+0x3C Simple LIN Control 2.
Configuration descriptor for ra8_sci_lin_init.
ra8_sci_cfg_t uart
Base async-UART baud + framing.
ra8_sci_lin_role_t role
Commander (generate) or responder (detect) the frame header.
ra8_sci_lin_timer_clk_t timer_clk
Break-field timer clock (TCSS).
uint16_t break_field_len
XCR2.BFLW: dominant time = (break_field_len + 1) x timer clock.