|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Native USB host-side CDC ECM (Communications Device Class -Ethernet Networking Control Model) class layer. More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_usb_hcdc_ecm_device_t |
| Snapshot of the attached CDC-ECM adapter, passed to the attach callback. More... | |
Typedefs | |
| typedef void(* | ra8_usb_hcdc_ecm_attach_fn_t) (void *ctx, const ra8_usb_hcdc_ecm_device_t *device) |
| Attach-callback signature. | |
Enumerations | |
| enum | ra8_usb_hcdc_ecm_pipe_t : uint8_t { k_ra8_hcdc_ecm_pipe_bulk_in = 1U , k_ra8_hcdc_ecm_pipe_bulk_out = 2U , k_ra8_hcdc_ecm_pipe_intr_in = 6U } |
| PIPE numbers used by the host-CDC-ECM driver for the attached adapter's endpoints. More... | |
| enum | ra8_usb_hcdc_ecm_packet_t : uint16_t { k_ra8_hcdc_ecm_bulk_max_packet_fs = 64U , k_ra8_hcdc_ecm_bulk_max_packet_hs = 512U , k_ra8_hcdc_ecm_intr_max_packet = 16U , k_ra8_hcdc_ecm_max_ethernet_frame = 1514U } |
| Packet sizing for the attached adapter's bulk + interrupt endpoints. More... | |
| enum | ra8_usb_hcdc_ecm_class_t : uint8_t { k_ra8_hcdc_ecm_class_comms = 0x02U , k_ra8_hcdc_ecm_subclass_ecm = 0x06U , k_ra8_hcdc_ecm_protocol_none = 0x00U , k_ra8_hcdc_ecm_class_data = 0x0AU , k_ra8_hcdc_ecm_subclass_zero = 0x00U , k_ra8_hcdc_ecm_protocol_zero = 0x00U } |
| Class / subclass / protocol triplets that identify a CDC ECM function within an attached USB device's descriptor walk. More... | |
| enum | ra8_usb_hcdc_ecm_request_t : uint8_t { k_ra8_hcdc_ecm_req_set_packet_filter = 0x43U , k_ra8_hcdc_ecm_req_get_statistic = 0x44U } |
| CDC-ECM class-specific request codes the host issues to the attached adapter (USB CDC ECM 1.20 sec 6.2 "Management
Element Requests"). More... | |
| enum | ra8_usb_hcdc_ecm_filter_t : uint16_t { k_ra8_hcdc_ecm_filter_promiscuous = 0x01U , k_ra8_hcdc_ecm_filter_all_multicast = 0x02U , k_ra8_hcdc_ecm_filter_directed = 0x04U , k_ra8_hcdc_ecm_filter_broadcast = 0x08U , k_ra8_hcdc_ecm_filter_multicast = 0x10U , k_ra8_hcdc_ecm_filter_all = 0x1FU } |
| Filter mask bits passed to ra8_usb_hcdc_ecm_set_packet_filter. More... | |
| enum | ra8_usb_hcdc_ecm_link_t : uint8_t { k_ra8_hcdc_ecm_link_down = 0U , k_ra8_hcdc_ecm_link_up = 1U } |
| Adapter link status reported by _get_link_status. More... | |
| enum | ra8_usb_hcdc_ecm_mac_t : uint8_t { k_ra8_hcdc_ecm_mac_bytes = 6U , k_ra8_hcdc_ecm_mac_hex_chars = 12U } |
| Sizes related to the 6-byte Ethernet MAC + its 12-character ASCII hex representation in the iMACAddress string descriptor. More... | |
Functions | |
| 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. | |
| ra8_err_t | ra8_usb_hcdc_ecm_close (void) |
| Tear down the host-CDC-ECM driver and release the controller. | |
| 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. | |
| 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. | |
| 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_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_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 *out_link. | |
| ra8_err_t | ra8_usb_hcdc_ecm_step (void) |
| Drive the enumeration step machine forward by one step. | |
| 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. | |
Native USB host-side CDC ECM (Communications Device Class -
Ethernet Networking Control Model) class layer.
Glues the host-mode bring-up paths in ra8_usb to a CDC-ECM USB Ethernet adapter attached on the EK-RA8D2's USB-HS host port. Mirrors FSP's r_usb_hcdc_ecm host-CDC-ECM class flow but compiled as part of this tree with no FSP / CherryUSB / TinyUSB binaries pulled in.
Lifecycle:
The starter does not support hubs; it tracks a single attached CDC-ECM adapter. Hub class enumeration is tracked as a deferred follow-up.
Definition in file ra8_usb_hcdc_ecm.h.
| typedef void(* ra8_usb_hcdc_ecm_attach_fn_t) (void *ctx, const ra8_usb_hcdc_ecm_device_t *device) |
Attach-callback signature.
| [in] | ctx | Caller-supplied context registered with ra8_usb_hcdc_ecm_attach_callback. |
| [in] | device | Snapshot of the attached CDC-ECM adapter. Pointer remains valid only for the duration of the call; copy out anything you need. |
Definition at line 198 of file ra8_usb_hcdc_ecm.h.
| enum ra8_usb_hcdc_ecm_class_t : uint8_t |
Class / subclass / protocol triplets that identify a CDC ECM function within an attached USB device's descriptor walk.
Numbered from the USB CDC ECM 1.20 spec (subclass 0x06) and the USB-IF Class Codes registry. Protocol = 0x00 (no specific protocol).
Definition at line 104 of file ra8_usb_hcdc_ecm.h.
| enum ra8_usb_hcdc_ecm_filter_t : uint16_t |
Filter mask bits passed to ra8_usb_hcdc_ecm_set_packet_filter.
Wire-level layout matches USB CDC ECM 1.20 sec 6.2.4 "Set Ethernet Packet Filter" (Table 6: PACKET_TYPE bitmap).
Definition at line 132 of file ra8_usb_hcdc_ecm.h.
| enum ra8_usb_hcdc_ecm_link_t : uint8_t |
Adapter link status reported by _get_link_status.
| Enumerator | |
|---|---|
| k_ra8_hcdc_ecm_link_down | NetworkConnection notification 0. |
| k_ra8_hcdc_ecm_link_up | NetworkConnection notification 1. |
Definition at line 145 of file ra8_usb_hcdc_ecm.h.
| enum ra8_usb_hcdc_ecm_mac_t : uint8_t |
Sizes related to the 6-byte Ethernet MAC + its 12-character ASCII hex representation in the iMACAddress string descriptor.
| Enumerator | |
|---|---|
| k_ra8_hcdc_ecm_mac_bytes | Ethernet MAC byte count. |
| k_ra8_hcdc_ecm_mac_hex_chars | 12 ASCII hex chars in iMACAddr. |
Definition at line 155 of file ra8_usb_hcdc_ecm.h.
| enum ra8_usb_hcdc_ecm_packet_t : uint16_t |
Packet sizing for the attached adapter's bulk + interrupt endpoints.
The Ethernet MTU plus 14-byte Ethernet header plus 4-byte FCS yields the canonical 1514-byte maximum frame size mirrored from FSP USB_HCDC_ECM_MAXIMUM_ETHERNET_FRAME_SIZE.
Definition at line 88 of file ra8_usb_hcdc_ecm.h.
| enum ra8_usb_hcdc_ecm_pipe_t : uint8_t |
PIPE numbers used by the host-CDC-ECM driver for the attached adapter's endpoints.
FSP / RA8D2 PIPE assignment rules constrain bulk pipes to PIPE1..PIPE5 and interrupt pipes to PIPE6..PIPE9.
| Enumerator | |
|---|---|
| k_ra8_hcdc_ecm_pipe_bulk_in | PIPE1 -> attached EP bulk IN. |
| k_ra8_hcdc_ecm_pipe_bulk_out | PIPE2 -> attached EP bulk OUT. |
| k_ra8_hcdc_ecm_pipe_intr_in | PIPE6 -> attached EP intr IN. |
Definition at line 73 of file ra8_usb_hcdc_ecm.h.
| enum ra8_usb_hcdc_ecm_request_t : uint8_t |
CDC-ECM class-specific request codes the host issues to the attached adapter (USB CDC ECM 1.20 sec 6.2 "Management Element Requests").
| Enumerator | |
|---|---|
| k_ra8_hcdc_ecm_req_set_packet_filter | SET_ETHERNET_PACKET_FILTER. |
| k_ra8_hcdc_ecm_req_get_statistic | GET_ETHERNET_STATISTIC. |
Definition at line 119 of file ra8_usb_hcdc_ecm.h.
|
nodiscard |
Register (or detach) the attach callback.
The supplied callback fires exactly once per attach event, after the descriptor walk identifies a CDC-ECM Communication + Data interface pair on the attached device and the iMACAddress string descriptor has been parsed into device->mac_address. Pass NULL to detach.
| [in] | on_attach | Callback. NULL detaches. |
| [in] | ctx | Context pointer threaded back into on_attach. |
| k_ra8_ok | Callback installed. |
| k_ra8_err_invalid_state | Driver was never initialized. |
Definition at line 780 of file ra8_usb_hcdc_ecm.c.
References k_ra8_err_invalid_state, k_ra8_ok, and s_state.
|
nodiscard |
Tear down the host-CDC-ECM driver and release the controller.
| k_ra8_ok | Released. |
| k_ra8_err_invalid_state | Driver was never initialized. |
Definition at line 759 of file ra8_usb_hcdc_ecm.c.
References k_ra8_err_invalid_state, k_ra8_hcdc_ecm_step_idle, ra8_usb_host_deinit(), ra8_usb_host_set_uact(), and s_state.
|
nodiscard |
Issue GET_ETHERNET_STATISTIC (bRequest=0x44) to read the adapter's link state and store the result in *out_link.
Builds a class-interface-in SETUP packet (bmRequestType=0xA1, bRequest=0x44) with a 1-byte data stage that carries the latest NetworkConnection notification value (0 = down, 1 = up). See USB CDC ECM 1.20 sec 6.2.5 "GetEthernetStatistic".
| [out] | out_link | Receives the current link state. |
| k_ra8_ok | Control transfer queued; *out_link populated. |
| k_ra8_err_invalid_state | Driver not initialized, or no adapter attached. |
| k_ra8_err_null_ptr | out_link was NULL. |
| k_ra8_err_busy | A control transfer is already in flight. |
Definition at line 855 of file ra8_usb_hcdc_ecm.c.
References k_ra8_err_invalid_state, k_ra8_hcdc_ecm_bm_class_iface_in, k_ra8_hcdc_ecm_data_alt, k_ra8_hcdc_ecm_req_get_statistic, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_usb_host_setup_request(), s_state, and s_tag.
|
nodiscard |
Bring up the host-CDC-ECM driver on a chosen USB controller.
Initialises the underlying ra8_usb driver in HOST mode for speed by delegating to ra8_usb_host_init, programs the DCP for 64-byte EP0 control transfers, leaves the bus in the "wait for attach" state (UACT cleared), and arms the internal enumeration step machine.
| [in] | speed | Which USB controller (FS or HS). |
| k_ra8_ok | Host-CDC-ECM ready, awaiting attach. |
| k_ra8_err_invalid_arg | speed out of range. |
| k_ra8_err_hw_init_failed | Underlying ra8_usb_host_init failed. |
Definition at line 735 of file ra8_usb_hcdc_ecm.c.
References k_ra8_err_hw_init_failed, k_ra8_err_invalid_arg, k_ra8_hcdc_ecm_link_down, k_ra8_hcdc_ecm_step_idle, k_ra8_ok, k_ra8_usb_speed_fs, k_ra8_usb_speed_hs, ra8_log_error_val, ra8_log_info_val, ra8_usb_host_init(), s_state, and s_tag.
|
nodiscard |
Parse 12 ASCII hex characters from an iMACAddress string descriptor payload into a 6-byte MAC.
USB string descriptors are UTF-16LE; the iMACAddress payload is a 12-character ASCII-hex MAC encoded as 12 UTF-16LE code units (24 bytes). This helper walks chars two ASCII hex digits at a time and writes each parsed nibble pair to out_mac[0..5].
See USB CDC ECM 1.20 sec 5.4 "iMACAddress".
| [in] | chars | Pointer to 12 ASCII hex characters (post-UTF-16 decoding). |
| [out] | out_mac | Receives the 6-byte MAC. |
| k_ra8_ok | Parsed successfully. |
| k_ra8_err_null_ptr | chars or out_mac was NULL. |
| k_ra8_err_invalid_arg | One of the characters was not a valid ASCII hex digit. |
Definition at line 888 of file ra8_usb_hcdc_ecm.c.
References internal_hex_nibble(), k_ra8_hcdc_ecm_mac_bytes, k_ra8_hcdc_ecm_shift_nibble, k_ra8_ok, RA8_CHECK_NULL_PTR, and s_tag.
|
nodiscard |
Drain an Ethernet frame IN from the attached CDC-ECM adapter.
Polling / non-blocking. Pulls bytes from PIPE1 (bulk IN) into buf and stores the actual byte count in *got_len. Per USB CDC ECM 1.20 sec 5.4 "Data Class Interface Definitions" one bulk IN transfer yields one Ethernet frame.
| [out] | buf | Destination buffer. |
| [in] | max_len | Capacity of buf, > 0. |
| [out] | got_len | Receives the number of bytes actually placed. |
| k_ra8_ok | Frame drained; *got_len reflects the count. |
| k_ra8_err_no_data | Pipe was empty. |
| k_ra8_err_invalid_state | Driver not initialized, or no adapter attached. |
| k_ra8_err_null_ptr | buf or got_len was NULL. |
| k_ra8_err_invalid_arg | max_len == 0. |
Definition at line 812 of file ra8_usb_hcdc_ecm.c.
References k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_hcdc_ecm_pipe_bulk_in, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_usb_queue_out(), s_state, and s_tag.
|
nodiscard |
Send an Ethernet frame OUT to the attached CDC-ECM adapter.
Pushes buf bytes on PIPE2 (bulk OUT) so the controller delivers them at the next OUT token. Per USB CDC ECM 1.20 sec 5.4 "Data Class Interface Definitions" each USB transfer carries exactly one Ethernet frame (no length prefix). A frame whose length is an integer multiple of wMaxPacketSize is followed by a zero-length packet to terminate the transfer.
| [in] | buf | Frame buffer. NULL allowed iff len == 0. |
| [in] | len | Byte count, 0..k_ra8_hcdc_ecm_max_ethernet_frame. |
| k_ra8_ok | Transfer queued. |
| k_ra8_err_invalid_state | Driver not initialized, or no adapter attached. |
| k_ra8_err_invalid_arg | Bad buf / len. |
Definition at line 795 of file ra8_usb_hcdc_ecm.c.
References k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_hcdc_ecm_max_ethernet_frame, k_ra8_hcdc_ecm_pipe_bulk_out, ra8_usb_queue_in(), and s_state.
|
nodiscard |
Issue SET_ETHERNET_PACKET_FILTER (bRequest=0x43) to the attached CDC-ECM adapter.
Builds a class-interface-out SETUP packet (bmRequestType=0x21, bRequest=0x43) with the requested filter mask in wValue and wLength=0, and hands it to ra8_usb_host_setup_request. See USB CDC ECM 1.20 sec 6.2.4 "SetEthernetPacketFilter".
| [in] | filter_mask | OR of k_ra8_hcdc_ecm_filter_* bits. |
| k_ra8_ok | Control transfer queued. |
| k_ra8_err_invalid_state | Driver not initialized, or no adapter attached. |
| k_ra8_err_invalid_arg | filter_mask has bits outside the documented set. |
| k_ra8_err_busy | A control transfer is already in flight. |
Definition at line 841 of file ra8_usb_hcdc_ecm.c.
References internal_setup_set_packet_filter(), k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_hcdc_ecm_filter_all, and s_state.
|
nodiscard |
Drive the enumeration step machine forward by one step.
Test / debug entry point. The production path drives this from the ra8_usb_dispatch callback when the controller fires a CTRT or BRDY interrupt; tests call it directly to walk the state machine deterministically.
| k_ra8_ok | Step advanced. |
| k_ra8_err_invalid_state | Driver not initialized. |
Definition at line 917 of file ra8_usb_hcdc_ecm.c.
References internal_step_advance(), k_ra8_err_invalid_state, and s_state.