ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_mdl_storage_ram.c
Go to the documentation of this file.
1
11
12#include "ra8_mdl_storage_ram.h"
13
14#include <stddef.h>
15#include <stdint.h>
16#include <string.h>
17
18#include "ra8_attributes.h"
19
38RA8_INTERNAL static ra8_err_t internal_ram_begin(void* context, const char* destination)
39{
40 if ((context == nullptr) || (destination == nullptr)) {
41 return k_ra8_err_null_ptr;
42 }
43 ra8_mdl_storage_ram_t* storage = context;
44 if (destination[0] == '\0') {
46 }
47 if (storage->active) {
49 }
50 storage->length = 0U;
51 storage->committed = false;
52 storage->active = true;
53 return k_ra8_ok;
54}
55
77internal_ram_write(void* context, const uint8_t* data, uint16_t length, uint16_t* written)
78{
79 if ((context == nullptr) || (written == nullptr)) {
80 return k_ra8_err_null_ptr;
81 }
82 *written = 0U;
83 if ((data == nullptr) && (length != 0U)) {
84 return k_ra8_err_null_ptr;
85 }
86 ra8_mdl_storage_ram_t* storage = context;
87 if (!storage->active) {
89 }
90 if ((size_t)length > (storage->capacity - storage->length)) {
91 return k_ra8_err_no_mem;
92 }
93 if (length != 0U) {
94 (void)memcpy(&storage->data[storage->length], data, length);
95 }
96 storage->length += length;
97 *written = length;
98 return k_ra8_ok;
99}
100
118{
119 if (context == nullptr) {
120 return k_ra8_err_null_ptr;
121 }
122 ra8_mdl_storage_ram_t* storage = context;
123 if ((!storage->active) || (storage->length == 0U)) {
125 }
126 storage->active = false;
127 storage->committed = true;
128 return k_ra8_ok;
129}
130
148{
149 if (context == nullptr) {
150 return k_ra8_err_null_ptr;
151 }
152 ra8_mdl_storage_ram_t* storage = context;
153 if (!storage->active) {
155 }
156 storage->length = 0U;
157 storage->active = false;
158 storage->committed = false;
159 return k_ra8_ok;
160}
161
162/* data cannot be const: it seeds the struct's non-const uint8_t* data
163 * field, which internal_ram_write() later writes through. */
165 ra8_mdl_storage_ram_t* storage,
167 // NOLINTNEXTLINE(readability-non-const-parameter) -- interface contract fixes this writable pointer type.
168 uint8_t* data,
169 size_t capacity)
170{
171 if ((storage == nullptr) || (output == nullptr) || (data == nullptr)) {
172 return k_ra8_err_null_ptr;
173 }
174 if (capacity == 0U) {
176 }
177 *storage = (ra8_mdl_storage_ram_t){.data = data, .capacity = capacity};
178 *output = (ra8_mdl_storage_iface_t){.begin = internal_ram_begin,
179 .write = internal_ram_write,
180 .validate = nullptr,
181 .commit = internal_ram_commit,
182 .abort = internal_ram_abort,
183 .ctx = storage};
184 return k_ra8_ok;
185}
186
188ra8_mdl_storage_ram_view(const ra8_mdl_storage_ram_t* storage, const uint8_t** data, size_t* length)
189{
190 if ((storage == nullptr) || (data == nullptr) || (length == nullptr)) {
191 return k_ra8_err_null_ptr;
192 }
193 if ((!storage->committed) || storage->active || (storage->length == 0U)) {
195 }
196 *data = storage->data;
197 *length = storage->length;
198 return k_ra8_ok;
199}
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
Definition ra8_err.h:142
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
Definition ra8_err.h:161
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
Definition ra8_err.h:167
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
static ra8_err_t internal_ram_begin(void *context, const char *destination)
Start a fresh private object in the bound caller buffer.
ra8_err_t ra8_mdl_storage_ram_view(const ra8_mdl_storage_ram_t *storage, const uint8_t **data, size_t *length)
Expose the complete committed source as an immutable byte view.
static ra8_err_t internal_ram_write(void *context, const uint8_t *data, uint16_t length, uint16_t *written)
Append one complete transfer fragment to private RAM storage.
static ra8_err_t internal_ram_commit(void *context)
Publish the current private extent to the caller.
ra8_err_t ra8_mdl_storage_ram_init(ra8_mdl_storage_ram_t *storage, ra8_mdl_storage_iface_t *output, uint8_t *data, size_t capacity)
Bind a caller buffer as one transactional media destination.
static ra8_err_t internal_ram_abort(void *context)
Discard the logical extent of one active private object.
Caller-buffer transaction adapter for verified C6 media sources.
Mutable transaction over one caller-owned destination span.
size_t capacity
Writable backing capacity.
size_t length
Private or committed byte count.
bool committed
A read-only view may be exposed.
bool active
A transfer may append bytes.
uint8_t * data
Caller-owned backing bytes.