ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

End-to-end demo of the ra8_io fabric (epic #155) over a RAM block device. More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_board_ek_ra8d2_console_stream.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_io.h"
#include "ra8_io_roundtrip.h"
#include "ra8_log.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  demo_const_t : uint32_t {
  k_demo_uart_baud = 115200U ,
  k_demo_disk_blocks = 512U ,
  k_demo_payload = 128U ,
  k_demo_note_len = 64U
}
 Console + volume knobs (no magic numbers). More...

Functions

static void internal_demo_print (const char *msg)
 Print a NUL-terminated string on the demo's UART stream.
static void internal_demo_setup_or_halt (void)
 Bring up CGC + SysTick + the board console; halt forever on failure.
static ra8_err_t internal_demo_run (ra8_fs_mount_t **out_mount)
 Bind the RAM block device, then run the shared FAT round-trip.
void main (void)
 Firmware entry point.

Variables

static uint8_t s_disk [(size_t) k_demo_disk_blocks *(size_t) k_ra8_io_block_size_bytes]
 256 KiB RAM-disk backing buffer (in SRAM .bss).
static ra8_io_blockdev_t s_bd
 Block-device handle + its RAM backend state.
static ra8_io_blockdev_ram_state_t s_bstate
static ra8_fs_backend_t s_be
 ra8_fs backend bridged onto the block device.
static ra8_io_stream_t s_uart
 Console output stream; the board owns the sink behind it.
static const char *const s_tag = "ra8_io_demo"
 Module log tag.
static const ra8_io_roundtrip_params_t s_params
 Shared round-trip parameters for this RAM-backed FAT12 volume.

Detailed Description

End-to-end demo of the ra8_io fabric (epic #155) over a RAM block device.

Tag
[Ring 6 / APP] {World: S}

Exercises the whole fabric in one app, with no external hardware. The fabric round-trip (bridge -> format -> mount -> VFS -> write/read/verify -> mkdir + nested round-trip) lives in this app's self-contained ra8_io_roundtrip.{h,c} (the SDRAM, OSPI/xSPI, and SD demos carry their own copy under the hw_pending tree); this app differs only by the ONE backend bind line – here ra8_io_blockdev_ram_init over an in-SRAM buffer (Phase 1, #156) – plus its own PASS banners.

The ra8_emulator captures the SCI8 console, so the PASS/FAIL line and the byte counts are observable headlessly: a successful run prints ra8_io_demo: wrote/read 128 bytes ram:/HELLO.TXT PASS followed by ra8_io_demo: mkdir+nested ram:/SUB/NOTE.TXT PASS.

Definition in file main.c.

Enumeration Type Documentation

◆ demo_const_t

enum demo_const_t : uint32_t

Console + volume knobs (no magic numbers).

Enumerator
k_demo_uart_baud 

Console baud.

k_demo_disk_blocks 

256 KiB RAM-disk (FAT12).

k_demo_payload 

Bytes written + read back at root.

k_demo_note_len 

Bytes round-tripped in the subdir.

Definition at line 42 of file main.c.

Function Documentation

◆ internal_demo_print()

void internal_demo_print ( const char * msg)
static

Print a NUL-terminated string on the demo's UART stream.

Thin wrapper over ra8_io_stream_puts bound to s_uart, so call sites do not repeat the sink handle.

Parameters
[in]msgNUL-terminated ASCII string (CR/LF supplied by the caller).
Returns
None.
Precondition
s_uart was bound by ra8_board_console_stream.
msg is non-NULL and NUL-terminated.
Postcondition
The bytes of msg are queued on the UART stream.
No other state changes.
Note
Blocking polled TX; not interrupt-safe.
Since
0.1.0

Definition at line 94 of file main.c.

References RA8_INTERNAL, ra8_io_stream_puts(), and s_uart.

◆ internal_demo_run()

ra8_err_t internal_demo_run ( ra8_fs_mount_t ** out_mount)
static

Bind the RAM block device, then run the shared FAT round-trip.

Binds the in-SRAM RAM backend (the single per-demo bind line), mounts the FAT12 volume through the shared helper, runs the root-file round-trip, and – on success – reports the result through mnt for the subsequent subdir round-trip in main.

Parameters
[out]out_mountReceives the mount handle on success, nullptr on error.
Returns
ra8_err_t Error code.
Return values
k_ra8_okThe RAM volume mounted and the root file round-tripped.
k_ra8_err_*The first failing bind / mount / round-trip step's code.
Precondition
internal_demo_setup_or_halt has run (clocks + console up).
out_mount is non-NULL.
Postcondition
On success ram:/HELLO.TXT holds the verified payload.
On any non-ok return *out_mount is nullptr.
Note
Not thread-safe; single-caller boot context.
Since
0.1.0

Definition at line 153 of file main.c.

References k_demo_disk_blocks, RA8_INTERNAL, ra8_io_blockdev_ram_init(), ra8_io_roundtrip_mount(), ra8_io_roundtrip_root_file(), RA8_RETURN_ON_ERROR, s_bd, s_be, s_bstate, s_disk, s_params, and s_tag.

◆ internal_demo_setup_or_halt()

void internal_demo_setup_or_halt ( void )
static

Bring up CGC + SysTick + the board console; halt forever on failure.

Initialises clocks, reads the CPU rate, starts the millisecond time base, and hands the console over to the BSP – which owns the channel, the PD02 / PD03 routing and the live-PCLKA bit-rate solve. Any failure spins forever so a debugger can inspect the halt.

Returns
None.
Precondition
SystemInit configured VTOR / FPU / priority grouping.
Runs single-threaded during early boot.
Postcondition
On success the console is open at k_demo_uart_baud and the time base runs.
On any failure the function never returns (infinite halt loop).
Note
Not thread-safe; boot-context only.
Since
0.1.0

Definition at line 118 of file main.c.

References k_demo_uart_baud, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_console_stream(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, ra8_time_init(), and s_uart.

◆ main()

void main ( void )

Firmware entry point.

The application entry point Reset_Handler hands control to.

Precondition
SystemInit set VTOR / FPU / priority grouping.

Definition at line 168 of file main.c.

References internal_demo_print(), internal_demo_run(), internal_demo_setup_or_halt(), k_ra8_ok, ra8_board_uart_console_flush(), ra8_io_log_attach(), ra8_io_roundtrip_subdir_file(), ra8_log_init(), s_params, and s_uart.

Variable Documentation

◆ s_bd

◆ s_be

ra8_fs_backend_t s_be
static

ra8_fs backend bridged onto the block device.

Definition at line 55 of file main.c.

◆ s_bstate

ra8_io_blockdev_ram_state_t s_bstate
static

Definition at line 53 of file main.c.

Referenced by demo_run(), internal_demo_probe_fat(), and internal_demo_run().

◆ s_disk

uint8_t s_disk[(size_t) k_demo_disk_blocks *(size_t) k_ra8_io_block_size_bytes]
static

256 KiB RAM-disk backing buffer (in SRAM .bss).

Definition at line 50 of file main.c.

◆ s_params

const ra8_io_roundtrip_params_t s_params
static
Initial value:
= {
.vfs_prefix = "ram",
.fat_type = k_ra8_fs_type_fat12,
.volume_label = "RAIO",
.log_tag = s_tag,
.root_file = "HELLO.TXT",
.root_path = "ram:/HELLO.TXT",
.root_bytes = (uint32_t)k_demo_payload,
.subdir_path = "ram:/SUB",
.subdir_file = "ram:/SUB/NOTE.TXT",
.subdir_bytes = (uint32_t)k_demo_note_len,
}
@ k_demo_payload
Source bytes (compressible).
Definition main.c:60
@ k_demo_note_len
Bytes round-tripped in the subdir.
Definition main.c:46
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
@ k_ra8_fs_type_fat12
count_of_clusters < 4085.

Shared round-trip parameters for this RAM-backed FAT12 volume.

Definition at line 63 of file main.c.

Referenced by demo_run(), demo_run(), internal_demo_run(), internal_sd_demo_roundtrip(), and main().

◆ s_tag

const char* const s_tag = "ra8_io_demo"
static

Module log tag.

Definition at line 60 of file main.c.

◆ s_uart

ra8_io_stream_t s_uart
static

Console output stream; the board owns the sink behind it.

Definition at line 57 of file main.c.