59typedef enum : uint64_t {
77typedef enum : uint16_t {
85typedef enum : uint8_t {
90typedef enum : uint16_t {
95typedef enum : uint16_t {
100typedef enum : uint8_t {
107typedef enum : uint32_t {
116typedef enum : uint8_t {
193 return (uint32_t)((off & ~(uint64_t)1U) / 2U);
283 return (off >= lo) && (off < hi);
315 return (uint16_t)(
s_hs.din_len -
s_hs.din_rd);
317 return (uint16_t)(
s_hs.pin_len[p] -
s_hs.pin_rd[p]);
357 uint8_t* data = (p == 0U) ?
s_hs.din :
s_hs.pin[p];
358 uint16_t* rd = (p == 0U) ? &
s_hs.din_rd : &
s_hs.pin_rd[p];
359 const uint16_t len = (p == 0U) ?
s_hs.din_len :
s_hs.pin_len[p];
361 for (
unsigned i = 0U; (i < size) && (*rd < len); i++) {
389 if (
s_hs.pout_len[0] > 0U) {
391 s_hs.pout_wait[0] =
true;
392 s_hs.pout_len[0] = 0U;
403 s_hs.pout_wait[p] =
true;
404 s_hs.pout_len[p] = 0U;
419 s_hs.pout_wait[0] =
false;
424 s_hs.pout_wait[p] =
false;
450 s_hs.din_ready =
true;
479 s_hs.ctrl_status_pending =
false;
485 s_hs.din_ready =
true;
490 if (!armed ||
s_hs.pin_ready[p]) {
497 s_hs.pin_ready[p] =
true;
516 const uint16_t cleared = (uint16_t)(before & (uint16_t)~value);
519 s_hs.din_ready =
false;
522 if ((cleared & (uint16_t)(1U << p)) != 0U) {
523 s_hs.pin_ready[p] =
false;
575 s_hs.ctrl_status_pending =
false;
582 s_hs.din_ready =
false;
602 if (
s_hs.ctrl_read) {
622 s_hs.ctrl_status_pending =
true;
643 if ((value & sureq) != 0U) {
646 if (((value & ccpl) != 0U) && ((before & ccpl) == 0U)) {
674 s_hs.din_ready =
false;
676 s_hs.pout_len[p] = 0U;
698 if (
s_hs.prev_usbrst && !usbrst) {
701 s_hs.prev_usbrst = usbrst;
723 switch ((uint16_t)off) {
769 const uint16_t v16 = (uint16_t)value;
770 switch ((uint16_t)off) {
830 if (dst_words ==
nullptr) {
834 if (n > word_capacity) {
837 (void)
memcpy(dst_words,
s_hs.reg, (
size_t)n *
sizeof(uint16_t));
846 (void)
memcpy(
s_hs.reg, phy_page,
sizeof(phy_page));
950 if (
s_hs.setups == 0U) {
954 " %s host : %u SETUP(s), %u bulk-OUT, %u bulk-IN (chip-internal loop)\n",
971 .name =
"USBHS-host",
Decentralized peripheral-block registry for the board emulator core.
void board_periph_register_block(const board_periph_block_t *block)
Register a peripheral block's descriptor with the core registry.
@ k_board_block_dev_any
Present on every modelled device (default).
static void internal_hs_set(uint16_t off, uint16_t value)
Write a 16-bit shadow register at window byte offset off.
static void internal_usbhs_reset(void)
Reset the USBHS host model to power-on state.
static uint64_t internal_hs_read(uc_engine *uc, uint64_t off, unsigned size)
Read one USBHS host register at window byte offset off.
usbhs_lines_t
SYSSTS0 / DVSTCTR0 host-role line-state fields (HUM Ch 37.2.3 / 37.2.5).
@ k_usbhs_lnst_j
SYSSTS0.LNST J-state: an FS device is attached.
@ k_usbhs_rhst_fs
DVSTCTR0.RHST = full speed.
static void internal_usbhs_block_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
MMIO write handler: dispatch inside the USBHS controller window.
void board_usbhs_host_reg_write(uc_engine *uc, uint64_t off, unsigned size, uint64_t value)
Host-model register write by window byte offset (role routing).
static void internal_hs_dcpctr_write(uc_engine *uc, uint16_t value)
Apply a DCPCTR write: SUREQ launches a SETUP, CCPL drives the status.
uint64_t board_usbhs_host_reg_read(uc_engine *uc, uint64_t off, unsigned size)
Host-model register read by window byte offset (role routing).
static uint16_t internal_hs_brdysts_read(uc_engine *uc)
Latch any device IN data the host is now polling for (BRDY sources).
uint32_t board_usbhs_host_shadow_handoff(uint16_t *dst_words, uint32_t word_capacity)
Hand the host model's register shadow off and reset the host model.
static void internal_hs_cfifoctr_write(uc_engine *uc, uint16_t value)
Apply a CFIFOCTR write: BCLR flushes the buffer, BVAL commits a bulk OUT.
usbhs_setup_idx_t
SETUP-packet byte offsets (USB 2.0 sec 9.3, little-endian fields).
@ k_usbhs_setup_wval_lo
wValue low byte.
@ k_usbhs_setup_widx_hi
wIndex high byte.
@ k_usbhs_setup_wlen_hi
wLength high byte.
@ k_usbhs_setup_breq
bRequest.
@ k_usbhs_setup_bmrt
bmRequestType.
@ k_usbhs_setup_wlen_lo
wLength low byte.
@ k_usbhs_setup_widx_lo
wIndex low byte.
@ k_usbhs_setup_wval_hi
wValue high byte.
usbhs_dvstctr_bit_t
DVSTCTR0 host-control bit positions (HUM Ch 37.2.5, p 2065).
@ k_usbhs_dvstctr_usbrst
USBRST: drive bus reset.
static void internal_usbhs_block_register(void)
Register the USBHS host block before main (host constructor).
usbhs_lit_t
Small shared literals (avoid bare numeric literals).
@ k_usbhs_cfifo_h
CFIFOH alias offset from CFIFO (+0x2).
@ k_usbhs_byte_mask
One-byte mask.
@ k_usbhs_cfifo_hh
CFIFOHH alias offset from CFIFO (+0x3).
@ k_usbhs_epnum_mask
PIPECFG endpoint-number field.
@ k_usbhs_byte_bits
Bits per byte.
static void internal_hs_bulk_out_commit(uc_engine *uc)
Deliver the selected bulk pipe's accumulated OUT payload to the device.
static uint32_t internal_hs_cfifo_read(unsigned size)
Read size bytes (LSB-first) from the selected IN staging buffer.
static uint16_t internal_hs_cfifo_dtln(void)
Bytes still available for the host to read on the selected IN staging.
static bool internal_hs_is_pipectr(uint64_t off)
True when off is inside the PIPECTR[9] array window.
static void internal_hs_setup_launch(uc_engine *uc)
Launch a SETUP (DCPCTR.SUREQ write): deliver it and latch SACK.
static const board_periph_block_t s_k_usbhs_block
USBHS host block descriptor (loop-only: owns 0x40351000 with –usbhs-loop).
static uint64_t internal_usbhs_block_read(uc_engine *uc, uint64_t addr, unsigned size)
MMIO read handler: dispatch inside the USBHS controller window.
static uint16_t internal_hs_bempsts_read(void)
BEMPSTS read: raise a pipe's BEMP once the device has drained its OUT packet.
usbhs_usb_std_t
Standard USB chapter-9 SETUP field values the model classifies on.
@ k_usbhs_setup_dir_in
bmRequestType device-to-host bit (USB 2.0 9.3).
@ k_usbhs_breq_set_config
SET_CONFIGURATION bRequest (USB 2.0 9.4).
@ k_usbhs_breq_set_addr
SET_ADDRESS bRequest (USB 2.0 9.4).
usbhs_pllsta_bit_t
PLLSTA lock flag reported so the firmware's PHY PLL wait completes.
@ k_usbhs_plllock
PLLSTA.PLLLOCK (HUM Ch 37.2.4 "PLLSTA" p 2064).
static void internal_hs_ctrl_status_complete(uc_engine *uc)
Finish a no-data / control-write IN status stage.
static usbhs_state_t s_hs
static void internal_usbhs_report(void)
End-of-run summary: enumeration + bulk traffic bridged to the device.
usbhs_status_bit_t
DCP (pipe 0) status bit shared by BRDYSTS / BEMPSTS / NRDYSTS.
@ k_usbhs_dcp_bit
BRDYSTS/BEMPSTS/NRDYSTS DCP (pipe 0) bit.
static uint16_t internal_hs_reg(uint16_t off)
Read a 16-bit shadow register at window byte offset off.
static uint8_t internal_hs_curpipe(void)
Currently-selected CFIFO pipe (CFIFOSEL.CURPIPE[3:0], modulo pipe count).
static uint8_t internal_hs_pipectr_index(uint64_t off)
PIPECTR array index (PIPE1..PIPE9, modulo pipe count) for off.
static void internal_hs_brdysts_write(uint16_t value)
Apply a BRDYSTS W0C write: a written 0 clears that bit, a 1 preserves it.
static void internal_hs_or(uint16_t off, uint16_t bits)
OR bits into the 16-bit shadow register at off.
static void internal_hs_write(uc_engine *uc, uint64_t off, unsigned size, uint64_t value)
Write one USBHS host register at window byte offset off.
static void internal_hs_ccpl_status(uc_engine *uc)
Handle a DCPCTR.CCPL rising edge: drive the control-transfer status stage.
static void internal_hs_capture_setup(void)
Copy USBREQ..USBLENG from the shadow into the 8-byte SETUP buffer.
static uint8_t internal_hs_pipesel(void)
The host pipe currently selected by PIPESEL (modulo pipe count).
usbhs_geom_t
USBHS host register-window geometry and staging-buffer caps.
@ k_usbhs_report_ord
End-of-run report slot (after USB-FS).
@ k_usbhs_pkt_cap
Per-pipe staging cap (HS bulk MPS).
@ k_usbhs_base
USBHS base (HUM Ch 37, p 2059).
@ k_usbhs_setup_len
SETUP packet length.
@ k_usbhs_pipes
DCP (0) + PIPE1..PIPE9.
@ k_usbhs_din_cap
DCP IN staging cap (full config desc).
@ k_usbhs_words
16-bit register-shadow word count.
@ k_usbhs_span
Modelled window (covers DEVADD / LPSTS).
@ k_usbhs_dev_span
Device-model span; PHY page lies past it.
static uint32_t internal_hs_word(uint64_t off)
16-bit shadow word index for a window byte offset.
static void internal_hs_cfifo_write(uint32_t value, unsigned size)
Append size bytes of value (LSB-first) to the selected OUT pipe.
static void internal_hs_dvstctr0_write(uc_engine *uc, uint16_t value)
Apply a DVSTCTR0 write, bridging a host bus-reset edge onto the device.
USBFS controller model + a virtual USB host for the board emulator.
void board_usb_bridge_mark_configured(uc_engine *uc)
Mark the device configured after a host SET_CONFIGURATION.
bool board_usb_bridge_bulk_out_consumed(uint8_t dev_pipe)
Whether the device has drained the last host bulk-OUT packet.
bool board_usb_bridge_dcp_out_consumed(void)
Whether the device has drained the last host DCP control-OUT packet.
void board_usb_bridge_ctrl_status(uc_engine *uc)
Drive the read-status stage of a host control-read (raise CTRT).
bool board_usb_roles_swapped(void)
Whether the self-loop window roles are swapped (Config B).
bool board_usb_bridge_dcp_in_ready(void)
Whether the device has queued a control-IN response on the DCP.
void board_usb_bridge_deliver_setup(uc_engine *uc, const uint8_t *setup)
Deliver an 8-byte host SETUP packet to the device (raise its CTRT).
uint16_t board_usb_bridge_bulk_in_take(uc_engine *uc, uint8_t dev_pipe, uint8_t *buf, uint16_t cap)
Consume a device bulk-IN packet from dev_pipe into buf.
void board_usb_dev_reg_write(uc_engine *uc, uint64_t off, unsigned size, uint64_t value)
Device-model register write by window byte offset (role routing).
void board_usb_roles_swap(uc_engine *uc)
Swap the self-loop window<->model bindings (enter Config B).
uint64_t board_usb_dev_reg_read(uc_engine *uc, uint64_t off, unsigned size)
Device-model register read by window byte offset (role routing).
void board_usb_bridge_bus_reset(uc_engine *uc)
Bridge a host bus reset onto the device (advance DVSQ to Default).
bool board_usb_dev_attached(void)
Whether the modelled USBFS device has asserted its D+ pull-up (DPRPU).
bool board_usb_bridge_bulk_in_ready(uint8_t dev_pipe)
Whether the device has queued a bulk-IN packet on dev_pipe.
void board_usb_bridge_dcp_out(uc_engine *uc, const uint8_t *data, uint16_t len)
Deliver a host control-write data-stage packet to the device DCP.
uint16_t board_usb_bridge_dcp_in_take(uint8_t *buf, uint16_t cap)
Consume the device's queued control-IN response into buf.
void board_usb_bridge_bulk_out(uc_engine *uc, uint8_t dev_pipe, const uint8_t *data, uint16_t len)
Deliver a host bulk-OUT packet to a device endpoint pipe.
bool board_usb_bridge_dev_took_ccpl(void)
Take (consume) the device's control-transfer completion (DCPCTR.CCPL).
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).
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
USB Full-Speed + High-Speed controller layout for the Renesas RA8D2.
@ k_ra8_int1_bit_sack
SETUP transaction ACKed.
@ k_ra8_pid_buf
BUF response (transmit/receive).
@ k_ra8_pid_mask
PID[1:0] field mask.
@ k_ra8_syscfg_bit_dprpu
D+ pull-up enable (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_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_cfifo
CFIFO : Control FIFO port.
@ k_ra8_usb_off_dcpctr
DCPCTR : DCP control.
@ k_ra8_usb_off_intsts0
INTSTS0 : Interrupt Status 0.
@ 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_dcpctr_bit_sureq
Send USB request (host mode).
@ k_ra8_dcpctr_bit_ccpl
Control transfer end enable.
@ k_ra8_fifosel_curpipe
Current pipe select [3:0].
@ k_ra8_usb_pipectr_count
PIPECTR[9] = PIPE1..PIPE9.
@ k_ra8_usbhs_off_pllsta
PLLSTA : PLL lock flag.
A modelled peripheral block's self-description for the core registry.
Aggregate USBHS host-controller model state.
uint16_t reg[k_usbhs_words]
16-bit reflect-on-read register shadow.
uint32_t bulk_out
Bulk-OUT packets delivered.
uint16_t din_len
Bytes staged in din.
uint8_t din[k_usbhs_din_cap]
DCP IN staging (device -> host control data).
bool pin_ready[k_usbhs_pipes]
Pipe holds an unread packet.
uint8_t pout[k_usbhs_pipes][k_usbhs_pkt_cap]
Per-pipe OUT staging (host->dev).
bool prev_usbrst
Previous DVSTCTR0.USBRST level (reset-edge detect).
bool pout_wait[k_usbhs_pipes]
OUT pipe awaiting device drain (BEMP).
uint8_t ctrl_breq
Last SETUP bRequest.
uint16_t pin_rd[k_usbhs_pipes]
Read cursor per IN pipe.
uint8_t pin[k_usbhs_pipes][k_usbhs_pkt_cap]
Per-pipe IN staging (dev->host).
bool ctrl_read
Last SETUP was a control read.
bool ctrl_status_pending
Control-write status awaits dev CCPL.
uint16_t pipe_pid[k_usbhs_pipes]
PIPECTR PID shadow per host pipe.
uint8_t setup[k_usbhs_setup_len]
Latched 8-byte SETUP packet.
uint16_t din_rd
Read cursor as the host drains din.
bool din_ready
din holds an unread packet (DCP BRDY source).
uint16_t pin_len[k_usbhs_pipes]
Bytes staged per IN pipe.
uint32_t bulk_in
Bulk-IN packets collected.
uint8_t pipe_ep[k_usbhs_pipes]
Device endpoint number per host pipe.
uint32_t setups
SETUP packets bridged to the device.
uint16_t pout_len[k_usbhs_pipes]
Bytes accumulated per OUT pipe.
uint16_t pipe_maxp[k_usbhs_pipes]
PIPEMAXP shadow per host pipe.