|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
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"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. | |
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.
Definition in file board_usb_bridge.c.
| bool board_usb_bridge_bulk_in_ready | ( | uint8_t | dev_pipe | ) |
Whether the device has queued a bulk-IN packet on dev_pipe.
| [in] | dev_pipe | Device pipe number to probe (1..9). |
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.
| true | The board USB bridge bulk in ready condition holds or completed successfully; false otherwise. |
Definition at line 189 of file board_usb_bridge.c.
References k_usb_pipe_count, and s_usb.
Referenced by internal_hs_brdysts_read().
| 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.
| [in,out] | uc | Unicorn engine (to pend the device USB interrupt). |
| [in] | dev_pipe | Device pipe number to drain (1..9). |
| [out] | buf | Destination buffer. |
| [in] | cap | Capacity of buf in bytes. |
| value | The operation-specific board USB bridge bulk in take value. |
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().
| 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.
| [in,out] | uc | Unicorn engine (to pend the device USB interrupt). |
| [in] | dev_pipe | Device pipe number the endpoint maps to (1..9). |
| [in] | data | Payload bytes (host -> device). |
| [in] | len | Payload length in bytes. |
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().
| 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.
| [in] | dev_pipe | Device pipe number the endpoint maps to (1..9). |
| true | The board USB bridge bulk out consumed condition holds or completed successfully; false otherwise. |
Definition at line 179 of file board_usb_bridge.c.
References k_usb_pipe_count, and s_usb.
Referenced by internal_hs_bempsts_read().
| 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.
| [in,out] | uc | Unicorn engine (to pend the device USB interrupt). |
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().
| 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.
| [in,out] | uc | Unicorn engine (to pend the device USB interrupt). |
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().
| bool board_usb_bridge_dcp_in_ready | ( | void | ) |
Whether the device has queued a control-IN response on the DCP.
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.
| true | The board USB bridge default control pipe in ready condition holds or completed successfully; false otherwise. |
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().
| uint16_t board_usb_bridge_dcp_in_take | ( | uint8_t * | buf, |
| uint16_t | cap ) |
Consume the device's queued control-IN response into buf.
| [out] | buf | Destination for the device's DCP IN bytes. |
| [in] | cap | Capacity of buf in bytes. |
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.
| value | The operation-specific board USB bridge default control pipe in take value. |
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().
| 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.
| [in,out] | uc | Unicorn engine (to pend the device USB interrupt). |
| [in] | data | Payload bytes (host -> device); ignored if NULL. |
| [in] | len | Payload length in bytes. |
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().
| 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.
| true | The board USB bridge default control pipe out consumed condition holds or completed successfully; false otherwise. |
Definition at line 233 of file board_usb_bridge.c.
References s_dcp_hold_pending, and s_usb.
Referenced by internal_hs_bempsts_read().
| 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).
| [in,out] | uc | Unicorn engine (to pend the device USB interrupt). |
| [in] | setup | Eight SETUP bytes (bmRequestType, bRequest, wValue, wIndex, wLength, little-endian) to deliver. |
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().
| 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.
| true | The board USB bridge dev took ccpl condition holds or completed successfully; false otherwise. |
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().
| void board_usb_bridge_mark_configured | ( | uc_engine * | uc | ) |
Mark the device configured after a host SET_CONFIGURATION.
| [in,out] | uc | Unicorn engine (to pend the device USB interrupt). |
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.
Definition at line 154 of file board_usb_bridge.c.
References priv_host_mark_configured().
Referenced by internal_hs_ctrl_status_complete().
| bool board_usb_dev_attached | ( | void | ) |
Whether the modelled USBFS device has asserted its D+ pull-up (DPRPU).
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.
| true | The board USB dev attached condition holds or completed successfully; false otherwise. |
Definition at line 76 of file board_usb_bridge.c.
References priv_host_device_attached().
Referenced by internal_hs_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).
| [in,out] | uc | Unicorn engine (unused; kept for handler symmetry). |
| [in] | off | Byte offset inside the controller register window (0 .. 0xFE; the device model spans 0x100 bytes). |
| [in] | size | Access width in bytes (1 or 2). |
off is inside the modelled 0x100-byte device register span. | value | The operation-specific board USB dev reg read value. |
Definition at line 64 of file board_usb_bridge.c.
References priv_usb_reg_read().
Referenced by internal_usbhs_block_read().
| 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).
| [in,out] | uc | Unicorn engine (unused; kept for handler symmetry). |
| [in] | off | Byte offset inside the controller register window (0 .. 0xFE; the device model spans 0x100 bytes). |
| [in] | size | Access width in bytes (1 or 2). |
| [in] | value | Value the firmware wrote. |
off is inside the modelled 0x100-byte device register span. Definition at line 70 of file board_usb_bridge.c.
References priv_usb_reg_write().
Referenced by internal_usbhs_block_write().
| 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.
| [in,out] | uc | Unicorn engine (unused today; kept for symmetry with the other bridge mutators, which pend device IRQs through it). |
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().
| 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).
| true | The board USB roles swapped condition holds or completed successfully; false otherwise. |
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().
| 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.
| [in] | present | true to hand the device over to the external host bridge. |
Definition at line 34 of file board_usb_bridge.c.
References s_external_host.
Referenced by internal_main_bringup_peripherals().
| 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.
| [in,out] | uc | Unicorn 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().