36static const char*
s_tag =
"USB";
50typedef enum : uint32_t {
55typedef enum : uint8_t {
96 volatile uint16_t*
const devadd = (
volatile uint16_t*)((uintptr_t)reg + off);
123 if ((*sts & mask) != 0U) {
200#if !(defined(RA8_OFF_TARGET) && defined(UNIT_TEST))
205 reg->
INTSTS1 = (uint16_t)~(uint16_t)(sack | sign);
209 const uint16_t sts1 = reg->
INTSTS1;
210#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
211 const bool got_sack = ra8_fake_mmio_wait_eval(®->
INTSTS1, i, ((sts1 & sack) != 0U));
213 const bool got_sack = ((sts1 & sack) != 0U);
216 reg->
INTSTS1 = (uint16_t)~sack;
219 if ((sts1 & sign) != 0U) {
220 reg->
INTSTS1 = (uint16_t)~sign;
251 if ((reg->
DCPCTR & sureq) != 0U) {
258 if ((reg->
DCPCTR & sureq) != 0U) {
296 reg->
INTENB1 = (uint16_t)(reg->
INTENB1 | (uint16_t)(sack | sign));
373 uint16_t chunk = dtln;
374 if ((uint16_t)(rx + chunk) > want) {
375 chunk = (uint16_t)(want - rx);
381 rx = (uint16_t)(rx + dtln);
522 const uint16_t step = (mxps == 0U) ? (uint16_t)1U : mxps;
525 uint16_t chunk = (uint16_t)(want - off);
542 off = (uint16_t)(off + chunk);
573 if (reg ==
nullptr) {
637 if (reg ==
nullptr) {
640 if ((buf ==
nullptr) || (out_rx ==
nullptr)) {
667 const uint16_t take = (dtln < cap) ? dtln : cap;
728 bool is_read =
false;
731 if (data !=
nullptr) {
736 *out_is_read = is_read;
739 if (data_len < want) {
744 if ((setup->
w_length > 0U) && !is_read && (data !=
nullptr)) {
767 uint16_t* out_received)
771 if (reg ==
nullptr) {
781 bool is_read =
false;
786 if (out_received !=
nullptr) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_busy
Resource busy – blocking operation cannot proceed.
@ k_ra8_err_no_data
No application data available (e.g.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Bounded wait-flag primitives for RA8D2 HAL drivers.
void priv_dcp_pid(volatile r_usb_regs_t *reg, ra8_usb_pid_t pid)
Set DCPCTR PID field to a specific value while preserving the rest of the register.
void priv_rmw16(volatile uint16_t *reg, uint16_t set_mask, uint16_t clr_mask)
Apply a generic read-modify-write to a 16-bit register.
void priv_select_cfifo(volatile r_usb_regs_t *reg, uint16_t pipe_num, bool is_in_dir)
Set CFIFOSEL.MBW + CURPIPE + ISEL for the given pipe / direction.
ra8_err_t priv_wait_frdy(volatile r_usb_regs_t *reg)
Spin until CFIFOCTR.FRDY asserts or a deadline elapses.
volatile r_usb_regs_t * priv_pick(ra8_usb_speed_t speed)
Resolve the per-speed register pointer.
bool priv_is_hs(volatile const r_usb_regs_t *reg)
Detect whether reg points at the USBHS (IP1) register block.
ra8_err_t priv_dcp_push_chunk(volatile r_usb_regs_t *reg, const uint8_t *p, uint16_t n)
Push a single DCP IN chunk: wait for FRDY, write FIFO, pulse BVAL.
void priv_fifo_read(volatile r_usb_regs_t *reg, uint8_t *data, uint16_t len)
Drain the CFIFO data port into a buffer.
Native USB controller driver public API (device + host modes).
ra8_usb_speed_t
Selects which controller instance the call targets.
ra8_err_t ra8_usb_dcp_out_arm(ra8_usb_speed_t speed)
Implementation of ra8_usb_dcp_out_arm() – arm the DCP for control-OUT.
static ra8_err_t internal_host_data_phase(volatile r_usb_regs_t *reg, const ra8_usb_setup_t *setup, uint8_t *data, uint16_t data_len, uint16_t *out_rx, bool *out_is_read)
Classify and execute the optional DATA stage of a host control transfer.
ra8_usb_host_ctrl_stage_code_t
Stage codes recorded by the host control-transfer engine.
@ k_ra8_usb_cs_status
STATUS stage entered.
@ k_ra8_usb_cs_done
STATUS done; transfer closed.
@ k_ra8_usb_cs_data_out
DATA-OUT stage entered.
@ k_ra8_usb_cs_begin
Before the SETUP stage.
@ k_ra8_usb_cs_setup
SETUP stage completed.
@ k_ra8_usb_cs_data_in
DATA-IN stage entered.
@ k_ra8_usb_cs_data_pkt
First DATA packet received.
@ k_ra8_usb_cs_data_done
DATA stage completed.
static volatile uint8_t s_host_ctrl_stage
Last host control-transfer stage reached (bring-up diagnostic).
static ra8_err_t internal_host_ctrl_data_in(volatile r_usb_regs_t *reg, uint8_t *data, uint16_t want, uint16_t mxps, uint16_t *out_rx)
Run the DATA-IN stage of a host control read into data.
static ra8_err_t internal_host_setup_wait(volatile r_usb_regs_t *reg)
Clear the SETUP outcome flags, launch SUREQ, and await SACK/SIGN.
static ra8_err_t internal_host_ctrl_status(volatile r_usb_regs_t *reg, bool write_zlp)
Run the zero-length STATUS stage and complete the control transfer.
static ra8_err_t internal_host_ctrl_setup(volatile r_usb_regs_t *reg, const ra8_usb_setup_t *setup)
Issue the SETUP stage of a host control transfer and wait for it.
static void internal_host_ctrl_data_arm(volatile r_usb_regs_t *reg)
Arm the DCP to receive a control-read data stage.
static ra8_err_t internal_host_dcp_in_wait(volatile r_usb_regs_t *reg)
Wait for a DCP IN packet (BRDY), re-arming on NRDY give-ups.
void priv_host_program_devadd(volatile r_usb_regs_t *reg, uint8_t dev_addr)
Program DEVADDn.USBSPD with the connected device's link speed.
ra8_usb_host_ctrl_lim_t
Tunables for the polled host control-transfer engine.
@ k_ra8_usb_ctrl_poll_limit
Spin bound per control stage.
static ra8_err_t internal_host_ctrl_data_out(volatile r_usb_regs_t *reg, const uint8_t *data, uint16_t want, uint16_t mxps)
Run the DATA-OUT stage of a host control write from data.
uint8_t ra8_usb_host_ctrl_stage(void)
Last stage reached by ra8_usb_host_control_xfer (bring-up diag).
ra8_err_t ra8_usb_host_control_xfer(ra8_usb_speed_t speed, const ra8_usb_setup_t *setup, uint8_t *data, uint16_t data_len, uint16_t *out_received)
Run a complete host control transfer (SETUP, optional DATA, STATUS).
ra8_err_t ra8_usb_dcp_out_read(ra8_usb_speed_t speed, uint8_t *buf, uint16_t cap, uint16_t *out_rx)
Implementation of ra8_usb_dcp_out_read() – drain an armed control-OUT.
static ra8_err_t internal_host_wait_sts(volatile const uint16_t *sts, uint16_t mask)
Spin until a W0C status bit asserts or the deadline elapses.
Cross-TU surface for the ra8_usb driver split.
@ k_ra8_usb_devadd0_off
DEVADD0 byte offset from base.
@ k_ra8_usb_usbspd_shift
DEVADDn.USBSPD field position.
@ k_ra8_usb_devadd_stride
Bytes between DEVADDn slots.
@ k_ra8_usb_byte_bits
Bits per byte (shift constant).
@ k_ra8_usb_devsel_shift
DCPMAXP/PIPEMAXP DEVSEL pos.
@ k_ra8_usb_devsel_field_mask
DEVSEL width once shifted.
@ k_ra8_usb_pid_stall_bit
PID[1]: set for either STALL.
@ k_ra8_usb_dcpmaxp_mxps
DCPMAXP MXPS (max packet) field.
@ k_ra8_usb_rhst_mask
DVSTCTR0.RHST connected-speed.
@ k_ra8_usb_dcp_pipe0_bit
BRDYSTS/BEMPSTS DCP (pipe 0) bit.
@ k_ra8_usb_setup_dir_in
bmRequestType device-to-host bit.
USB Full-Speed + High-Speed controller layout for the Renesas RA8D2.
@ k_ra8_int1_bit_sign
SETUP transaction failed (3x).
@ k_ra8_int1_bit_sack
SETUP transaction ACKed.
@ k_ra8_pid_buf
BUF response (transmit/receive).
@ k_ra8_pid_nak
NAK response.
@ k_ra8_fifoctr_bclr
Buffer clear.
@ k_ra8_fifoctr_dtln
Data length (write-bytes-rem).
@ k_ra8_fifoctr_bval
Buffer valid.
@ k_ra8_dcpctr_bit_sureq
Send USB request (host mode).
@ k_ra8_dcpctr_bit_sqset
Sequence toggle set.
@ k_ra8_dcpctr_bit_ccpl
Control transfer end enable.
@ k_ra8_dcpctr_bit_sureqclr
SUREQ clear (USBHS host only).
@ k_ra8_dcpcfg_bit_dir
Transfer direction (host: 0 = IN, 1 = OUT).
USB FS / HS register window (device-mode subset).
volatile uint16_t USBINDX
+0x058 USB Request wIndex.
volatile uint16_t NRDYENB
+0x038 NRDY Interrupt Enable.
volatile uint16_t DCPCTR
+0x060 DCP Control.
volatile uint16_t USBVAL
+0x056 USB Request wValue.
volatile uint16_t CFIFOCTR
+0x022 Control FIFO control.
volatile uint16_t DCPMAXP
+0x05E DCP Max Packet.
volatile uint16_t USBLENG
+0x05A USB Request wLength.
volatile uint16_t DVSTCTR0
+0x008 Device State Control.
volatile uint16_t BRDYENB
+0x036 BRDY Interrupt Enable.
volatile uint16_t BEMPSTS
+0x04A BEMP Interrupt Status.
volatile uint16_t INTSTS1
+0x042 Interrupt Status 1.
volatile uint16_t INTENB1
+0x032 Interrupt Enable 1.
volatile uint16_t DCPCFG
+0x05C DCP Configuration.
volatile uint16_t NRDYSTS
+0x048 NRDY Interrupt Status.
volatile uint16_t BEMPENB
+0x03A BEMP Interrupt Enable.
volatile uint16_t BRDYSTS
+0x046 BRDY Interrupt Status.
volatile uint16_t USBREQ
+0x054 USB Request type/bRequest.
Decoded 8-byte USB SETUP packet.
uint16_t w_length
wLength.
uint8_t b_request
bRequest code.
uint8_t bm_request_type
Request direction / type / recipient.