38static const char*
s_tag =
"USBHMSC";
49typedef enum : uint32_t {
70typedef enum : uint8_t {
208 if (*dev_addr != 0U) {
338 off = (uint16_t)(off + dlen);
422 .w_value = cfg_value,
436 uint16_t lun_rx = 0U;
510 if (out_device !=
nullptr) {
542 uint8_t cfg_value = 0U;
574 uint8_t dev_addr = 0U;
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Cross-translation-unit private helpers shared inside ra8_hal.
ra8_usb_hmsc_state_t g_usb_hmsc_state
Singleton host-MSC shadow state, shared across the ra8_usb_hmsc split.
SysTick-based tick counter, delay and timestamp helpers.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
uint32_t ra8_time_ms(void)
Get the current 1 kHz tick count.
Native USB controller driver public API (device + host modes).
Native USB host-side MSC (Mass Storage Class) class layer.
@ k_ra8_hmsc_protocol_bbb
Bulk-Only Transport.
@ k_ra8_hmsc_class_msc
MSC interface class.
@ k_ra8_hmsc_subclass_scsi
Transparent SCSI subclass.
@ k_ra8_hmsc_pipe_bulk_in
PIPE3 -> attached EP bulk IN.
@ k_ra8_hmsc_pipe_bulk_out
PIPE4 -> attached EP bulk OUT.
@ k_ra8_hmsc_req_get_max_lun
1-byte response.
static ra8_err_t internal_enum_read_dev_desc(uint8_t *desc)
Read the 18-byte device descriptor over the polled control engine.
static ra8_err_t internal_enum_read_config(uint8_t *out_cfg_value)
Read + parse the configuration descriptor set.
ra8_usb_hmsc_enum_tune_t
Timing / retry tunables for the polled enumeration ladder.
@ k_ra8_hmsc_vbus_settle_ms
Supply settle before probing.
@ k_ra8_hmsc_addr_settle_ms
Post-SET_ADDRESS recovery.
@ k_ra8_hmsc_cfg_buf_len
Full-configuration read buffer.
@ k_ra8_hmsc_attach_spin_limit
P10 iteration bound on the attach wait: the loop is primarily ms-bounded via ra8_time_ms,...
@ k_ra8_hmsc_reset_hold_ms
USB bus-reset hold (>=10 ms).
@ k_ra8_hmsc_no_reset_tries
Attempts before using bus reset.
@ k_ra8_hmsc_recovery_ms
Post-reset recovery (TRSTRCY).
@ k_ra8_hmsc_enum_tries
(reset?
@ k_ra8_hmsc_attach_to_ms
Wait for the D+ pull-up.
@ k_ra8_hmsc_debounce_ms
Post-attach debounce (>=100 ms).
@ k_ra8_hmsc_addr_alt_mask
Alternate addr 0..3 per attempt.
static ra8_err_t internal_enum_walk_cfg(const uint8_t *cfg, uint16_t len)
Walk a configuration blob for the MSC interface + bulk endpoints.
ra8_usb_hmsc_walk_off_t
Descriptor-walk byte offsets and identity codes.
@ k_ra8_hmsc_byte_bits
Bit width of one byte.
@ k_ra8_hmsc_off_dlen
Any descriptor: bLength.
@ k_ra8_hmsc_off_dtype
Any descriptor: bDescriptorType.
@ k_ra8_hmsc_off_ep_attr
Endpoint: bmAttributes.
@ k_ra8_hmsc_off_iface_sub
Interface: bInterfaceSubClass.
@ k_ra8_hmsc_off_iface_proto
Interface: bInterfaceProtocol.
@ k_ra8_hmsc_off_ep_mps
Endpoint: wMaxPacketSize LSB.
@ k_ra8_hmsc_off_dev_vid
Device: idVendor LSB.
@ k_ra8_hmsc_off_cfg_value
Configuration: bConfigValue.
@ k_ra8_hmsc_ep_attr_bulk
bmAttributes: bulk transfer.
@ k_ra8_hmsc_off_iface_num
Interface: bInterfaceNumber.
@ k_ra8_hmsc_off_cfg_total
Configuration: wTotalLength LSB.
@ k_ra8_hmsc_ep_num_mask
bEndpointAddress number field.
@ k_ra8_hmsc_off_ep_addr
Endpoint: bEndpointAddress.
@ k_ra8_hmsc_off_dev_pid
Device: idProduct LSB.
@ k_ra8_hmsc_ep_dir_in_bit
bEndpointAddress direction bit.
@ k_ra8_hmsc_off_iface_class
Interface: bInterfaceClass.
@ k_ra8_hmsc_ep_attr_mask
bmAttributes transfer-type mask.
static void internal_enum_fill_ids(const uint8_t *desc)
Unpack VID/PID from a device descriptor into the snapshot.
static ra8_err_t internal_enum_assign_addr(uint8_t *dev_addr)
Move the device to address 1 when it answered at the default.
ra8_err_t ra8_usb_hmsc_enumerate(ra8_usb_hmsc_device_t *out_device)
Implementation of ra8_usb_hmsc_enumerate().
static bool internal_enum_iface_is_msc(const uint8_t *d)
Test whether an interface descriptor is MSC SCSI Bulk-Only.
static ra8_err_t internal_enum_hunt(uint8_t *desc, uint8_t *out_addr)
Wait for a device to attach, then hunt for its address.
static ra8_err_t internal_enum_ladder(uint8_t *out_addr)
Run the enumeration ladder: hunt, address, configure, pipes.
static ra8_err_t internal_enum_configure(uint8_t dev_addr, uint8_t cfg_value)
SET_CONFIGURATION, best-effort GET_MAX_LUN, and pipe setup.
static void internal_enum_publish(uint8_t dev_addr, ra8_usb_hmsc_device_t *out_device)
Publish a completed enumeration: snapshot, callback, out-copy.
static void internal_enum_note_endpoint(const uint8_t *d)
Record one bulk endpoint descriptor into the device snapshot.
Cross-TU surface shared between the host-MSC class layer(ra8_usb_hmsc.c) and the polled enumeration l...
@ k_ra8_hmsc_assigned_address
First assigned device addr.
@ k_ra8_hmsc_get_max_lun_len
Get-Max-LUN response len.
@ k_ra8_hmsc_dev_desc_len
USB DEVICE descriptor.
@ k_ra8_hmsc_cfg_desc_len
CONFIGURATION descriptor hdr.
@ k_ra8_hmsc_desc_interface
INTERFACE descriptor.
@ k_ra8_hmsc_bm_std_dev_out
Std | Device | Out.
@ k_ra8_hmsc_breq_get_descriptor
GET_DESCRIPTOR.
@ k_ra8_hmsc_breq_set_config
SET_CONFIGURATION.
@ k_ra8_hmsc_desc_endpoint
ENDPOINT descriptor.
@ k_ra8_hmsc_desc_configuration
CONFIGURATION descriptor.
@ k_ra8_hmsc_desc_device
DEVICE descriptor.
@ k_ra8_hmsc_bm_std_dev_in
Std | Device | In.
@ k_ra8_hmsc_bm_class_iface_in
Class | Interface | In.
@ k_ra8_hmsc_breq_set_address
SET_ADDRESS.
ra8_err_t ra8_usb_host_bus_reset(ra8_usb_speed_t speed, bool assert_reset)
Drive (or release) the bus reset line.
uint16_t ra8_usb_host_line_state(ra8_usb_speed_t speed)
Read the host port's D+/D- line state (SYSSTS0.LNST).
ra8_err_t ra8_usb_host_pipe_setup(ra8_usb_speed_t speed, uint8_t pipe_num, uint8_t dev_addr, uint8_t ep_num, bool device_to_host, uint16_t max_packet)
Configure a controller pipe against an attached device's bulk endpoint.
ra8_err_t ra8_usb_host_control_xfer(ra8_usb_speed_t speed, const ra8_usb_setup_t *setup, uint8_t *data, uint16_t data_len, uint16_t *out_received)
Run a complete host control transfer (SETUP, optional DATA, STATUS).
ra8_err_t ra8_usb_host_set_uact(ra8_usb_speed_t speed, bool enable)
Enable / disable SOF (Start-of-Frame) generation on the bus.
ra8_err_t ra8_usb_host_set_target(ra8_usb_speed_t speed, uint8_t dev_addr)
Retarget the host's default control pipe at a device address.
Snapshot of the attached MSC device, passed to the attach callback.
Decoded 8-byte USB SETUP packet.
uint16_t w_length
wLength.