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

UART/SCI byte-stream sink – polled writes through ra8_sci. More...

#include "ra8_io_stream_uart.h"
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_io_stream_backend.h"
#include "ra8_sci.h"
Include dependency graph for ra8_io_stream_uart.c:

Go to the source code of this file.

Functions

static ra8_err_t internal_uart_write (void *ctx, const uint8_t *buf, uint32_t len, uint32_t *out_written)
 UART sink: write all bytes out of the SCI channel by polling.
static ra8_err_t internal_uart_flush (void *ctx)
 UART sink: drain the SCI transmit shift register.
ra8_err_t ra8_io_stream_uart_init (ra8_io_stream_t *s, ra8_io_stream_uart_state_t *state, uint8_t channel)
 Bind a UART stream sink into a caller-owned stream handle.

Variables

static const char *const s_tag = "ra8_io_stream_uart"
 Module log tag.
static const ra8_io_stream_iface_t s_uart_iface
 UART stream sink vtable.

Detailed Description

UART/SCI byte-stream sink – polled writes through ra8_sci.

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

Thin wrapper binding ra8_io_stream_iface to ra8_sci_write_polling / ra8_sci_flush. Touches no raw MMIO – the ra8_sci driver owns the HUM citations.

Definition in file ra8_io_stream_uart.c.

Function Documentation

◆ internal_uart_flush()

ra8_err_t internal_uart_flush ( void * ctx)
static

UART sink: drain the SCI transmit shift register.

Forwards to ra8_sci_flush so a caller can guarantee the line is on the wire before sleeping or asserting a panic.

Parameters
[in]ctxUART sink state (as a void cookie).
Returns
ra8_err_t Error code.
Return values
k_ra8_okTransmit drained.
k_ra8_err_null_ptrctx was NULL.
k_ra8_err_*Propagated from ra8_sci_flush.
Precondition
ctx is a populated UART sink state.
The SCI channel is initialised.
Postcondition
On success the shift register is empty.
No sink state is mutated.
Note
Not thread-safe with respect to the same channel.
Since
0.1.0

Definition at line 95 of file ra8_io_stream_uart.c.

References ra8_io_stream_uart_state_t::channel, RA8_CHECK_NULL_PTR, RA8_INTERNAL, ra8_sci_flush(), and s_tag.

◆ internal_uart_write()

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

UART sink: write all bytes out of the SCI channel by polling.

Forwards to ra8_sci_write_polling. On success every byte was shifted out, so the accepted count equals len.

Parameters
[in]ctxUART sink state (as a void cookie).
[in]bufSource bytes.
[in]lenNumber of bytes to send.
[out]out_writtenAccepted byte count, or NULL.
Returns
ra8_err_t Error code.
Return values
k_ra8_okAll bytes sent.
k_ra8_err_null_ptrctx or buf was NULL.
k_ra8_err_*Propagated from ra8_sci_write_polling.
Precondition
ctx is a populated UART sink state.
The SCI channel is initialised.
Postcondition
On success all len bytes were transmitted.
*out_written (when provided) equals len on success.
Note
Not thread-safe with respect to the same channel.
Since
0.1.0

Definition at line 57 of file ra8_io_stream_uart.c.

References ra8_io_stream_uart_state_t::channel, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_sci_write_polling(), and s_tag.

Referenced by priv_ra8_esp_hosted_osi_bind_absent().

◆ ra8_io_stream_uart_init()

ra8_err_t ra8_io_stream_uart_init ( ra8_io_stream_t * s,
ra8_io_stream_uart_state_t * state,
uint8_t channel )
nodiscard

Bind a UART 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]channelSCI channel index to write to.
Returns
ra8_err_t Error code.
Return values
k_ra8_okSink bound; s is usable.
k_ra8_err_null_ptrs or state was NULL.
Precondition
The SCI channel has been initialised with ra8_sci_init.
s and state out-live every call made through the stream.
Postcondition
On success s writes bytes out of channel.
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 109 of file ra8_io_stream_uart.c.

References ra8_io_stream_uart_state_t::channel, RA8_CHECK_NULL_PTR, ra8_io_stream_bind(), s_tag, and s_uart_iface.

Referenced by main(), and ra8_board_console_stream().

Variable Documentation

◆ s_tag

const char* const s_tag = "ra8_io_stream_uart"
static

Module log tag.

Definition at line 28 of file ra8_io_stream_uart.c.

◆ s_uart_iface

const ra8_io_stream_iface_t s_uart_iface
static
Initial value:
= {
}
static ra8_err_t internal_uart_flush(void *ctx)
UART sink: drain the SCI transmit shift register.
static ra8_err_t internal_uart_write(void *ctx, const uint8_t *buf, uint32_t len, uint32_t *out_written)
UART sink: write all bytes out of the SCI channel by polling.

UART stream sink vtable.

Definition at line 103 of file ra8_io_stream_uart.c.

Referenced by ra8_io_stream_uart_init().