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
47
48#include <stddef.h>
49#include <stdint.h>
50
51#include "ra8_app.h"
53#include "ra8_boot_entry.h"
54#include "ra8_cgc.h"
55#include "ra8_err.h"
56#include "ra8_log.h"
57#include "ra8_widget.h"
58
67typedef enum : uint32_t {
70
82static const uint8_t k_app_launch_pass_banner[] = "app_launch_demo: demo PASS\r\n";
83
107{
108 if (ra8_cgc_init() != k_ra8_ok) {
109 return false;
110 }
112 return false;
113 }
114 return true;
115}
116
141
155#ifndef APP_LAUNCH_SETTINGS
157#define APP_LAUNCH_SETTINGS (1)
158#endif
159
165typedef enum : uint16_t {
169
175typedef enum : uint16_t {
180
194typedef struct {
195 const char* name;
196 uint32_t enters;
197 uint32_t leaves;
198 uint32_t renders;
199 uint32_t inputs;
201
210
219
227static uint16_t s_nav_stack[k_app_nav_cap];
228
237
245static app_launch_ctx_t s_reader_ctx = {.name = "reader"};
246
255
256#if APP_LAUNCH_SETTINGS
264static app_launch_ctx_t s_settings_ctx = {.name = "settings"};
265
274#endif
275
276/* ===========================================================================
277 * Stub-app vtable callbacks (one shared vtable; behaviour keyed off ctx)
278 * ===========================================================================
279 */
280
291{
293 c->enters++;
294 ra8_log_info(c->name, "on_enter");
295}
296
307{
309 c->leaves++;
310 ra8_log_info(c->name, "on_leave");
311}
312
322static void app_stub_render(const ra8_app_t* a)
323{
325 c->renders++;
326 ra8_log_info(c->name, "render");
327}
328
343{
345 c->inputs++;
346 if (ev->kind != k_ra8_widget_ev_button) {
347 return false;
348 }
349 if (ev->button_id != (uint16_t)k_app_btn_back) {
350 return false;
351 }
352 ra8_log_info(c->name, "back requested");
353 return true;
354}
355
365 .init = nullptr,
366 .on_enter = app_stub_on_enter,
367 .tick = nullptr,
368 .render = app_stub_render,
369 .on_input = app_stub_on_input,
370 .on_leave = app_stub_on_leave,
371 .deinit = nullptr,
372};
373
374/* ===========================================================================
375 * Registration + self-check (the "chrome")
376 * ===========================================================================
377 */
378
400static bool app_launch_register(void)
401{
403 return false;
404 }
406 return false;
407 }
409 .ctx = &s_reader_ctx,
410 .id = (uint16_t)k_app_id_reader,
411 .name = "reader",
412 .removable = false};
413 bool ok = (ra8_app_register(&s_reg, &s_reader_app) == k_ra8_ok);
414#if APP_LAUNCH_SETTINGS
416 .ctx = &s_settings_ctx,
417 .id = (uint16_t)k_app_id_settings,
418 .name = "settings",
419 .removable = true};
420 if (ok) {
422 }
423#endif
424 return ok;
425}
426
447static bool app_launch_enter_reader(void)
448{
449 uint16_t depth = 1U;
450 if (ra8_app_nav_go(&s_nav, (uint16_t)k_app_id_reader) != k_ra8_ok) {
451 return false;
452 }
453 if (ra8_app_render(&s_reg) != k_ra8_ok) {
454 return false;
455 }
456 if (s_reader_ctx.enters != 1U) {
457 return false;
458 }
459 if (ra8_app_nav_depth(&s_nav, &depth) != k_ra8_ok) {
460 return false;
461 }
462 return (depth == 0U);
463}
464
485static bool app_launch_route_back(void)
486{
487 const ra8_widget_event_t back = {.kind = k_ra8_widget_ev_button,
488 .button_id = (uint16_t)k_app_btn_back};
489 bool handled = false;
490 if (ra8_app_route_input(&s_reg, &back, &handled) != k_ra8_ok) {
491 return false;
492 }
493 if (!handled) {
494 return false;
495 }
496 return (s_reader_ctx.inputs == 1U);
497}
498
499#if APP_LAUNCH_SETTINGS
521{
522 uint16_t depth = 0U;
523 bool popped = false;
524 if (ra8_app_nav_go(&s_nav, (uint16_t)k_app_id_settings) != k_ra8_ok) {
525 return false;
526 }
527 if (s_reader_ctx.leaves != 1U) {
528 return false;
529 }
530 if (s_settings_ctx.enters != 1U) {
531 return false;
532 }
533 if (ra8_app_nav_depth(&s_nav, &depth) != k_ra8_ok) {
534 return false;
535 }
536 if (depth != 1U) {
537 return false;
538 }
539 if (ra8_app_nav_back(&s_nav, &popped) != k_ra8_ok) {
540 return false;
541 }
542 if (!popped) {
543 return false;
544 }
545 if (s_settings_ctx.leaves != 1U) {
546 return false;
547 }
548 return (s_reader_ctx.enters == 2U);
549}
550#endif
551
571static bool app_launch_selfcheck(void)
572{
574 return false;
575 }
576 if (!app_launch_route_back()) {
577 return false;
578 }
579#if APP_LAUNCH_SETTINGS
581 return false;
582 }
583#endif
584 ra8_app_t* act = nullptr;
585 if (ra8_app_active(&s_reg, &act) != k_ra8_ok) {
586 return false;
587 }
588 if (act == nullptr) {
589 return false;
590 }
591 return (act->id == (uint16_t)k_app_id_reader);
592}
593
609static void app_launch_banner(void)
610{
611 uint16_t n = 0U;
612 (void)ra8_app_count(&s_reg, &n);
613 (void)n; /* used only by the (level-gated) log lines below */
614 ra8_log_info_val("app_launch", "apps", (uint32_t)n);
615 ra8_log_info_val("app_launch", "reader enters", s_reader_ctx.enters);
616 ra8_log_info("app_launch", "demo PASS");
617 /* Additive HIL banner: the Pi rig has no ITM/SWO capture, so mirror the PASS
618 * verdict to the SCI8 / J-Link OB VCOM console for uart_scrape to gate. */
620}
621
631void main(void)
632{
633 ra8_log_init();
634 ra8_log_info("app_launch", "boot");
635
636 /* Bring up the VCOM console so the success path can emit the HIL banner.
637 * Best-effort: a failure is narrated over ITM and the demo continues. */
639 ra8_log_info("app_launch", "VCOM console init failed -- HIL banner unavailable");
640 }
641
642 bool ok = app_launch_register();
643 if (!ok) {
644 ra8_log_info("app_launch", "FAIL register");
645 }
646 if (ok) {
648 if (!ok) {
649 ra8_log_info("app_launch", "FAIL selfcheck");
650 }
651 }
652 if (ok) {
654 }
655
656 while (1) {
657 __asm__ volatile("wfi");
658 }
659}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static void app_stub_on_leave(ra8_app_t *a)
Stub on_leave: count the focus loss and log it.
Definition main.c:306
static bool app_launch_switch_and_back(void)
Switch reader -> settings and back, verifying the focus + back-stack.
Definition main.c:520
static ra8_app_nav_t s_nav
Navigation back-stack layered over s_reg.
Definition main.c:236
static ra8_app_t s_reader_app
The core reader app instance (registered into s_reg).
Definition main.c:254
app_launch_hil_t
VCOM-console line rate for the deterministic HIL success banner.
Definition main.c:67
@ k_app_launch_hil_baud
VCOM console line rate (8N1).
Definition main.c:68
static bool app_launch_hil_console_init(void)
Bring up the SCI8 / J-Link OB VCOM console for the HIL success banner.
Definition main.c:106
static uint16_t s_nav_stack[k_app_nav_cap]
Caller-owned storage backing the navigation back-stack (app ids).
Definition main.c:227
app_launch_id_t
Registered app ids (launch keys).
Definition main.c:165
@ k_app_id_settings
Optional settings app (removable).
Definition main.c:167
@ k_app_id_reader
Core EPUB-reader app (non-removable).
Definition main.c:166
static bool app_launch_route_back(void)
Route a back-button event through the chrome to the active app.
Definition main.c:485
static const uint8_t k_app_launch_pass_banner[]
Deterministic, run-to-run-stable HIL success banner (uart_scrape gate).
Definition main.c:82
static app_launch_ctx_t s_reader_ctx
Stub state for the core reader app.
Definition main.c:245
static app_launch_ctx_t s_settings_ctx
Stub state for the optional settings app.
Definition main.c:264
static void app_launch_hil_emit_pass(void)
Emit the deterministic HIL success banner over the VCOM console.
Definition main.c:135
static void app_stub_on_enter(ra8_app_t *a)
Stub on_enter: count the focus gain and log it.
Definition main.c:290
static bool app_launch_selfcheck(void)
Run the whole deterministic registry + launch + back-stack surface.
Definition main.c:571
static bool app_launch_enter_reader(void)
Launch the reader app from the chrome and verify first focus.
Definition main.c:447
static bool app_launch_register(void)
Initialise the registry + back-stack and register every app.
Definition main.c:400
static const ra8_app_vtable_t k_app_stub_vt
Shared lifecycle vtable for every stub app (behaviour keyed off ctx).
Definition main.c:364
static void app_stub_render(const ra8_app_t *a)
Stub render: count the frame and log it (stands in for drawing).
Definition main.c:322
static void app_launch_banner(void)
Emit the PASS banner: app count, reader enters, and the PASS line.
Definition main.c:609
static bool app_stub_on_input(ra8_app_t *a, const ra8_widget_event_t *ev)
Stub on_input: count the event, consume only the "back" button.
Definition main.c:342
static ra8_app_t s_settings_app
The optional settings app instance (registered into s_reg).
Definition main.c:273
app_launch_const_t
Capacities + the button id the stub apps understand.
Definition main.c:175
@ k_app_btn_back
Button id a chrome routes to mean "go back".
Definition main.c:178
@ k_app_nav_cap
Back-stack depth (history of focused apps).
Definition main.c:177
@ k_app_reg_cap
Registry storage slots (reader + settings).
Definition main.c:176
Zero-heap app framework: lifecycle + static registry + launcher (#146).
ra8_err_t ra8_app_nav_init(ra8_app_nav_t *nav, ra8_app_registry_t *reg, uint16_t *storage, uint16_t cap)
Bind a navigation back-stack to a registry + caller-owned storage.
Definition ra8_app.c:186
ra8_err_t ra8_app_nav_back(ra8_app_nav_t *nav, bool *out_popped)
Return to the most recently pushed app (pop the back-stack).
Definition ra8_app.c:251
ra8_err_t ra8_app_register(ra8_app_registry_t *reg, ra8_app_t *app)
Register an app (calls its init once) and add it to the registry.
Definition ra8_app.c:48
ra8_err_t ra8_app_nav_go(ra8_app_nav_t *nav, uint16_t id)
Focus app id, pushing the outgoing app onto the back-stack.
Definition ra8_app.c:201
ra8_err_t ra8_app_count(const ra8_app_registry_t *reg, uint16_t *out_count)
Number of registered apps (for the launcher to list).
Definition ra8_app.c:166
ra8_err_t ra8_app_route_input(ra8_app_registry_t *reg, const ra8_widget_event_t *ev, bool *out_handled)
Route an input event to the focused app.
Definition ra8_app.c:124
ra8_err_t ra8_app_nav_depth(const ra8_app_nav_t *nav, uint16_t *out_depth)
Current back-stack depth (apps the user can still go back through).
Definition ra8_app.c:270
ra8_err_t ra8_app_active(const ra8_app_registry_t *reg, ra8_app_t **out_app)
Get the currently focused app.
Definition ra8_app.c:115
ra8_err_t ra8_app_render(ra8_app_registry_t *reg)
Run the focused app's render (on-target; no-op if none / NULL).
Definition ra8_app.c:153
ra8_err_t ra8_app_registry_init(ra8_app_registry_t *reg, ra8_app_t **storage, uint16_t cap)
Bind a registry to caller-owned pointer storage (empty, no focus).
Definition ra8_app.c:20
I/O-expander, USB, camera, external-memory, MIPI-DSI, UART console, and Ethernet portion of the EK-RA...
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.
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
static const ra8_io_fsfmt_t * s_reg[(uint32_t) k_ra8_io_fsfmt_max]
Registered formats, in probe priority order.
static ra8_isr_slot_t s_slots[k_ra8_isr_slot_count]
Per-slot dispatch table.
Definition ra8_isr.c:77
Lightweight Logging Interface for ra8-firmware.
void ra8_log_init(void)
Initialise the logging backend.
Definition ra8_log.c:379
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Definition ra8_log.h:366
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364
Zero-heap composable widget layer (dwm-style) over ra8_box + ra8_ui.
@ k_ra8_widget_ev_button
A physical button press (button_id).
Definition ra8_widget.h:70
Per-app stub state: a display name + lifecycle-call counters.
Definition main.c:194
uint32_t enters
Times on_enter fired.
Definition main.c:196
const char * name
Display name + ITM log tag (non-NULL).
Definition main.c:195
uint32_t leaves
Times on_leave fired.
Definition main.c:197
uint32_t inputs
Times on_input fired.
Definition main.c:199
uint32_t renders
Times render fired.
Definition main.c:198
A bounded back-stack of app ids layered over a registry (zero-heap).
Definition ra8_app.h:485
Fixed table of registered apps + the focused index.
Definition ra8_app.h:161
One app instance + its metadata (caller-owned, static).
App lifecycle callbacks (shared by all instances of one app).
Definition ra8_app.h:133
One input event delivered to ra8_widget_dispatch.
Definition ra8_widget.h:77
ra8_widget_ev_kind_t kind
Touch or button.
Definition ra8_widget.h:78
uint16_t button_id
Button id (for k_ra8_widget_ev_button).
Definition ra8_widget.h:80