|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Byte-stream dispatcher + no-varargs formatted-output primitives. More...
#include "ra8_io_stream.h"#include <stddef.h>#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_io_stream_backend.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_io_stream_const_t : uint32_t { k_ra8_io_dec_base = 10 , k_ra8_io_hex_base = 16 , k_ra8_io_u32_max_digits = 10 , k_ra8_io_u64_max_digits = 20 , k_ra8_io_hex_max_digits = 8 , k_ra8_io_puts_max = 65535 } |
| Rendering constants for the formatted-output helpers. More... | |
Functions | |
| static ra8_err_t | internal_validate (const ra8_io_stream_t *s) |
| Reject a handle that is NULL or has no sink bound. | |
| 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. | |
| ra8_err_t | ra8_io_stream_write (ra8_io_stream_t *s, const uint8_t *buf, uint32_t len, uint32_t *out_written) |
| Write len bytes to the bound sink. | |
| ra8_err_t | ra8_io_stream_flush (ra8_io_stream_t *s) |
| Flush any sink-side buffering to its destination. | |
| ra8_err_t | ra8_io_stream_putc (ra8_io_stream_t *s, char c) |
| Write a single byte to the bound sink. | |
| ra8_err_t | ra8_io_stream_puts (ra8_io_stream_t *s, const char *str) |
| Write a NUL-terminated string (without the NUL) to the bound sink. | |
| ra8_err_t | ra8_io_stream_put_u32 (ra8_io_stream_t *s, uint32_t value) |
| Write value as unsigned decimal ASCII (no leading zeros). | |
| ra8_err_t | ra8_io_stream_put_u64 (ra8_io_stream_t *s, uint64_t value) |
| Write value as unsigned 64-bit decimal ASCII without leading zeros. | |
| ra8_err_t | ra8_io_stream_put_hex (ra8_io_stream_t *s, uint32_t value, uint8_t min_digits) |
| Write value as lowercase hex ASCII, zero-padded to min_digits. | |
Variables | |
| static const char *const | s_tag = "ra8_io_stream" |
| Module log tag. | |
Byte-stream dispatcher + no-varargs formatted-output primitives.
Validates the stream handle then forwards through the bound sink vtable. The formatted helpers (puts / put_u32 / put_hex) render into a small bounded stack buffer and call ra8_io_stream_write – no varargs, no allocation, so the _sbrk trap and the bounded-stack budget stay intact.
Definition in file ra8_io_stream.c.
| enum ra8_io_stream_const_t : uint32_t |
Rendering constants for the formatted-output helpers.
| Enumerator | |
|---|---|
| k_ra8_io_dec_base | Base for ra8_io_stream_put_u32. |
| k_ra8_io_hex_base | Base for ra8_io_stream_put_hex. |
| k_ra8_io_u32_max_digits | Decimal digits in UINT32_MAX. |
| k_ra8_io_u64_max_digits | Decimal digits in UINT64_MAX. |
| k_ra8_io_hex_max_digits | Hex digits in a 32-bit value. |
| k_ra8_io_puts_max | Bounded scan limit for ra8_io_stream_puts. |
Definition at line 37 of file ra8_io_stream.c.
|
static |
Reject a handle that is NULL or has no sink bound.
Run on every entry point. Kept tiny so each public function stays under the NASA Power-of-10 Rule 4 sixty-line cap.
| [in] | s | Candidate handle. |
| k_ra8_ok | s is non-NULL with a bound sink. |
| k_ra8_err_null_ptr | s was NULL. |
| k_ra8_err_not_initialized | s->iface was NULL (never bound). |
Definition at line 69 of file ra8_io_stream.c.
References ra8_io_stream_t::iface, k_ra8_err_not_initialized, k_ra8_err_null_ptr, k_ra8_ok, and RA8_INTERNAL.
Referenced by ra8_io_stream_flush(), ra8_io_stream_put_hex(), ra8_io_stream_put_u32(), ra8_io_stream_put_u64(), ra8_io_stream_putc(), ra8_io_stream_puts(), and ra8_io_stream_write().
|
nodiscard |
Bind a backend vtable and caller-owned state into a stream handle.
| [out] | stream | Stream handle to initialize. |
| [in] | iface | Immutable backend operations. |
| [in,out] | context | Backend-owned state retained by the handle. |
| k_ra8_ok | The handle is bound and ready. |
| k_ra8_err_null_ptr | A required pointer is null. |
| k_ra8_err_invalid_arg | The mandatory write operation is absent. |
iface and context outlive every operation through stream. stream while binding it. stream with the requested binding. stream unchanged. Definition at line 81 of file ra8_io_stream.c.
References k_ra8_err_invalid_arg, k_ra8_err_null_ptr, k_ra8_ok, and ra8_io_stream_iface::write.
Referenced by ra8_io_stream_blockdev_init(), ra8_io_stream_posix_init(), ra8_io_stream_ram_init(), ra8_io_stream_uart_init(), and ra8_io_stream_usbcdc_init().
|
nodiscard |
Flush any sink-side buffering to its destination.
| [in] | s | Bound stream handle. |
| k_ra8_ok | Pending bytes committed (or none pending). |
| k_ra8_err_null_ptr | s was NULL. |
| k_ra8_err_not_initialized | No sink is bound to s. |
Definition at line 116 of file ra8_io_stream.c.
References ra8_io_stream_t::ctx, ra8_io_stream_iface::flush, ra8_io_stream_t::iface, internal_validate(), and k_ra8_ok.
Referenced by internal_solve_words(), main(), and priv_mdl_stream_flush().
|
nodiscard |
Write value as lowercase hex ASCII, zero-padded to min_digits.
| [in] | s | Bound stream handle. |
| [in] | value | Value to render. |
| [in] | min_digits | Minimum digit count (1..8); pad with leading zeros. |
| k_ra8_ok | Digits written. |
| k_ra8_err_null_ptr | s was NULL. |
| k_ra8_err_not_initialized | No sink is bound to s. |
| k_ra8_err_invalid_arg | min_digits is zero or greater than eight. |
| k_ra8_err_no_mem | A bounded sink could not accept the digits. |
Definition at line 197 of file ra8_io_stream.c.
References internal_validate(), k_ra8_err_invalid_arg, k_ra8_io_hex_base, k_ra8_io_hex_max_digits, k_ra8_ok, and ra8_io_stream_write().
Referenced by internal_put_hex(), and priv_mdl_stream_hex().
|
nodiscard |
Write value as unsigned decimal ASCII (no leading zeros).
| [in] | s | Bound stream handle. |
| [in] | value | Value to render. |
| k_ra8_ok | Digits written. |
| k_ra8_err_null_ptr | s was NULL. |
| k_ra8_err_not_initialized | No sink is bound to s. |
| k_ra8_err_no_mem | A bounded sink could not accept the digits. |
Definition at line 155 of file ra8_io_stream.c.
References internal_validate(), k_ra8_io_dec_base, k_ra8_io_u32_max_digits, k_ra8_ok, and ra8_io_stream_write().
Referenced by demo_report_map(), demo_report_wear(), internal_emit_match(), internal_put_u32(), internal_report_header(), internal_report_row(), internal_swap_run_one(), and main().
|
nodiscard |
Write value as unsigned 64-bit decimal ASCII without leading zeros.
| [in] | s | Bound stream handle. |
| [in] | value | Value to render. |
| k_ra8_ok | Digits written. |
| k_ra8_err_null_ptr | s was null. |
| k_ra8_err_not_initialized | No sink is bound to s. |
| k_ra8_err_no_mem | A bounded sink could not accept the digits. |
s and the stream is idle. value. Definition at line 176 of file ra8_io_stream.c.
References internal_validate(), k_ra8_io_dec_base, k_ra8_io_u64_max_digits, k_ra8_ok, and ra8_io_stream_write().
Referenced by internal_cli_reject_limit(), internal_put_padded_u64(), internal_put_u64(), internal_report_header(), internal_run_report(), and priv_mdl_stream_u64().
|
nodiscard |
Write a single byte to the bound sink.
| [in] | s | Bound stream handle. |
| [in] | c | Byte to write. |
| k_ra8_ok | Byte written. |
| k_ra8_err_null_ptr | s was NULL. |
| k_ra8_err_not_initialized | No sink is bound to s. |
| k_ra8_err_no_mem | A bounded sink was full. |
Definition at line 128 of file ra8_io_stream.c.
References internal_validate(), k_ra8_ok, and ra8_io_stream_write().
Referenced by internal_emit_match(), internal_log_byte(), internal_log_sink(), internal_put_padded_u64(), internal_report_row(), and priv_mdl_stream_repeat().
|
nodiscard |
Write a NUL-terminated string (without the NUL) to the bound sink.
Scans up to a bounded maximum for the terminator (NASA Power-of-10 Rule 2), then writes that many bytes. An unterminated or overlong string is rejected; it is never silently truncated.
| [in] | s | Bound stream handle. |
| [in] | str | NUL-terminated string. |
| k_ra8_ok | String written. |
| k_ra8_err_null_ptr | s or str was NULL. |
| k_ra8_err_not_initialized | No sink is bound to s. |
| k_ra8_err_no_mem | A bounded sink could not accept all bytes. |
| k_ra8_err_invalid_size | No terminator appeared inside the scan bound. |
Definition at line 138 of file ra8_io_stream.c.
References internal_validate(), k_ra8_err_invalid_size, k_ra8_io_puts_max, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_io_stream_write(), and s_tag.
Referenced by demo_print(), internal_cli_usage_network_options(), internal_demo_print(), internal_diagnostic(), internal_emit_match(), internal_prepare_args(), internal_prepare_credentials(), internal_put_text(), internal_report_header(), internal_report_row(), internal_run_report(), internal_swap_run_one(), internal_swap_uart_print(), internal_write_parts(), main(), priv_mdl_cli_put_parts(), priv_mdl_stream_text(), priv_viewer_output_capacity(), priv_viewer_output_error(), priv_viewer_output_index_error(), priv_viewer_output_open_error(), priv_viewer_output_opened(), priv_viewer_output_text(), priv_viewer_output_tile(), priv_viewer_output_usage(), and priv_viewer_output_wrote().
|
nodiscard |
Write len bytes to the bound sink.
Forwards to the sink's write primitive. out_written (if non-NULL) receives the number of bytes the sink accepted, which may be less than len for a bounded sink (e.g. a full RAM buffer).
| [in] | s | Bound stream handle. |
| [in] | buf | Source bytes. |
| [in] | len | Number of bytes to write. |
| [out] | out_written | Bytes accepted by the sink, or NULL if not needed. |
| k_ra8_ok | All len bytes accepted. |
| k_ra8_err_null_ptr | s or buf was NULL. |
| k_ra8_err_not_initialized | No sink is bound to s. |
| k_ra8_err_no_mem | A bounded sink could not accept all bytes. |
| k_ra8_err_protocol_error | Backend reported an impossible count or success after a short write. |
Definition at line 94 of file ra8_io_stream.c.
References ra8_io_stream_t::ctx, ra8_io_stream_t::iface, internal_validate(), k_ra8_err_protocol_error, k_ra8_ok, RA8_CHECK_NULL_PTR, s_tag, and ra8_io_stream_iface::write.
Referenced by internal_io_log_byte(), internal_swap_replay_capture(), ra8_camera_codec_encode_to_stream(), ra8_io_stream_put_hex(), ra8_io_stream_put_u32(), ra8_io_stream_put_u64(), ra8_io_stream_putc(), and ra8_io_stream_puts().
|
static |
Module log tag.
Definition at line 29 of file ra8_io_stream.c.