|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Native USB host-side HUB class layer. More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_usb_hhub_device_t |
| Snapshot of the attached HUB device, passed to the attach callback. More... | |
Typedefs | |
| typedef void(* | ra8_usb_hhub_attach_fn_t) (void *ctx, const ra8_usb_hhub_device_t *device) |
| Attach-callback signature. | |
Functions | |
| ra8_err_t | ra8_usb_hhub_init (ra8_usb_speed_t speed) |
| Bring up the host-HUB driver on a chosen USB controller. | |
| ra8_err_t | ra8_usb_hhub_close (void) |
| Tear down the host-HUB driver and release the controller. | |
| ra8_err_t | ra8_usb_hhub_attach_callback (ra8_usb_hhub_attach_fn_t on_attach, void *ctx) |
| Register (or detach) the HUB attach callback. | |
| ra8_err_t | ra8_usb_hhub_get_port_count (uint8_t *count) |
| Read the cached downstream port count from the HUB descriptor. | |
| ra8_err_t | ra8_usb_hhub_get_port_status (uint8_t port, uint32_t *status) |
| Issue GET_PORT_STATUS (USB 2.0 sec 11.24.2.7) over the DCP. | |
| ra8_err_t | ra8_usb_hhub_set_port_feature (uint8_t port, ra8_usb_hhub_feature_t feature) |
| Issue SET_PORT_FEATURE (USB 2.0 sec 11.24.2.13) over the DCP. | |
| ra8_err_t | ra8_usb_hhub_clear_port_feature (uint8_t port, ra8_usb_hhub_feature_t feature) |
| Issue CLEAR_PORT_FEATURE (USB 2.0 sec 11.24.2.2) over the DCP. | |
| ra8_err_t | ra8_usb_hhub_step (void) |
| Drive the enumeration step machine forward by one step. | |
Native USB host-side HUB class layer.
Glues the host-mode bring-up paths in ra8_usb to a USB HUB device (class code 0x09) attached to the EK-RA8D2's USB host port. Mirrors FSP's r_usb_basic hub-support pattern: detect a HUB descriptor, read the per-port descriptor, expose GET_PORT_STATUS and SET_PORT_FEATURE control transfers so the application can sequence port power-on, port reset, and child-device enumeration on downstream ports.
Lifecycle:
Reference: USB 2.0 specification chapter 11 "Hub Specification" (USB-IF, 2000-04-27). Class request encoding follows USB 2.0 sec 11.24 "Hub Class Requests".
Definition in file ra8_usb_hhub.h.
| typedef void(* ra8_usb_hhub_attach_fn_t) (void *ctx, const ra8_usb_hhub_device_t *device) |
Attach-callback signature.
| [in] | ctx | Caller-supplied context registered with ra8_usb_hhub_attach_callback. |
| [in] | device | Snapshot of the attached HUB device. The pointer remains valid only for the duration of the call; copy out anything you need. |
Definition at line 157 of file ra8_usb_hhub.h.
| enum ra8_usb_hhub_class_t : uint8_t |
HUB class code per USB 2.0 sec 11.24.1.
| Enumerator | |
|---|---|
| k_ra8_hhub_class_hub | bDeviceClass / bInterfaceClass = HUB. |
Definition at line 61 of file ra8_usb_hhub.h.
| enum ra8_usb_hhub_desc_t : uint8_t |
HUB descriptor types (USB 2.0 sec 11.23.2).
| Enumerator | |
|---|---|
| k_ra8_hhub_desc_hub | HUB class descriptor type. |
Definition at line 69 of file ra8_usb_hhub.h.
| enum ra8_usb_hhub_feature_t : uint16_t |
HUB port feature selectors (USB 2.0 Table 11-17).
Definition at line 91 of file ra8_usb_hhub.h.
| enum ra8_usb_hhub_limits_t : uint8_t |
Hard ceilings on hub topology this driver tracks.
FSP's r_usb_basic hub support tracks up to 16 downstream ports per hub; we mirror that ceiling.
| Enumerator | |
|---|---|
| k_ra8_hhub_max_ports | FSP-aligned downstream port ceiling. |
| k_ra8_hhub_first_port | Port numbering starts at 1. |
Definition at line 130 of file ra8_usb_hhub.h.
| enum ra8_usb_hhub_port_status_bits_t : uint8_t |
Bit positions in the 32-bit port status word (USB 2.0 Table 11-21).
Low 16 bits = wPortStatus, high 16 bits = wPortChange.
Definition at line 112 of file ra8_usb_hhub.h.
| enum ra8_usb_hhub_request_t : uint8_t |
HUB class-specific request codes (USB 2.0 sec 11.24.2).
Definition at line 77 of file ra8_usb_hhub.h.
|
nodiscard |
Register (or detach) the HUB attach callback.
| [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 514 of file ra8_usb_hhub.c.
References k_ra8_err_invalid_state, k_ra8_ok, and s_state.
|
nodiscard |
Issue CLEAR_PORT_FEATURE (USB 2.0 sec 11.24.2.2) over the DCP.
Builds an 8-byte SETUP packet with bmRequestType = 0x23 (H2D | Class | Other), bRequest = 0x01 (CLEAR_FEATURE), wValue = feature, wIndex = port, wLength = 0. Most commonly used to acknowledge change bits like C_PORT_RESET / C_PORT_CONNECTION.
| [in] | port | Downstream port number. |
| [in] | feature | Feature selector. |
| k_ra8_ok | Control transfer queued. |
| k_ra8_err_invalid_state | Driver not initialized, or no HUB attached. |
| k_ra8_err_invalid_arg | port out of range. |
| k_ra8_err_busy | Controller busy with a prior SETUP. |
Definition at line 607 of file ra8_usb_hhub.c.
References internal_port_ok(), k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_hhub_bm_class_other_out, k_ra8_hhub_req_clear_feature, ra8_usb_host_setup_request(), and s_state.
|
nodiscard |
Tear down the host-HUB driver and release the controller.
| k_ra8_ok | Released. |
| k_ra8_err_invalid_state | Driver was never initialized. |
Definition at line 494 of file ra8_usb_hhub.c.
References k_ra8_err_invalid_state, k_ra8_hhub_step_idle, ra8_usb_host_deinit(), ra8_usb_host_set_uact(), and s_state.
|
nodiscard |
Read the cached downstream port count from the HUB descriptor.
Returns the value of bNbrPorts collected during enumeration (USB 2.0 sec 11.23.2.1). Does NOT issue a fresh GET_DESCRIPTOR(HUB) on every call – the descriptor is cached at attach time.
| [out] | count | Receives port count, in range [k_ra8_hhub_first_port .. k_ra8_hhub_max_ports]. |
| k_ra8_ok | Count copied to *count. |
| k_ra8_err_null_ptr | count was NULL. |
| k_ra8_err_invalid_state | Driver not initialized, or no HUB attached. |
Definition at line 529 of file ra8_usb_hhub.c.
References k_ra8_err_invalid_state, k_ra8_ok, RA8_CHECK_NULL_PTR, s_state, and s_tag.
|
nodiscard |
Issue GET_PORT_STATUS (USB 2.0 sec 11.24.2.7) over the DCP.
Builds an 8-byte SETUP packet with bmRequestType = 0xA3 (D2H | Class | Other), bRequest = 0x00 (GET_STATUS), wValue = 0, wIndex = port, wLength = 4. The data stage delivers a 32-bit word whose low half is wPortStatus and high half is wPortChange.
| [in] | port | Downstream port number, in [k_ra8_hhub_first_port .. k_ra8_hhub_max_ports]. |
| [out] | status | Receives the 32-bit status word once the data stage lands. The starter zeroes this on entry; the production path overwrites it from the data stage handler. |
| k_ra8_ok | Control transfer queued. |
| k_ra8_err_null_ptr | status was NULL. |
| k_ra8_err_invalid_state | Driver not initialized, or no HUB attached. |
| k_ra8_err_invalid_arg | port out of range. |
| k_ra8_err_busy | Controller busy with a prior SETUP. |
Definition at line 549 of file ra8_usb_hhub.c.
References internal_port_ok(), k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_hhub_bm_class_other_in, k_ra8_hhub_port_status_len, k_ra8_hhub_req_get_status, RA8_CHECK_NULL_PTR, ra8_usb_host_setup_request(), s_state, and s_tag.
|
nodiscard |
Bring up the host-HUB driver on a chosen USB controller.
Initialises the underlying ra8_usb driver in HOST mode for speed, leaves the bus in the "wait for attach" state (UACT cleared), and arms the internal enumeration step machine so the next CTRT interrupt advances enumeration.
| [in] | speed | Which USB controller (FS or HS). |
| k_ra8_ok | Host-HUB 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 471 of file ra8_usb_hhub.c.
References k_ra8_err_hw_init_failed, k_ra8_err_invalid_arg, k_ra8_hhub_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 |
Issue SET_PORT_FEATURE (USB 2.0 sec 11.24.2.13) over the DCP.
Builds an 8-byte SETUP packet with bmRequestType = 0x23 (H2D | Class | Other), bRequest = 0x03 (SET_FEATURE), wValue = feature, wIndex = port, wLength = 0. Used to drive PORT_POWER, PORT_RESET, PORT_SUSPEND, PORT_ENABLE, etc.
| [in] | port | Downstream port number. |
| [in] | feature | Feature selector (see ra8_usb_hhub_feature_t). |
| k_ra8_ok | Control transfer queued. |
| k_ra8_err_invalid_state | Driver not initialized, or no HUB attached. |
| k_ra8_err_invalid_arg | port out of range. |
| k_ra8_err_busy | Controller busy with a prior SETUP. |
Definition at line 579 of file ra8_usb_hhub.c.
References internal_port_ok(), k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_hhub_bm_class_other_out, k_ra8_hhub_req_set_feature, ra8_usb_host_setup_request(), and s_state.
|
nodiscard |
Drive the enumeration step machine forward by one step.
Test / debug entry point. Production 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 633 of file ra8_usb_hhub.c.
References internal_step_advance(), k_ra8_err_invalid_state, and s_state.