56typedef enum : uint32_t {
99static const char*
const s_tag =
"compress_demo";
143 uint32_t cpuclk0_hz = 0U;
144 uint32_t pclka_hz = 0U;
158 .pclk_hz = pclka_hz};
241 const size_t prefix_limit =
sizeof(path) -
sizeof(
"STORY.RBK");
242 const size_t prefix_len =
strnlen(prefix, prefix_limit);
243 if (prefix_len >= prefix_limit) {
246 (void)
memcpy(path, prefix, prefix_len);
247 (void)
memcpy(&path[prefix_len],
"STORY.RBK",
sizeof(
"STORY.RBK"));
249 uint32_t blob_len = 0;
261 uint32_t out_len = 0;
276 *out_blob_len = blob_len;
315 "ram blockdev init");
317 uint32_t ram_blob_len = 0;
324 "sdram blockdev init");
326 uint32_t dr_blob_len = 0;
329 *out_blob_len = ram_blob_len;
346 uint32_t blob_len = 0;
void main(void)
Secure fallback main entry point.
static void internal_demo_print(const char *s)
Convenience wrapper to write a NUL-terminated string to SCI8.
static void internal_demo_setup_or_halt(void)
Bring CGC + the J-Link OB VCOM console + on-board Ethernet + RSIP up.
static ra8_err_t internal_demo_run(uint32_t *out_blob_len)
Bind both backends and run the transparent round-trip on each.
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.
demo_const_t
Console + volume + payload knobs (no magic numbers).
@ k_demo_payload
Source bytes (compressible).
@ k_demo_disk_blocks
256 KiB per volume (FAT12).
@ k_demo_uart_baud
Console baud.
@ k_demo_uart_chan
SCI8 J-Link OB console.
@ k_demo_pin_shift
Port byte position in ra8_port_pin_t.
@ k_demo_pattern_mod
Small alphabet -> highly compressible.
@ k_demo_seed_mul
Test-pattern multiplier.
@ k_demo_blob_cap
Compressed-blob staging capacity.
static uint8_t s_payload[(size_t) k_demo_payload]
Original payload, compressed-blob staging, and the inflated copy.
static ra8_io_stream_uart_state_t s_ust
static ra8_io_blockdev_ram_state_t s_bstate_dr
static ra8_io_blockdev_t s_bd_ram
RAM block-device handle + its backend state.
static const ra8_port_pin_t s_demo_rxd
SCI8 console RXD = PD03.
static const ra8_port_pin_t s_demo_txd
SCI8 console TXD = PD02.
static ra8_io_stream_t s_uart
UART output stream + its sink state.
static ra8_fs_backend_t s_be_dr
static ra8_io_blockdev_ram_state_t s_bstate_ram
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_io_blockdev_t s_bd_dr
SDRAM block-device handle + its (reused RAM-backend) state.
static uint8_t s_blob[(size_t) k_demo_blob_cap]
static ra8_fs_backend_t s_be_ram
ra8_fs backends bridged onto each block device.
static uint8_t s_scratch[(size_t) k_ra8_compress_scratch_bytes]
Compressor scratch (one miniz tdefl_compressor) in SRAM.
static uint8_t s_restored[(size_t) k_demo_payload]
static ra8_err_t internal_demo_roundtrip(void)
Erase a block, program a pattern into it, read it back, and compare.
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
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.
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
@ k_ra8_clock_id_pclka
PCLKA.
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
@ k_ra8_compress_scratch_bytes
Minimum compress scratch size (one miniz tdefl_compressor).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_checksum_mismatch
Stored / transmitted checksum does not match computed value.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
size_t strnlen(const char *s, size_t maxlen)
Calculate bounded string length.
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
ra8_err_t ra8_fs_format(const ra8_fs_backend_t *backend, const ra8_fs_format_opts_t *opts)
Format a block device as a fresh, empty FAT12/FAT16/FAT32/exFAT volume.
ra8_err_t ra8_fs_mount(const ra8_fs_backend_t *backend, ra8_fs_mount_t **out_handle)
Mount a FAT volume from a block-device backend, auto-selecting the first partition.
@ k_ra8_fs_type_fat12
count_of_clusters < 4085.
@ k_ra8_psel_sci_async
00100b: SCI async serial (UART).
ra8_io – unified peripheral-agnostic I/O fabric (umbrella header).
@ k_ra8_io_block_size_bytes
Bytes per logical block (the only size).
ra8_err_t ra8_io_blockdev_as_fs_backend(const ra8_io_blockdev_t *bd, ra8_fs_backend_t *out)
Expose a bound block device as an ra8_fs_backend_t for ra8_fs.
ra8_err_t ra8_io_blockdev_ram_init(ra8_io_blockdev_t *bd, ra8_io_blockdev_ram_state_t *state, uint8_t *storage, uint32_t block_count, bool read_only)
Bind a RAM block-device backend into a caller-owned handle.
ra8_err_t ra8_io_blockdev_sdram_init(ra8_io_blockdev_t *bd, ra8_io_blockdev_ram_state_t *state, uint32_t block_count)
Bring up the SDRAM controller and bind it as a volatile ramdisk.
ra8_err_t ra8_io_log_attach(ra8_io_stream_t *s)
Route ra8_log output to a bound ra8_io stream.
ra8_err_t ra8_io_stream_puts(ra8_io_stream_t *s, const char *str)
Write a NUL-terminated string (without the NUL) to the bound sink.
ra8_err_t ra8_io_stream_put_u32(ra8_io_stream_t *s, uint32_t value)
Write value as unsigned decimal ASCII (no leading zeros).
ra8_err_t ra8_io_stream_uart_init(ra8_io_stream_t *s, ra8_io_stream_uart_state_t *state, uint8_t channel)
Bind a UART stream sink into a caller-owned stream handle.
ra8_err_t ra8_io_vfs_mount(const char *name, ra8_fs_mount_t *mount)
Register a mounted volume under a name.
@ k_ra8_io_vfs_name_max
Mount name length incl NUL.
Lightweight Logging Interface for ra8-firmware.
void ra8_log_init(void)
Initialise the logging backend.
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
@ k_ra8_port_13
RA8 port 13.
High-level GPIO helpers on top of the PORT + PFS register layer.
ra8_err_t ra8_pfs_route_peripheral(ra8_port_pin_t pin, ra8_psel_t psel, const char *owner)
Route a pin to a non-IRQ peripheral function via PFS.PSEL.
Full-featured Serial Communications Interface driver.
@ k_ra8_sci_stop_1
RA8 SCI stop 1.
@ k_ra8_sci_parity_none
RA8 SCI parity none.
ra8_err_t ra8_sci_init(uint8_t channel, const ra8_sci_cfg_t *cfg)
Initialise an SCI channel using the descriptor.
@ k_ra8_sci_data_8
RA8 SCI data 8.
ra8_err_t ra8_sci_flush(uint8_t channel)
Block until the channel's transmit shift register is empty.
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.
Transparent VFS-level whole-file compression (compress-on-write,decompress-on-read) over the ra8_io f...
ra8_err_t ra8_vfs_compress_read(const char *path, uint8_t *blob_buf, uint32_t blob_cap, uint8_t *out, uint32_t out_cap, uint32_t *out_len)
Read a whole compressed file through the VFS and decompress it.
ra8_err_t ra8_vfs_compress_write(const char *path, const uint8_t *src, uint32_t src_len, void *scratch, uint32_t scratch_len, uint8_t *blob_buf, uint32_t blob_cap, uint32_t *out_blob_len)
Compress a payload and store it as a whole file through the VFS.
Block-device interface that ra8_fs runs on top of.
Cached parse of one mounted FAT volume.
Caller-owned private state for a RAM block device.
Caller-allocated block-device handle binding a backend to its context.
Caller-allocated byte-stream handle binding a sink to its context.
Caller-owned private state for a UART stream sink.
Configuration descriptor for ra8_sci_init.