ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_io_stream_ram.c File Reference

RAM byte-stream sink – append into a caller-owned buffer. More...

#include "ra8_io_stream_ram.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_io_stream_backend.h"
Include dependency graph for ra8_io_stream_ram.c:

Go to the source code of this file.

Functions

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_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_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.

Variables

static const char *const s_tag = "ra8_io_stream_ram"
 Module log tag.
static const ra8_io_stream_iface_t s_ram_iface
 RAM stream sink vtable.

Detailed Description

RAM byte-stream sink – append into a caller-owned buffer.

Tag
[Ring 4 / PAL] {World: NS}

Reference sink implementation of ra8_io_stream_iface. Writes are a bounds-checked memcpy into the caller buffer; a full buffer reports k_ra8_err_no_mem. Pure memory access – identical on host and target.

Definition in file ra8_io_stream_ram.c.

Function Documentation

◆ internal_ram_write()

ra8_err_t internal_ram_write ( void * ctx,
const uint8_t * buf,
uint32_t len,
uint32_t * out_written )
static

RAM sink: append bytes into the caller buffer.

Copies as many bytes as fit, advances the captured length, and reports the accepted count. Returns k_ra8_err_no_mem when not all bytes fit.

Parameters
[in]ctxRAM sink state (as a void cookie).
[in]bufSource bytes.
[in]lenNumber of bytes to append.
[out]out_writtenAccepted byte count, or NULL.
Returns
ra8_err_t Error code.
Return values
k_ra8_okAll bytes appended.
k_ra8_err_null_ptrctx or buf was NULL.
k_ra8_err_no_memThe buffer could not accept all bytes.
Precondition
ctx is a populated RAM sink state.
buf is readable for len bytes.
Postcondition
On success the buffer grew by len bytes.
*out_written (when provided) holds the accepted count.
Note
Not thread-safe with respect to the same stream.
Since
0.1.0

Definition at line 58 of file ra8_io_stream_ram.c.

References ra8_io_stream_ram_state_t::buf, ra8_io_stream_ram_state_t::cap, k_ra8_err_no_mem, k_ra8_ok, ra8_io_stream_ram_state_t::len, memcpy(), RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_io_stream_ram_init()

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 )
nodiscard

Bind a RAM stream sink into a caller-owned stream handle.

Parameters
[out]sStream handle to bind (zero-initialised by the caller).
[out]stateCaller-owned sink state to populate.
[in]bufCapture buffer of cap bytes.
[in]capBuffer capacity in bytes (>= 1).
Returns
ra8_err_t Error code.
Return values
k_ra8_okSink bound; s is usable.
k_ra8_err_null_ptrs, state, or buf was NULL.
k_ra8_err_invalid_sizecap was zero.
Precondition
buf covers at least cap bytes.
s and state out-live every call made through the stream.
Postcondition
On success s appends written bytes into buf.
On any non-ok return s and state are left unbound/untouched.
Note
Not thread-safe with respect to the same stream.
Since
0.1.0

Definition at line 80 of file ra8_io_stream_ram.c.

References ra8_io_stream_ram_state_t::buf, ra8_io_stream_ram_state_t::cap, k_ra8_err_invalid_size, ra8_io_stream_ram_state_t::len, RA8_CHECK_NULL_PTR, ra8_io_stream_bind(), s_ram_iface, and s_tag.

Referenced by main().

◆ ra8_io_stream_ram_used()

ra8_err_t ra8_io_stream_ram_used ( const ra8_io_stream_ram_state_t * state,
uint32_t * out_used )
nodiscard

Report how many bytes have been captured into the RAM sink.

Parameters
[in]stateBound RAM sink state.
[out]out_usedNumber of captured bytes.
Returns
ra8_err_t Error code.
Return values
k_ra8_ok*out_used populated.
k_ra8_err_null_ptrstate or out_used was NULL.
Precondition
state was populated by ra8_io_stream_ram_init.
out_used is writable.
Postcondition
On success *out_used holds the captured length.
No state is mutated.
Note
Thread-safe (pure read).
Since
0.1.0

Definition at line 97 of file ra8_io_stream_ram.c.

References k_ra8_ok, ra8_io_stream_ram_state_t::len, RA8_CHECK_NULL_PTR, and s_tag.

Referenced by internal_swap_replay_capture().

Variable Documentation

◆ s_ram_iface

const ra8_io_stream_iface_t s_ram_iface
static
Initial value:
= {
.flush = nullptr,
}
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.

RAM stream sink vtable.

flush is NULL: writes land in memory.

Definition at line 75 of file ra8_io_stream_ram.c.

◆ s_tag

const char* const s_tag = "ra8_io_stream_ram"
static

Module log tag.

Definition at line 29 of file ra8_io_stream_ram.c.