|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
VBATT backup-register read/write + reset-survival demo (EK-RA8D2). More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_bkup.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_time.h"Go to the source code of this file.
Enumerations | |
| enum | bkup_demo_config_t : uint32_t { k_bkup_demo_baud = 115200U , k_bkup_demo_period_ms = 1000U , k_bkup_demo_sentinel = 0x600DCAFEU , k_bkup_demo_pat_mult = 0x01010101U , k_bkup_demo_pat_xor = 0xA5A5A5A5U } |
| Compile-time settings. More... | |
| enum | bkup_demo_layout_t : uint8_t { k_bkup_demo_data_words = 30U , k_bkup_demo_idx_sentinel = 30U , k_bkup_demo_idx_boot = 31U } |
| Backup-word layout (32 words total; 0..29 data, 30/31 reserved). More... | |
Functions | |
| static void | internal_bkup_demo_panic_halt (void) |
| Park forever after a fatal initialization failure. | |
| static uint32_t | internal_bkup_demo_pattern (uint8_t i) |
| Derive the deterministic pattern for one backup word. | |
| static void | internal_bkup_demo_setup_or_halt (void) |
| Initialize clocks, time, console, LEDs, and the backup domain. | |
| static ra8_err_t | internal_bkup_demo_rw_check (uint8_t *out_ok) |
| Write words 0..29 with the pattern, read them back, and compare. | |
| static ra8_err_t | internal_bkup_demo_survival_check (void) |
| Detect reset survival and maintain the boot counter. | |
| static void | internal_bkup_demo_report_survival (void) |
| Emit the fixed-width reset-survival suffix over the console. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| static const char * | s_tag = "bkup_demo" |
| Diagnostic / log tag. | |
| static const uint8_t | s_bkup_demo_ok_msg [] = "bkup: rw=ok " |
| Prefix for a successful backup-word read/write report. | |
| static const uint8_t | s_bkup_demo_bad_msg [] = "bkup: rw=BAD " |
| Prefix for a failed backup-word read/write report. | |
| static const uint8_t | s_bkup_demo_surv_y [] = "survived=Y " |
| Warm-reset survival suffix. | |
| static const uint8_t | s_bkup_demo_surv_n [] = "survived=N " |
| Cold-start survival suffix. | |
| static const uint8_t | s_bkup_demo_crlf [] = "\r\n" |
| Console line terminator for each periodic report. | |
| volatile uint32_t | g_bkup_rw_ok = 0U |
| 1 when words 0..29 read back exactly what was written. | |
| volatile uint32_t | g_bkup_survived = 0U |
| 1 when the sentinel was found at boot (state retained across reset). | |
| volatile uint32_t | g_bkup_boot_count = 0U |
| Boot counter held in backup word 31 (increments per reset on HW). | |
| volatile uint32_t | g_bkup_heartbeat = 0U |
| Bumps once per main-loop pass – liveness for headless probes. | |
VBATT backup-register read/write + reset-survival demo (EK-RA8D2).
The RA8D2 keeps 128 bytes (32 x 32-bit VBTBKRn words) of backup register storage in the VBATT-backed power domain, which retains its contents across a CPU reset (and, with a battery on VBATT, across a power cycle). This demo exercises both halves of that contract:
Bring-up: CGC + SysTick + SCI8 + LEDs. Once a second the loop reports "bkup: rw=ok survived=Y boot=3\r\n" on the J-Link OB CDC channel. LED1 toggles while the read/write window is healthy; LED2 toggles if it ever mismatches.
Bare EK-RA8D2 only – no shields or external transceivers.
Definition in file main.c.
| enum bkup_demo_config_t : uint32_t |
| enum bkup_demo_layout_t : uint8_t |
|
static |
Park forever after a fatal initialization failure.
Repeatedly executes the target wait-for-interrupt instruction so the failed application cannot advance its heartbeat or diagnostics.
Definition at line 172 of file main.c.
References RA8_INTERNAL.
Referenced by internal_bkup_demo_setup_or_halt(), and main().
|
static |
Derive the deterministic pattern for one backup word.
Multiplies the word index into repeated bytes and XORs the fixed mask, producing visibly distinct values for adjacent slots.
| [in] | i | Backup data-word index. |
| 0x00000000..0xFFFFFFFF | Deterministic index-derived word. |
Definition at line 193 of file main.c.
References k_bkup_demo_pat_mult, k_bkup_demo_pat_xor, and RA8_INTERNAL.
Referenced by internal_bkup_demo_rw_check().
|
static |
Emit the fixed-width reset-survival suffix over the console.
Selects the affirmative or negative string from the retained-state diagnostic and writes its common payload length without allocation.
Definition at line 375 of file main.c.
References g_bkup_survived, ra8_board_uart_console_write(), RA8_INTERNAL, s_bkup_demo_surv_n, and s_bkup_demo_surv_y.
Referenced by main().
|
staticnodiscard |
Write words 0..29 with the pattern, read them back, and compare.
| [out] | out_ok | 1 if every word read back exactly, else 0. |
| k_ra8_err_null_ptr | out_ok was NULL. |
Definition at line 283 of file main.c.
References internal_bkup_demo_pattern(), k_bkup_demo_data_words, k_ra8_ok, ra8_bkup_read_word(), ra8_bkup_write_word(), RA8_CHECK_NULL_PTR, RA8_INTERNAL, and s_tag.
Referenced by main().
|
static |
Initialize clocks, time, console, LEDs, and the backup domain.
Brings dependencies up in order, then explicitly enables VBATT backup access under the board's VCC-tied supply configuration.
Definition at line 209 of file main.c.
References internal_bkup_demo_panic_halt(), k_bkup_demo_baud, k_ra8_bkup_vdet_2p80v, k_ra8_board_led1, k_ra8_board_led2, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_bkup_init(), 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().
|
staticnodiscard |
Detect reset survival and maintain the boot counter.
Reads the sentinel word. If it already holds the marker the domain retained state across a reset, so the boot counter is incremented; otherwise this is a cold boot, so the marker is planted and the counter set to 1.
| k_ra8_ok | Retained-state diagnostics and counter were updated. |
Definition at line 332 of file main.c.
References g_bkup_boot_count, g_bkup_survived, k_bkup_demo_idx_boot, k_bkup_demo_idx_sentinel, k_bkup_demo_sentinel, k_ra8_ok, ra8_bkup_read_word(), ra8_bkup_write_word(), and RA8_INTERNAL.
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.
Definition at line 385 of file main.c.
References g_bkup_heartbeat, g_bkup_rw_ok, internal_bkup_demo_panic_halt(), internal_bkup_demo_report_survival(), internal_bkup_demo_rw_check(), internal_bkup_demo_setup_or_halt(), internal_bkup_demo_survival_check(), k_bkup_demo_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_bkup_demo_bad_msg, s_bkup_demo_crlf, and s_bkup_demo_ok_msg.
| volatile uint32_t g_bkup_boot_count = 0U |
Boot counter held in backup word 31 (increments per reset on HW).
Definition at line 151 of file main.c.
Referenced by internal_bkup_demo_survival_check().
| volatile uint32_t g_bkup_heartbeat = 0U |
| volatile uint32_t g_bkup_rw_ok = 0U |
| volatile uint32_t g_bkup_survived = 0U |
1 when the sentinel was found at boot (state retained across reset).
Definition at line 143 of file main.c.
Referenced by internal_bkup_demo_report_survival(), and internal_bkup_demo_survival_check().
|
static |
|
static |
|
static |
|
static |
Cold-start survival suffix.
Reports that startup had to plant a new retained sentinel.
Definition at line 119 of file main.c.
Referenced by internal_bkup_demo_report_survival().
|
static |
Warm-reset survival suffix.
Reports that the retained sentinel was present at startup.
Definition at line 111 of file main.c.
Referenced by internal_bkup_demo_report_survival().