36#include "ux_device_stack.h"
38#include "ux_utility.h"
210typedef enum : uint8_t {
230typedef enum : uint16_t {
254typedef enum : uintptr_t {
306typedef enum : uint16_t {
321typedef enum : uint8_t {
390 UX_SLAVE_TRANSFER* tr)
432 if (setup ==
nullptr) {
449 if (_ux_system_slave == UX_NULL) {
453 UX_SLAVE_DEVICE* device = &_ux_system_slave->ux_system_slave_device;
454 UX_SLAVE_TRANSFER* tr =
455 &device->ux_slave_device_control_endpoint.ux_slave_endpoint_transfer_request;
463 tr->ux_slave_transfer_request_actual_length = 0UL;
464 tr->ux_slave_transfer_request_current_data_pointer = tr->ux_slave_transfer_request_data_pointer;
469 tr->ux_slave_transfer_request_completion_code = UX_SUCCESS;
479 const unsigned int rc = _ux_device_stack_control_request_process(tr);
480 if (rc != UX_SUCCESS) {
513 uint64_t fingerprint)
530 if (_ux_system_slave != UX_NULL) {
531 UX_SLAVE_DEVICE*
const dev = &_ux_system_slave->ux_system_slave_device;
532 switch (dev->ux_slave_device_state) {
533 case (
ULONG)UX_DEVICE_ATTACHED:
534 case (
ULONG)UX_DEVICE_ADDRESSED:
535 case (
ULONG)UX_DEVICE_CONFIGURED:
538 dev->ux_slave_device_state = (
ULONG)UX_DEVICE_ATTACHED;
543 ? _ux_system_slave->ux_system_slave_device.ux_slave_device_state
582 if (reg ==
nullptr) {
585 const uint16_t usbreq_live = reg->
USBREQ;
586 const uint16_t usbval_live = reg->
USBVAL;
587 const uint16_t usbindx_live = reg->
USBINDX;
588 const uint16_t usbleng_live = reg->
USBLENG;
589 const uint64_t fingerprint = ((uint64_t)usbreq_live) | ((uint64_t)usbval_live << 16) |
590 ((uint64_t)usbindx_live << 32) |
608 bool is_set_address =
false;
611 if (usbleng_live == 0U) {
612 is_set_address =
true;
616 if (is_set_address) {
718 if (reg ==
nullptr) {
737 tr->ux_slave_transfer_request_data_pointer,
742 tr->ux_slave_transfer_request_actual_length = rx;
745 (void)_ux_device_stack_control_request_process(tr);
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
Event Link Controller (ELC) register layout for the Renesas RA8D2.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
NVIC + ICU IELSR allocator.
Lightweight Logging Interface for ra8-firmware.
ra8_err_t ra8_usb_dcp_out_arm(ra8_usb_speed_t speed)
Arm the DCP (EP0) to receive a host-to-device control data stage.
ra8_err_t ra8_usb_control_response(ra8_usb_speed_t speed, bool accept)
Issue a control-transfer status response on EP0.
ra8_err_t ra8_usb_read_setup_unconditional(ra8_usb_speed_t speed, ra8_usb_setup_t *out_setup)
Snapshot the current SETUP packet from the controller without gating on INTSTS0.VALID (HS / SQMON pol...
ra8_usb_speed_t
Selects which controller instance the call targets.
@ k_ra8_usb_speed_hs
High-Speed controller (USBHS @ 0x40351000).
ra8_err_t ra8_usb_dcp_out_read(ra8_usb_speed_t speed, uint8_t *buf, uint16_t cap, uint16_t *out_rx)
Drain an armed control-OUT data stage from the DCP (EP0).
USB Full-Speed + High-Speed controller layout for the Renesas RA8D2.
@ k_ra8_ctsq_sqer
Sequence error.
@ k_ra8_ctsq_rdss
Control read status stage.
@ k_ra8_ctsq_wrss
Control write status stage.
@ k_ra8_ctsq_wrnd
Control write nodata status.
static volatile r_usb_regs_t * ra8_usb_hs(void)
Get pointer to the USB HS controller register block.
@ k_ra8_intsts0_mask_valid
SETUP packet detect flag.
@ k_ra8_intsts0_mask_ctsq
Control transfer stage.
static volatile r_usb_regs_t * ra8_usb_fs(void)
Compile-time offset and size insurance for r_usb_regs_t.
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
USB FS / HS register window (device-mode subset).
volatile uint16_t USBINDX
+0x058 USB Request wIndex.
volatile uint16_t USBVAL
+0x056 USB Request wValue.
volatile uint16_t INTSTS0
+0x040 Interrupt Status 0.
volatile uint16_t USBLENG
+0x05A USB Request wLength.
volatile uint16_t BRDYSTS
+0x046 BRDY Interrupt Status.
volatile uint16_t USBREQ
+0x054 USB Request type/bRequest.
Decoded 8-byte USB SETUP packet.
uint16_t w_length
wLength.
uint8_t b_request
bRequest code.
uint8_t bm_request_type
Request direction / type / recipient.
USBX device-controller-driver (DCD) bridge to ra8_usb.
USBX device-controller-driver bridge to ra8_usb – per-module cross-translation-unit contract.
volatile uint64_t g_last_dispatched_setup_fp
64-bit fingerprint of the last dispatched SETUP packet.
volatile uint32_t g_setup_packet_count
Total SETUP packets latched into g_setup_packet_buffer.
@ k_ra8_usb_skip_process_ok
control_request_process returned OK.
volatile uint8_t g_setup_packet_buffer[8]
Wire-format bytes of the most recent SETUP packet.
ra8_usb_dcd_t g_dcd
The single bridge instance, defined in ux_dcd_ra8_usb.c.
@ k_setup_byte_shift
Bits per byte for the hi-byte extraction.
@ k_setup_byte_mask
Low-byte mask after the shift.
@ k_dcd_trace_kind_ccpl
EP0 H2D status stage driven.
@ k_dcd_trace_kind_shift
Kind field bit offset.
@ k_dcd_trace_entries
Ring slots (power of two).
@ k_dcd_trace_code_shift
Code field bit offset.
@ k_dcd_trace_kind_setup
EP0 SETUP received.
@ k_ra8_usb_state_unknown
Device-state snapshot sentinel.
volatile uint32_t g_dispatch_skip_reason
Last-iteration bitmask of why a SETUP dispatch was skipped or completed.
@ k_setup_idx_brq
bRequest (offset 1).
@ k_setup_idx_val_lo
wValue low byte (offset 2).
@ k_setup_idx_idx_hi
wIndex high byte (offset 5).
@ k_setup_idx_val_hi
wValue high byte (offset 3).
@ k_setup_idx_bmrt
bmRequestType (offset 0).
@ k_setup_idx_len_hi
wLength high byte (offset 7).
@ k_setup_idx_len_lo
wLength low byte (offset 6).
@ k_setup_idx_idx_lo
wIndex low byte (offset 4).
volatile uint32_t g_setup_dispatch_count
Count of SETUP packets fed into the chapter-9 dispatcher.
static void internal_pack_setup_le(volatile uint8_t *buf, const ra8_usb_setup_t *setup)
Pack a decoded SETUP into the 8-byte USB-wire little-endian layout.
ra8_dcd_dwt_t
Armv8-M Data Watchpoint and Trace unit register addresses.
@ k_dcd_dwt_cyccnt_addr
DWT_CYCCNT free-running cycle counter.
void priv_trace_event(uint8_t kind, uint8_t code, uint16_t length)
Append one packed event to the JLink-readable trace ring.
volatile uint64_t g_dispatched_fp_ring[4]
Ring of the last 4 dispatched SETUP fingerprints (oldest at index 0).
volatile uint16_t g_ctrl_out_wlen
wLength (cap) of the pending control-write data stage, in bytes.
static volatile uint32_t *const s_dcd_dwt_cyccnt
DWT cycle counter address (Armv8-M DWT_CYCCNT).
volatile uint8_t g_state_at_dispatch
Snapshot of ux_slave_device_state at the moment of the most recent SETUP dispatch.
static volatile uint32_t s_trace_ts[k_dcd_trace_entries]
DWT cycle-count timestamp per s_trace slot.
ra8_usb_setup_local_t
Local USB SETUP-packet bit-field constants.
@ k_ra8_usb_setup_dir_mask
RA8 USB setup dir mask.
@ k_ra8_usb_breq_set_address
RA8 USB breq set address.
static volatile uint32_t s_trace[k_dcd_trace_entries]
JLink-readable ring of packed transfer/SETUP events.
volatile uint32_t g_ctrl_out_done
Count of completed deferred control-OUT data stages.
static bool internal_try_defer_ctrl_out(const ra8_usb_setup_t *setup, UX_SLAVE_TRANSFER *tr)
Arm + defer a control-WRITE data stage; report whether it was deferred.
void priv_handle_ctrt(ra8_usb_speed_t speed, uint16_t intsts0)
Handle the CTRT (control-transfer-stage) interrupt branch.
ra8_usb_dcp_brdy_t
BRDYSTS / BRDYENB bit for the Default Control Pipe (pipe 0).
@ k_ra8_usb_dcp_brdy_bit
DCP (pipe 0) BRDYSTS / BRDYENB bit.
ra8_usb_setup_fp_shift_t
Bit offset of each 16-bit SETUP mirror inside the 64-bit SETUP fingerprint word.
@ k_ra8_usb_fp_shift_usbleng
USBLENG packs into fingerprint bits 48-63.
volatile uint8_t g_dispatched_fp_ring_idx
volatile uint32_t g_ctrl_out_rx
Byte count drained by the most recent deferred control-OUT receive.
UX_SLAVE_TRANSFER * g_ctrl_out_tr
EP0 transfer request whose data buffer the deferred OUT data fills.
static void internal_ctrt_dispatch_fresh_setup(ra8_usb_speed_t speed, uint64_t fingerprint)
Drain a fresh SETUP and forward to the chapter-9 dispatcher.
static void internal_ctrt_handle_valid(ra8_usb_speed_t speed)
VALID-observed branch of priv_handle_ctrt.
volatile bool g_ctrl_out_pending
A control-write data stage is armed and awaiting the host's OUT data.
ra8_usb_setup_usbreq_t
Byte masks and request encodings applied to the USBREQ mirror.
@ k_ra8_usb_usbreq_bmrt_mask
bmRequestType (low) byte of USBREQ.
@ k_ra8_usb_usbreq_breq_mask
bRequest (high) byte of USBREQ.
@ k_ra8_usb_usbreq_set_addr
USBREQ high byte == SET_ADDRESS (5).
static volatile uint32_t s_trace_seq
Monotonic count of events written to s_trace.
unsigned int priv_dispatch_setup(const ra8_usb_setup_t *setup)
Push a decoded SETUP packet into the USBX chapter-9 dispatcher.
void priv_handle_ctrl_out_data(ra8_usb_speed_t speed)
Drain a deferred control-OUT data stage and run chapter-9.