33static const char*
const s_tag =
"ra8_cache_store";
40typedef enum : uint32_t {
63 if (store ==
nullptr) {
66 if (store->
index ==
nullptr) {
70 for (uint16_t i = 0U; i < store->
index_cap; i++) {
97 if (store ==
nullptr) {
100 if (store->
index ==
nullptr) {
103 uint32_t end = start + count;
104 for (uint16_t i = 0U; i < store->
index_cap; i++) {
186 uint16_t data_sectors = (uint16_t)(count - 1U);
189 for (uint16_t i = 0U; i < data_sectors; i++) {
190 uint32_t remain = len - off;
191 uint32_t chunk = (remain < sec_sz) ? remain : sec_sz;
204 .start_sector = start,
205 .sector_count = count,
318 uint32_t count = 1U + ((len + (sec_sz - 1U)) / sec_sz);
355 uint32_t* out_copied)
360 uint32_t sector = data_start + (uint32_t)(byte_pos / sec_sz);
361 uint32_t soff = (uint32_t)(byte_pos % sec_sz);
362 uint32_t space = sec_sz - soff;
363 uint32_t chunk = (max < space) ? max : space;
394 for (uint16_t i = 0U; i < count; i++) {
466 uint32_t data_sectors,
474 uint32_t max_iter = data_sectors + 1U;
475 for (uint32_t g = 0U; g <= max_iter; g++) {
479 uint32_t copied = 0U;
481 internal_read_at(store, data_start, offset + (uint64_t)done, &buf[done], len - done, &copied),
496 if ((offset + (uint64_t)len) > (uint64_t)r->
byte_len) {
553 (void)lx_nor_flash_close(store->
flash);
static const char * s_tag
Logging / check tag.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
ra8_board_eth_pin_t pin
Pin.
static ra8_err_t internal_read_stream(const ra8_cache_store_t *store, uint32_t data_start, uint32_t data_sectors, uint64_t offset, uint8_t *buf, uint32_t len)
Stream len payload bytes at offset, sector by sector, into buf.
static ra8_err_t internal_write_entry(ra8_cache_store_t *store, uint32_t start, uint32_t seq, uint32_t key, const uint8_t *data, uint32_t len, uint16_t count)
Write one entry: payload sectors first, then the header (atomic commit).
static ra8_err_t internal_alloc_run(const ra8_cache_store_t *store, uint32_t count, uint32_t *out_start)
First-fit a free contiguous run of count sectors in the log region.
ra8_err_t ra8_cache_store_close(ra8_cache_store_t *store)
Checkpoint, set the clean-shutdown marker, and close the store.
ra8_cs_rt_const_t
Runtime sizing limits.
@ k_ra8_cs_max_run
Max run length (fits ra8_cs_entry_hdr_t sector_count).
ra8_err_t ra8_cache_store_sync(ra8_cache_store_t *store)
Checkpoint the index to flash (directory + clean marker not set).
static ra8_err_t internal_read_at(const ra8_cache_store_t *store, uint32_t data_start, uint64_t byte_pos, uint8_t *dst, uint32_t max, uint32_t *out_copied)
Copy the payload slice that starts at byte_pos, within one sector.
static ra8_err_t internal_mark_dirty(ra8_cache_store_t *store)
Stamp a dirty superblock before mutating (unless already dirty).
static uint16_t internal_index_used(const ra8_cache_store_t *store)
Count the in-use index slots.
static ra8_err_t internal_checkpoint(ra8_cache_store_t *store)
Save the directory + a clean superblock (the checkpoint commit).
ra8_err_t ra8_cache_store_pin(ra8_cache_store_t *store, uint32_t key, bool pin)
Pin or unpin an entry (pinned entries are never evicted).
static ra8_err_t internal_release_run(ra8_cache_store_t *store, uint32_t start, uint16_t count)
Release every logical sector of a run back to the free pool.
ra8_err_t ra8_cache_store_read(void *ctx, uint64_t offset, uint8_t *buf, uint32_t len)
ra8_vsource_read_fn-shaped random read over an open entry.
ra8_err_t ra8_cache_store_get(const ra8_cache_store_t *store, uint32_t key, ra8_cache_store_reader_t *out_reader)
Open a sealed entry for random reads through ra8_cache_store_read.
ra8_err_t ra8_cache_store_put(ra8_cache_store_t *store, uint32_t key, const uint8_t *data, uint32_t len)
Seal a new entry once: append data under key, atomically.
static ra8_err_t internal_put_check(const ra8_cache_store_t *store, uint32_t key, const uint8_t *data, uint32_t len, uint32_t *out_count)
Validate a put request and compute its run length.
static bool internal_run_free(const ra8_cache_store_t *store, uint32_t start, uint32_t count)
True when [start, start+count) overlaps no in-use entry's run.
ra8_err_t ra8_cache_store_evict(ra8_cache_store_t *store, uint32_t key)
Drop an entry and reclaim its sectors (no write-back).
Persistent key(CRC32)->blob cache for compiled .rabook containers,built on the vendored,...
@ k_ra8_cache_store_flag_pinned
Never-evict (open book / metadata).
@ k_ra8_cache_store_flag_in_use
Slot holds a live entry.
@ k_ra8_cache_store_sector_bytes
LevelX logical-sector size (bytes).
Internal on-media format + cross-TU helpers for ra8_cache_store (#201).
uint32_t priv_cache_store_crc32(const uint8_t *data, uint32_t len)
Fold a byte block into a CRC-32/ISO-HDLC value (seeded + finalised).
@ k_ra8_cs_entry_magic
Entry-header tag 'R','C','S','E'.
int32_t priv_cache_store_index_add(ra8_cache_store_t *store, uint32_t key, uint32_t start_sector, uint16_t sector_count, uint32_t byte_len, bool pinned)
Claim a free index slot and populate it for key.
@ k_ra8_cs_dirty
Session open or crashed -> mount must replay the log.
@ k_ra8_cs_clean
Clean shutdown -> the checkpoint directory is valid.
ra8_err_t priv_cache_store_dir_save(ra8_cache_store_t *store, uint32_t *out_entry_count)
Serialize the live index into the on-flash checkpoint directory.
ra8_err_t priv_cache_store_sector_read(const ra8_cache_store_t *store, uint32_t sector, uint8_t *out512)
Read one LevelX logical sector into the store staging buffer region.
int32_t priv_cache_store_index_find(const ra8_cache_store_t *store, uint32_t key)
Find the index slot holding key.
ra8_err_t priv_cache_store_super_write(ra8_cache_store_t *store, uint32_t clean)
Write the superblock (sector 0) with the given clean marker.
ra8_err_t priv_cache_store_sector_write(ra8_cache_store_t *store, uint32_t sector, const uint8_t *in512)
Write one LevelX logical sector from a one-sector source buffer.
ra8_err_t priv_cache_store_sector_release(ra8_cache_store_t *store, uint32_t sector)
Release a LevelX logical sector back to the free pool.
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_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_busy
Resource busy – blocking operation cannot proceed.
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
@ k_ra8_err_exists
Item already exists – cannot create again.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
@ 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.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
One RAM index slot: key -> {header sector, run length, payload len}.
uint32_t byte_len
Payload length in bytes.
uint32_t start_sector
Logical sector of the entry header.
uint8_t flags
ra8_cache_store_flag_t bit set.
uint16_t sector_count
Run length (header + payload sectors).
Handle to an open entry that streams through ra8_cache_store_read.
uint32_t byte_len
Payload length (== vsource size).
const ra8_cache_store_t * store
Parent store (flash + staging).
uint32_t data_start
First payload logical sector.
uint32_t data_sectors
Payload sector count.
Caller-owned store handle.
bool inited
True between init and close.
uint32_t data_capacity
Overprovisioned live-sector budget.
uint32_t log_start
First append-log sector.
uint32_t live_sectors
Sectors currently held by live entries.
uint8_t * staging
Caller-owned >=1-sector scratch.
ra8_cache_store_entry_t * index
Caller-owned index slot array.
uint16_t index_cap
Number of index slots.
uint32_t next_seq
Monotonic append sequence number.
struct LX_NOR_FLASH_STRUCT * flash
LevelX control block (borrowed).
uint8_t flash_state
RAM shadow of sector 0 (dirty/clean).
uint32_t logical_sectors
Usable LevelX logical-sector span.
On-flash entry header at a run's first logical sector.
uint32_t hdr_crc
CRC-32 over the six fields above.