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
39
40#include <stddef.h>
41#include <stdint.h>
42
43#include "epub.h"
44#include "epub_stress_fixture.h"
45#include "ra8_board_ek_ra8d2.h"
46#include "ra8_boot_entry.h"
47#include "ra8_cgc.h"
48#include "ra8_err.h"
49#include "ra8_isr.h"
50#include "ra8_mstp.h"
51#include "ra8_time.h"
52
54typedef enum : uint32_t {
55 k_est_uart_baud = 115200U,
61
64
65static const uint8_t k_msg_boot[] = "epub-stress-hil: boot\r\n";
66static const uint8_t k_msg_fail[] = "epub-stress-hil: FAIL init\r\n";
67static const uint8_t k_msg_open[] = "epub-stress-hil: FAIL open (arena no_mem?)\r\n";
68static const uint8_t k_msg_chap[] = "epub-stress-hil: FAIL chapters\r\n";
69static const uint8_t k_msg_toc[] = "epub-stress-hil: FAIL toc\r\n";
70static const uint8_t k_msg_cov[] = "epub-stress-hil: FAIL cover\r\n";
71static const uint8_t k_msg_pre[] = "epub-stress-hil: files=125 chapters=";
72static const uint8_t k_msg_tocp[] = " toc=";
73static const uint8_t k_msg_covp[] = " cover=ok";
74static const uint8_t k_msg_ok[] = " PASS\r\n";
75
77static void est_print(const uint8_t* msg, uint32_t len)
78{
79 (void)ra8_board_uart_console_write(msg, (size_t)len);
80}
81
83static void est_panic_halt(const uint8_t* msg, uint32_t len)
84{
85 est_print(msg, len);
86 __asm__ volatile("bkpt #0");
87 while (1) {
88 __asm__ volatile("wfi");
89 }
90}
91
93static void est_print_uint(uint32_t value)
94{
95 uint8_t buf[k_est_dec_ten];
96 uint32_t n = 0U;
97 if (value == 0U) {
98 buf[n] = '0';
99 n++;
100 }
101 while ((value > 0U) && (n < (uint32_t)k_est_dec_ten)) {
102 buf[n] = (uint8_t)('0' + (value % (uint32_t)k_est_dec_ten));
103 n++;
104 value /= (uint32_t)k_est_dec_ten;
105 }
106 for (uint32_t i = 0U; i < n; i++) {
107 est_print(&buf[n - 1U - i], 1U);
108 }
109}
110
112static void est_setup_or_halt(void)
113{
114 uint32_t cpuclk0_hz = 0U;
115 if ((ra8_cgc_init() != k_ra8_ok) || (ra8_mstp_init() != k_ra8_ok)) {
116 est_panic_halt(k_msg_fail, (uint32_t)sizeof(k_msg_fail) - 1U);
117 }
119 est_panic_halt(k_msg_fail, (uint32_t)sizeof(k_msg_fail) - 1U);
120 }
121 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
122 est_panic_halt(k_msg_fail, (uint32_t)sizeof(k_msg_fail) - 1U);
123 }
125 est_panic_halt(k_msg_fail, (uint32_t)sizeof(k_msg_fail) - 1U);
126 }
127}
128
143static void est_open_or_halt(uint16_t* out_chap, uint16_t* out_toc)
144{
145 const epub_mem_media_t media = {.data = k_epub_stress_fixture,
146 .size = (size_t)k_epub_stress_fixture_len};
147 if (epub_open(&media, "stress.epub", &s_book) != k_ra8_ok) {
148 est_panic_halt(k_msg_open, (uint32_t)sizeof(k_msg_open) - 1U);
149 }
150 uint16_t chapters = 0U;
151 if ((epub_get_chapter_count(&s_book, &chapters) != k_ra8_ok) ||
152 (chapters != (uint16_t)k_est_expect_chap)) {
153 est_panic_halt(k_msg_chap, (uint32_t)sizeof(k_msg_chap) - 1U);
154 }
155 uint16_t toc = 0U;
156 if ((epub_get_toc_count(&s_book, &toc) != k_ra8_ok) || (toc != (uint16_t)k_est_expect_toc)) {
157 est_panic_halt(k_msg_toc, (uint32_t)sizeof(k_msg_toc) - 1U);
158 }
159 if (s_book.cover_path[0] == '\0') {
160 est_panic_halt(k_msg_cov, (uint32_t)sizeof(k_msg_cov) - 1U);
161 }
162 *out_chap = chapters;
163 *out_toc = toc;
164}
165
174void main(void)
175{
178 est_print(k_msg_boot, (uint32_t)sizeof(k_msg_boot) - 1U);
179
180 uint16_t chapters = 0U;
181 uint16_t toc = 0U;
182 est_open_or_halt(&chapters, &toc);
183
184 est_print(k_msg_pre, (uint32_t)sizeof(k_msg_pre) - 1U);
185 est_print_uint((uint32_t)chapters);
186 est_print(k_msg_tocp, (uint32_t)sizeof(k_msg_tocp) - 1U);
187 est_print_uint((uint32_t)toc);
188 est_print(k_msg_covp, (uint32_t)sizeof(k_msg_covp) - 1U);
189 est_print(k_msg_ok, (uint32_t)sizeof(k_msg_ok) - 1U);
190
191 while (1) {
192 __asm__ volatile("wfi");
193 }
194}
void main(void)
Secure fallback main entry point.
Definition main.c:37
EPUB (.epub) reader and chapter iterator for ra8-firmware.
ra8_err_t epub_open(const void *media, const char *path, epub_book_t *out_book)
Open an EPUB book from an opaque media handle.
Definition epub_open.c:405
ra8_err_t epub_get_chapter_count(const epub_book_t *book, uint16_t *out_count)
Report how many chapters the spine contains.
ra8_err_t epub_get_toc_count(const epub_book_t *book, uint16_t *out_count)
Report how many table-of-contents entries the book exposes.
Baked synthetic large-structure EPUB3 for the #144 pool-stress gate.
@ k_epub_stress_fixture_len
EPUB stress fixture length.
static const uint8_t k_epub_stress_fixture[k_epub_stress_fixture_len]
Baked synthetic large-structure EPUB3 byte stream.
static epub_book_t s_book
Opened book (large – file-scope, not on the stack).
Definition main.c:132
static const uint8_t k_msg_pre[]
Definition main.c:151
static const uint8_t k_msg_ok[]
Definition main.c:153
static const uint8_t k_msg_boot[]
Definition main.c:140
static const uint8_t k_msg_chap[]
Definition main.c:65
static const uint8_t k_msg_open[]
Definition main.c:64
static const uint8_t k_msg_fail[]
Definition main.c:63
static void est_setup_or_halt(void)
Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
Definition main.c:112
est_consts_t
Console / assertion knobs (no magic numbers).
Definition main.c:54
@ k_est_expect_toc
navPoint count in the synthetic NCX.
Definition main.c:57
@ k_est_dec_ten
Decimal base for the small printer.
Definition main.c:59
@ k_est_expect_chap
Spine length of the synthetic book.
Definition main.c:56
@ k_est_expect_files
Archive entries (reported, not gated).
Definition main.c:58
@ k_est_uart_baud
Console baud.
Definition main.c:55
static const uint8_t k_msg_tocp[]
Definition main.c:72
static const uint8_t k_msg_cov[]
Definition main.c:70
static const uint8_t k_msg_covp[]
Definition main.c:73
static void est_print_uint(uint32_t value)
Print a small unsigned integer in decimal.
Definition main.c:93
static void est_print(const uint8_t *msg, uint32_t len)
Emit a byte run on the SCI8 console.
Definition main.c:77
static void est_open_or_halt(uint16_t *out_chap, uint16_t *out_toc)
Open the stress EPUB through bounded ZIP/XML paths; assert the structure.
Definition main.c:143
static const uint8_t k_msg_toc[]
Definition main.c:69
static void est_panic_halt(const uint8_t *msg, uint32_t len)
Print the fail banner and trap (ra8_emulator halts on the BKPT).
Definition main.c:83
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.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
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
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
Definition ra8_mstp.c:291
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
Opened EPUB book.
Definition epub.h:286
In-memory EPUB media descriptor.
Definition epub.h:179