ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_io_stream_ram.c
Go to the documentation of this file.
1
16
17#include "ra8_io_stream_ram.h"
18
19#include <stddef.h>
20#include <stdint.h>
21#include <string.h>
22
23#include "ra8_attributes.h"
24#include "ra8_check.h"
25#include "ra8_err.h"
27
29static const char* const s_tag = "ra8_io_stream_ram";
30
58internal_ram_write(void* ctx, const uint8_t* buf, uint32_t len, uint32_t* out_written)
59{
60 RA8_CHECK_NULL_PTR(ctx, s_tag, "ctx must not be nullptr");
61 RA8_CHECK_NULL_PTR(buf, s_tag, "buf must not be nullptr");
63 const uint32_t room = st->cap - st->len;
64 const bool fits = (len <= room);
65 const uint32_t accepted = fits ? len : room;
66 (void)memcpy(&st->buf[st->len], buf, (size_t)accepted);
67 st->len += accepted;
68 if (out_written != nullptr) {
69 *out_written = accepted;
70 }
71 return fits ? k_ra8_ok : k_ra8_err_no_mem;
72}
73
76 .write = internal_ram_write,
77 .flush = nullptr,
78};
79
82 uint8_t* buf,
83 uint32_t cap)
84{
85 RA8_CHECK_NULL_PTR(s, s_tag, "s must not be nullptr");
86 RA8_CHECK_NULL_PTR(state, s_tag, "state must not be nullptr");
87 RA8_CHECK_NULL_PTR(buf, s_tag, "buf must not be nullptr");
88 if (cap == 0U) {
90 }
91 state->buf = buf;
92 state->cap = cap;
93 state->len = 0;
94 return ra8_io_stream_bind(s, &s_ram_iface, state);
95}
96
98{
99 RA8_CHECK_NULL_PTR(state, s_tag, "state must not be nullptr");
100 RA8_CHECK_NULL_PTR(out_used, s_tag, "out_used must not be nullptr");
101 *out_used = state->len;
102 return k_ra8_ok;
103}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
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_no_mem
Static buffer exhausted (no dynamic memory on this project).
Definition ra8_err.h:142
@ 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 * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
static const ra8_io_blockdev_iface_t s_ram_iface
RAM backend vtable.
struct ra8_io_stream_iface ra8_io_stream_iface_t
Public implementer contract for ra8_io byte-stream backends.
ra8_err_t ra8_io_stream_bind(ra8_io_stream_t *stream, const ra8_io_stream_iface_t *iface, void *context)
Bind a backend vtable and caller-owned state into a stream handle.
static ra8_err_t internal_ram_write(void *ctx, const uint8_t *buf, uint32_t len, uint32_t *out_written)
RAM sink: append bytes into the caller buffer.
ra8_err_t ra8_io_stream_ram_used(const ra8_io_stream_ram_state_t *state, uint32_t *out_used)
Report how many bytes have been captured into the RAM sink.
ra8_err_t ra8_io_stream_ram_init(ra8_io_stream_t *s, ra8_io_stream_ram_state_t *state, uint8_t *buf, uint32_t cap)
Bind a RAM stream sink into a caller-owned stream handle.
ra8_io byte-stream sink over a caller-owned RAM buffer.
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.
Caller-owned private state for a RAM stream sink.
uint32_t len
Bytes captured so far (private).
uint8_t * buf
Caller-owned capture buffer (private).
uint32_t cap
Buffer capacity in bytes (private).
Caller-allocated byte-stream handle binding a sink to its context.