|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
SRAM ECC fault-injection + detection demo (EK-RA8D2, issue #130). More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_sram.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | mecc_config_t : uint32_t { k_mecc_baud = 115200U , k_mecc_period_ms = 1000U } |
| Compile-time settings. More... | |
| enum | mecc_geom_t : uint32_t { k_mecc_bank = 2U , k_mecc_probe_offset = 0U } |
| ECC target geometry. More... | |
Functions | |
| static void | internal_mecc_panic_halt (void) |
| Park forever after a fatal initialization failure. | |
| static void | internal_mecc_setup_or_halt (void) |
| Bring CGC + SysTick + SCI8 + LEDs + MSTP up. | |
| static ra8_err_t | internal_mecc_configure (void) |
| Enable full ECC + zero-init on spare bank 2. | |
| static ra8_err_t | internal_mecc_inject (bool two_bit, uint8_t *out_caught) |
| Inject one ECC fault via the decoder self-test and record the verdict. | |
| static ra8_err_t | internal_mecc_run_pass (uint8_t *out_ok) |
| Run both fault injections and fold them into a single verdict. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| static const char * | s_tag = "mem_ecc" |
| Diagnostic / log tag. | |
| static const uint8_t | s_mecc_ok_msg [] = "ecc: sram2 1bit-inj=caught 2bit-inj=caught ok=Y\r\n" |
| Success banner for the complete one-bit and two-bit injection pass. | |
| static const uint8_t | s_mecc_bad_msg [] = "ecc: sram2 fault-inject ok=N\r\n" |
| Failure banner for an incomplete or rejected injection pass. | |
| volatile uint32_t | g_mecc_1bit_caught = 0U |
| 1 when the injected 1-bit fault was latched by SRAMESR. | |
| volatile uint32_t | g_mecc_2bit_caught = 0U |
| 1 when the injected 2-bit fault was latched by SRAMESR. | |
| volatile uint32_t | g_mecc_1bit_mask = 0U |
| Per-bank 1-bit-error bitmap decoded after the 1-bit injection. | |
| volatile uint32_t | g_mecc_2bit_mask = 0U |
| Per-bank 2-bit-error bitmap decoded after the 2-bit injection. | |
| volatile uint32_t | g_mecc_heartbeat = 0U |
| Bumps once per main-loop pass – liveness for headless probes. | |
SRAM ECC fault-injection + detection demo (EK-RA8D2, issue #130).
Where ecc_monitor_demo only brings ECC up and reads a (clean) status, this demo closes the loop the SIL-3 / DAL-B bar actually cares about: it deliberately provokes a memory error and proves the hardware-error path latches it.
It enables full SECDED ECC on a spare SRAM bank (bank 2, which the linker leaves unused), then runs the HUM Ch 58.3.4 ECC decoder self-test twice via ra8_sram_self_test:
The ESR status is cleared between injections so each is independently proven. The detected per-bank 1-bit / 2-bit masks are published to globals for HIL probing. Once a second the headless banner is emitted:
"ecc: sram2 1bit-inj=caught 2bit-inj=caught ok=Y\r\n" (both latched), or "ecc: sram2 fault-inject ok=N\r\n" (any miss).
LED1 toggles while both injections are caught; LED2 toggles on a miss.
Bare EK-RA8D2 only – no shields or external transceivers.
Definition in file main.c.
| enum mecc_config_t : uint32_t |
| enum mecc_geom_t : uint32_t |
|
staticnodiscard |
Enable full ECC + zero-init on spare bank 2.
Bank 2 gets with-check ECC, the 1-bit latch, a 128 KiB ECC region, and the zero-init pass that lays down valid ECC across the bank (so a read of a never-written line does not raise a spurious 2-bit error before the deliberate injection). on_error is NMI – see the file's silicon note.
| k_ra8_ok | Bank 2 configured for ECC with-check. |
Definition at line 215 of file main.c.
References ra8_sram_config_t::banks, ra8_sram_bank_cfg_t::ecc_mode, ra8_sram_bank_cfg_t::eccrgn, ra8_sram_bank_cfg_t::enable_1bit_latch, k_mecc_bank, k_ra8_sram_ecc_with_chk, k_ra8_sram_on_error_interrupt, k_ra8_sram_region_128kb, ra8_sram_bank_cfg_t::on_error, RA8_INTERNAL, ra8_sram_init(), and ra8_sram_bank_cfg_t::zero_init.
Referenced by main().
|
staticnodiscard |
Inject one ECC fault via the decoder self-test and record the verdict.
Runs ra8_sram_self_test on bank 2 (which corrupts the syndrome of the probe line and confirms the SRAMESR latch), snapshots the decoded error masks for HIL probing, then clears the latched status so the next injection starts clean.
| [in] | two_bit | true to inject a 2-bit (uncorrectable) fault. |
| [out] | out_caught | Receives 1 when SRAMESR latched the injected fault. |
| k_ra8_ok | Injection ran; *out_caught set. |
| k_ra8_err_null_ptr | out_caught was NULL. |
| k_ra8_err_invalid_arg | Bank / probe rejected by ra8_sram_self_test. |
Definition at line 248 of file main.c.
References g_mecc_1bit_mask, g_mecc_2bit_mask, k_mecc_bank, k_mecc_probe_offset, k_ra8_ok, ra8_sram_status_t::one_bit_mask, RA8_CHECK_NULL_PTR, RA8_INTERNAL, ra8_sram_clear_status(), ra8_sram_get_status(), ra8_sram_self_test(), ra8_sram_status_t::raw_esr, s_tag, and ra8_sram_status_t::two_bit_mask.
Referenced by internal_mecc_run_pass().
|
static |
Park forever after a fatal initialization failure.
Retains ECC and setup state for inspection in a permanent WFI loop.
Definition at line 149 of file main.c.
References RA8_INTERNAL.
Referenced by internal_mecc_setup_or_halt(), and main().
|
staticnodiscard |
Run both fault injections and fold them into a single verdict.
Executes the correctable and uncorrectable self-tests sequentially, publishes both liveness flags, and sets the aggregate result only when both hardware latches were observed.
| [out] | out_ok | 1 only when both the 1-bit and 2-bit faults were caught. |
| k_ra8_ok | Both injections ran; *out_ok set. |
| k_ra8_err_null_ptr | out_ok was NULL. |
Definition at line 297 of file main.c.
References g_mecc_1bit_caught, g_mecc_2bit_caught, internal_mecc_inject(), k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_INTERNAL, and s_tag.
Referenced by main().
|
static |
Bring CGC + SysTick + SCI8 + LEDs + MSTP up.
Initializes each boot dependency in order and treats any failure as terminal before SRAM ECC configuration begins.
Definition at line 167 of file main.c.
References internal_mecc_panic_halt(), k_mecc_baud, k_ra8_board_led1, k_ra8_board_led2, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, ra8_mstp_init(), and ra8_time_init().
Referenced by main().
| void main | ( | void | ) |
The application entry point Reset_Handler hands control to.
Returns void, not int. This is a freestanding image: there is no hosted C environment, no process and nothing to report an exit status to. ISO C fixes main at int only for a hosted implementation; for a freestanding one (C23 5.1.2.1) the startup function's name and type are implementation-defined, and this is that definition. Reset_Handler discards no value because there is none to discard, and if main ever does return, startup halts the CPU rather than resuming anything.
The firmware lane is compiled -ffreestanding (see cmake/ra8_add_app.cmake) and the flag and this signature travel together: without it both GCC and clang reject a non-int main (-Wmain / -Wmain-return-type). Do not remove one without the other.
That coupling is why the declaration sits behind __STDC_HOSTED__ == 0, which -ffreestanding sets and a hosted build does not. The guard is not defensive dressing: this header is reachable from host builds (the unit tests compile ra8_core natively), and an unguarded void main(void); makes every hosted translation unit that includes it fail with conflicting types for 'main' against its own ISO int main. The declaration therefore exists exactly where its contract does.
Hosted first-party code – everything under tests/ and tools/ – uses the ISO int main(...) contract instead, because it genuinely does run under an OS that reads the exit status. scripts/checks/check_entry_points.py holds each domain to its own contract (#707).
Declared here, once, for the same reason SystemInit is: every vector_table.c used to restate it as a local extern int32_t main(void);, sixteen copies that no compiler ever compared against the definition – and roughly thirty of them had silently drifted out of agreement with the main they called.
The application entry point Reset_Handler hands control to.
Brings up CGC + BSP audio then plays blocks.
The application entry point Reset_Handler hands control to.
Brings up CGC + GPT triple, runs sweep.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART, then enters ThreadX.
The application entry point Reset_Handler hands control to.
Brings up LED, console, SDHI pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up CGC + USB-FS + UAC1, then enters the iso-IN feed loop forever.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
See file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Definition at line 326 of file main.c.
References g_mecc_heartbeat, internal_mecc_configure(), internal_mecc_panic_halt(), internal_mecc_run_pass(), internal_mecc_setup_or_halt(), k_mecc_period_ms, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_led_toggle(), ra8_board_uart_console_write(), ra8_delay_ms(), ra8_isr_globals_enable(), s_mecc_bad_msg, and s_mecc_ok_msg.
| volatile uint32_t g_mecc_1bit_caught = 0U |
1 when the injected 1-bit fault was latched by SRAMESR.
Definition at line 105 of file main.c.
Referenced by internal_mecc_run_pass().
| volatile uint32_t g_mecc_1bit_mask = 0U |
Per-bank 1-bit-error bitmap decoded after the 1-bit injection.
Definition at line 121 of file main.c.
Referenced by internal_mecc_inject().
| volatile uint32_t g_mecc_2bit_caught = 0U |
1 when the injected 2-bit fault was latched by SRAMESR.
Definition at line 113 of file main.c.
Referenced by internal_mecc_run_pass().
| volatile uint32_t g_mecc_2bit_mask = 0U |
Per-bank 2-bit-error bitmap decoded after the 2-bit injection.
Definition at line 129 of file main.c.
Referenced by internal_mecc_inject().
| volatile uint32_t g_mecc_heartbeat = 0U |
|
static |
|
static |