80static const char*
s_tag =
"CNECC";
176typedef enum : uint16_t {
262 if (reg ==
nullptr) {
332 live = ((live & ~mask) | (new_bits & mask));
364 if (reg !=
nullptr) {
411 if (reg ==
nullptr) {
446 uint32_t set_bits = 0U;
552 if (mirror !=
nullptr) {
656 void*
const instance_ctx = (
void*)(uintptr_t)i;
664 for (uint8_t j = 0U; j < i; ++j) {
692 if (reg ==
nullptr) {
747 fn(ctx, instance, is_2bit, err_addr);
779typedef enum : uint32_t {
789typedef enum : uint8_t {
817 for (uint32_t i = 0U; i < bytes; ++i) {
818 crc ^= (uint32_t)data[i];
821 crc = (crc >> 1U) ^ mask;
835 {.correct_1bit =
true, .irq_1bit =
true, .irq_2bit =
true, .enable =
true},
836 {.correct_1bit =
true, .irq_1bit =
true, .irq_2bit =
true, .enable =
true},
844 if (out_ecc ==
nullptr) {
859 *out_ecc =
internal_crc32((
const uint8_t*)(uintptr_t)addr, aligned_len);
869 if (got != expected_ecc) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#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.
ra8_err_t ra8_cnecc_attach_handler(ra8_cnecc_error_fn_t fn, void *ctx)
Attach a callback for CNECC fault events.
static const ra8_mstp_t s_cnecc_mstp_table[k_ra8_cnecc_instance_count]
Per-instance MSTP id used to ungate the parent CANFD block.
ra8_err_t ra8_cnecc_set_counter_mirror(uint8_t instance, ra8_cnecc_counters_t *mirror)
Attach a BBR-mirrored counter triple for one instance.
ra8_err_t ra8_cnecc_disable_instance(uint8_t instance)
Disable error judgment for one instance only.
void ra8_cnecc_dispatch_overflow(uint8_t instance)
Force-bump the overflow counter (used by the ISR trampoline).
ra8_err_t ra8_cnecc_enter_standby(void)
Software-standby preparation (HUM 42.5.1 p 2876).
static ra8_cnecc_error_fn_t s_cnecc_fn
Currently registered fault callback.
ra8_err_t ra8_cnecc_open(void)
One-shot CNECC bring-up using the driver's default config.
ra8_err_t ra8_cnecc_detach_isr(void)
Tear down the ICU vector wiring established by ra8_cnecc_attach_isr.
static bool s_cnecc_isr_attached
True when ra8_cnecc_attach_isr has wired the ICU vectors.
ra8_err_t ra8_cnecc_get_counters(uint8_t instance, ra8_cnecc_counters_t *out)
Read the cumulative fault counters for one instance.
ra8_err_t ra8_cnecc_inject_fault(uint8_t instance, const ra8_cnecc_inject_t *req)
Run the HUM Ch 42.3.2 fault-injection sequence for one instance.
ra8_err_t ra8_cnecc_enable_instance(uint8_t instance)
Enable error judgment for one instance only.
ra8_err_t ra8_cnecc_test_mode_disable(uint8_t instance)
Force EC710TMC = 0x8000 to leave fault-injection mode.
ra8_err_t ra8_cnecc_init(const ra8_cnecc_config_t *cfg)
Initialise the CNECC driver and configure both instances.
static uint32_t s_cnecc_overflow_count[k_ra8_cnecc_instance_count]
Cumulative ECOVFF counter, per instance.
static uint32_t s_cnecc_one_bit_count[k_ra8_cnecc_instance_count]
Cumulative 1-bit fault counter, per instance.
ra8_err_t ra8_cnecc_set_correction_permission(uint8_t instance, bool correct_1bit)
Update the 1-bit correction permission for one instance.
static const ra8_elc_event_t s_cnecc_event_table[k_ra8_cnecc_instance_count]
Per-instance ICU event for the shared CANn_MRAM_ERI vector.
ra8_err_t ra8_cnecc_clear_status(uint8_t instance)
Clear the latched ECC fault state for one instance.
ra8_err_t ra8_cnecc_set_irq_enables(uint8_t instance, bool irq_1bit, bool irq_2bit)
Update the IRQ enable bits for one instance without touching any other CTL field.
ra8_cnecc_compute_align_t
Alignment / size constants for the compute path.
@ k_ra8_cnecc_compute_byte_mask
Byte mask.
@ k_ra8_cnecc_compute_byte_bits
Bits per byte.
@ k_ra8_cnecc_compute_align
4-byte alignment for addr / len.
ra8_cnecc_compute_const_t
Magic numbers used by ra8_cnecc_compute promoted to typed enums.
@ k_ra8_cnecc_crc_poly
Reflected CRC32 polynomial.
@ k_ra8_cnecc_crc_seed
Initial CRC32 register value.
@ k_ra8_cnecc_crc_xorout
Final XOR mask.
void ra8_cnecc_dispatch(uint8_t instance, bool is_2bit, uint16_t err_addr)
Dispatch a CNECC fault event to the installed handler.
ra8_cnecc_isr_const_t
Numeric constants for ISR ctx packing.
@ k_ra8_cnecc_isr_ctx_inst_mask
Low byte of ctx -> instance.
ra8_err_t ra8_cnecc_reset_counters(uint8_t instance)
Zero the cumulative fault counters for one instance.
static uint32_t s_cnecc_two_bit_count[k_ra8_cnecc_instance_count]
Cumulative 2-bit fault counter, per instance.
static ra8_cnecc_config_t s_cnecc_cached_cfg
Last-applied configuration – replayed by exit_standby.
ra8_err_t ra8_cnecc_test_mode_active(uint8_t instance, bool *out)
Query whether fault injection is currently armed.
static ra8_err_t internal_apply_instance(uint8_t instance, const ra8_cnecc_instance_cfg_t *cfg)
Apply one instance's configuration.
static bool s_cnecc_initialized
True between successful init and matching deinit.
void ra8_cnecc_isr_handler(void *ctx)
Generic ICU trampoline for both CANn_MRAM_ERI vectors.
static ra8_cnecc_counters_t * s_cnecc_bbr_mirror[k_ra8_cnecc_instance_count]
Optional BBR-mirrored counter pointer, per instance.
ra8_err_t ra8_cnecc_verify(uint32_t addr, uint32_t len, uint32_t expected_ecc)
Verify a region's ECC tag matches an expected value.
static void internal_ctl_rmw(volatile r_cnecc_regs_t *reg, uint32_t new_bits, uint32_t mask)
Read-modify-write helper for EC710CTL that preserves the unlock pattern and clears RO/clear-on-write ...
ra8_err_t ra8_cnecc_deinit(void)
Tear down both CNECC instances and gate the CANFD MSTP bits.
ra8_err_t ra8_cnecc_attach_isr(uint8_t priority)
Wire the CANn_MRAM_ERI ICU vectors to the driver dispatcher.
ra8_err_t ra8_cnecc_exit_standby(void)
Software-standby exit (HUM 42.5.2 p 2876).
static void * s_cnecc_ctx
Opaque context passed to s_cnecc_fn.
ra8_err_t ra8_cnecc_get_status(uint8_t instance, ra8_cnecc_status_t *out)
Snapshot the current ECC state of one CNECC instance.
ra8_err_t ra8_cnecc_compute(uint32_t addr, uint32_t len, uint32_t *out_ecc)
Compute a 32-bit ECC code over a (addr, len) memory region.
static uint32_t internal_cnecc_ctl_value(const ra8_cnecc_instance_cfg_t *cfg)
Compute the EC710CTL value one instance's configuration asks for.
static uint32_t internal_crc32(const uint8_t *data, uint32_t bytes)
Reflected CRC32 (poly 0xEDB88320) over a byte buffer.
CANFD ECC (CNECC) HAL driver public API.
void(* ra8_cnecc_error_fn_t)(void *ctx, uint8_t instance, bool is_2bit, uint16_t err_addr)
CANFD ECC fault callback signature.
void ra8_cnecc_isr_handler(void *ctx)
Generic ICU trampoline for both CANn_MRAM_ERI vectors.
CANFD ECC (CNECC) register layout for the RA8D2.
@ k_ra8_cnecc_instance_count
ECCMB0 + ECCMB1.
static volatile r_cnecc_regs_t * ra8_cnecc(uint8_t instance)
Get pointer to CNECC instance instance.
@ k_ra8_cnecc_mask_ecead
ECEAD[9:0].
@ k_ra8_cnecc_mask_ectmce
ECTMCE test-mode enable.
@ k_ra8_cnecc_mask_test_subst
Figure 42.2 "Use ECEDB".
@ k_ra8_cnecc_mask_test_enable
Figure 42.2 "Enable test".
@ k_ra8_cnecc_mask_test_disable
Figure 42.2 "Disable test".
@ k_ra8_cnecc_mask_ecovff
ECOVFF overflow.
@ k_ra8_cnecc_mask_ecemf
ECEMF.
@ k_ra8_cnecc_mask_ecer1f
ECER1F.
@ k_ra8_cnecc_mask_ec1ecp
EC1ECP.
@ k_ra8_cnecc_mask_ecer1c
ECER1C (write-1-clear).
@ k_ra8_cnecc_mask_ctl_writable
Bits we may legally write (excludes RO + reserved).
@ k_ra8_cnecc_mask_ecer2c
ECER2C (write-1-clear).
@ k_ra8_cnecc_mask_emca_unlock
EMCA = 01b -> unlock ECERVF.
@ k_ra8_cnecc_mask_clear_all
ECER1C | ECER2C bundle.
@ k_ra8_cnecc_mask_ec2edic
EC2EDIC.
@ k_ra8_cnecc_mask_emca
EMCA[1:0] @ [15:14].
@ k_ra8_cnecc_mask_ecsedf0
1-bit address captured.
@ k_ra8_cnecc_mask_ecervf
ECERVF.
@ k_ra8_cnecc_mask_ecer2f
ECER2F.
@ k_ra8_cnecc_mask_ec1edic
EC1EDIC.
@ k_ra8_cnecc_mask_ecdedf0
2-bit address captured.
@ k_ra8_cnecc_mask_irq_all
EC1EDIC | EC2EDIC.
Event Link Controller (ELC) register layout for the Renesas RA8D2.
ra8_elc_event_t
Partial list of ELC events (populate as drivers need them).
@ k_ra8_elc_event_can1_mram_eri
CANFD1 MRAM ECC error (HUM Ch 19 Table 19.3).
@ k_ra8_elc_event_can0_mram_eri
CANFD0 MRAM ECC error (HUM Ch 19 Table 19.3).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_init_failed
Hardware peripheral failed to initialise.
@ k_ra8_err_crc_mismatch
CRC mismatch detected on received data.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ 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.
NVIC + ICU IELSR allocator.
@ k_ra8_isr_prio_max
Lowest priority.
ra8_err_t ra8_isr_register(ra8_elc_event_t event, ra8_isr_handler_t handler, void *ctx, uint8_t priority, uint16_t *out_slot)
Allocate an IELSR slot for an ELC event + handler.
ra8_err_t ra8_isr_unregister(ra8_elc_event_t event)
Release a previously-allocated IELSR slot.
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.
#define ra8_log_info(tag, message)
RA8 log info.
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.
ra8_mstp_t
Packed (reg << 8) | bit module-stop identifier.
@ k_ra8_mstp_canfd1
MSTPC26 CANFD1.
@ k_ra8_mstp_canfd0
MSTPC27 CANFD0.
Per-instance CNECC register window (size = 0x14 bytes).
volatile uint32_t EC710TED
+0x0C Test substitute data.
volatile uint32_t EC710EAD0
+0x10 Captured error address (read-only).
volatile uint32_t EC710CTL
+0x00 ECC control / status / IRQ enables.
volatile uint16_t EC710TMC
+0x04 Test-mode control.
Top-level driver configuration.
ra8_cnecc_instance_cfg_t instances[k_ra8_cnecc_instance_count]
Per-instance settings.
Cumulative per-instance fault counters.
uint32_t one_bit_count
Lifetime 1-bit fault count for this instance.
uint32_t two_bit_count
Lifetime 2-bit fault count for this instance.
uint32_t overflow_count
Lifetime ECOVFF count for this instance.
Fault-injection request descriptor.
uint32_t substitute
32-bit value stored in EC710TED.
bool one_bit_flip
true => 1-bit error variant; false => 2-bit.
Per-instance ECC configuration descriptor.
bool enable
true => leave ECERVF set after init.
bool irq_2bit
true => raise IRQ on every 2-bit fault.
bool correct_1bit
true => HW corrects 1-bit faults (clears EC1ECP).
bool irq_1bit
true => raise IRQ on every 1-bit fault.
Snapshot of one CNECC instance, returned by ra8_cnecc_get_status.
uint16_t reserved0
Padding for alignment.
bool overflow
Live ECOVFF: address-capture overflow.
bool err_present
Live ECEMF: present-cycle error.
uint32_t two_bit_count
Cumulative 2-bit fault count.
bool irq2_enabled
Live EC2EDIC.
uint32_t raw_ctl
Live EC710CTL value.
bool addr_is_2bit
true => last_addr was a 2-bit fault.
bool judgment_active
Live ECERVF: judgment currently enabled.
uint16_t raw_tmc
Live EC710TMC value.
bool irq1_enabled
Live EC1EDIC.
uint16_t last_addr
Last captured ECEAD[9:0] RAM offset.
bool err_1bit
Live ECER1F: 1-bit fault latched.
uint32_t one_bit_count
Cumulative 1-bit fault count.
bool addr_is_1bit
true => last_addr was a 1-bit fault.
uint32_t overflow_count
Cumulative ECOVFF count.
bool test_mode
Live ECTMCE: fault-injection currently armed.
bool err_2bit
Live ECER2F: 2-bit fault latched.
bool correct_enabled
true => 1-bit correction enabled (EC1ECP=0).