ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
cache_bench_io.c
Go to the documentation of this file.
1
13#include "cache_bench_io.h"
14
15#include <stdio.h>
16
17typedef enum : size_t {
19 k_cb_write_limit = 1048576U,
21
22cb_io_status_t cb_sink_write_all(cb_sink_t* sink, const void* data, size_t length)
23{
24 if ((sink == nullptr) || (sink->write == nullptr) || ((data == nullptr) && (length != 0U))) {
25 return k_cb_io_fault;
26 }
27 size_t offset = 0U;
28 size_t calls = 0U;
29 while (offset < length) {
30 size_t written = 0U;
31 const cb_io_status_t status =
32 sink->write(sink->ctx, &((const uint8_t*)data)[offset], length - offset, &written);
33 if ((status != k_cb_io_ok) || (written == 0U) || (written > (length - offset))) {
34 return (status == k_cb_io_ok) ? k_cb_io_fault : status;
35 }
36 offset += written;
37 calls++;
38 if (calls > (size_t)k_cb_write_limit) {
39 return k_cb_io_fault;
40 }
41 }
42 return k_cb_io_ok;
43}
44
45cb_io_status_t cb_sink_vformat(cb_sink_t* sink, const char* format, va_list args)
46{
47 if ((sink == nullptr) || (format == nullptr)) {
48 return k_cb_io_fault;
49 }
50 char buffer[k_cb_format_capacity];
51 const int length = vsnprintf(buffer, sizeof(buffer), format, args);
52 if ((length < 0) || ((size_t)length >= sizeof(buffer))) {
53 return k_cb_io_capacity;
54 }
55 return cb_sink_write_all(sink, buffer, (size_t)length);
56}
57
58cb_io_status_t cb_sink_format(cb_sink_t* sink, const char* format, ...)
59{
60 va_list args;
61 va_start(args, format);
62 const cb_io_status_t status = cb_sink_vformat(sink, format, args);
63 va_end(args);
64 return status;
65}
cb_io_status_t cb_sink_write_all(cb_sink_t *sink, const void *data, size_t length)
Write every byte, retrying bounded short writes.
cb_io_limit_t
@ k_cb_write_limit
Fail-closed short-write retry bound.
@ k_cb_format_capacity
Largest single report fragment.
cb_io_status_t cb_sink_format(cb_sink_t *sink, const char *format,...)
Format one bounded record and publish it atomically to the sink seam.
cb_io_status_t cb_sink_vformat(cb_sink_t *sink, const char *format, va_list args)
Format one bounded record and publish it atomically to the sink seam.
Bounded byte-source and text-sink seams for cache_bench.
cb_io_status_t
Status returned by tool-local injected I/O callbacks.
@ k_cb_io_ok
Operation completed.
@ k_cb_io_fault
Backing device or sink failed.
@ k_cb_io_capacity
Caller-owned storage was too small.
Injected output sink.
cb_sink_write_fn write
Write implementation.
void * ctx
Caller-owned binding.