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

USB-CDC byte-stream sink – bulk-IN writes through ra8_usb_pal. More...

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

Go to the source code of this file.

Enumerations

enum  ra8_io_usbcdc_const_t : uint32_t { k_usbcdc_max_chunk = 65535 }
 USB-CDC sink constants. More...

Functions

static ra8_err_t internal_usbcdc_write (void *ctx, const uint8_t *buf, uint32_t len, uint32_t *out_written)
 USB-CDC sink: send all bytes through the bulk-IN endpoint.
ra8_err_t ra8_io_stream_usbcdc_init (ra8_io_stream_t *s, ra8_io_stream_usbcdc_state_t *state, uint8_t ep_addr)
 Bind a USB-CDC stream sink into a caller-owned stream handle.

Variables

static const char *const s_tag = "ra8_io_stream_usbcdc"
 Module log tag.
static const ra8_io_stream_iface_t s_usbcdc_iface
 USB-CDC stream sink vtable.

Detailed Description

USB-CDC byte-stream sink – bulk-IN writes through ra8_usb_pal.

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

Binds ra8_io_stream_iface to ra8_usb_pal_ep_send. The PAL takes a 16-bit length, so a larger write is split into 65535-byte chunks. Touches no raw MMIO – the PAL owns the USB controller access.

Definition in file ra8_io_stream_usbcdc.c.

Enumeration Type Documentation

◆ ra8_io_usbcdc_const_t

enum ra8_io_usbcdc_const_t : uint32_t

USB-CDC sink constants.

Since
0.1.0
Enumerator
k_usbcdc_max_chunk 

Largest single ra8_usb_pal_ep_send length.

Definition at line 36 of file ra8_io_stream_usbcdc.c.

Function Documentation

◆ internal_usbcdc_write()

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

USB-CDC sink: send all bytes through the bulk-IN endpoint.

Splits the request into at most 65535-byte PAL transfers and stops at the first non-ok status, reporting how many bytes were sent.

Parameters
[in]ctxUSB-CDC sink state (as a void cookie).
[in]bufSource bytes.
[in]lenNumber of bytes to send.
[out]out_writtenSent 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_usb_pal_ep_send.
Precondition
ctx is a populated USB-CDC sink state.
The USB device + CDC class are up.
Postcondition
On success all len bytes were queued to the endpoint.
*out_written (when provided) holds the sent count.
Note
Not thread-safe with respect to the same endpoint.
Since
0.1.0

Definition at line 67 of file ra8_io_stream_usbcdc.c.

References ra8_io_stream_usbcdc_state_t::ep_addr, k_ra8_ok, k_usbcdc_max_chunk, RA8_CHECK_NULL_PTR, ra8_usb_pal_ep_send(), and s_tag.

◆ ra8_io_stream_usbcdc_init()

ra8_err_t ra8_io_stream_usbcdc_init ( ra8_io_stream_t * s,
ra8_io_stream_usbcdc_state_t * state,
uint8_t ep_addr )
nodiscard

Bind a USB-CDC 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]ep_addrUSB bulk-IN endpoint address 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 USB device stack + CDC class are up and ep_addr is configured.
s and state out-live every call made through the stream.
Postcondition
On success s sends bytes through ep_addr.
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 100 of file ra8_io_stream_usbcdc.c.

References ra8_io_stream_usbcdc_state_t::ep_addr, RA8_CHECK_NULL_PTR, ra8_io_stream_bind(), s_tag, and s_usbcdc_iface.

Variable Documentation

◆ s_tag

const char* const s_tag = "ra8_io_stream_usbcdc"
static

Module log tag.

Definition at line 28 of file ra8_io_stream_usbcdc.c.

◆ s_usbcdc_iface

const ra8_io_stream_iface_t s_usbcdc_iface
static
Initial value:
= {
.flush = nullptr,
}
static ra8_err_t internal_usbcdc_write(void *ctx, const uint8_t *buf, uint32_t len, uint32_t *out_written)
USB-CDC sink: send all bytes through the bulk-IN endpoint.

USB-CDC stream sink vtable.

flush is NULL: the PAL queues directly.

Definition at line 94 of file ra8_io_stream_usbcdc.c.

Referenced by ra8_io_stream_usbcdc_init().