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

USBHS HOST-mode controller model (self-loop peer of the USBFS device). More...

#include <stdint.h>
#include <unicorn/unicorn.h>
Include dependency graph for board_usb_host.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void board_usb_host_init (bool trace)
 Reset the USBHS host-mode model to its power-on state.
void board_usb_host_set_allowed (bool allowed)
 Grant (or deny) the register-level loop for this firmware.
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.
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.
void board_usb_host_report (void)
 Print the USBHS host-model section of the end-of-run summary.

Detailed Description

USBHS HOST-mode controller model (self-loop peer of the USBFS device).

Models the RA8D2 USB 2.0 High-Speed controller (USBHS, base 0x40351000, HUM Ch 37) in HOST role at register granularity, for firmware that is ITSELF the bus host on the self-loop bench: USBHS (J7) host cabled to USBFS (J11) device, both driven by the same chip (usb_selftest_cdc's topology, and the TrustZone NS image of tz_nsc_cgc_usb). The registers the polled first-party host engine (ra8_usb_host_* in libs/ra8_hal) drives – SYSCFG / DVSTCTR0 / DCPCTR.SUREQ / USBREQ..USBLENG / CFIFO / BRDYSTS / BEMPSTS / INTSTS1 SACK / the PIPESEL window – are serviced here, and every bus transaction is forwarded over the loop-cable transport (board_usb.h board_usb_loop_*) to the modelled USBFS device the device-side firmware is serving.

ENGAGEMENT: the model stays dormant (every access falls through to the sparse register fallback, preserving existing app behaviour byte-for-byte) until BOTH hold:

  1. main.c granted the loop (board_usb_host_set_allowed – no C-level usb-host symbol seam was installed for this firmware, so the register path is the real one), and
  2. the firmware selects host mode on the HS instance (a SYSCFG write with DCFM set – HUM Ch 37.2.1). Engagement also latches the self-loop (board_usb_loop_latch), parking the built-in virtual host for the rest of the run.

Modelling boundary: single-packet-in-flight, polled transfers only – what the synchronous ra8_usb_host_* engine issues. A multi-chunk control-OUT data stage overwrites the device's single DCP staging bank if the device firmware does not drain between chunks (no consumer in the EIL suite does this; DFU class flows stay on their C-level seams).

Since
0.1.0

Definition in file board_usb_host.h.

Function Documentation

◆ board_usb_host_init()

void board_usb_host_init ( bool trace)

Reset the USBHS host-mode model to its power-on state.

Clears the register shadows, the per-pipe configuration window, the FIFO staging and the engagement latch. Call once from board_periph_init before the run loop, next to board_usb_init.

Parameters
[in]traceWhen true, each loop-cable transaction is logged to injected error sink.
Returns
Nothing.
Postcondition
The model is dormant; every window access falls through until the firmware engages host mode (and the loop is allowed).
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB host init.
The call executes on the emulator's single owning thread.
Postcondition
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 789 of file board_usb_host.c.

References s_hs, and s_hs_trace.

Referenced by board_periph_init().

◆ board_usb_host_read()

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.

Parameters
[in,out]ucUnicorn engine (loop-cable calls pend device IRQs).
[in]addrAbsolute peripheral address being read.
[in]sizeAccess width in bytes (1 / 2 / 4).
[out]handledTrue iff the model is engaged and addr is inside the USBHS window.
Returns
The register value when *handled is true, else 0.
Since
0.1.0

Dispatch an mmio read inside the usbhs register window; this step is contained within the board USB host model and uses bounded caller or module-owned storage.

Return values
valueThe operation-specific board USB host read value.
Precondition
Arguments satisfy the ranges documented for board USB host read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB host model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 800 of file board_usb_host.c.

References internal_usbhs_reg_read(), k_usbhs_base, k_usbhs_span, and s_hs.

Referenced by board_periph_read().

◆ board_usb_host_report()

void board_usb_host_report ( void )

Print the USBHS host-model section of the end-of-run summary.

Silent unless the model engaged; then reports the SETUP / bulk transaction totals the firmware host drove over the loop.

Returns
Nothing.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB host report.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB host model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 843 of file board_usb_host.c.

References priv_emu_io_errf(), and s_hs.

Referenced by board_periph_report().

◆ board_usb_host_set_allowed()

void board_usb_host_set_allowed ( bool allowed)

Grant (or deny) the register-level loop for this firmware.

main.c calls this after its usb-host seam installer ran: when a C-level seam (virtual keyboard / virtual MSC disk) was installed for the firmware's host API, the register path is shadowed by those seams and this model must stay dormant so seamed apps keep their exact current behaviour. Only an unseamed firmware (e.g. the TrustZone NS image, whose symbols the seam installer never scans) gets the register-level loop.

Parameters
[in]allowedtrue to allow engagement on a host-mode SYSCFG write.
Returns
Nothing.
Postcondition
With allowed false the model never claims the window this run.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB host set allowed.
The call executes on the emulator's single owning thread.
Postcondition
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 795 of file board_usb_host.c.

References s_hs.

Referenced by internal_main_install_run_seams().

◆ board_usb_host_write()

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.

Pre-engagement, only the SYSCFG word is watched (for the DCFM host-role select that engages the model); the write still reports unhandled so the sparse fallback keeps recording it, preserving the behaviour of every USBHS app that never engages.

Parameters
[in,out]ucUnicorn engine (loop-cable calls pend device IRQs).
[in]addrAbsolute peripheral address being written.
[in]sizeAccess width in bytes (1 / 2 / 4).
[in]valueValue being written.
[out]handledTrue iff the model is engaged and consumed the write.
Returns
Nothing.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB host write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB host model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 811 of file board_usb_host.c.

References board_usb_loop_latch(), internal_usbhs_reg_write(), internal_usbhs_word(), k_ra8_syscfg_bit_dcfm, k_ra8_usb_off_syscfg, k_usbhs_base, k_usbhs_span, priv_emu_io_errf(), and s_hs.

Referenced by board_periph_write().