|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Block-device byte-stream sink – buffer bytes into 512-byte sectors. More...
#include "ra8_io_stream_blockdev.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_blockdev.h"#include "ra8_io_stream_backend.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_io_stream_bd_const_t : uint32_t { k_bd_one_block = 1 , k_bd_pad_byte = 0 } |
| Block-device sink constants. More... | |
Functions | |
| static ra8_err_t | internal_bdsink_commit_sector (ra8_io_stream_blockdev_state_t *st) |
| Commit the buffered sector as one logical block and advance the LBA. | |
| static uint32_t | internal_bdsink_fill_chunk (ra8_io_stream_blockdev_state_t *st, const uint8_t *buf, uint32_t len, uint32_t *done) |
| Copy one bounded chunk from the source into the sector buffer. | |
| static ra8_err_t | internal_bdsink_commit_if_full (ra8_io_stream_blockdev_state_t *st) |
| Commit the buffered sector iff it is exactly full. | |
| static ra8_err_t | internal_bdsink_write (void *ctx, const uint8_t *buf, uint32_t len, uint32_t *out_written) |
| Block-device sink: buffer bytes, auto-committing full sectors. | |
| static ra8_err_t | internal_bdsink_flush (void *ctx) |
| Block-device sink: commit a partial trailing sector (zero-padded). | |
| ra8_err_t | ra8_io_stream_blockdev_init (ra8_io_stream_t *s, ra8_io_stream_blockdev_state_t *state, const ra8_io_blockdev_t *bd, uint32_t start_lba) |
| Bind a block-device stream sink into a caller-owned stream handle. | |
Variables | |
| static const char *const | s_tag = "ra8_io_stream_blockdev" |
| Module log tag. | |
| static const ra8_io_stream_iface_t | s_bd_iface |
| Block-device stream sink vtable. | |
Block-device byte-stream sink – buffer bytes into 512-byte sectors.
Accumulates stream bytes into a sector buffer; a full sector is committed via ra8_io_blockdev_write and the LBA advances. A flush zero-pads and commits the partial trailing sector. The sector buffer lives in the caller-owned state, so there is no allocation.
Definition in file ra8_io_stream_blockdev.c.
| enum ra8_io_stream_bd_const_t : uint32_t |
Block-device sink constants.
| Enumerator | |
|---|---|
| k_bd_one_block | Single-block transfer count. |
| k_bd_pad_byte | Pad value for a partial trailing sector. |
Definition at line 39 of file ra8_io_stream_blockdev.c.
|
static |
Commit the buffered sector iff it is exactly full.
Helper for internal_bdsink_write – writes the staged sector through internal_bdsink_commit_sector only when fill has reached one logical block, otherwise it is a no-op. Extracted so internal_bdsink_write stays within the nesting-depth limit.
| [in] | st | Block-device sink state. |
| k_ra8_ok | Sector committed, or none was full yet. |
| k_ra8_err_* | Propagated from internal_bdsink_commit_sector. |
Definition at line 148 of file ra8_io_stream_blockdev.c.
References ra8_io_stream_blockdev_state_t::fill, internal_bdsink_commit_sector(), k_ra8_io_block_size_bytes, k_ra8_ok, and RA8_INTERNAL.
Referenced by internal_bdsink_write().
|
static |
Commit the buffered sector as one logical block and advance the LBA.
Writes the full sector buffer to the device at the current LBA via ra8_io_blockdev_write. On success the LBA advances by one block and the fill counter is reset to zero; on failure the error is returned and the state is left unchanged so the caller can decide how to report it.
| [in,out] | st | Block-device sink state with a sector ready to commit. |
| k_ra8_ok | Sector written; LBA advanced and fill reset. |
| k_ra8_err_* | Propagated from ra8_io_blockdev_write. |
Definition at line 68 of file ra8_io_stream_blockdev.c.
References ra8_io_stream_blockdev_state_t::bd, ra8_io_stream_blockdev_state_t::fill, k_bd_one_block, k_ra8_ok, ra8_io_stream_blockdev_state_t::lba, RA8_CHECK_NULL_PTR, RA8_INTERNAL, ra8_io_blockdev_write(), s_tag, and ra8_io_stream_blockdev_state_t::sector.
Referenced by internal_bdsink_commit_if_full(), and internal_bdsink_flush().
|
static |
Copy one bounded chunk from the source into the sector buffer.
Copies up to a full sector's worth of bytes – limited by both the bytes that remain in the source (len - done) and the room left in the sector buffer – then advances both the fill counter and the consumed count. Performs no device I/O; committing a now-full sector is the caller's responsibility.
| [in,out] | st | Block-device sink state receiving the bytes. |
| [in] | buf | Source bytes. |
| [in] | len | Total number of bytes the caller is streaming. |
| [in,out] | done | Running consumed-byte count, advanced by the chunk. |
| k_ra8_io_block_size_bytes | The chunk filled the remaining sector room (source had at least that many bytes left). |
| other | A value in [1, k_ra8_io_block_size_bytes) when the source (len - *done) is exhausted before the sector fills. |
Definition at line 110 of file ra8_io_stream_blockdev.c.
References ra8_io_stream_blockdev_state_t::fill, k_ra8_io_block_size_bytes, memcpy(), RA8_INTERNAL, and ra8_io_stream_blockdev_state_t::sector.
Referenced by internal_bdsink_write().
|
static |
Block-device sink: commit a partial trailing sector (zero-padded).
If a partial sector is buffered, the remainder is zero-filled and the sector is written as one logical block. A flush with no pending bytes is a no-op.
| [in] | ctx | Block-device sink state (as a void cookie). |
| k_ra8_ok | Pending sector committed (or none pending). |
| k_ra8_err_null_ptr | ctx was NULL. |
| k_ra8_err_* | Propagated from ra8_io_blockdev_write. |
Definition at line 229 of file ra8_io_stream_blockdev.c.
References ra8_io_stream_blockdev_state_t::fill, internal_bdsink_commit_sector(), k_bd_pad_byte, k_ra8_io_block_size_bytes, k_ra8_ok, memset(), RA8_CHECK_NULL_PTR, RA8_INTERNAL, s_tag, and ra8_io_stream_blockdev_state_t::sector.
|
static |
Block-device sink: buffer bytes, auto-committing full sectors.
Copies bytes into the sector buffer in chunks; whenever the buffer fills it is written as one logical block and the LBA advances. Reports the consumed count.
| [in] | ctx | Block-device sink state (as a void cookie). |
| [in] | buf | Source bytes. |
| [in] | len | Number of bytes to stream. |
| [out] | out_written | Consumed byte count, or NULL. |
| k_ra8_ok | All bytes buffered (full sectors committed). |
| k_ra8_err_null_ptr | ctx or buf was NULL. |
| k_ra8_err_* | Propagated from ra8_io_blockdev_write. |
Definition at line 184 of file ra8_io_stream_blockdev.c.
References internal_bdsink_commit_if_full(), internal_bdsink_fill_chunk(), k_ra8_ok, RA8_CHECK_NULL_PTR, and s_tag.
|
nodiscard |
Bind a block-device stream sink into a caller-owned stream handle.
| [out] | s | Stream handle to bind (zero-initialised by the caller). |
| [out] | state | Caller-owned sink state to populate. |
| [in] | bd | Bound block device to stream into. |
| [in] | start_lba | First logical block address to write. |
| k_ra8_ok | Sink bound; s is usable. |
| k_ra8_err_null_ptr | s, state, or bd was NULL. |
Definition at line 247 of file ra8_io_stream_blockdev.c.
References ra8_io_stream_blockdev_state_t::bd, ra8_io_stream_blockdev_state_t::fill, ra8_io_stream_blockdev_state_t::lba, RA8_CHECK_NULL_PTR, ra8_io_stream_bind(), s_bd_iface, and s_tag.
|
static |
Block-device stream sink vtable.
Definition at line 242 of file ra8_io_stream_blockdev.c.
Referenced by ra8_io_stream_blockdev_init().
|
static |
Module log tag.
Definition at line 31 of file ra8_io_stream_blockdev.c.