ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
50
51#include <stddef.h>
52#include <stdint.h>
53
54#include "ra8_board_ek_ra8d2.h"
55#include "ra8_boot_entry.h"
56#include "ra8_cache.h"
57#include "ra8_cgc.h"
58#include "ra8_err.h"
59#include "ra8_log.h"
60
68typedef enum : uint32_t {
69 k_cache_hal_baud = 115200U,
73
81typedef enum : uint8_t {
85
86static_assert((uint32_t)k_cache_hal_buf_bytes >= (uint32_t)k_cache_hal_buf_min,
87 "cacheable self-test buffer must be at least 4 KiB");
88
99alignas(32) static uint8_t s_cache_hal_buf[k_cache_hal_buf_bytes];
100
110static const uint8_t k_cache_hal_pass_banner[] = "cache_hal_enable_demo: L1-cache-via-HAL PASS\r\n";
111
119static const uint8_t k_cache_hal_fail_setup[] = "cache_hal_enable_demo: setup FAIL\r\n";
120
127static const uint8_t k_cache_hal_fail_rw[] = "cache_hal_enable_demo: cacheable-RW FAIL\r\n";
128
146[[noreturn]] static void cache_hal_wfi_forever(void)
147{
148 while (1) {
149 __asm volatile("wfi");
150 }
151}
152
175{
176 for (uint32_t i = 0U; i < (uint32_t)k_cache_hal_buf_bytes; i++) {
177 s_cache_hal_buf[i] =
178 (uint8_t)((i * (uint32_t)k_cache_hal_pat_mul) + (uint32_t)k_cache_hal_pat_add);
179 }
180
181 /* Force the freshly written (dirty) lines back to SRAM and drop them, so the
182 * verify pass below must refill from memory -- the full write-back + refill
183 * round-trip with the HAL-enabled D-cache on. */
185 (uint32_t)sizeof(s_cache_hal_buf)) != k_ra8_ok) {
186 return false;
187 }
188
189 for (uint32_t i = 0U; i < (uint32_t)k_cache_hal_buf_bytes; i++) {
190 const uint8_t expected =
191 (uint8_t)((i * (uint32_t)k_cache_hal_pat_mul) + (uint32_t)k_cache_hal_pat_add);
192 if (s_cache_hal_buf[i] != expected) {
193 return false;
194 }
195 }
196 return true;
197}
198
218static bool cache_hal_setup(void)
219{
220 if (ra8_cgc_init() != k_ra8_ok) {
221 return false;
222 }
224 return false;
225 }
226 return true;
227}
228
250static void cache_hal_emit(const uint8_t* line, size_t len)
251{
252 if (line == nullptr) {
253 return;
254 }
255 if (len == 0U) {
256 return;
257 }
258 (void)ra8_board_uart_console_write(line, len);
260}
261
280void main(void)
281{
282 ra8_log_init();
283 ra8_log_info("CACHE_HAL", "==== cache_hal_enable_demo: L1 cache via ra8_cache HAL ====");
284
285 if (!cache_hal_setup()) {
286 ra8_log_info("CACHE_HAL", "setup FAILED (CGC / console) -- halting");
289 }
290
292 ra8_log_info("CACHE_HAL", "cacheable-RW step FAILED");
295 }
296
297 ra8_log_info("CACHE_HAL", "L1-cache-via-HAL PASS (cacheable RW round-trip)");
300}
void main(void)
Secure fallback main entry point.
Definition main.c:37
cache_hal_pattern_t
Affine byte-pattern coefficients: buf[i] = i * MUL + ADD.
Definition main.c:81
@ k_cache_hal_pat_mul
Pattern multiplier.
Definition main.c:82
@ k_cache_hal_pat_add
Pattern addend.
Definition main.c:83
static bool cache_hal_setup(void)
Bring up the clock tree and the VCOM console for the banner.
Definition main.c:218
static bool cache_hal_test_cacheable_rw(void)
Prove cacheable RW works with the HAL-enabled D-cache (SRAM region 1).
Definition main.c:174
static const uint8_t k_cache_hal_fail_setup[]
Failure banner: clock / console bring-up failed before the self-test.
Definition main.c:119
cache_hal_config_t
Compile-time scalar parameters for the cache-via-HAL self-test.
Definition main.c:68
@ k_cache_hal_buf_bytes
Cacheable self-test buffer size (>= 4 KiB).
Definition main.c:70
@ k_cache_hal_baud
VCOM console line rate (8N1).
Definition main.c:69
@ k_cache_hal_buf_min
Self-test buffer floor (4 KiB minimum).
Definition main.c:71
static uint8_t s_cache_hal_buf[k_cache_hal_buf_bytes]
4 KiB cacheable scratch buffer in M85-private SRAM (MPU region 1).
Definition main.c:99
static void cache_hal_emit(const uint8_t *line, size_t len)
Emit one banner line over the VCOM console and flush it.
Definition main.c:250
static const uint8_t k_cache_hal_fail_rw[]
Failure banner: the cacheable-SRAM readback mismatched.
Definition main.c:127
static void cache_hal_wfi_forever(void)
Park the Cortex-M85 forever in a WFI idle loop.
Definition main.c:146
static const uint8_t k_cache_hal_pass_banner[]
Deterministic one-shot HIL success banner (uart_scrape gate).
Definition main.c:110
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
ra8_err_t ra8_board_uart_console_flush(void)
Block until every byte queued on the J-Link OB VCOM console has finished clocking out on the wire.
Boot entry points shared between a vector table and its startup code.
Cortex-M85 L1 cache maintenance, enable/disable, and I-cache invalidate.
ra8_err_t ra8_cache_dcache_clean_invalidate_by_addr(const void *addr, uint32_t size)
Clean and invalidate the D-cache lines covering a byte range.
Definition ra8_cache.c:190
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
Lightweight Logging Interface for ra8-firmware.
void ra8_log_init(void)
Initialise the logging backend.
Definition ra8_log.c:379
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364