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

ra8_io block-device backend over the on-chip extra/data MRAM region. More...

#include <stdint.h>
#include "ra8_err.h"
#include "ra8_io_blockdev.h"
Include dependency graph for ra8_io_blockdev_mram.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_io_blockdev_mram_state_t
 Caller-owned private state for an MRAM block device. More...

Functions

ra8_err_t ra8_io_blockdev_mram_init (ra8_io_blockdev_t *bd, ra8_io_blockdev_mram_state_t *state, uintptr_t base_addr, uint32_t block_count, bool read_only)
 Bind a hard-fenced MRAM block-device backend into a caller handle.

Detailed Description

ra8_io block-device backend over the on-chip extra/data MRAM region.

Tag
[Ring 4 / PAL] {World: NS}

The MRAM backend exposes a hard-fenced window of the on-chip MRAM data region as an array of 512-byte logical blocks on top of the ra8_io_blockdev_iface fabric. It wraps the ra8_flash HAL driver: reads memcpy directly from the memory-mapped MRAM array, writes route through ra8_flash_write (chunked into the 32-byte MRAM program unit), and erases route through ra8_flash_erase (mapping each 512-byte logical block onto sixteen 32-byte MRAM erase blocks).

MRAM also holds the running firmware's .text, so this backend is dangerous: ra8_io_blockdev_mram_init refuses any window that is not wholly contained in the extra/data MRAM region ([k_ra8_flash_extra_start, k_ra8_flash_extra_start + k_ra8_flash_extra_size)) or that overlaps the code-MRAM region ([k_ra8_flash_code_start, k_ra8_flash_code_start + k_ra8_flash_code_size)). The fence is enforced at bind time and the per-call bounds check keeps every access inside the bound window, so no operation can ever reach code MRAM.

MRAM erases to all-ones (0xFF) and requires an erase before a program can change a bit from 0 to 1, so the reported capabilities advertise must_erase_before_write = true and erase_value = 0xFF.

Since
0.1.0

Definition in file ra8_io_blockdev_mram.h.

Function Documentation

◆ ra8_io_blockdev_mram_init()

ra8_err_t ra8_io_blockdev_mram_init ( ra8_io_blockdev_t * bd,
ra8_io_blockdev_mram_state_t * state,
uintptr_t base_addr,
uint32_t block_count,
bool read_only )
nodiscard

Bind a hard-fenced MRAM block-device backend into a caller handle.

Validates the requested window aggressively, records it in state, marks it read-only per read_only, and points bd at the MRAM vtable with state as its context. No allocation occurs; the caller owns both bd and state.

The window [base_addr, base_addr + block_count * 512) must be erase-block aligned, an integral number of erase blocks, wholly inside the extra/data MRAM region, and must not overlap the code-MRAM .text region. Any violation leaves bd and state untouched and returns k_ra8_err_invalid_arg.

Parameters
[out]bdHandle to bind (zero-initialised by the caller).
[out]stateCaller-owned backend state to populate.
[in]base_addrFirst MRAM byte address of the window (erase aligned).
[in]block_countNumber of 512-byte logical blocks (>= 1).
[in]read_onlytrue to reject writes and erases on this device.
Returns
ra8_err_t Error code.
Return values
k_ra8_okBackend bound; bd is usable.
k_ra8_err_null_ptrbd or state was NULL.
k_ra8_err_invalid_argblock_count was zero, the window was misaligned, not a whole number of erase blocks, outside the extra/data MRAM region, or overlapped code MRAM.
Precondition
bd and state out-live every call made through the device.
ra8_flash_init (or ra8_flash_open) has been called before any write.
Postcondition
On success bd dispatches to the MRAM backend over the fenced window.
On any non-ok return bd and state are left unbound/untouched.
Note
Not thread-safe with respect to the same device.
Warning
The bound window is the ONLY range this device can ever touch; the fence is what keeps writes and erases out of the running .text.
See also
ra8_io_blockdev_ram_init
Since
0.1.0

Definition at line 355 of file ra8_io_blockdev_mram.c.

References ra8_io_blockdev_mram_state_t::base, ra8_io_blockdev_mram_state_t::block_count, ra8_io_blockdev_t::ctx, ra8_io_blockdev_t::iface, internal_mram_window_ok(), k_ra8_err_invalid_arg, k_ra8_io_mram_min_blocks, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_io_blockdev_mram_state_t::read_only, s_mram_iface, and s_tag.

Referenced by demo_open(), and internal_demo_open().