80typedef enum : uint32_t {
103typedef enum : uint32_t {
174static const char*
const s_tag =
"ra8_io_swap_demo";
221 for (uint32_t i = 0U; i < len; ++i) {
346 opts.
label = b->label;
427 *out_failed =
nullptr;
449 {.bd = &
s_ram_bd, .name =
"ram", .label =
"RAIORAM", .file =
"ram:/DATA.BIN"},
450 {.bd = &
s_xspi_bd, .name =
"xs", .label =
"RAIOXS", .file =
"xs:/DATA.BIN"},
456 *out_failed = table[i].
name;
483 uint32_t cpuclk0_hz = 0U;
484 uint32_t pclka_hz = 0U;
498 .pclk_hz = pclka_hz};
533 const char* failed =
nullptr;
536 uint32_t captured = 0U;
541 }
else if (failed !=
nullptr) {
549 if ((rep_e ==
k_ra8_ok) && (captured > 0U)) {
void main(void)
Secure fallback main entry point.
static void internal_demo_setup_or_halt(void)
Bring CGC + the J-Link OB VCOM console + on-board Ethernet + RSIP up.
static uint8_t s_payload[(size_t) k_demo_payload]
Original payload, compressed-blob staging, and the inflated copy.
static ra8_io_stream_t s_uart
UART output stream + its sink state.
static ra8_fs_backend_t s_be
ra8_fs backend bridged onto the cached block device.
static ra8_io_blockdev_ram_state_t s_ram_state
static ra8_err_t internal_swap_vfs_write(const char *path, uint32_t len)
Open a VFS path for writing, write len bytes, and close it.
static ra8_io_stream_ram_state_t s_ram_log_state
static const ra8_port_pin_t s_swap_rxd
SCI8 console receive pin, PD03.
static ra8_err_t internal_swap_vfs_read_verify(const char *path, uint32_t len)
Re-open a VFS path for reading and byte-compare against s_payload.
static ra8_io_stream_t s_ram_log
In-RAM stdio capture stream + its sink state and backing buffer.
static uint8_t s_ram_disk[(size_t) k_swap_ram_blocks *(size_t) k_ra8_io_block_size_bytes]
128 KiB RAM-disk backing buffer (in SRAM .bss).
static ra8_io_blockdev_t s_xspi_bd
xSPI (OSPI NOR) block-device handle + its backend state.
static void internal_swap_uart_print(const char *msg)
Print a NUL-terminated string on the UART console stream.
static uint8_t s_ram_log_buf[k_swap_log_cap]
swap_pattern_t
Deterministic payload-pattern coefficients (no magic numbers).
@ k_swap_pat_xor
Linear pattern XOR mask.
@ k_swap_pat_add
Linear pattern additive bias.
@ k_swap_pat_mul
Linear pattern multiplier.
swap_const_t
Console, volume, and payload knobs (no magic numbers).
@ k_swap_log_cap
RAM stdio-capture buffer capacity.
@ k_swap_backends
Number of block-device backends swapped.
@ k_swap_xspi_inst
xSPI controller instance index.
@ k_swap_payload
Bytes written + read back per backend.
@ k_swap_uart_chan
SCI8 J-Link OB console.
@ k_swap_xspi_blocks
256 KiB OSPI NOR window (FAT12).
@ k_swap_uart_baud
Console baud.
@ k_swap_pin_shift
Port byte position in ra8_port_pin_t.
@ k_swap_ram_blocks
128 KiB in-SRAM RAM disk (FAT12).
@ k_swap_xspi_base
Flash byte offset of logical block 0.
static ra8_err_t internal_swap_run_all(const char **out_failed)
Bind both block-device backends and run the swap over the table.
static ra8_err_t internal_swap_replay_capture(uint32_t *out_used)
Replay the RAM-captured stdio out of the UART console.
static ra8_io_stream_uart_state_t s_uart_state
static void internal_swap_fill(uint32_t len)
Fill s_payload with the deterministic linear byte pattern.
static const ra8_port_pin_t s_swap_txd
SCI8 console transmit pin, PD02.
static ra8_err_t internal_swap_run_one(const swap_backend_t *b, uint32_t len, ra8_io_stream_t *log)
Run the identical FAT/VFS round-trip over one pre-bound block device.
static ra8_io_blockdev_t s_ram_bd
RAM block-device handle + its backend state.
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_VALIDATE_INIT(initialized, tag, message)
Precondition: module must be initialized.
#define RA8_CHECK_RANGE_TAG(value, min, max, errcode, tag)
Tagged range check (adds a component tag to the log line).
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
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.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
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_write(ra8_fs_file_t *file, const uint8_t *buf, uint32_t len)
Write len bytes; allocate new clusters from FAT free-space scan as needed.
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.
ra8_err_t ra8_fs_read(ra8_fs_file_t *file, uint8_t *buf, uint32_t max_len, uint32_t *got_len)
Read up to max_len bytes; advance the cluster chain on cluster crossings.
ra8_err_t ra8_fs_unmount(ra8_fs_mount_t *handle)
Unmount a previously mounted volume and release its slot.
ra8_err_t ra8_fs_close(ra8_fs_file_t *file)
Close an open file, stamping its final modification time.
@ k_ra8_fs_type_fat12
count_of_clusters < 4085.
@ k_ra8_fs_mode_read
Read-only, must exist.
@ k_ra8_fs_mode_write
Truncate (or create) for writing.
@ 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_xspi_init(ra8_io_blockdev_t *bd, ra8_io_blockdev_xspi_state_t *state, uint8_t instance, uint32_t base_off, uint32_t block_count, bool read_only)
Bind an OSPI NOR block-device backend into a caller-owned handle.
static uint8_t s_readback[k_ra8_io_roundtrip_max_payload]
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_write(ra8_io_stream_t *s, const uint8_t *buf, uint32_t len, uint32_t *out_written)
Write len bytes to the bound sink.
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_ram_used(const ra8_io_stream_ram_state_t *state, uint32_t *out_used)
Report how many bytes have been captured into the RAM sink.
ra8_err_t ra8_io_stream_ram_init(ra8_io_stream_t *s, ra8_io_stream_ram_state_t *state, uint8_t *buf, uint32_t cap)
Bind a RAM stream sink into a caller-owned stream handle.
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.
ra8_err_t ra8_io_vfs_open(const char *path, ra8_fs_mode_t mode, ra8_fs_file_t **out_file)
Open a file by "name:/path".
ra8_err_t ra8_io_vfs_unmount(const char *name)
Remove a named mount from the table.
Lightweight Logging Interface for ra8-firmware.
void ra8_log_init(void)
Initialise the logging backend.
@ k_ra8_xspi_lio_1s1s1s
1S-1S-1S extended SPI.
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.
static ra8_xspi_state_t s_xspi_state[k_ra8_xspi_instance_count]
Per-instance callback state (s_ prefix for file-static).
xSPI / Octo-SPI driver (flash read/program/erase + ID/status)
ra8_err_t ra8_xspi_init(uint8_t instance, ra8_xspi_lio_mode_t mode)
Initialise an xSPI instance in the chosen link-layer IO mode.
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-owned private state for an OSPI NOR block device.
Caller-owned private state for a RAM stream sink.
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.
One row of the drop-in block-device swap table.
ra8_io_blockdev_t * bd
Pre-bound block-device handle (RAM or xSPI).
const char * label
11-char-max FAT volume label literal.
const char * name
VFS volume name, e.g.
const char * file
Full "<name>:/DATA.BIN" VFS path.