ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_usb.h
Go to the documentation of this file.
1
46
47#pragma once
48
49#include <stdint.h>
50#include <unicorn/unicorn.h>
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
68typedef void (*board_usb_irq_raiser_t)(uc_engine* uc, uint16_t event);
69
87void board_usb_init(bool trace);
88
103
119uint64_t board_usb_read(uc_engine* uc, uint64_t addr, unsigned size, bool* handled);
120
136void board_usb_write(uc_engine* uc, uint64_t addr, unsigned size, uint64_t value, bool* handled);
137
157void board_usb_tick(uc_engine* uc);
158
171bool board_usb_configured(void);
172
189const char* board_usb_state_string(void);
190
208void board_usb_feed_bulk_in(const uint8_t* data, uint32_t len);
209
221uint32_t board_usb_echo_received(void);
222
237void board_usb_report(void);
238
239/* =============================================================================
240 * Chip-internal USBHS-host <-> USBFS-device bridge.
241 *
242 * These entry points let the modelled on-chip USBHS host controller
243 * (board_periph_usbhs_host.c, register window 0x40351000) drive THIS USBFS
244 * device model directly, closing the RA8D2's chip-internal self-loop (the two
245 * jacks cabled to each other on the bench). When an external real-firmware host
246 * is present the built-in virtual chapter-9 host stands down (::board_usb_tick
247 * returns early) so exactly one host drives the device: the real firmware, via
248 * these primitives, exactly as the physical port-to-port cable does.
249 * =============================================================================
250 */
251
268void board_usb_set_external_host(bool present);
269
282bool board_usb_dev_attached(void);
283
299void board_usb_bridge_bus_reset(uc_engine* uc);
300
319void board_usb_bridge_deliver_setup(uc_engine* uc, const uint8_t* setup);
320
334
349uint16_t board_usb_bridge_dcp_in_take(uint8_t* buf, uint16_t cap);
350
364void board_usb_bridge_ctrl_status(uc_engine* uc);
365
386
399void board_usb_bridge_mark_configured(uc_engine* uc);
400
418void board_usb_bridge_bulk_out(uc_engine* uc, uint8_t dev_pipe, const uint8_t* data, uint16_t len);
419
439void board_usb_bridge_dcp_out(uc_engine* uc, const uint8_t* data, uint16_t len);
440
456
474bool board_usb_bridge_bulk_out_consumed(uint8_t dev_pipe);
475
488bool board_usb_bridge_bulk_in_ready(uint8_t dev_pipe);
489
507uint16_t board_usb_bridge_bulk_in_take(uc_engine* uc, uint8_t dev_pipe, uint8_t* buf, uint16_t cap);
508
509/* =============================================================================
510 * Self-loop role routing (Config A vs Config B).
511 *
512 * The two on-chip controllers can run the self-loop in either polarity: HS
513 * host + FS device ("Config A", the default) or FS host + HS device ("Config
514 * B", dfu_selftest_fs_host). On silicon each controller's role is selected by
515 * the firmware itself through SYSCFG: DCFM=1 declares controller (host) mode
516 * (HUM Ch 36.2.1 / 37.2.1), DPRPU=1 declares the device-role D+ pull-up. The
517 * models mirror that: a DCFM=1 write to the USBFS window, or a DPRPU=1 write
518 * to the USBHS window, swaps the window<->model binding so the single host
519 * model serves the window the firmware drives as host and the single device
520 * model serves the other -- no per-app configuration, the register writes
521 * decide, exactly as the silicon does.
522 * =============================================================================
523 */
524
543bool board_usb_roles_swapped(void);
544
567void board_usb_roles_swap(uc_engine* uc);
568
591uint64_t board_usb_dev_reg_read(uc_engine* uc, uint64_t off, unsigned size);
592
614void board_usb_dev_reg_write(uc_engine* uc, uint64_t off, unsigned size, uint64_t value);
615
637uint64_t board_usbhs_host_reg_read(uc_engine* uc, uint64_t off, unsigned size);
638
659void board_usbhs_host_reg_write(uc_engine* uc, uint64_t off, unsigned size, uint64_t value);
660
682uint32_t board_usbhs_host_shadow_handoff(uint16_t* dst_words, uint32_t word_capacity);
683
684/* =============================================================================
685 * Loop-cable transport -- consumed by the USBHS HOST-mode model
686 * (board_usb_host.c) when the firmware itself is the host on the self-loop
687 * bench (USBHS J7 host cabled to USBFS J11 device). Each call is one bus
688 * operation the firmware host performs against the modelled USBFS device.
689 * =============================================================================
690 */
691
710void board_usb_loop_latch(void);
711
723bool board_usb_loop_attached(void);
724
741void board_usb_loop_bus_reset(uc_engine* uc);
742
766bool board_usb_loop_setup(uc_engine* uc, uint16_t req, uint16_t val, uint16_t indx, uint16_t leng);
767
785bool board_usb_loop_take_ccpl(uc_engine* uc);
786
799uint16_t board_usb_loop_ctrl_in_avail(void);
800
816uint16_t board_usb_loop_ctrl_in_read(uint8_t* dst, uint16_t cap);
817
831
848void board_usb_loop_ctrl_out(uc_engine* uc, const uint8_t* data, uint16_t len);
849
864void board_usb_loop_status_out_zlp(uc_engine* uc);
865
885void board_usb_loop_bulk_out(uc_engine* uc, uint8_t ep, const uint8_t* data, uint16_t len);
886
899uint16_t board_usb_loop_bulk_in_avail(uint8_t ep);
900
919uint16_t board_usb_loop_bulk_in_read(uc_engine* uc, uint8_t ep, uint8_t* dst, uint16_t cap);
920
932void board_usb_loop_bulk_in_flush(uint8_t ep);
933
934#ifdef __cplusplus
935}
936#endif
void board_usb_bridge_mark_configured(uc_engine *uc)
Mark the device configured after a host SET_CONFIGURATION.
void board_usb_loop_bulk_in_flush(uint8_t ep)
Drop whatever remains of a device pipe's bulk-IN staging.
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).
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).
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_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value, bool *handled)
Dispatch an MMIO write inside the USBFS register window.
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.
void(* board_usb_irq_raiser_t)(uc_engine *uc, uint16_t event)
Signature of the ICU event-raise hook board_periph installs.
Definition board_usb.h:68
void board_usb_feed_bulk_in(const uint8_t *data, uint32_t len)
Queue host->device bulk bytes for the CDC data OUT pipe (echo test).
Definition board_usb.c:196
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_loop_take_ccpl(uc_engine *uc)
Poll the device's control-transfer completion (DCPCTR.CCPL).
void board_usb_report(void)
Print the USB section of the end-of-run summary.
Definition board_usb.c:250
bool board_usb_bridge_dcp_in_ready(void)
Whether the device has queued a control-IN response on the DCP.
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.
uint32_t board_usb_echo_received(void)
Number of bulk bytes the host has read back as the device's echo.
Definition board_usb.c:206
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_loop_attached(void)
Whether the modelled USBFS device presents its D+ pull-up.
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_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.
void board_usb_tick(uc_engine *uc)
Advance the virtual USB host one emulation chunk.
Definition board_usb.c:116
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_init(bool trace)
Reset the USBFS controller model and the virtual host state machine.
Definition board_usb.c:165
const char * board_usb_state_string(void)
One-line, human-readable USB device state for the board view.
Definition board_usb.c:228
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_loop_latch(void)
Latch the self-loop: the firmware brought a controller up as HOST.
bool board_usb_configured(void)
Report whether enumeration reached the CONFIGURED state.
Definition board_usb.c:191
void board_usb_roles_swap(uc_engine *uc)
Swap the self-loop window<->model bindings (enter Config B).
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_set_external_host(bool present)
Declare (or withdraw) a real-firmware USB host driving the device.
void board_usb_loop_bus_reset(uc_engine *uc)
Deliver a bus reset to the modelled USBFS device (host released RST).
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_loop_ctrl_in_flush(void)
Drop whatever remains of the device's control-IN staging.
void board_usb_bridge_bus_reset(uc_engine *uc)
Bridge a host bus reset onto the device (advance DVSQ to Default).
void board_usb_set_irq_raiser(board_usb_irq_raiser_t raise)
Install the ICU event-raise hook used to pend the USBFS interrupt.
Definition board_usb.c:186
uint64_t board_usb_read(uc_engine *uc, uint64_t addr, unsigned size, bool *handled)
Dispatch an MMIO read inside the USBFS register window.
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.
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).