|
Safe Data API
CRC-protected (optionally redundant) data containers for Zephyr
|
|
v0.0-dev+gbb519af | |
Typed container definition and access macros - the primary API. More...
Macros | |
| #define | SAFE_CONTAINER_DEFINE(_container_name, _payload_type) |
Declare a CRC-protected container type wrapping _payload_type. | |
| #define | SAFE_CONTAINER_DEFINE_UNCHECKED(_container_name, _payload_type) |
| As SAFE_CONTAINER_DEFINE but without the tag-strength size bound. For documented deviations only. | |
| #define | SAFE_INIT(_c) |
| Initialise and seal a container. | |
| #define | SAFE_VERIFY(_c) |
| Verify integrity only (pure, never modifies the payload). | |
| #define | SAFE_READ(_c, _out_ptr) |
Validated copy out into _out_ptr. | |
| #define | SAFE_WRITE(_c, _in_ptr) |
Validated copy in from _in_ptr + reseal. | |
| #define | SAFE_UPDATE(_c, _fn, _user) |
| Atomic read-modify-write via callback. | |
| #define | SAFE_COMMIT(_c) |
| Reseal after an explicit external modification. | |
| #define | SAFE_SECTION(_c, _pvar) |
| Scoped lock + verify ... reseal + unlock around a block. | |
Typed container definition and access macros - the primary API.
Declare a container type with SAFE_CONTAINER_DEFINE(), then access it exclusively through the SAFE_* operations; they derive the type-erased arguments at compile time and forward to Type-Erased Core.
| #define SAFE_COMMIT | ( | _c | ) |
Reseal after an explicit external modification.
| _c | Pointer to a container declared with SAFE_CONTAINER_DEFINE(). |
Definition at line 616 of file safe_data.h.
Satisfies requirement SD-REQ-020 (Reduced API surface at the Strict level).
| #define SAFE_CONTAINER_DEFINE | ( | _container_name, | |
| _payload_type ) |
Declare a CRC-protected container type wrapping _payload_type.
Generates a struct with an optional mutex (only when CONFIG_SAFE_DATA_LOCKING, the default), an integrity tag, an optional redundant shadow copy (only when CONFIG_SAFE_DATA_REDUNDANT), and the user payload.
Rejects zero-size payloads and payloads exceeding the size bound of the configured tag (CRC-8: 16 bytes, CRC-16: 256 bytes) at compile time.
Usage:
| _container_name | Name of the generated struct type. |
| _payload_type | Complete type of the protected payload. |
Definition at line 523 of file safe_data.h.
Satisfies requirement SD-REQ-019 (Compile-time payload guards).
| #define SAFE_CONTAINER_DEFINE_UNCHECKED | ( | _container_name, | |
| _payload_type ) |
As SAFE_CONTAINER_DEFINE but without the tag-strength size bound. For documented deviations only.
| _container_name | Name of the generated struct type. |
| _payload_type | Complete type of the protected payload. |
Definition at line 540 of file safe_data.h.
| #define SAFE_INIT | ( | _c | ) |
Initialise and seal a container.
| _c | Pointer to a container declared with SAFE_CONTAINER_DEFINE(). |
Definition at line 562 of file safe_data.h.
| #define SAFE_READ | ( | _c, | |
| _out_ptr ) |
Validated copy out into _out_ptr.
| _c | Pointer to a container declared with SAFE_CONTAINER_DEFINE(). |
| _out_ptr | Destination buffer of at least sizeof(payload) bytes. |
Definition at line 582 of file safe_data.h.
| #define SAFE_SECTION | ( | _c, | |
| _pvar ) |
Scoped lock + verify ... reseal + unlock around a block.
Inside the block, _pvar is a typed pointer to the (verified) payload and may be used with plain C syntax. On normal exit the integrity tag is resealed and the lock released. This is the ergonomic, leak-free replacement for the original "checkout pointer / remember to update" pattern.
The block is entered only if the pre-check passes (or the data was recovered from the shadow copy). On an unrecoverable fault the block is skipped and the lock is released; the configured fault action has already run inside safe_data_verify().
The block is also skipped (and the lock-timeout event reported) when the container lock cannot be acquired within CONFIG_SAFE_DATA_LOCK_TIMEOUT_MS.
| _c | Pointer to a container declared with SAFE_CONTAINER_DEFINE(). |
| _pvar | Name of the typed payload-pointer variable scoped to the block. |
Definition at line 663 of file safe_data.h.
Satisfies requirements SD-REQ-014 (Bounded lock acquisition), SD-REQ-015 (No ISR-context locking), SD-REQ-016 (Serialised access — no torn snapshots), SD-REQ-020 (Reduced API surface at the Strict level), and SD-REQ-021 (Scoped access block).
| #define SAFE_UPDATE | ( | _c, | |
| _fn, | |||
| _user ) |
Atomic read-modify-write via callback.
| _c | Pointer to a container declared with SAFE_CONTAINER_DEFINE(). |
| _fn | Mutator of type safe_data_mutator_t. |
| _user | Opaque context forwarded to _fn. |
Definition at line 603 of file safe_data.h.
| #define SAFE_VERIFY | ( | _c | ) |
Verify integrity only (pure, never modifies the payload).
| _c | Pointer to a container declared with SAFE_CONTAINER_DEFINE(). |
Definition at line 572 of file safe_data.h.
| #define SAFE_WRITE | ( | _c, | |
| _in_ptr ) |
Validated copy in from _in_ptr + reseal.
| _c | Pointer to a container declared with SAFE_CONTAINER_DEFINE(). |
| _in_ptr | Source buffer of at least sizeof(payload) bytes. |
Definition at line 592 of file safe_data.h.