|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Transparent compress-on-write / decompress-on-read over the VFS (#161). 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_log.h"#include "ra8_port_constants.h"#include "ra8_port_utils.h"#include "ra8_sci.h"#include "ra8_time.h"#include "ra8_vfs_compress.h"Go to the source code of this file.
Enumerations | |
| enum | demo_const_t : uint32_t { k_demo_uart_chan = 8U , k_demo_uart_baud = 115200U , k_demo_disk_blocks = 512U , k_demo_payload = 4096U , k_demo_blob_cap = 8192U , k_demo_pin_shift = 8U , k_demo_seed_mul = 31U , k_demo_pattern_mod = 7U } |
| Console + volume + payload 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 SCI8 console; halt forever on any failure. | |
| static ra8_err_t | internal_demo_mount (ra8_io_blockdev_t *bd, ra8_fs_backend_t *be, const char *name) |
| Format + mount a fresh FAT12 volume and register it in the VFS. | |
| static ra8_err_t | internal_demo_roundtrip (const char *prefix, uint32_t *out_blob_len) |
| Run the transparent compressed round-trip on one mounted volume. | |
| static ra8_err_t | internal_demo_run (uint32_t *out_blob_len) |
| Bind both backends and run the transparent round-trip on each. | |
| 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 (in SRAM .bss) for the "ram" mount. | |
| static ra8_io_blockdev_t | s_bd_ram |
| RAM block-device handle + its backend state. | |
| static ra8_io_blockdev_ram_state_t | s_bstate_ram |
| static ra8_io_blockdev_t | s_bd_dr |
| SDRAM block-device handle + its (reused RAM-backend) state. | |
| static ra8_io_blockdev_ram_state_t | s_bstate_dr |
| static ra8_fs_backend_t | s_be_ram |
| ra8_fs backends bridged onto each block device. | |
| static ra8_fs_backend_t | s_be_dr |
| static ra8_io_stream_t | s_uart |
| UART output stream + its sink state. | |
| static ra8_io_stream_uart_state_t | s_ust |
| static uint8_t | s_payload [(size_t) k_demo_payload] |
| Original payload, compressed-blob staging, and the inflated copy. | |
| static uint8_t | s_blob [(size_t) k_demo_blob_cap] |
| static uint8_t | s_restored [(size_t) k_demo_payload] |
| static uint8_t | s_scratch [(size_t) k_ra8_compress_scratch_bytes] |
| Compressor scratch (one miniz tdefl_compressor) in SRAM. | |
| static const char *const | s_tag = "compress_demo" |
| Module log tag. | |
Transparent compress-on-write / decompress-on-read over the VFS (#161).
Demonstrates that DEFLATE compression is a TRANSPARENT property of the fabric: the app hands a plain payload to ra8_vfs_compress_write and reads it back with ra8_vfs_compress_read – it NEVER touches the codec (ra8_compress / ra8_decompress) or ra8_fs_write_file directly. The bytes on the backing store are the compressed blob; the API hides the codec.
Because the compression seam sits ABOVE the VFS, it composes over WHATEVER backend is mounted. To prove that, this demo mounts TWO backends and runs the SAME compressed round-trip through the fabric on each:
For each backend the demo: a. Formats + mounts a FAT12 volume and registers it in the VFS. b. ra8_vfs_compress_write – compresses + stores STORY.RBK. c. ra8_vfs_compress_read – reads + inflates the blob. d. memcmp against the original payload.
This mirrors the firmware's real .rabook RBKC compress-on-write path. The ra8_emulator captures the SCI8 console, so the PASS line is observable headlessly: a successful run ends with compress_demo: ram+dr 4096 -> N bytes -> 4096 round-trip PASS.
Definition in file main.c.
| enum demo_const_t : uint32_t |
Console + volume + payload 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 per volume (FAT12). |
| k_demo_payload | Source bytes (compressible). |
| k_demo_blob_cap | Compressed-blob staging capacity. |
| k_demo_pin_shift | Port byte position in ra8_port_pin_t. |
| k_demo_seed_mul | Test-pattern multiplier. |
| k_demo_pattern_mod | Small alphabet -> highly compressible. |
|
static |
Format + mount a fresh FAT12 volume and register it in the VFS.
Bridges an already-bound block device to ra8_fs, formats a FAT12 volume, mounts it, and registers the mount under name in the VFS. The block device and backend storage are caller-owned.
| [in] | bd | Bound block device (RAM or SDRAM). |
| [out] | be | Caller-owned ra8_fs backend to populate. |
| [in] | name | VFS mount name (e.g. "ram" or "dr"). |
| k_ra8_ok | Volume formatted, mounted, and registered. |
| k_ra8_err_null_ptr | bd, be, or name was NULL. |
| (other) | The first failing fabric step's code. |
bd was bound by a block-device init call. be and name out-live the registration. name.Definition at line 190 of file main.c.
References k_ra8_fs_type_fat12, k_ra8_ok, ra8_fs_format_opts_t::label, RA8_CHECK_NULL_PTR, ra8_fs_format(), ra8_fs_mount(), ra8_io_blockdev_as_fs_backend(), ra8_io_vfs_mount(), RA8_RETURN_ON_ERROR, s_tag, and ra8_fs_format_opts_t::type.
Referenced by internal_demo_run(), and internal_demo_run().
|
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.
| [in] | msg | NUL-terminated ASCII string (CR/LF supplied by the caller). |
msg is non-NULL and NUL-terminated. msg are queued on the UART stream. Definition at line 119 of file main.c.
References RA8_INTERNAL, ra8_io_stream_puts(), and s_uart.
|
static |
Run the transparent compressed round-trip on one mounted volume.
Calls ONLY the fabric's transparent compression API: it writes the shared payload to "<prefix>STORY.RBK" with ra8_vfs_compress_write (compress-on-write), reads it back with ra8_vfs_compress_read (decompress-on-read), and byte-compares against the original. The codec is never invoked directly. This body is backend-agnostic: the only thing that varies between volumes is prefix.
| [in] | prefix | VFS path prefix incl. the trailing slash ("ram:/"). |
| [out] | out_blob_len | Compressed blob length stored on success. |
| k_ra8_ok | The payload round-tripped intact. |
| k_ra8_err_null_ptr | prefix or out_blob_len was NULL. |
| k_ra8_err_invalid_size | The inflated length differed. |
| k_ra8_err_checksum_mismatch | The inflated bytes differed. |
| (other) | The first failing fabric step's code. |
prefix is mounted in the VFS. Definition at line 235 of file main.c.
References k_demo_blob_cap, k_demo_payload, k_ra8_compress_scratch_bytes, k_ra8_err_checksum_mismatch, k_ra8_err_invalid_size, k_ra8_io_vfs_name_max, k_ra8_ok, memcmp(), memcpy(), RA8_CHECK_NULL_PTR, RA8_INTERNAL, RA8_RETURN_ON_ERROR, ra8_vfs_compress_read(), ra8_vfs_compress_write(), s_blob, s_payload, s_restored, s_scratch, s_tag, and strnlen().
|
static |
Bind both backends and run the transparent round-trip on each.
Builds the deterministic compressible payload once, then for each backend (RAM then SDRAM) binds the block device, mounts a FAT12 volume in the VFS, and runs internal_demo_roundtrip through the fabric. The per-backend difference is exactly the bind line plus the VFS prefix.
| [out] | out_blob_len | Compressed blob length from the RAM round-trip. |
| k_ra8_ok | Both backends round-tripped intact. |
| k_ra8_err_null_ptr | out_blob_len was NULL. |
| (other) | The first failing backend's failing-step code. |
Definition at line 303 of file main.c.
References internal_demo_mount(), internal_demo_roundtrip(), k_demo_disk_blocks, k_demo_pattern_mod, k_demo_payload, k_demo_seed_mul, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_INTERNAL, ra8_io_blockdev_ram_init(), ra8_io_blockdev_sdram_init(), RA8_RETURN_ON_ERROR, s_bd_dr, s_bd_ram, s_be_dr, s_be_ram, s_bstate_dr, s_bstate_ram, s_disk, s_payload, and s_tag.
Referenced by main().
|
static |
Bring up CGC + SysTick + the SCI8 console; halt forever on any failure.
Initialises clocks, reads CPU/PCLKA rates, starts the millisecond time base, routes the SCI8 console pins, and opens the SCI8 UART. Any failure spins forever so a debugger can inspect the halt.
Definition at line 141 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.
| void main | ( | void | ) |
Firmware entry point.
The application entry point Reset_Handler hands control to.
Definition at line 338 of file main.c.
References internal_demo_print(), internal_demo_run(), 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 |
SDRAM block-device handle + its (reused RAM-backend) state.
Definition at line 81 of file main.c.
Referenced by internal_demo_run().
|
static |
RAM block-device handle + its backend state.
Definition at line 78 of file main.c.
Referenced by internal_demo_run().
|
static |
Definition at line 85 of file main.c.
Referenced by internal_demo_run().
|
static |
ra8_fs backends bridged onto each block device.
Definition at line 84 of file main.c.
Referenced by internal_demo_run().
|
static |
Definition at line 93 of file main.c.
Referenced by internal_demo_roundtrip(), sh_comic_open(), and sh_comic_probe_blob().
|
static |
Definition at line 82 of file main.c.
Referenced by internal_demo_run().
|
static |
Definition at line 79 of file main.c.
Referenced by internal_demo_run().
|
static |
SCI8 console RXD = PD03.
Definition at line 71 of file main.c.
Referenced by internal_demo_setup_or_halt().
|
static |
SCI8 console TXD = PD02.
Definition at line 68 of file main.c.
Referenced by internal_demo_setup_or_halt().
|
static |
256 KiB RAM-disk backing buffer (in SRAM .bss) for the "ram" mount.
Definition at line 75 of file main.c.
Referenced by internal_demo_mount(), internal_demo_probe_fat(), internal_demo_run(), internal_demo_run(), wlun_msc_read(), and wlun_msc_write().
|
static |
Original payload, compressed-blob staging, and the inflated copy.
Definition at line 92 of file main.c.
Referenced by fs_fmt_create_and_verify(), fs_fmt_fill_payload(), fs_fmt_rename_and_verify(), internal_demo_roundtrip(), internal_demo_run(), internal_ra8_io_roundtrip_fill_alpha(), internal_ra8_io_roundtrip_fill_linear(), internal_ra8_io_roundtrip_read_verify(), internal_ra8_io_roundtrip_write_subdir(), internal_swap_fill(), internal_swap_vfs_read_verify(), internal_swap_vfs_write(), main(), ra8_io_roundtrip_fill_alpha(), ra8_io_roundtrip_fill_linear(), ra8_io_roundtrip_read_verify(), ra8_io_roundtrip_root_file(), ra8_io_roundtrip_subdir_file(), sdhi_card_block_roundtrip(), sdhi_card_fill_payload(), sdhi_demo_fill_payload(), sdhi_demo_read_and_verify(), and sdhi_demo_write_payload().
|
static |
Definition at line 94 of file main.c.
Referenced by internal_demo_roundtrip().
|
static |
Compressor scratch (one miniz tdefl_compressor) in SRAM.
Definition at line 96 of file main.c.
Referenced by demo_reopen_naive(), demo_wear_phase(), internal_bind_transfer(), internal_demo_roundtrip(), internal_rcs_build_cfg(), and mg_setup_cache().
|
static |
|
static |
UART output stream + its sink state.
Definition at line 88 of file main.c.
Referenced by demo_print(), demo_report_map(), demo_report_wear(), internal_demo_print(), internal_demo_setup_or_halt(), internal_swap_replay_capture(), internal_swap_uart_print(), and main().
|
static |