50static const char*
s_tag =
"USBHCDCECM";
66typedef enum : uint8_t {
85typedef enum : uint8_t {
112typedef enum : uint16_t {
128typedef enum : uint8_t {
139typedef enum : uint32_t {
292 .w_value = (uint16_t)address,
319 .w_value = (uint16_t)config_value,
376 .w_value = filter_mask,
401 if ((c >=
'0') && (c <=
'9')) {
402 *out_nibble = (uint8_t)(c -
'0');
405 if ((c >=
'a') && (c <=
'f')) {
409 if ((c >=
'A') && (c <=
'F')) {
443 s_state.device.bulk_in_ep = 1U;
444 s_state.device.bulk_out_ep = 2U;
445 s_state.device.intr_in_ep = 3U;
451 s_state.device.i_mac_address = 4U;
493 "hcdc_ecm: release bus reset");
518 "hcdc_ecm: set USBADDR");
681 if (
s_state.attach_cb !=
nullptr) {
803 if ((buf ==
nullptr) && (len != 0U)) {
825 uint16_t inout_len = max_len;
829 *got_len = inout_len;
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.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_init_failed
Hardware peripheral failed to initialise.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
#define ra8_log_error_val(tag, message, value)
RA8 log error val.
Native USB controller driver public API (device + host modes).
ra8_err_t ra8_usb_queue_out(ra8_usb_speed_t speed, uint8_t pipe_num, uint8_t *out_buf, uint16_t *inout_len, bool rearm)
Drain an OUT transfer (host -> device) from pipe_num.
@ k_ra8_usb_ep_type_bulk
Bulk transfer.
@ k_ra8_usb_ep_type_intr
Interrupt transfer.
ra8_err_t ra8_usb_set_address(ra8_usb_speed_t speed, uint8_t address)
Program the device USB address into USBADDR.
ra8_err_t ra8_usb_configure_endpoint(ra8_usb_speed_t speed, uint8_t pipe_num, uint8_t ep_addr, ra8_usb_ep_dir_t dir, ra8_usb_ep_type_t type, uint16_t max_packet)
Configure a non-control PIPE for IN or OUT bulk / interrupt / iso transfers.
@ k_ra8_usb_ep_dir_in
Device -> host.
@ k_ra8_usb_ep_dir_out
Host -> device.
ra8_usb_speed_t
Selects which controller instance the call targets.
@ k_ra8_usb_speed_hs
High-Speed controller (USBHS @ 0x40351000).
@ k_ra8_usb_speed_fs
Full-Speed controller (USBFS @ 0x40250000).
ra8_err_t ra8_usb_queue_in(ra8_usb_speed_t speed, uint8_t pipe_num, const uint8_t *data, uint16_t len)
Queue an IN transfer (device -> host) on pipe_num.
ra8_usb_hcdc_ecm_setup_field_t
Standard chapter-9 + CDC-ECM class request bmRequestType / bRequest encodings.
@ k_ra8_hcdc_ecm_desc_interface
INTERFACE descriptor.
@ k_ra8_hcdc_ecm_breq_set_config
SET_CONFIGURATION.
@ k_ra8_hcdc_ecm_breq_get_descriptor
GET_DESCRIPTOR.
@ k_ra8_hcdc_ecm_desc_endpoint
ENDPOINT descriptor.
@ k_ra8_hcdc_ecm_breq_set_interface
SET_INTERFACE.
@ k_ra8_hcdc_ecm_bm_std_dev_out
Std | Device | Out.
@ k_ra8_hcdc_ecm_func_subtype_ecm
Ethernet Networking subtype.
@ k_ra8_hcdc_ecm_bm_class_iface_in
Class | Interface | In.
@ k_ra8_hcdc_ecm_bm_class_iface_out
Class | Interface | Out.
@ k_ra8_hcdc_ecm_bm_std_iface_out
Std | Interface | Out.
@ k_ra8_hcdc_ecm_desc_cs_interface
CS_INTERFACE functional.
@ k_ra8_hcdc_ecm_desc_configuration
CONFIGURATION descriptor.
@ k_ra8_hcdc_ecm_bm_std_dev_in
Std | Device | In.
@ k_ra8_hcdc_ecm_breq_set_address
SET_ADDRESS.
@ k_ra8_hcdc_ecm_desc_string
STRING descriptor.
@ k_ra8_hcdc_ecm_desc_device
DEVICE descriptor.
static ra8_err_t internal_do_set_address(void)
Step handler – store assigned address + SETUP for GET_DEVICE_DESCRIPTOR.
ra8_err_t ra8_usb_hcdc_ecm_get_link_status(ra8_usb_hcdc_ecm_link_t *out_link)
Issue GET_ETHERNET_STATISTIC (bRequest=0x44) to read the adapter's link state and store the result in...
static ra8_err_t internal_setup_set_config(uint8_t config_value)
Stage a SET_CONFIGURATION SETUP request.
ra8_err_t ra8_usb_hcdc_ecm_set_packet_filter(uint16_t filter_mask)
Issue SET_ETHERNET_PACKET_FILTER (bRequest=0x43) to the attached CDC-ECM adapter.
ra8_usb_hcdc_ecm_byte_mask_t
Single-byte mask used during serialisation.
@ k_ra8_hcdc_ecm_byte_mask
RA8 hcdc ecm byte mask.
static ra8_err_t internal_do_idle(void)
Step handler – bus-reset assert.
static ra8_err_t internal_step_advance(void)
Drive the enumeration step machine forward by one step.
static ra8_err_t internal_do_set_config(void)
Step handler – pure software descriptor walk.
ra8_err_t ra8_usb_hcdc_ecm_parse_mac(const char *chars, uint8_t *out_mac)
Parse 12 ASCII hex characters from an iMACAddress string descriptor payload into a 6-byte MAC.
static ra8_err_t internal_hex_nibble(char c, uint8_t *out_nibble)
Convert one ASCII hex digit to a 0..15 nibble.
static ra8_err_t internal_do_bus_reset(void)
Step handler – bus-reset release + SETUP for SET_ADDRESS.
static ra8_err_t internal_do_get_dev_desc(void)
Step handler – SETUP for GET_CONFIGURATION_DESCRIPTOR.
ra8_err_t ra8_usb_hcdc_ecm_init(ra8_usb_speed_t speed)
Bring up the host-CDC-ECM driver on a chosen USB controller.
static void internal_walk_config_descriptor(void)
Populate s_state.device with stub descriptor data.
ra8_err_t ra8_usb_hcdc_ecm_close(void)
Tear down the host-CDC-ECM driver and release the controller.
static ra8_err_t internal_do_set_interface(void)
Step handler – finalise pipes + fire attach callback.
ra8_usb_hcdc_ecm_size_t
Standard descriptor sizes and request payload sizes.
@ k_ra8_hcdc_ecm_cfg_desc_len
CONFIGURATION descriptor hdr.
@ k_ra8_hcdc_ecm_lang_id_us
wIndex for English (US).
@ k_ra8_hcdc_ecm_assigned_address
First assigned device addr.
@ k_ra8_hcdc_ecm_iface_desc_len
INTERFACE descriptor.
@ k_ra8_hcdc_ecm_ep_desc_len
ENDPOINT descriptor.
@ k_ra8_hcdc_ecm_string_desc_len
wLength for string fetch.
@ k_ra8_hcdc_ecm_data_alt
Data IF alt setting = 1.
@ k_ra8_hcdc_ecm_dev_desc_len
USB DEVICE descriptor.
@ k_ra8_hcdc_ecm_default_config
bConfigurationValue = 1.
ra8_err_t ra8_usb_hcdc_ecm_send_frame(const uint8_t *buf, uint16_t len)
Send an Ethernet frame OUT to the attached CDC-ECM adapter.
static ra8_err_t internal_setup_set_interface_data(void)
Stage a SET_INTERFACE (alt 1, iface 1) SETUP request.
static ra8_err_t internal_do_walk_desc(void)
Step handler – SETUP for GET_STRING_DESCRIPTOR(iMACAddress).
ra8_usb_hcdc_ecm_byte_shift_t
Per-byte shift constants for descriptor / wValue serialisation.
@ k_ra8_hcdc_ecm_hex_alpha
Offset for 'A'/'a' in hex digit.
@ k_ra8_hcdc_ecm_shift_byte0
RA8 hcdc ecm shift byte0.
@ k_ra8_hcdc_ecm_shift_byte1
RA8 hcdc ecm shift byte1.
@ k_ra8_hcdc_ecm_shift_nibble
RA8 hcdc ecm shift nibble.
static ra8_err_t internal_do_set_filter(void)
Step handler – SETUP for SET_INTERFACE (data IF, alt 1).
static ra8_err_t internal_setup_get_descriptor(uint8_t desc_type, uint8_t desc_index, uint16_t lang_id, uint16_t length)
Stage a chapter-9 GET_DESCRIPTOR SETUP request.
ra8_err_t ra8_usb_hcdc_ecm_recv_frame(uint8_t *buf, uint16_t max_len, uint16_t *got_len)
Drain an Ethernet frame IN from the attached CDC-ECM adapter.
ra8_usb_hcdc_ecm_step_t
Enumeration step machine states.
@ k_ra8_hcdc_ecm_step_set_filter
SET_ETHERNET_PACKET_FILTER.
@ k_ra8_hcdc_ecm_step_set_interface
SET_INTERFACE (alt 1).
@ k_ra8_hcdc_ecm_step_walk_desc
Find ECM IFs; populate pipes.
@ k_ra8_hcdc_ecm_step_get_cfg_desc
GET_CONFIGURATION_DESCRIPTOR.
@ k_ra8_hcdc_ecm_step_set_config
SET_CONFIGURATION (1).
@ k_ra8_hcdc_ecm_step_bus_reset
Drive USBRST then release.
@ k_ra8_hcdc_ecm_step_get_dev_desc
GET_DEVICE_DESCRIPTOR (18 B).
@ k_ra8_hcdc_ecm_step_done
Attach callback fires.
@ k_ra8_hcdc_ecm_step_get_string_mac
GET_STRING_DESCRIPTOR(iMAC).
@ k_ra8_hcdc_ecm_step_set_address
SET_ADDRESS to assigned 1.
@ k_ra8_hcdc_ecm_step_idle
Pre-attach.
static uint16_t internal_bulk_max_packet(ra8_usb_speed_t speed)
Pick the bulk-max-packet ceiling matching the negotiated speed.
ra8_err_t ra8_usb_hcdc_ecm_attach_callback(ra8_usb_hcdc_ecm_attach_fn_t on_attach, void *ctx)
Register (or detach) the attach callback.
static ra8_err_t internal_setup_set_address(uint8_t address)
Stage a SET_ADDRESS SETUP request.
static ra8_err_t internal_do_get_string_mac(void)
Step handler – SETUP for SET_ETHERNET_PACKET_FILTER.
static ra8_err_t internal_do_get_cfg_desc(void)
Step handler – SETUP for SET_CONFIGURATION.
static ra8_err_t internal_setup_set_packet_filter(uint16_t filter_mask)
Stage SET_ETHERNET_PACKET_FILTER (bRequest=0x43).
ra8_err_t ra8_usb_hcdc_ecm_step(void)
Drive the enumeration step machine forward by one step.
static ra8_err_t internal_configure_pipes(void)
Configure the three host-CDC-ECM pipes against the attached adapter's endpoints.
Native USB host-side CDC ECM (Communications Device Class -Ethernet Networking Control Model) class l...
@ k_ra8_hcdc_ecm_mac_bytes
Ethernet MAC byte count.
@ k_ra8_hcdc_ecm_req_get_statistic
GET_ETHERNET_STATISTIC.
@ k_ra8_hcdc_ecm_req_set_packet_filter
SET_ETHERNET_PACKET_FILTER.
ra8_usb_hcdc_ecm_link_t
Adapter link status reported by _get_link_status.
@ k_ra8_hcdc_ecm_link_down
NetworkConnection notification 0.
@ k_ra8_hcdc_ecm_pipe_bulk_in
PIPE1 -> attached EP bulk IN.
@ k_ra8_hcdc_ecm_pipe_intr_in
PIPE6 -> attached EP intr IN.
@ k_ra8_hcdc_ecm_pipe_bulk_out
PIPE2 -> attached EP bulk OUT.
@ k_ra8_hcdc_ecm_filter_all
All bits set.
void(* ra8_usb_hcdc_ecm_attach_fn_t)(void *ctx, const ra8_usb_hcdc_ecm_device_t *device)
Attach-callback signature.
@ k_ra8_hcdc_ecm_bulk_max_packet_fs
Bulk size at full speed.
@ k_ra8_hcdc_ecm_max_ethernet_frame
Ethernet frame ceiling.
@ k_ra8_hcdc_ecm_intr_max_packet
Notification pipe size.
@ k_ra8_hcdc_ecm_bulk_max_packet_hs
Bulk size at high speed.
ra8_err_t ra8_usb_host_bus_reset(ra8_usb_speed_t speed, bool assert_reset)
Drive (or release) the bus reset line.
ra8_err_t ra8_usb_host_init(ra8_usb_speed_t speed)
Bring up a USB controller in HOST mode.
ra8_err_t ra8_usb_host_deinit(ra8_usb_speed_t speed)
Tear down a host-mode controller and drop its MSTP reference.
ra8_err_t ra8_usb_host_setup_request(ra8_usb_speed_t speed, const ra8_usb_setup_t *setup)
Issue a SETUP packet through the DCP (host -> peripheral).
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.
Snapshot of the attached CDC-ECM adapter, passed to the attach callback.
Singleton shadow state for the host-CDC-ECM driver.
ra8_usb_hcdc_ecm_link_t link
Cached link state.
ra8_usb_hcdc_ecm_step_t step
Current enum step.
ra8_usb_hcdc_ecm_attach_fn_t attach_cb
Attach callback, or NULL.
void * attach_ctx
Attach callback ctx.
ra8_usb_hcdc_ecm_device_t device
Snapshot of attached dev.
bool initialized
True after _init.
bool attached
True after enumeration.
ra8_usb_speed_t speed
Underlying controller.
Decoded 8-byte USB SETUP packet.