ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_vsource.c
Go to the documentation of this file.
1
16
17#include "ra8_vsource.h"
18
19#include <stddef.h>
20#include <stdint.h>
21#include <string.h>
22
23#include "ra8_check.h"
24#include "ra8_err.h"
25
27static const char* const s_tag = "ra8_vsource";
28
30{
31 RA8_CHECK_NULL_PTR(vs, s_tag, "vs must not be nullptr");
32 RA8_CHECK_NULL_PTR(objs, s_tag, "objs must not be nullptr");
33 if (cap == 0U) {
35 }
36 vs->objs = objs;
37 vs->cap = cap;
38 vs->count = 0U;
39 return k_ra8_ok;
40}
41
44 void* ctx,
45 uint64_t base,
46 uint64_t size,
47 uint32_t* out_id)
48{
49 RA8_CHECK_NULL_PTR(vs, s_tag, "vs must not be nullptr");
50 RA8_CHECK_NULL_PTR(read, s_tag, "read must not be nullptr");
51 RA8_CHECK_NULL_PTR(out_id, s_tag, "out_id must not be nullptr");
52 if (size == 0U) {
54 }
55 if (vs->count >= vs->cap) {
56 return k_ra8_err_no_mem;
57 }
58 vs->objs[vs->count] =
59 (ra8_vsource_obj_t){.read = read, .ctx = ctx, .xip = nullptr, .base = base, .size = size};
60 *out_id = vs->count;
61 vs->count++;
62 return k_ra8_ok;
63}
64
66ra8_vsource_add_xip(ra8_vsource_t* vs, const uint8_t* xip_base, uint64_t size, uint32_t* out_id)
67{
68 RA8_CHECK_NULL_PTR(vs, s_tag, "vs must not be nullptr");
69 RA8_CHECK_NULL_PTR(xip_base, s_tag, "xip_base must not be nullptr");
70 RA8_CHECK_NULL_PTR(out_id, s_tag, "out_id must not be nullptr");
71 if (size == 0U) {
73 }
74 if (vs->count >= vs->cap) {
75 return k_ra8_err_no_mem;
76 }
77 vs->objs[vs->count] =
78 (ra8_vsource_obj_t){.read = nullptr, .ctx = nullptr, .xip = xip_base, .base = 0U, .size = size};
79 *out_id = vs->count;
80 vs->count++;
81 return k_ra8_ok;
82}
83
85 uint32_t object_id,
86 uint64_t offset,
87 uint8_t* frame,
88 uint32_t frame_bytes)
89{
90 RA8_CHECK_NULL_PTR(ctx, s_tag, "ctx must not be nullptr");
91 RA8_CHECK_NULL_PTR(frame, s_tag, "frame must not be nullptr");
92 const ra8_vsource_t* vs = (const ra8_vsource_t*)ctx;
93 if (object_id >= vs->count) {
95 }
96 const ra8_vsource_obj_t* o = &vs->objs[object_id];
97 if (offset >= o->size) {
99 }
100 const uint64_t avail = o->size - offset;
101 const uint32_t to_fill = (avail < (uint64_t)frame_bytes) ? (uint32_t)avail : frame_bytes;
102 (void)memset(frame, 0, (size_t)frame_bytes);
103 if (o->xip != nullptr) {
104 (void)memcpy(frame, &o->xip[offset], (size_t)to_fill);
105 return k_ra8_ok;
106 }
107 return o->read(o->ctx, o->base + offset, frame, to_fill);
108}
109
111 uint32_t object_id,
112 uint64_t offset,
113 uint32_t len,
114 const uint8_t** out_ptr)
115{
116 RA8_CHECK_NULL_PTR(vs, s_tag, "vs must not be nullptr");
117 RA8_CHECK_NULL_PTR(out_ptr, s_tag, "out_ptr must not be nullptr");
118 if (object_id >= vs->count) {
120 }
121 const ra8_vsource_obj_t* o = &vs->objs[object_id];
122 if (o->xip == nullptr) {
124 }
125 if (offset >= o->size) {
127 }
128 if ((uint64_t)len > (o->size - offset)) {
130 }
131 *out_ptr = &o->xip[offset];
132 return k_ra8_ok;
133}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
Definition ra8_err.h:180
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
Definition ra8_err.h:142
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
Definition ra8_err.h:337
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ 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 * 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.
ra8_err_t ra8_vsource_xip_ptr(const ra8_vsource_t *vs, uint32_t object_id, uint64_t offset, uint32_t len, const uint8_t **out_ptr)
Get a direct pointer into an XIP object (no copy, no cache).
ra8_err_t ra8_vsource_loader(void *ctx, uint32_t object_id, uint64_t offset, uint8_t *frame, uint32_t frame_bytes)
Fill a page frame from an object – the ra8_vmem_loader_fn adapter.
Definition ra8_vsource.c:84
ra8_err_t ra8_vsource_add_paged(ra8_vsource_t *vs, ra8_vsource_read_fn read, void *ctx, uint64_t base, uint64_t size, uint32_t *out_id)
Register a storage-paged object; returns its object_id.
Definition ra8_vsource.c:42
ra8_err_t ra8_vsource_add_xip(ra8_vsource_t *vs, const uint8_t *xip_base, uint64_t size, uint32_t *out_id)
Register an execute-in-place (memory-mapped) object; returns its id.
Definition ra8_vsource.c:66
ra8_err_t ra8_vsource_init(ra8_vsource_t *vs, ra8_vsource_obj_t *objs, uint32_t cap)
Initialise an empty source registry over a caller-owned object array.
Definition ra8_vsource.c:29
Virtual-memory object sources – the page-cache storage seam (Layer 1, #147).
ra8_err_t(* ra8_vsource_read_fn)(void *ctx, uint64_t offset, uint8_t *buf, uint32_t len)
Read len bytes at offset from a paged object's backing.
Definition ra8_vsource.h:79
One registered object's backing (paged or XIP).
Definition ra8_vsource.h:90
ra8_vsource_read_fn read
Paged read callback (NULL for an XIP object).
Definition ra8_vsource.h:91
void * ctx
Context passed to read.
Definition ra8_vsource.h:92
uint64_t size
Object length in bytes.
Definition ra8_vsource.h:95
uint64_t base
Paged: absolute base offset of the object.
Definition ra8_vsource.h:94
const uint8_t * xip
XIP base pointer (NULL for a paged object).
Definition ra8_vsource.h:93
Object-source registry (caller-owned; treat as private).
uint32_t count
Registered objects (next id == count).
uint32_t cap
Slot capacity.
ra8_vsource_obj_t * objs
cap object slots (caller-owned).