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

USBHS-host <-> USBFS-device bridge (see board_usb_internal.h). More...

#include <stdio.h>
#include <string.h>
#include "board_usb_internal.h"
#include "emu_host_io_internal.h"
#include "ra8_elc_regs.h"
#include "ra8_usb_regs.h"
Include dependency graph for board_usb_bridge.c:

Go to the source code of this file.

Functions

void board_usb_set_external_host (bool present)
 Declare (or withdraw) a real-firmware USB host driving the device.
bool board_usb_roles_swapped (void)
 Whether the self-loop window roles are swapped (Config B).
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_dev_reg_write (uc_engine *uc, uint64_t off, unsigned size, uint64_t value)
 Device-model register write by window byte offset (role routing).
bool board_usb_dev_attached (void)
 Whether the modelled USBFS device has asserted its D+ pull-up (DPRPU).
void board_usb_bridge_bus_reset (uc_engine *uc)
 Bridge a host bus reset onto the device (advance DVSQ to Default).
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).
bool board_usb_bridge_dcp_in_ready (void)
 Whether the device has queued a control-IN response on the 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_ctrl_status (uc_engine *uc)
 Drive the read-status stage of a host control-read (raise CTRT).
bool board_usb_bridge_dev_took_ccpl (void)
 Take (consume) the device's control-transfer completion (DCPCTR.CCPL).
void board_usb_bridge_mark_configured (uc_engine *uc)
 Mark the device configured after a host SET_CONFIGURATION.
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_bulk_out_consumed (uint8_t dev_pipe)
 Whether the device has drained the last host bulk-OUT packet.
bool board_usb_bridge_bulk_in_ready (uint8_t dev_pipe)
 Whether the device has queued a bulk-IN packet on dev_pipe.
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_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.
bool board_usb_bridge_dcp_out_consumed (void)
 Whether the device has drained the last host DCP control-OUT packet.
void priv_bridge_pump_device (uc_engine *uc)
 Re-assert a device level-triggered condition the polled host awaits.

Detailed Description

USBHS-host <-> USBFS-device bridge (see board_usb_internal.h).

The chip-internal self-loop surface: role declaration + swap, the device register accessors the emulated USBHS host controller drives, the control/bulk hand-off primitives and the level-triggered DCP-OUT pump – moved verbatim out of board_usb.c.

Since
0.1.0

Definition in file board_usb_bridge.c.

Function Documentation

◆ board_usb_bridge_bulk_in_ready()

bool board_usb_bridge_bulk_in_ready ( uint8_t dev_pipe)

Whether the device has queued a bulk-IN packet on dev_pipe.

Parameters
[in]dev_pipeDevice pipe number to probe (1..9).
Returns
true when the device has staged bytes for the host to read.
Since
0.1.0

Whether the device has queued a bulk-in packet on dev_pipe; this step is contained within the board USB model and uses bounded caller or module-owned storage.

Return values
trueThe board USB bridge bulk in ready condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for board USB bridge bulk in ready.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 189 of file board_usb_bridge.c.

References k_usb_pipe_count, and s_usb.

Referenced by internal_hs_brdysts_read().

◆ board_usb_bridge_bulk_in_take()

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.

Copies the device's queued IN bytes out and raises the pipe's BEMP interrupt so the device firmware can stage the next packet.

Parameters
[in,out]ucUnicorn engine (to pend the device USB interrupt).
[in]dev_pipeDevice pipe number to drain (1..9).
[out]bufDestination buffer.
[in]capCapacity of buf in bytes.
Returns
The number of bytes copied (0 if none were queued).
Since
0.1.0
Return values
valueThe operation-specific board USB bridge bulk in take value.
Precondition
Arguments satisfy the ranges documented for board USB bridge bulk in take.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 195 of file board_usb_bridge.c.

References internal_usb_word(), k_ra8_int0_bit_bemp, k_ra8_usb_off_bempsts, k_usb_pipe_count, memcpy(), priv_usb_intsts0_set(), priv_usb_raise_irq(), and s_usb.

Referenced by internal_hs_brdysts_read().

◆ board_usb_bridge_bulk_out()

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.

Stages len bytes into the device's OUT pipe buffer and raises the pipe's BRDY interrupt, so the device firmware's bulk-OUT receive path (e.g. the CDC-ACM read, or the MSC CBW/data receive) completes.

Parameters
[in,out]ucUnicorn engine (to pend the device USB interrupt).
[in]dev_pipeDevice pipe number the endpoint maps to (1..9).
[in]dataPayload bytes (host -> device).
[in]lenPayload length in bytes.
Returns
Nothing.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB bridge bulk out.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 159 of file board_usb_bridge.c.

References internal_usb_word(), k_ra8_int0_bit_brdy, k_ra8_usb_off_brdysts, k_usb_pipe_count, memcpy(), priv_usb_intsts0_set(), priv_usb_raise_irq(), and s_usb.

Referenced by internal_hs_bulk_out_commit().

◆ board_usb_bridge_bulk_out_consumed()

bool board_usb_bridge_bulk_out_consumed ( uint8_t dev_pipe)

Whether the device has drained the last host bulk-OUT packet.

The USBHS host model gates a bulk-OUT pipe's buffer-empty (BEMP) completion on this so a multi-packet data stage (e.g. a WRITE(10) payload) hands the device one packet at a time: the polled host does not push the next OUT packet until the device firmware has drained the current one from its CFIFO, otherwise the fresh packet would overwrite the undrained bank.

Parameters
[in]dev_pipeDevice pipe number the endpoint maps to (1..9).
Returns
true once the device has fully drained the staged OUT packet.
Since
0.1.0
Return values
trueThe board USB bridge bulk out consumed condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for board USB bridge bulk out consumed.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 179 of file board_usb_bridge.c.

References k_usb_pipe_count, and s_usb.

Referenced by internal_hs_bempsts_read().

◆ board_usb_bridge_bus_reset()

void board_usb_bridge_bus_reset ( uc_engine * uc)

Bridge a host bus reset onto the device (advance DVSQ to Default).

Mirrors the physical USB reset the host drives on DVSTCTR0.USBRST: returns the device to the Default state and raises its DVST interrupt so the device firmware re-arms its DCP, exactly as the built-in virtual host's reset phase does.

Parameters
[in,out]ucUnicorn engine (to pend the device USB interrupt).
Returns
Nothing.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB bridge bus reset.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 81 of file board_usb_bridge.c.

References k_ra8_dvsq_default, k_ra8_int0_bit_dvst, priv_usb_intsts0_set(), priv_usb_log_line(), priv_usb_raise_irq(), and s_usb.

Referenced by internal_hs_dvstctr0_write().

◆ board_usb_bridge_ctrl_status()

void board_usb_bridge_ctrl_status ( uc_engine * uc)

Drive the read-status stage of a host control-read (raise CTRT).

Advertises the read status stage (CTSQ) and raises the device CTRT so the device firmware closes its side of a completed control-read transfer.

Parameters
[in,out]ucUnicorn engine (to pend the device USB interrupt).
Returns
Nothing.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB bridge ctrl status.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 141 of file board_usb_bridge.c.

References k_ra8_ctsq_rdss, k_ra8_int0_bit_ctrt, priv_usb_intsts0_set(), priv_usb_raise_irq(), and s_usb.

Referenced by internal_hs_ccpl_status().

◆ board_usb_bridge_dcp_in_ready()

bool board_usb_bridge_dcp_in_ready ( void )

Whether the device has queued a control-IN response on the DCP.

Returns
true when the device armed its DCP (PID=BUF) with valid IN data for the host to read (e.g. a GET_DESCRIPTOR response).
Since
0.1.0

Whether the device has queued a control-in response on the dcp; this step is contained within the board USB model and uses bounded caller or module-owned storage.

Return values
trueThe board USB bridge default control pipe in ready condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for board USB bridge default control pipe in ready.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 108 of file board_usb_bridge.c.

References priv_host_dcp_pid_buf(), and s_usb.

Referenced by internal_hs_brdysts_read().

◆ board_usb_bridge_dcp_in_take()

uint16_t board_usb_bridge_dcp_in_take ( uint8_t * buf,
uint16_t cap )

Consume the device's queued control-IN response into buf.

Parameters
[out]bufDestination for the device's DCP IN bytes.
[in]capCapacity of buf in bytes.
Returns
The number of bytes copied (0 if none were queued).
Postcondition
The device DCP IN buffer is cleared and ready for the next transfer.
Since
0.1.0

Consume the device's queued control-in response into buf; this step is contained within the board USB model and uses bounded caller or module-owned storage.

Return values
valueThe operation-specific board USB bridge default control pipe in take value.
Precondition
Arguments satisfy the ranges documented for board USB bridge default control pipe in take.
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 113 of file board_usb_bridge.c.

References k_usb_log_width, k_usb_trace_dump_max, memcpy(), priv_emu_io_errf(), priv_usb_detect_class(), priv_usb_log_count(), s_trace, and s_usb.

Referenced by internal_hs_brdysts_read().

◆ board_usb_bridge_dcp_out()

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.

Stages len bytes of a control-OUT data stage (e.g. a DFU_DNLOAD firmware block) into the device's DCP (EP0) OUT buffer and raises the device DCP BRDY so the device firmware's control-OUT receive path drains it. The companion pump in board_usb_tick re-asserts BRDY until the device – which arms its DCP off its own IRQ – has actually received the packet, mirroring the SIE's OUT-token retry on real silicon.

Parameters
[in,out]ucUnicorn engine (to pend the device USB interrupt).
[in]dataPayload bytes (host -> device); ignored if NULL.
[in]lenPayload length in bytes.
Returns
Nothing.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB bridge default control pipe out.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 215 of file board_usb_bridge.c.

References memcpy(), s_dcp_hold, s_dcp_hold_len, and s_dcp_hold_pending.

Referenced by internal_hs_bulk_out_commit().

◆ board_usb_bridge_dcp_out_consumed()

bool board_usb_bridge_dcp_out_consumed ( void )

Whether the device has drained the last host DCP control-OUT packet.

The USBHS host model gates a control-write data stage's buffer-empty (BEMP) completion on this, exactly as it does for a bulk-OUT pipe, so the polled host hands the device one control-OUT packet at a time.

Returns
true once the device has fully drained the staged DCP OUT packet.
Since
0.1.0
Return values
trueThe board USB bridge default control pipe out consumed condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for board USB bridge default control pipe out consumed.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 233 of file board_usb_bridge.c.

References s_dcp_hold_pending, and s_usb.

Referenced by internal_hs_bempsts_read().

◆ board_usb_bridge_deliver_setup()

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).

Latches the packet into the device's USBREQ..USBLENG mirror registers, sets the control-transfer stage (CTSQ) from the request direction, and raises the device CTRT interrupt so the real device ISR decodes it. A SET_ADDRESS additionally applies the SIE side effect the hardware performs (USBADDR latched, DVSQ -> Address).

Parameters
[in,out]ucUnicorn engine (to pend the device USB interrupt).
[in]setupEight SETUP bytes (bmRequestType, bRequest, wValue, wIndex, wLength, little-endian) to deliver.
Returns
Nothing.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB bridge deliver setup.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 89 of file board_usb_bridge.c.

References priv_host_apply_no_data(), and priv_host_deliver_setup().

Referenced by internal_hs_setup_launch().

◆ board_usb_bridge_dev_took_ccpl()

bool board_usb_bridge_dev_took_ccpl ( void )

Take (consume) the device's control-transfer completion (DCPCTR.CCPL).

The device firmware pulses DCPCTR.CCPL once it has finished processing a no-data host-to-device control transfer (e.g. after SET_CONFIGURATION has activated its class and armed the class endpoints). The USBHS host model gates a no-data control-write status stage on this so the polled host does not race past a request the device is still applying – the same completion the built-in virtual host waits on. Returns true exactly once per device CCPL pulse, then clears it so the next transfer starts clean.

Returns
true if the device had pulsed CCPL since the last call, else false.
Postcondition
Any observed CCPL latch is cleared.
Since
0.1.0
Return values
trueThe board USB bridge dev took ccpl condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for board USB bridge dev took ccpl.
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 149 of file board_usb_bridge.c.

References priv_host_take_ccpl().

Referenced by internal_hs_brdysts_read(), and internal_hs_setup_launch().

◆ board_usb_bridge_mark_configured()

void board_usb_bridge_mark_configured ( uc_engine * uc)

Mark the device configured after a host SET_CONFIGURATION.

Parameters
[in,out]ucUnicorn engine (to pend the device USB interrupt).
Returns
Nothing.
Postcondition
The device DVSQ reaches Configured and DVST is raised.
Since
0.1.0

Mark the device configured after a host set_configuration; this step is contained within the board USB model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for board USB bridge mark configured.
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 154 of file board_usb_bridge.c.

References priv_host_mark_configured().

Referenced by internal_hs_ctrl_status_complete().

◆ board_usb_dev_attached()

bool board_usb_dev_attached ( void )

Whether the modelled USBFS device has asserted its D+ pull-up (DPRPU).

Returns
true once the device firmware called ra8_usb_device_attach (SYSCFG.DPRPU set), i.e. a device is electrically present for the host to enumerate.
Since
0.1.0

Whether the modelled usbfs device has asserted its d+ pull-up (dprpu); this step is contained within the board USB model and uses bounded caller or module-owned storage.

Return values
trueThe board USB dev attached condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for board USB dev attached.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB 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 76 of file board_usb_bridge.c.

References priv_host_device_attached().

Referenced by internal_hs_read().

◆ board_usb_dev_reg_read()

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).

Offset-addressed twin of the USBFS-window claim inside board_usb_read, exported so the USBHS window block can route its reads into the device model when the roles are swapped (Config B: the DCD drives the USBHS controller in device role).

Parameters
[in,out]ucUnicorn engine (unused; kept for handler symmetry).
[in]offByte offset inside the controller register window (0 .. 0xFE; the device model spans 0x100 bytes).
[in]sizeAccess width in bytes (1 or 2).
Returns
The register value, zero-extended to 64 bits.
Precondition
off is inside the modelled 0x100-byte device register span.
board_usb_init has run (model state is live).
Postcondition
Read side effects (CFIFO drain cursors) match the device model's.
Note
Not thread-safe; single-threaded emulation loop use.
See also
board_usb_dev_reg_write
Since
0.1.0
Return values
valueThe operation-specific board USB dev reg read value.
Postcondition
Ownership of caller-supplied storage is unchanged.

Definition at line 64 of file board_usb_bridge.c.

References priv_usb_reg_read().

Referenced by internal_usbhs_block_read().

◆ board_usb_dev_reg_write()

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).

Offset-addressed twin of the USBFS-window claim inside board_usb_write, exported so the USBHS window block can route its writes into the device model when the roles are swapped (Config B).

Parameters
[in,out]ucUnicorn engine (unused; kept for handler symmetry).
[in]offByte offset inside the controller register window (0 .. 0xFE; the device model spans 0x100 bytes).
[in]sizeAccess width in bytes (1 or 2).
[in]valueValue the firmware wrote.
Returns
Nothing.
Precondition
off is inside the modelled 0x100-byte device register span.
board_usb_init has run (model state is live).
Postcondition
Write side effects (CFIFO staging, W0C status) match the device model's.
Note
Not thread-safe; single-threaded emulation loop use.
See also
board_usb_dev_reg_read
Since
0.1.0
Postcondition
Ownership of caller-supplied storage is unchanged.

Definition at line 70 of file board_usb_bridge.c.

References priv_usb_reg_write().

Referenced by internal_usbhs_block_write().

◆ board_usb_roles_swap()

void board_usb_roles_swap ( uc_engine * uc)

Swap the self-loop window<->model bindings (enter Config B).

One-shot and sticky until board_usb_init: migrates the USBHS window's accumulated register shadow out of the host model into the device model (the device firmware's PHY + module-init writes landed there before its role became knowable), resets the host model for its fresh life behind the USBFS window, and retargets the device interrupt at the USBHS ICU event (USBHS_USB_INT_RESUME) instead of USBFS_INT. Idempotent: a second call in the same run is a no-op.

Parameters
[in,out]ucUnicorn engine (unused today; kept for symmetry with the other bridge mutators, which pend device IRQs through it).
Returns
Nothing.
Precondition
board_usb_set_external_host declared the self-loop bridge active.
No USB traffic has crossed the loop yet (both roles still initializing).
Postcondition
board_usb_roles_swapped reports true.
The device model raises the USBHS interrupt event from now on.
Note
Not thread-safe; single-threaded emulation loop use.
See also
board_usb_roles_swapped
Since
0.1.0

Definition at line 44 of file board_usb_bridge.c.

References board_usbhs_host_shadow_handoff(), g_dev_irq_event, k_ra8_elc_event_usbhs_int_resume, k_usb_reg_words, priv_usb_log_line(), s_roles_swapped, and s_usb.

Referenced by board_usb_write(), and internal_usbhs_block_write().

◆ board_usb_roles_swapped()

bool board_usb_roles_swapped ( void )

Whether the self-loop window roles are swapped (Config B).

false (default): USBFS window = device model, USBHS window = host model (Config A). true: the firmware declared the opposite polarity (FS SYSCFG.DCFM=1 or HS SYSCFG.DPRPU=1), so the USBFS window routes to the host model and the USBHS window routes to the device model (Config B).

Returns
true when the bindings are swapped for this run.
Precondition
None; safe at any time (reset to false by board_usb_init).
Postcondition
No model state is modified (read-only accessor).
Note
Not thread-safe; single-threaded emulation loop use.
See also
board_usb_roles_swap
Since
0.1.0
Return values
trueThe board USB roles swapped condition holds or completed successfully; false otherwise.
Precondition
The call executes on the emulator's single owning thread.
Postcondition
Ownership of caller-supplied storage is unchanged.

Definition at line 39 of file board_usb_bridge.c.

References s_roles_swapped.

Referenced by internal_usbhs_block_read(), internal_usbhs_block_write(), and internal_usbhs_report().

◆ board_usb_set_external_host()

void board_usb_set_external_host ( bool present)

Declare (or withdraw) a real-firmware USB host driving the device.

When present is true the built-in virtual chapter-9 host stops driving the device from board_usb_tick, because the emulated USBHS host controller (board_periph_usbhs_host.c) now enumerates and talks to the device through the bridge primitives below. Set once at startup for a self-loop app.

Parameters
[in]presenttrue to hand the device over to the external host bridge.
Returns
Nothing.
Postcondition
board_usb_tick no longer advances the built-in virtual host.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board USB set external host.
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 34 of file board_usb_bridge.c.

References s_external_host.

Referenced by internal_main_bringup_peripherals().

◆ priv_bridge_pump_device()

void priv_bridge_pump_device ( uc_engine * uc)

Re-assert a device level-triggered condition the polled host awaits.

Pump the device's level-triggered DCP-OUT receive (bridge).

In the chip-internal self-loop the polled host issues a control-write data stage (e.g. a DFU_DNLOAD block) on the DCP before the device firmware – running on the same core off its own IRQ – has armed the DCP to receive it. On real silicon the SIE keeps re-issuing the OUT token until the device ACKs; here the one-shot BRDY the delivery pended is cleared by the device's own ra8_usb_dcp_out_arm (W0C) and never re-raised, so the receive stalls. This pump, run each emulation chunk while the external host drives the device, re-raises the device DCP BRDY whenever the device has armed the DCP for OUT (PID=BUF and BRDYENB.PIPE0) and undrained OUT data is still staged – exactly the SIE's OUT-retry, so the device reads the block on its next BRDY ISR.

Parameters
[in,out]ucUnicorn engine (to pend the device USB interrupt).

Definition at line 258 of file board_usb_bridge.c.

References internal_usb_word(), k_ra8_int0_bit_brdy, k_ra8_pid_buf, k_ra8_pid_mask, k_ra8_usb_off_brdyenb, k_ra8_usb_off_brdysts, k_ra8_usb_off_dcpctr, k_usb_dcp_pipe_bit, memcpy(), priv_usb_intsts0_set(), priv_usb_raise_irq(), s_dcp_hold, s_dcp_hold_len, s_dcp_hold_pending, and s_usb.

Referenced by board_usb_tick().