|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
ThreadX + LevelX wear-levelling demo for EK-RA8D2 OSPI flash. More...
#include <stdint.h>#include <string.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_time.h"#include "lx_api.h"#include "lx_nor_driver_ra8_xspi.h"#include "tx_api.h"Go to the source code of this file.
Enumerations | |
| enum | lx_log_pace_t : uint32_t { k_lx_log_every_n = 100U } |
| Compile-time settings for the LevelX wear-levelling demo. More... | |
| enum | demo_config_t : uint32_t { k_demo_baud = 115200U , k_demo_thread_stack = 4096U , k_demo_sector_index = 0U , k_demo_burnin_writes = 10000U , k_demo_tick_ms = 1000U , k_demo_sector_bytes = 512U , k_demo_radix_dec = 10U , k_demo_u32_buf_size = 12U } |
Functions | |
| static void | demo_panic_halt (void) |
| Halt forever in WFI, after draining the J-Link OB VCOM TX FIFO. | |
| static void | demo_setup_or_halt (void) |
| Bring CGC + the J-Link OB VCOM console up. | |
| static void | demo_print (const char *s) |
| Convenience wrapper to write a NUL-terminated string to the console. | |
| static void | demo_print_u32 (uint32_t value) |
| Print an unsigned 32-bit integer in decimal to SCI8. | |
| static void | demo_print_stat (const char *label, ULONG value) |
| Print one labelled ULONG LevelX statistic line over SCI8. | |
| static void | demo_lx_format_or_panic (void) |
| Format + open the LevelX partition. | |
| static UINT | demo_heartbeat (uint32_t counter) |
| Run one heartbeat: program counter into sector 0 + read back. | |
| static void | demo_print_wear_stats (void) |
| Dump LevelX's wear-levelling statistics to SCI8. | |
| static void | demo_report_rw_once (uint32_t counter, uint32_t readback) |
| Emit a one-shot HIL success banner after the first verified heartbeat. | |
| static void | demo_thread_entry (ULONG thread_input) |
| ThreadX worker entry: format LevelX, run the heartbeat loop, dump stats. | |
| void | tx_application_define (void *first_unused_memory) |
| ThreadX system-define hook: build the worker thread + LevelX core. | |
| void | main (void) |
| Application entry. | |
Variables | |
| static LX_NOR_FLASH | s_nor_flash |
| static ULONG | s_demo_sector_io [k_demo_sector_bytes/sizeof(ULONG)] |
| static TX_THREAD | s_demo_thread |
| static UCHAR | s_demo_stack [k_demo_thread_stack] |
ThreadX + LevelX wear-levelling demo for EK-RA8D2 OSPI flash.
Brings the chip up the same way uart_hello does (CGC -> SCI8 @ 115200 8N1), then hands control to ThreadX. tx_application_define spawns one worker thread that:
Recipe (see also the README.md alongside this main.c):
Definition in file main.c.
| enum demo_config_t : uint32_t |
| Enumerator | |
|---|---|
| k_demo_baud | Console baud (matches uart_hello / threadx_fs_demo). |
| k_demo_thread_stack | Worker-thread stack size in bytes. |
| k_demo_sector_index | LevelX logical sector the heartbeat counter is stored in. |
| k_demo_burnin_writes | Number of heartbeats before printing wear-levelling stats. |
| k_demo_tick_ms | Heartbeat tick in milliseconds. |
| k_demo_sector_bytes | LevelX bytes per logical sector (= 512). |
| k_demo_radix_dec | Decimal radix used by demo_print_u32. |
| k_demo_u32_buf_size | Buffer size for demo_print_u32 (10 digits + sign + NUL). |
| enum lx_log_pace_t : uint32_t |
|
static |
Run one heartbeat: program counter into sector 0 + read back.
| [in] | counter | Heartbeat sequence number. |
Definition at line 273 of file main.c.
References k_demo_sector_index, s_demo_sector_io, and s_nor_flash.
Referenced by demo_thread_entry().
|
static |
Format + open the LevelX partition.
Panics on any failure.
Definition at line 242 of file main.c.
References demo_panic_halt(), demo_print(), lx_nor_driver_ra8_xspi_initialize(), and s_nor_flash.
Referenced by demo_thread_entry().
|
static |
Halt forever in WFI, after draining the J-Link OB VCOM TX FIFO.
Calls ra8_board_uart_console_flush so any panic message previously queued via ra8_board_uart_console_write finishes clocking onto the wire before WFI gates the SCI clock. Without the flush, only the first 1-3 bytes of the failure log reach the host because WFI silences the peripheral mid-frame. Return code is intentionally discarded – if the flush times out we still want to halt rather than spin.
Definition at line 133 of file main.c.
References ra8_board_uart_console_flush().
|
static |
Convenience wrapper to write a NUL-terminated string to the console.
| [in] | s | NUL-terminated ASCII string. Must not be NULL. |
Definition at line 177 of file main.c.
References ra8_board_uart_console_write(), and strlen().
|
static |
Print one labelled ULONG LevelX statistic line over SCI8.
| [in] | label | NUL-terminated stat name. Must not be NULL. |
| [in] | value | Stat value. |
Definition at line 225 of file main.c.
References demo_print(), and demo_print_u32().
Referenced by demo_print_wear_stats().
|
static |
Print an unsigned 32-bit integer in decimal to SCI8.
| [in] | value | Integer to print. |
Definition at line 196 of file main.c.
References demo_print(), k_demo_radix_dec, and k_demo_u32_buf_size.
Referenced by demo_print_stat(), demo_report_rw_once(), and demo_thread_entry().
|
static |
Dump LevelX's wear-levelling statistics to SCI8.
Definition at line 297 of file main.c.
References demo_print(), demo_print_stat(), and s_nor_flash.
Referenced by demo_thread_entry().
|
static |
Emit a one-shot HIL success banner after the first verified heartbeat.
On the first heartbeat (counter == 1) the worker has written the counter into LevelX logical sector 0 and read it back. A matching read-back proves the whole stack (LevelX format + open + sector write/read over the xSPI NOR) round-tripped real data – not just that the chip booted. Emits a distinct success-only banner the HIL uart_scrape gate keys on, or a MISMATCH banner its negative regex catches. Does nothing on later heartbeats.
| [in] | counter | Current heartbeat sequence number. |
| [in] | readback | Value read back from LevelX logical sector 0. |
Definition at line 336 of file main.c.
References demo_print(), and demo_print_u32().
Referenced by demo_thread_entry().
|
static |
Bring CGC + the J-Link OB VCOM console up.
Panic-halts on any failure.
Definition at line 149 of file main.c.
References demo_panic_halt(), k_demo_baud, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), and ra8_time_init().
|
static |
ThreadX worker entry: format LevelX, run the heartbeat loop, dump stats.
| [in] | thread_input | Unused. |
Definition at line 361 of file main.c.
References demo_heartbeat(), demo_lx_format_or_panic(), demo_print(), demo_print_u32(), demo_print_wear_stats(), demo_report_rw_once(), k_demo_burnin_writes, k_demo_tick_ms, k_lx_log_every_n, s_demo_sector_io, s_nor_flash, and tx_thread_sleep.
| void main | ( | void | ) |
Application entry.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART, then enters ThreadX.
Definition at line 451 of file main.c.
References demo_panic_halt(), demo_print(), demo_setup_or_halt(), and ra8_isr_globals_enable().
| void tx_application_define | ( | void * | first_unused_memory | ) |
ThreadX system-define hook: build the worker thread + LevelX core.
| [in] | first_unused_memory | Pointer to the start of free RAM provided by the ThreadX port; unused – we statically allocate. |
Definition at line 422 of file main.c.
References demo_thread_entry(), s_demo_stack, s_demo_thread, s_thread_name, TX_AUTO_START, TX_NO_TIME_SLICE, and tx_thread_create.
|
static |
Definition at line 108 of file main.c.
Referenced by demo_heartbeat(), and demo_thread_entry().
|
static |