53typedef enum : uint64_t {
62typedef enum : uint16_t {
68typedef enum : uint16_t {
78typedef enum : uint16_t {
84typedef enum : uint16_t {
92typedef enum : uint32_t {
97typedef enum : uint16_t {
177 return (uint32_t)((off & ~(uint64_t)1U) / 2U);
227 return (ep != 0U) ? ep : pipe;
306 s_hs.last_setup_in =
false;
307 s_hs.sie_status_done =
false;
308 s_hs.ccpl_armed =
false;
309 s_hs.status_zlp =
false;
324 (void)
priv_emu_io_errf(
" USBHS host : SETUP req=0x%04X wVal=0x%04X wLen=%u%s\n",
328 s_hs.sie_status_done ?
" (SIE status)" :
"");
355 if (
s_hs.last_setup_in) {
360 if (
s_hs.sie_status_done) {
361 s_hs.status_zlp =
true;
364 s_hs.ccpl_armed =
true;
390 s_hs.ccpl_armed =
false;
391 s_hs.status_zlp =
true;
398 if (
s_hs.pipecfg[pipe] == 0U) {
405 v = (uint16_t)(v | (uint16_t)(1U << pipe));
446 const uint16_t dtln = (avail < mps) ? avail : mps;
471 uint8_t bytes[
sizeof(uint32_t)] = {};
472 const uint16_t cap = (size <
sizeof(bytes)) ? (uint16_t)size : (uint16_t)
sizeof(bytes);
487 for (uint32_t i = 0U; i < (uint32_t)cap; i++) {
550 s_hs.status_zlp =
false;
564 }
else if ((pipe != 0U) && (
s_hs.stage_len > 0U)) {
566 s_hs.reg[wb] = (uint16_t)(
s_hs.reg[wb] | (uint16_t)(1U << pipe));
594 const uint16_t old =
s_hs.reg[w];
598 if (was_rst && !is_rst) {
629 const uint16_t old =
s_hs.reg[w];
672 switch ((uint16_t)off) {
725 const uint16_t value = (uint16_t)value64;
735 switch ((uint16_t)off) {
753 s_hs.status_zlp =
false;
797 s_hs.allowed = allowed;
834 " USBHS host : host mode engaged (SYSCFG.DCFM) -- self-loop to USBFS\n");
849 " USBHS host : %u SETUP(s), %u bulk-OUT commit(s), %u bulk-IN drain(s)\n",
@ k_usbhs_byte_mask
One-byte mask.
@ k_usbhs_byte_bits
Bits per byte.
@ k_usbhs_setup_dir_in
bmRequestType device-to-host bit (USB 2.0 9.3).
static usbhs_state_t s_hs
@ k_usbhs_dcp_bit
BRDYSTS/BEMPSTS/NRDYSTS DCP (pipe 0) bit.
usbhs_geom_t
USBHS host register-window geometry and staging-buffer caps.
@ k_usbhs_base
USBHS base (HUM Ch 37, p 2059).
@ k_usbhs_span
Modelled window (covers DEVADD / LPSTS).
USBFS controller model + a virtual USB host for the board emulator.
void board_usb_loop_bulk_in_flush(uint8_t ep)
Drop whatever remains of a device pipe's bulk-IN staging.
bool board_usb_loop_take_ccpl(uc_engine *uc)
Poll the device's control-transfer completion (DCPCTR.CCPL).
void board_usb_loop_ctrl_out(uc_engine *uc, const uint8_t *data, uint16_t len)
Deliver a control-OUT data-stage packet to the device's DCP.
bool board_usb_loop_attached(void)
Whether the modelled USBFS device presents its D+ pull-up.
void board_usb_loop_bulk_out(uc_engine *uc, uint8_t ep, const uint8_t *data, uint16_t len)
Deliver one bulk-OUT packet from the firmware host to a device pipe.
uint16_t board_usb_loop_ctrl_in_avail(void)
Control-IN bytes the device has queued and the host not yet drained.
uint16_t board_usb_loop_ctrl_in_read(uint8_t *dst, uint16_t cap)
Drain up to cap control-IN bytes from the device's DCP staging.
void board_usb_loop_latch(void)
Latch the self-loop: the firmware brought a controller up as HOST.
uint16_t board_usb_loop_bulk_in_read(uc_engine *uc, uint8_t ep, uint8_t *dst, uint16_t cap)
Drain up to cap bulk-IN bytes from a device pipe's staging.
void board_usb_loop_status_out_zlp(uc_engine *uc)
Run the control-read status stage against the device (host OUT ZLP).
bool board_usb_loop_setup(uc_engine *uc, uint16_t req, uint16_t val, uint16_t indx, uint16_t leng)
Deliver one SETUP packet from the firmware host to the device.
void board_usb_loop_bus_reset(uc_engine *uc)
Deliver a bus reset to the modelled USBFS device (host released RST).
void board_usb_loop_ctrl_in_flush(void)
Drop whatever remains of the device's control-IN staging.
uint16_t board_usb_loop_bulk_in_avail(uint8_t ep)
Bulk-IN bytes a device pipe has queued and the host not yet drained.
usbhs_pulse_t
DCPCTR / PIPECTR write-pulse bits that never persist in a shadow.
@ k_usbhs_ctr_sqclr
SQCLR: force DATA0 (pulse).
@ k_usbhs_dcpctr_ccpl
CCPL: run the status stage.
@ k_usbhs_ctr_pulse_mask
SUREQ | SQCLR | SQSET (never stored).
@ k_usbhs_dcpctr_sureqclr
SUREQCLR: abort a SETUP (pulse).
@ k_usbhs_dcpctr_sureq
SUREQ: launch the SETUP (pulse).
@ k_usbhs_ctr_sqset
SQSET: force DATA1 (pulse).
static void internal_usbhs_cfifoctr_write(uc_engine *uc, uint16_t value)
Apply a CFIFOCTR write: BCLR discards, BVAL commits over the loop.
void board_usb_host_report(void)
Print the USBHS host-model section of the end-of-run summary.
static void internal_usbhs_dvstctr_write(uc_engine *uc, uint16_t value)
Apply a DVSTCTR0 write: bus-reset delivery + RHST latch.
static void internal_usbhs_dcpctr_write(uc_engine *uc, uint16_t value)
Apply a DCPCTR write: PID persists, SUREQ / CCPL pulses execute.
static bool internal_usbhs_cfifo_isel(void)
True when CFIFOSEL selects the write (ISEL) side of the DCP port.
usbhs_bits_t
SETUP-word decode + status-bit constants for the host model.
@ k_usbhs_lnst_j_state
SYSSTS0.LNST: J-state (FS idle).
static void internal_usbhs_do_setup(uc_engine *uc)
Run the SETUP transaction the firmware host launched with SUREQ.
static void internal_usbhs_reg_write(uc_engine *uc, uint64_t off, unsigned size, uint64_t value64)
Write one USBHS register (engaged path).
void board_usb_host_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value, bool *handled)
Dispatch an MMIO write inside the USBHS register window.
static uint32_t internal_usbhs_word(uint64_t off)
Word index into the 16-bit register shadow for a window offset.
static uint8_t internal_usbhs_pipe_ep(uint8_t pipe)
Device endpoint number a host pipe addresses (PIPECFG.EPNUM).
static uint64_t internal_usbhs_reg_read(uc_engine *uc, uint64_t off, unsigned size)
Read one USBHS register (engaged path).
static bool internal_usbhs_pipe_is_tx(uint8_t pipe)
True when a host pipe transmits (host-to-device; PIPECFG.DIR set).
static uint16_t internal_usbhs_dcp_mps(void)
The DCP's effective max packet size (fallback when unprogrammed).
static void internal_usbhs_do_ccpl(uc_engine *uc)
Run the status stage the firmware host launched with CCPL.
static bool s_hs_trace
When true, each loop-cable transaction is logged to injected error sink.
usbhs_int1_t
INTSTS1 host-event bits the model latches (HUM Ch 37.2.15).
@ k_usbhs_int1_sack
SACK: the device ACKed the SETUP.
@ k_usbhs_int1_sign
SIGN: three SETUP attempts failed.
static uint16_t internal_usbhs_pipe_mps(uint8_t pipe)
A pipe's effective max packet size (fallback when unprogrammed).
static uint16_t internal_usbhs_brdysts_value(uc_engine *uc)
Compose the live BRDYSTS value (and poll the device's CCPL).
static void internal_usbhs_cfifo_write(uint64_t value, unsigned size)
Append CFIFO data-port write bytes to the OUT staging buffer.
uint64_t board_usb_host_read(uc_engine *uc, uint64_t addr, unsigned size, bool *handled)
Dispatch an MMIO read inside the USBHS register window.
usbhs_dvst_t
DVSTCTR0 fields the model owns (HUM Ch 37.2.5).
@ k_usbhs_dvst_usbrst
USBRST: bus-reset signalling.
@ k_usbhs_dvst_rhst_fs
RHST = 10b: full-speed link.
static uint16_t internal_usbhs_cfifoctr_value(void)
CFIFOCTR read value: FRDY plus the receive-side DTLN.
usbhs_field_t
Register field masks (HUM Ch 37.2) not exported by ra8_usb_regs.h.
@ k_usbhs_rhst_mask
DVSTCTR0.RHST: connected-speed (RO).
@ k_usbhs_pipemaxp_mxps
PIPEMAXP.MXPS: pipe max packet field.
@ k_usbhs_dcpmaxp_mxps
DCPMAXP.MXPS: DCP max packet field.
static uint64_t internal_usbhs_cfifo_read(uc_engine *uc, unsigned size)
Service a CFIFO data-port read: drain receive bytes, packed LE.
usbhs_misc_t
Small integer constants (shifts / offsets) used by the model.
void board_usb_host_set_allowed(bool allowed)
Grant (or deny) the register-level loop for this firmware.
@ k_usbhs_reg_words
16-bit register shadow word count.
@ k_usbhs_mps_fall
DTLN clamp when no MPS is programmed.
@ k_usbhs_stage_cap
OUT staging (one HS bulk packet).
void board_usb_host_init(bool trace)
Reset the USBHS host-mode model to its power-on state.
static uint8_t internal_usbhs_cur_pipe(void)
Currently-selected CFIFO pipe number (CFIFOSEL.CURPIPE[3:0]).
USBHS HOST-mode controller model (self-loop peer of the USBFS device).
Bounded raw-descriptor I/O seam for the RA8 emulator.
emu_io_result_t priv_emu_io_errf(const char *format,...)
Format bounded text and write it to the injected error descriptor.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
USB Full-Speed + High-Speed controller layout for the Renesas RA8D2.
@ k_ra8_pllsta_plllock
b0 : PHY PLL locked flag.
@ k_ra8_syscfg_bit_dcfm
1 = host mode, 0 = device.
@ k_ra8_usb_off_pipecfg
PIPECFG : Selected pipe cfg.
@ k_ra8_usb_off_pipectr
PIPECTR : PIPE1..9 control.
@ k_ra8_usb_off_syssts0
SYSSTS0 : System status 0.
@ k_ra8_usb_off_usbleng
USBLENG : USB request wLength.
@ k_ra8_usb_off_dvstctr0
DVSTCTR0 : Device state ctrl.
@ k_ra8_usb_off_usbindx
USBINDX : USB request wIndex.
@ k_ra8_usb_off_nrdysts
NRDYSTS : NRDY Status.
@ k_ra8_usb_off_pipebuf
PIPEBUF : Selected pipe buf.
@ k_ra8_usb_off_usbval
USBVAL : USB request wValue.
@ k_ra8_usb_off_cfifosel
CFIFOSEL : Control FIFO select.
@ k_ra8_usb_off_bempsts
BEMPSTS : BEMP Status.
@ k_ra8_usb_off_intsts1
INTSTS1 : Interrupt Status 1.
@ k_ra8_usb_off_pipeperi
PIPEPERI : Selected pipe period.
@ k_ra8_usb_off_dcpmaxp
DCPMAXP : DCP max packet.
@ k_ra8_usb_off_cfifo
CFIFO : Control FIFO port.
@ k_ra8_usb_off_dcpctr
DCPCTR : DCP control.
@ k_ra8_usb_off_usbreq
USBREQ : USB request type.
@ k_ra8_usb_off_pipemaxp
PIPEMAXP : Selected pipe maxp.
@ k_ra8_usb_off_brdysts
BRDYSTS : BRDY Status.
@ k_ra8_usb_off_pipesel
PIPESEL : Pipe window select.
@ k_ra8_usb_off_cfifoctr
CFIFOCTR : Control FIFO control.
@ k_ra8_usb_off_syscfg
SYSCFG : System config.
@ k_ra8_fifoctr_frdy
FIFO ready.
@ k_ra8_fifoctr_bclr
Buffer clear.
@ k_ra8_fifoctr_dtln
Data length (write-bytes-rem).
@ k_ra8_fifoctr_bval
Buffer valid.
@ k_ra8_fifosel_isel
CFIFO direction (DCP only).
@ k_ra8_fifosel_curpipe
Current pipe select [3:0].
@ k_ra8_pipecfg_epnum_mask
Endpoint number [3:0].
@ k_ra8_pipecfg_dir_in
1 = IN, 0 = OUT (peri).
@ k_ra8_usb_pipectr_count
PIPECTR[9] = PIPE1..PIPE9.
@ k_ra8_usb_pipe_count
DCP (pipe 0) + PIPE1..PIPE9.
@ k_ra8_usbhs_off_pllsta
PLLSTA : PLL lock flag.
Aggregate USBHS host-controller model state.
uint16_t rhst
DVSTCTR0.RHST after bus reset.
uint16_t stage_len
Staged OUT bytes.
uint32_t bulk_out
Bulk-OUT packets delivered.
uint16_t pipeperi[k_ra8_usb_pipe_count]
Windowed PIPEPERI per pipe.
uint8_t stage[k_usbhs_stage_cap]
CFIFO OUT staging buffer.
bool last_setup_in
Last SETUP was device-to-host.
bool status_zlp
Status ZLP ready for the host.
uint16_t pipemaxp[k_ra8_usb_pipe_count]
Windowed PIPEMAXP per pipe.
bool ccpl_armed
Awaiting the device's CCPL.
bool engaged
Model owns the window.
bool allowed
main.c granted the loop.
uint32_t bulk_in
Bulk-IN packets collected.
uint32_t setups
SETUP packets bridged to the device.
bool sie_status_done
SIE ran the status (SET_ADDR).
uint16_t pipecfg[k_ra8_usb_pipe_count]
Windowed PIPECFG per pipe.
uint16_t pipebuf[k_ra8_usb_pipe_count]
Windowed PIPEBUF per pipe.