|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
ra8_io pluggable filesystem-format registry demo (Phase 4, #159). More...
#include <stdint.h>#include <string.h>#include "ra8_attributes.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_fs.h"#include "ra8_io.h"#include "ra8_io_fsfmt.h"#include "ra8_log.h"#include "ra8_port_constants.h"#include "ra8_port_utils.h"#include "ra8_sci.h"#include "ra8_time.h"Go to the source code of this file.
Data Structures | |
| struct | demo_stub_mount_t |
| Single caller-independent mount context for the demo format. More... | |
| struct | demo_stub_file_t |
| Single bounded stream context for the foreign demo file. More... | |
Enumerations | |
| enum | demo_const_t : uint32_t { k_demo_uart_chan = 8U , k_demo_uart_baud = 115200U , k_demo_disk_blocks = 512U , k_demo_stub_blocks = 8U , k_demo_pin_shift = 8U , k_demo_stub_maxname = 16U , k_demo_stub_magic = 0x5AU } |
| Console + volume knobs (no magic numbers). More... | |
Functions | |
| static void | internal_demo_print (const char *msg) |
| Print a NUL-terminated string on the UART stream. | |
| static bool | internal_stub_probe (const ra8_fs_backend_t *be) |
| Test whether block zero carries the foreign-format stub signature. | |
| static ra8_err_t | internal_stub_mount (const ra8_fs_backend_t *backend, void **out_mount) |
| Mount the bounded foreign demo format. | |
| static ra8_err_t | internal_stub_unmount (void *mount_ctx) |
| Release the mounted foreign demo context. | |
| static ra8_err_t | internal_stub_open (void *mount_ctx, const char *path, ra8_fs_mode_t mode, void **out_file) |
| Open the immutable foreign demo file. | |
| static ra8_err_t | internal_stub_close (void *file_ctx) |
| Close the immutable foreign demo file. | |
| static ra8_err_t | internal_stub_read (void *file_ctx, void *buf, uint32_t bytes, uint32_t *out_read) |
| Read a bounded prefix from the immutable foreign payload. | |
| static ra8_err_t | internal_stub_seek (void *file_ctx, uint64_t offset_bytes) |
| Seek within the immutable foreign demo file. | |
| static ra8_err_t | internal_stub_tell (const void *file_ctx, uint64_t *out_offset) |
| Report the current foreign stream offset. | |
| static ra8_err_t | internal_stub_size (const void *file_ctx, uint64_t *out_bytes) |
| Report the immutable foreign payload size. | |
| static ra8_err_t | internal_stub_stat (void *mount_ctx, const char *path, ra8_fs_stat_t *out) |
| Report metadata for the foreign root or immutable file. | |
| static ra8_err_t | internal_stub_listdir (void *mount_ctx, const char *path, ra8_fs_listdir_cb_t cb, void *cb_ctx) |
| Enumerate the foreign root's immutable file. | |
| static void | internal_demo_setup_or_halt (void) |
| Bring up CGC, SysTick, and the SCI8 console; halt on failure. | |
| static ra8_err_t | internal_demo_probe_fat (const ra8_io_fsfmt_t **out_fmt) |
| Format a FAT12 RAM volume and require the fat format probe result. | |
| static ra8_err_t | internal_demo_probe_foreign (void) |
| Register the foreign stub format, craft a volume, and require it wins. | |
| void | main (void) |
| Firmware entry point. | |
Variables | |
| static const ra8_port_pin_t | s_demo_txd |
| SCI8 console TXD = PD02. | |
| static const ra8_port_pin_t | s_demo_rxd |
| SCI8 console RXD = PD03. | |
| 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 for the FAT volume (in SRAM .bss). | |
| static uint8_t | s_stub_disk [(size_t) k_demo_stub_blocks *(size_t) k_ra8_io_block_size_bytes] |
| 4 KiB RAM-disk backing buffer for the stub-signature volume. | |
| static ra8_io_blockdev_t | s_bd |
| Block-device handle + its RAM backend state (FAT volume). | |
| static ra8_io_blockdev_ram_state_t | s_bstate |
| static ra8_fs_backend_t | s_be |
| ra8_fs backend bridged onto the FAT block device. | |
| static ra8_io_stream_t | s_uart |
| UART output stream + its sink state. | |
| static ra8_io_stream_uart_state_t | s_ust |
| static const char *const | s_tag = "ra8_io_fsfmt_demo" |
| Module log tag. | |
| static const uint8_t | s_demo_stub_payload [] = "registered-format-data" |
| Immutable contents served by the foreign demo format. | |
| static demo_stub_mount_t | s_demo_stub_mount |
| Caller-independent foreign-format mount state. | |
| static demo_stub_file_t | s_demo_stub_file |
| Caller-independent foreign-format stream state. | |
| static const ra8_io_fsfmt_ops_t | s_demo_stub_ops |
| Complete read-side operations for the bounded foreign descriptor. | |
| static const ra8_io_fsfmt_t | s_demo_stub |
| Foreign stub format descriptor (read-only, case-sensitive). | |
ra8_io pluggable filesystem-format registry demo (Phase 4, #159).
Exercises the format registry that lets the fabric recognise the on-disk filesystem without the upper layers hard-coding a switch over FAT vs exFAT:
The ra8_emulator captures the SCI8 console, so the PASS line is observable headlessly: a successful run prints ra8_io_fsfmt_demo: probed fat maxname=741 + foreign stub seam PASS.
Definition in file main.c.
| enum demo_const_t : uint32_t |
Console + volume knobs (no magic numbers).
| Enumerator | |
|---|---|
| k_demo_uart_chan | SCI8 J-Link OB console. |
| k_demo_uart_baud | Console baud. |
| k_demo_disk_blocks | 256 KiB RAM-disk (FAT12). |
| k_demo_stub_blocks | 4 KiB tiny disk for the stub vol. |
| k_demo_pin_shift | Port byte position in ra8_port_pin_t. |
| k_demo_stub_maxname | Stub format max name length. |
| k_demo_stub_magic | Stub block-0 signature byte. |
|
static |
Print a NUL-terminated string on the UART stream.
Delegates string emission to the initialized stream and intentionally ignores diagnostic-output errors in this terminal demo.
| [in] | msg | NUL-terminated message to emit. |
msg is non-NULL and readable through its terminator. Definition at line 115 of file main.c.
References RA8_INTERNAL, ra8_io_stream_puts(), and s_uart.
|
static |
Format a FAT12 RAM volume and require the fat format probe result.
Initializes the RAM backend, formats FAT12, initializes the registry, probes the volume, and validates the reported FAT capabilities.
| [out] | out_fmt | Receives the detected FAT descriptor on success. |
| k_ra8_ok | FAT was detected with the expected writable capabilities. |
| k_ra8_err_not_found | A different format name was reported. |
| k_ra8_err_not_supported | Required write capability was absent. |
| k_ra8_err_invalid_size | The advertised maximum name length differed. |
out_fmt addresses writable descriptor-pointer storage. out_fmt points at the registered FAT descriptor. Definition at line 548 of file main.c.
References k_demo_disk_blocks, k_ra8_err_invalid_size, k_ra8_err_not_found, k_ra8_err_not_supported, k_ra8_fs_type_fat12, k_ra8_io_fsfmt_fat_max_name_utf8, k_ra8_ok, ra8_fs_format_opts_t::label, RA8_CHECK_NULL_PTR, ra8_fs_format(), RA8_INTERNAL, ra8_io_blockdev_as_fs_backend(), ra8_io_blockdev_ram_init(), ra8_io_fsfmt_init(), ra8_io_fsfmt_probe(), RA8_RETURN_ON_ERROR, s_bd, s_be, s_bstate, s_disk, s_tag, strcmp(), and ra8_fs_format_opts_t::type.
Referenced by main().
|
static |
Register the foreign stub format, craft a volume, and require it wins.
Registers the file-local descriptor, initializes a tiny RAM backend, writes its signature block, probes it, and verifies advertised capabilities.
| k_ra8_ok | The stub format was detected with the expected capabilities. |
| k_ra8_err_not_found | The registry selected a different format. |
| k_ra8_err_not_supported | Required stub capabilities were absent. |
Definition at line 592 of file main.c.
References k_demo_stub_blocks, k_demo_stub_magic, k_ra8_err_not_found, k_ra8_err_not_supported, k_ra8_io_block_size_bytes, k_ra8_ok, RA8_INTERNAL, ra8_io_blockdev_as_fs_backend(), ra8_io_blockdev_ram_init(), ra8_io_blockdev_write(), ra8_io_fsfmt_probe(), ra8_io_fsfmt_register(), RA8_RETURN_ON_ERROR, s_demo_stub, s_stub_disk, s_tag, and strcmp().
Referenced by main().
|
static |
Bring up CGC, SysTick, and the SCI8 console; halt on failure.
Resolves CPUCLK0 and PCLKA, initializes the time base, routes both console pins, and configures SCI8 in dependency order.
Definition at line 505 of file main.c.
References k_demo_uart_baud, k_demo_uart_chan, k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, k_ra8_psel_sci_async, k_ra8_sci_data_8, k_ra8_sci_parity_none, k_ra8_sci_stop_1, ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, ra8_pfs_route_peripheral(), ra8_sci_init(), ra8_time_init(), s_demo_rxd, and s_demo_txd.
|
static |
Close the immutable foreign demo file.
Validates the singleton identity and consumes its open lifecycle.
| [in,out] | file_ctx | Context returned by internal_stub_open. |
| k_ra8_ok | The live file context was closed. |
file_ctx is the single format-owned stream context. Definition at line 261 of file main.c.
References k_ra8_err_invalid_state, k_ra8_ok, RA8_INTERNAL, and s_demo_stub_file.
|
static |
Enumerate the foreign root's immutable file.
Accepts only / and invokes the supplied callback exactly once.
| [in] | mount_ctx | Active foreign mount context. |
| [in] | path | Normalized directory path. |
| [in] | cb | Caller callback receiving the one entry. |
| [in,out] | cb_ctx | Caller context forwarded unchanged. |
| k_ra8_ok | The root entry was reported once. |
mount_ctx identifies the active demo mount. Definition at line 438 of file main.c.
References k_ra8_err_invalid_state, k_ra8_err_not_found, k_ra8_err_null_ptr, k_ra8_fs_attr_read_only, k_ra8_ok, s_demo_stub_mount, s_demo_stub_payload, and strcmp().
|
static |
Mount the bounded foreign demo format.
Revalidates the volume marker and publishes the one statically allocated mount context when it is not already active.
| [in] | backend | Backend selected by the registry. |
| [out] | out_mount | Receives the mounted foreign context. |
| k_ra8_ok | The foreign context was mounted and published. |
backend identifies the backend that matched the signature probe. out_mount, when non-NULL, is owned by the caller. Definition at line 169 of file main.c.
References internal_stub_probe(), k_ra8_err_busy, k_ra8_err_not_found, k_ra8_err_null_ptr, k_ra8_ok, RA8_INTERNAL, and s_demo_stub_mount.
|
static |
Open the immutable foreign demo file.
Accepts only read mode and the exact /README.TXT path, then resets the single bounded cursor.
| [in] | mount_ctx | Active foreign mount context. |
| [in] | path | Normalized volume-relative path. |
| [in] | mode | Requested open mode. |
| [out] | out_file | Receives the singleton file context. |
| k_ra8_ok | The immutable file was opened at offset zero. |
mount_ctx identifies the active demo mount. Definition at line 225 of file main.c.
References k_ra8_err_busy, k_ra8_err_invalid_state, k_ra8_err_not_found, k_ra8_err_not_supported, k_ra8_err_null_ptr, k_ra8_fs_mode_read, k_ra8_ok, s_demo_stub_file, s_demo_stub_mount, and strcmp().
|
static |
Test whether block zero carries the foreign-format stub signature.
Validates the backend seam, reads exactly one block into bounded stack storage, and compares its first byte with the demo magic value.
| [in] | be | Backend whose block zero is probed. |
| true | The block read succeeded and the signature byte matched. |
| false | The backend was invalid, the read failed, or the byte differed. |
Definition at line 137 of file main.c.
References ra8_fs_backend_t::ctx, k_demo_stub_magic, k_ra8_io_block_size_bytes, k_ra8_ok, RA8_INTERNAL, and ra8_fs_backend_t::read_block.
Referenced by internal_stub_mount().
|
static |
Read a bounded prefix from the immutable foreign payload.
Copies at most the remaining payload bytes and advances only by the count reported through out_read.
| [in,out] | file_ctx | Active foreign file context. |
| [out] | buf | Caller-owned read destination. |
| [in] | bytes | Requested byte count. |
| [out] | out_read | Receives the copied byte count. |
| k_ra8_ok | Zero or more bytes were copied without exceeding bytes. |
buf addresses bytes writable bytes when bytes is nonzero. out_read addresses writable count storage. Definition at line 288 of file main.c.
References k_ra8_err_invalid_state, k_ra8_err_null_ptr, k_ra8_ok, memcpy(), s_demo_stub_file, and s_demo_stub_payload.
|
static |
Seek within the immutable foreign demo file.
Clamps the requested absolute offset to the payload extent.
| [in,out] | file_ctx | Active foreign file context. |
| [in] | offset_bytes | Requested absolute stream offset. |
| k_ra8_ok | The bounded stream offset was updated. |
file_ctx identifies the open singleton stream. offset_bytes may span the public 64-bit interface range. Definition at line 321 of file main.c.
References k_ra8_err_invalid_state, k_ra8_ok, RA8_INTERNAL, s_demo_stub_file, and s_demo_stub_payload.
|
static |
Report the immutable foreign payload size.
Publishes the compile-time payload extent without changing the cursor.
| [in] | file_ctx | Active foreign file context. |
| [out] | out_bytes | Receives the payload byte count. |
| k_ra8_ok | The immutable payload size was published. |
file_ctx identifies the open singleton stream. out_bytes addresses writable storage. Definition at line 371 of file main.c.
References k_ra8_err_invalid_state, k_ra8_err_null_ptr, k_ra8_ok, RA8_INTERNAL, s_demo_stub_file, and s_demo_stub_payload.
|
static |
Report metadata for the foreign root or immutable file.
Recognizes only / and /README.TXT and publishes bounded metadata.
| [in] | mount_ctx | Active foreign mount context. |
| [in] | path | Normalized volume-relative path. |
| [out] | out | Receives metadata for the recognized path. |
| k_ra8_ok | Metadata for a recognized path was published. |
mount_ctx identifies the active demo mount. out. Definition at line 399 of file main.c.
References ra8_fs_stat_t::attr, ra8_fs_stat_t::is_directory, k_ra8_err_invalid_state, k_ra8_err_not_found, k_ra8_err_null_ptr, k_ra8_fs_attr_directory, k_ra8_fs_attr_read_only, k_ra8_ok, s_demo_stub_mount, s_demo_stub_payload, ra8_fs_stat_t::size_bytes, and strcmp().
|
static |
Report the current foreign stream offset.
Copies the bounded singleton cursor into caller storage.
| [in] | file_ctx | Active foreign file context. |
| [out] | out_offset | Receives the current byte offset. |
| k_ra8_ok | The current stream offset was published. |
file_ctx identifies the open singleton stream. out_offset addresses writable storage. Definition at line 345 of file main.c.
References k_ra8_err_invalid_state, k_ra8_err_null_ptr, k_ra8_ok, RA8_INTERNAL, and s_demo_stub_file.
|
static |
Release the mounted foreign demo context.
Validates the singleton identity before clearing its lifecycle bit.
| [in,out] | mount_ctx | Context previously returned by internal_stub_mount. |
| k_ra8_ok | The live foreign context was released. |
mount_ctx is the only context this format can publish. Definition at line 198 of file main.c.
References k_ra8_err_invalid_state, k_ra8_ok, RA8_INTERNAL, s_demo_stub_file, and s_demo_stub_mount.
| void main | ( | void | ) |
Firmware entry point.
The application entry point Reset_Handler hands control to.
Definition at line 624 of file main.c.
References internal_demo_print(), internal_demo_probe_fat(), internal_demo_probe_foreign(), internal_demo_setup_or_halt(), k_demo_uart_chan, k_ra8_ok, ra8_io_log_attach(), ra8_io_stream_put_u32(), ra8_io_stream_uart_init(), ra8_log_init(), ra8_sci_flush(), s_uart, and s_ust.
|
static |
|
static |
|
static |
|
static |
SCI8 console RXD = PD03.
|
static |
Foreign stub format descriptor (read-only, case-sensitive).
Definition at line 479 of file main.c.
Referenced by internal_demo_probe_foreign().
|
static |
Caller-independent foreign-format stream state.
Definition at line 99 of file main.c.
Referenced by internal_stub_close(), internal_stub_open(), internal_stub_read(), internal_stub_seek(), internal_stub_size(), internal_stub_tell(), and internal_stub_unmount().
|
static |
Caller-independent foreign-format mount state.
Definition at line 97 of file main.c.
Referenced by internal_stub_listdir(), internal_stub_mount(), internal_stub_open(), internal_stub_stat(), and internal_stub_unmount().
|
static |
Complete read-side operations for the bounded foreign descriptor.
|
static |
Immutable contents served by the foreign demo format.
Definition at line 83 of file main.c.
Referenced by internal_stub_listdir(), internal_stub_read(), internal_stub_seek(), internal_stub_size(), and internal_stub_stat().
|
static |
SCI8 console TXD = PD02.
|
static |
|
static |
4 KiB RAM-disk backing buffer for the stub-signature volume.
Definition at line 69 of file main.c.
Referenced by internal_demo_probe_foreign().
|
static |
|
static |
|
static |