ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
Loading...
Searching...
No Matches
tables.c File Reference

Generic ground-loadable table engine implementation. More...

#include "icarus/icarus.h"
#include <string.h>

Go to the source code of this file.

Data Structures

struct  tbl_slot_t
 

Functions

static tbl_slot_tfind_slot (tbl_id_t id)
 
void __tbl_init (void)
 
bool __tbl_register (const tbl_descriptor_t *desc)
 
bool __tbl_load (tbl_id_t id, const uint8_t *data, uint16_t len, uint16_t schema_crc)
 
bool __tbl_activate_prepare (tbl_id_t id, uint8_t *out_data, uint16_t *out_len, tbl_activate_fn *out_activate)
 Validate a staged table and copy it into a caller-provided scratch buffer for the activate callback.
 
bool __tbl_activate_commit (tbl_id_t id, const uint8_t *data, uint16_t len)
 Commit a previously prepared table into the active buffer.
 
int16_t __tbl_dump (tbl_id_t id, uint8_t *out, uint16_t max)
 
const tbl_descriptor_t__tbl_get_descriptor (tbl_id_t id)
 
uint8_t __tbl_count (void)
 

Variables

static tbl_slot_t registry [8]
 
static uint8_t reg_count
 

Detailed Description

Generic ground-loadable table engine implementation.

Maintains a registry of up to TBL_MAX_REGISTERED table descriptors. Each registered table has a staging buffer and an active buffer (double-buffered swap):

  1. tbl_load() — writes raw bytes to staging (chunked OK).
  2. tbl_activate() — validates CRC, calls activate callback, copies staging → active on success.
  3. tbl_dump() — returns the active buffer contents.

Registry, staging, and active buffers all live in DTCM_DATA_PRIV. Public access goes through SVC gates.

tbl_activate is split across two privileged calls so the user activate callback can run in thread mode between them:

__tbl_activate_prepare() — validate + copy staging into a caller-provided scratch buffer user activate(scratch) — runs in thread mode, no SVC __tbl_activate_commit() — copy scratch into active

The engine itself is silent — no logging dependency.

Author
Souham Biswas
Date
2026

Definition in file tables.c.

Function Documentation

◆ __tbl_activate_commit()

bool __tbl_activate_commit ( tbl_id_t  id,
const uint8_t *  data,
uint16_t  len 
)

Commit a previously prepared table into the active buffer.

Called only after the user activate callback has succeeded.

< Maximum bytes per table buffer

Definition at line 176 of file tables.c.

References tbl_slot_t::active, tbl_slot_t::active_len, find_slot(), and TBL_MAX_SIZE.

Referenced by SVC_Handler_C(), and tbl_activate().

◆ __tbl_activate_prepare()

bool __tbl_activate_prepare ( tbl_id_t  id,
uint8_t *  out_data,
uint16_t *  out_len,
tbl_activate_fn out_activate 
)

Validate a staged table and copy it into a caller-provided scratch buffer for the activate callback.

The active buffer is not touched yet.

Parameters
idTable id.
out_dataCaller scratch buffer (must be ≥ TBL_MAX_SIZE).
out_len[out] Number of bytes written to scratch.
out_activate[out] Pointer to the user activate callback (or NULL).
Returns
true on validation success; false otherwise.

Definition at line 139 of file tables.c.

References tbl_descriptor_t::activate, crc16_ccitt(), tbl_slot_t::desc, find_slot(), tbl_descriptor_t::schema_crc, tbl_descriptor_t::size, tbl_slot_t::staged_data_crc, tbl_slot_t::staged_len, tbl_slot_t::staged_schema_crc, tbl_slot_t::staged_valid, and tbl_slot_t::staging.

Referenced by SVC_Handler_C(), and tbl_activate().

◆ __tbl_count()

uint8_t __tbl_count ( void  )

Definition at line 216 of file tables.c.

References reg_count.

Referenced by SVC_Handler_C(), and tbl_count().

◆ __tbl_dump()

int16_t __tbl_dump ( tbl_id_t  id,
uint8_t *  out,
uint16_t  max 
)

Definition at line 190 of file tables.c.

References tbl_slot_t::active, tbl_slot_t::active_len, and find_slot().

Referenced by SVC_Handler_C(), and tbl_dump().

◆ __tbl_get_descriptor()

const tbl_descriptor_t * __tbl_get_descriptor ( tbl_id_t  id)

Definition at line 211 of file tables.c.

References tbl_slot_t::desc, and find_slot().

Referenced by SVC_Handler_C(), and tbl_get_descriptor().

◆ __tbl_init()

void __tbl_init ( void  )

Definition at line 71 of file tables.c.

References reg_count, and registry.

Referenced by SVC_Handler_C(), and tbl_init().

◆ __tbl_load()

bool __tbl_load ( tbl_id_t  id,
const uint8_t *  data,
uint16_t  len,
uint16_t  schema_crc 
)

◆ __tbl_register()

bool __tbl_register ( const tbl_descriptor_t desc)

< Maximum number of registered tables

< Maximum bytes per table buffer

< Maximum name length (incl. NUL)

Definition at line 76 of file tables.c.

References tbl_slot_t::desc, tbl_descriptor_t::id, tbl_descriptor_t::name, reg_count, registry, tbl_descriptor_t::size, TBL_MAX_REGISTERED, TBL_MAX_SIZE, and TBL_NAME_LEN.

Referenced by SVC_Handler_C(), and tbl_register().

◆ find_slot()

static tbl_slot_t * find_slot ( tbl_id_t  id)
static

Variable Documentation

◆ reg_count

uint8_t reg_count
static

Definition at line 56 of file tables.c.

Referenced by __tbl_count(), __tbl_init(), __tbl_register(), and find_slot().

◆ registry

tbl_slot_t registry[8]
static

Definition at line 55 of file tables.c.

Referenced by __tbl_init(), __tbl_register(), and find_slot().