41typedef enum : uint16_t {
57 s_usb.pipe_in[pipe].len = 0U;
58 s_usb.pipe_in[pipe].valid =
false;
59 s_usb.pipe_out[pipe].len = 0U;
60 s_usb.pipe_out[pipe].rd = 0U;
61 s_usb.pipe_out[pipe].ready =
false;
75 s_usb.dcp_in.len = 0U;
76 s_usb.dcp_in.valid =
false;
77 s_usb.dcp_out.len = 0U;
78 s_usb.dcp_out.rd = 0U;
79 s_usb.dcp_out.ready =
false;
89 priv_usb_log_line(
"self-loop latched: firmware host owns the bus (virtual host parked)");
103 s_usb.setup_valid =
false;
129 "loop: SETUP bm=0x%02X bReq=0x%02X wVal=0x%04X wLen=%u",
149 s_usb.setup_valid =
true;
152 }
else if (leng != 0U) {
176 if (!
s_usb.dcp_in.valid) {
185 const uint16_t n = (avail < cap) ? avail : cap;
186 for (uint16_t i = 0U; i < n; i++) {
192 s_usb.dcp_in.len = 0U;
193 s_usb.dcp_in.valid =
false;
201 s_usb.dcp_in.len = 0U;
202 s_usb.dcp_in.valid =
false;
209 if (n > (uint16_t)
sizeof(
s_usb.dcp_out.data)) {
210 n = (uint16_t)
sizeof(
s_usb.dcp_out.data);
213 s_usb.dcp_out.len = n;
214 s_usb.dcp_out.rd = 0U;
215 s_usb.dcp_out.ready =
true;
225 s_usb.setup_valid =
false;
234 if (n > (uint16_t)
sizeof(b->data)) {
235 n = (uint16_t)
sizeof(b->data);
237 (void)
memcpy(b->data, data, n);
262 const uint16_t n = (avail < cap) ? avail : cap;
263 for (uint16_t i = 0U; i < n; i++) {
275 s_usb.reg[w] = (uint16_t)(
s_usb.reg[w] | (uint16_t)(1U << pipe));
285 s_usb.pipe_in[pipe].len = 0U;
286 s_usb.pipe_in[pipe].valid =
false;
Module-private state + interfaces shared by the board_usb TUs.
@ k_usb_dir_host_to_device
OUT: host -> device (control write).
@ k_usb_dir_device_to_host
IN: device -> host (control read).
void priv_usb_raise_irq(uc_engine *uc)
Pend the device's ICU interrupt via the registered raiser (dev).
uint32_t s_loop_bulk_in_pkts
Bulk-IN packets (loop).
uint32_t s_loop_setups
SETUPs from the fw host (loop).
usb_state_t s_usb
Controller + FIFO state (core).
uint32_t s_loop_bulk_out_pkts
Bulk-OUT packets (loop).
void priv_host_mark_configured(uc_engine *uc)
Advance the device state to CONFIGURED (vhost).
@ k_usb_req_set_config
SET_CONFIGURATION.
@ k_usb_req_set_address
SET_ADDRESS.
void priv_usb_intsts0_set(uint8_t bit)
Set one INTSTS0 event bit in the register shadow (dev).
bool priv_host_take_ccpl(void)
Consume the device's CCPL (control transfer complete) (vhost).
@ k_usb_pipe_count
DCP (0) + PIPE1..PIPE9.
bool priv_host_device_attached(void)
True when SYSCFG.DPRPU is set: the device attached its pull-up (vhost).
void priv_usb_log_line(const char *msg)
Append one already-formatted line to the enumeration-step log (core).
@ k_usb_log_width
Bytes per enumeration-step log line.
@ k_usb_byte_bits
Bits per byte.
static uint32_t internal_usb_word(uint64_t off)
Word index into the 16-bit register shadow for a window offset.
void priv_usb_detect_class(const uint8_t *d, uint16_t len)
Detect the device class from the enumerated config descriptor (vhost).
bool s_loop_latched
Firmware host owns the bus (loop).
void board_usb_loop_bulk_in_flush(uint8_t ep)
Drop whatever remains of a device pipe's bulk-IN staging.
static void internal_loop_reset_dcp(void)
Reset the DCP staging (both directions) plus the host read cursor.
static uint16_t s_loop_pipe_rd[k_usb_pipe_count]
Host cursors into pipe_in.
static bool s_loop_pending_cfg
SET_CONFIGURATION in flight.
bool board_usb_loop_take_ccpl(uc_engine *uc)
Poll the device's control-transfer completion (DCPCTR.CCPL).
static uint16_t s_loop_dcp_rd
Host cursor into dcp_in.
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.
bool board_usb_loop_attached(void)
Whether the modelled USBFS device presents its D+ pull-up.
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.
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_loop_latch(void)
Latch the self-loop: the firmware brought a controller up as HOST.
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.
static void internal_loop_reset_pipe(uint8_t pipe)
Reset one pipe's IN/OUT staging plus the host-side read cursor.
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_loop_bus_reset(uc_engine *uc)
Deliver a bus reset to the modelled USBFS device (host released RST).
void board_usb_loop_ctrl_in_flush(void)
Drop whatever remains of the device's control-IN staging.
loop_req_mask_t
SETUP-word decode helpers + the DCP status bit for the loop path.
@ k_loop_req_bm_mask
bmRequestType byte of USBREQ.
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.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Event Link Controller (ELC) register layout for the Renesas RA8D2.
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_usb_off_usbleng
USBLENG : USB request wLength.
@ k_ra8_usb_off_usbindx
USBINDX : USB request wIndex.
@ k_ra8_usb_off_usbaddr
USBADDR : USB address.
@ k_ra8_usb_off_usbval
USBVAL : USB request wValue.
@ k_ra8_usb_off_bempsts
BEMPSTS : BEMP Status.
@ k_ra8_usb_off_usbreq
USBREQ : USB request type.
@ k_ra8_usb_off_brdysts
BRDYSTS : BRDY Status.
@ k_ra8_usbaddr_addr_mask
7-bit USB address [6:0].
@ k_ra8_ctsq_rdss
Control read status stage.
@ k_ra8_ctsq_rdds
Control read data stage.
@ k_ra8_ctsq_idle
Idle / setup stage end.
@ k_ra8_ctsq_wrds
Control write data stage.
@ k_ra8_ctsq_wrnd
Control write nodata status.
@ k_ra8_int0_bit_bemp
Buffer-empty interrupt.
@ k_ra8_int0_bit_dvst
Device-state transition.
@ k_ra8_int0_bit_brdy
Buffer-ready interrupt.
@ k_ra8_int0_bit_ctrt
Control-transfer-stage transition.
@ k_ra8_dvsq_address
Address assigned.
@ k_ra8_dvsq_default
Default (post bus reset).
One pipe's device-visible IN staging buffer (device -> host payload).
One pipe's host-visible OUT staging buffer (host -> device payload).
@ k_ra8_usb_dcp_brdy_bit
DCP (pipe 0) BRDYSTS / BRDYENB bit.