|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
USBX host-controller-driver bridge to ra8_usb – implementation. More...
#include "ux_hcd_ra8_usb.h"#include <stdint.h>#include <string.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_log.h"#include "ux_api.h"Go to the source code of this file.
Data Structures | |
| struct | ra8_usb_hcd_t |
| Bridge-singleton state. More... | |
Macros | |
| #define | UX_SOURCE_CODE |
Enumerations | |
| enum | ra8_usb_hcd_ep_addr_field_t : uint8_t { k_ra8_usb_hcd_ep_addr_dir_in_bit = 0x80U , k_ra8_usb_hcd_ep_addr_num_mask = 0x0FU } |
| Bit fields of a USB endpoint address (bEndpointAddress). More... | |
| enum | ra8_usb_hcd_pipe_t : uint8_t { k_ra8_usb_hcd_pipe_count = 10U } |
| Pipe-index bounds for the host bridge. More... | |
| enum | ra8_usb_hcd_ctrl_id_t : uint8_t { k_ra8_usb_hcd_controller_id = 99U } |
| Private USBX controller-type id reported by this HCD bridge. More... | |
Functions | |
| static uint8_t | internal_ep_to_pipe (uint8_t ep_addr) |
| Ep to pipe. | |
| static unsigned int | internal_endpoint_create (struct UX_ENDPOINT_STRUCT *ep) |
| Endpoint create. | |
| static unsigned int | internal_control_xfer (struct UX_TRANSFER_STRUCT *tr) |
| Drive the EP0 control transfer SETUP + optional data stage. | |
| static unsigned int | internal_bulk_xfer (struct UX_TRANSFER_STRUCT *tr, uint8_t ep_addr, uint8_t pipe) |
| Drive a bulk / interrupt transfer on a non-EP0 pipe. | |
| static unsigned int | internal_transfer_request (struct UX_TRANSFER_STRUCT *tr) |
| Transfer request. | |
| static unsigned int | internal_port_reset (void) |
| Pulse the root-hub port reset (assert then deassert). | |
| static unsigned int | internal_port_set_enabled (bool enable) |
| Enable or disable the root-hub port via DVSTCTR0.UACT. | |
| unsigned int | _ux_hcd_ra8_usb_function (struct UX_HCD_STRUCT *hcd, unsigned int function, void *parameter) |
| USBX host-side HCD function dispatcher. | |
| ra8_err_t | ux_hcd_ra8_usb_initialize (ra8_usb_speed_t speed) |
| Ux hcd ra usb initialize. | |
| ra8_err_t | ux_hcd_ra8_usb_uninitialize (void) |
| Ux hcd ra usb uninitialize. | |
| ra8_usb_hcd_state_t | ux_hcd_ra8_usb_state (void) |
| Ux hcd ra usb state. | |
Variables | |
| static const char *const | s_tag = "ux_hcd_ra8_usb" |
| static ra8_usb_hcd_t | s_hcd |
| Bridge instance. | |
USBX host-controller-driver bridge to ra8_usb – implementation.
Counterpart to ux_dcd_ra8_usb.c: routes USBX host-stack dispatch into the ra8_usb_host_* register-level driver. Mirrors the surface of upstream USBX HCD ports (e.g. ux_hcd_ehci_entry).
Definition in file ux_hcd_ra8_usb.c.
| #define UX_SOURCE_CODE |
Definition at line 19 of file ux_hcd_ra8_usb.c.
| enum ra8_usb_hcd_ctrl_id_t : uint8_t |
Private USBX controller-type id reported by this HCD bridge.
| Enumerator | |
|---|---|
| k_ra8_usb_hcd_controller_id | RA-USB private controller id. |
Definition at line 83 of file ux_hcd_ra8_usb.c.
| enum ra8_usb_hcd_ep_addr_field_t : uint8_t |
Bit fields of a USB endpoint address (bEndpointAddress).
USB 2.0 sec 9.6.6: bit 7 is the direction bit (1 = IN) and bits 3:0 carry the endpoint number. The same direction bit also appears as bit 7 of bmRequestType in a SETUP packet (USB 2.0 sec 9.3).
| Enumerator | |
|---|---|
| k_ra8_usb_hcd_ep_addr_dir_in_bit | Direction bit set => IN. |
| k_ra8_usb_hcd_ep_addr_num_mask | Endpoint-number field (bits 3:0). |
Definition at line 62 of file ux_hcd_ra8_usb.c.
| enum ra8_usb_hcd_pipe_t : uint8_t |
Pipe-index bounds for the host bridge.
Hardware exposes the DCP (pipe 0) plus PIPE1..PIPE9, so a valid pipe index is 0..9; the value 10 is both the count of valid pipes and the out-of-range sentinel returned by internal_ep_to_pipe.
| Enumerator | |
|---|---|
| k_ra8_usb_hcd_pipe_count | Valid pipes 0..9; 10 == out-of-range. |
Definition at line 75 of file ux_hcd_ra8_usb.c.
| unsigned int _ux_hcd_ra8_usb_function | ( | struct UX_HCD_STRUCT * | hcd, |
| unsigned int | function, | ||
| void * | parameter ) |
USBX host-side HCD function dispatcher.
ux hcd ra usb function.
Stamped into UX_HCD::ux_hcd_entry_function during ux_hcd_ra8_usb_initialize. The USBX host stack calls this with a UX_HCD_* selector to request endpoint create/destroy/reset, transfer request, transfer abort, and root-hub port management (reset / enable / disable). The trampoline routes each selector to the matching internal_* helper.
| [in,out] | hcd | USBX HCD ownership block (currently unused; the bridge keeps its own static state in s_hcd). |
| [in] | function | USBX UX_HCD_* selector (e.g. UX_HCD_TRANSFER_REQUEST, UX_HCD_RESET_PORT). |
| [in,out] | parameter | Selector-dependent argument (UX_TRANSFER* / UX_ENDPOINT* / opaque). |
| UX_SUCCESS | Function handled. |
| UX_CONTROLLER_UNKNOWN | Bridge has not been initialized. |
| UX_ERROR | Selector unsupported, or helper rejected the call. |
Definition at line 427 of file ux_hcd_ra8_usb.c.
References internal_endpoint_create(), internal_port_reset(), internal_port_set_enabled(), internal_transfer_request(), k_ux_hcd_ra8_usb_state_uninit, and s_hcd.
Referenced by ux_hcd_ra8_usb_initialize().
|
static |
Drive a bulk / interrupt transfer on a non-EP0 pipe.
IN endpoints (ep_addr & 0x80U) read from the device and fill the caller buffer via ra8_usb_queue_out (the host-side OUT direction is "data flowing out of the chip into caller memory"). OUT endpoints write caller bytes to the device via ra8_usb_queue_in.
| [in,out] | tr | USBX transfer request. |
| [in] | ep_addr | Endpoint address (bit 7 = direction). |
| [in] | pipe | Pipe index in 1..9. |
| UX_SUCCESS | Bytes queued; actual_length updated. |
| UX_TRANSFER_ERROR | Underlying queue call failed. |
Definition at line 269 of file ux_hcd_ra8_usb.c.
References k_ra8_ok, k_ra8_usb_hcd_ep_addr_dir_in_bit, ra8_usb_queue_in(), ra8_usb_queue_out(), and s_hcd.
Referenced by internal_transfer_request().
|
static |
Drive the EP0 control transfer SETUP + optional data stage.
Builds an ra8_usb_setup_t from the USBX transfer request, fires the SETUP token via ra8_usb_host_setup_request, then for the optional data stage routes IN (D2H) through ra8_usb_queue_out (chip reads from device, fills caller buffer) and OUT (H2D) through ra8_usb_queue_in (chip writes caller buffer onto wire).
| [in,out] | tr | USBX EP0 control transfer request. |
| UX_SUCCESS | Token accepted; data stage (if any) queued. |
| UX_TRANSFER_ERROR | ra8_usb_host_setup_request or queue failed. |
Definition at line 212 of file ux_hcd_ra8_usb.c.
References ra8_usb_setup_t::bm_request_type, k_ra8_ok, k_ra8_usb_hcd_ep_addr_dir_in_bit, RA8_INTERNAL, ra8_usb_host_setup_request(), ra8_usb_queue_in(), ra8_usb_queue_out(), and s_hcd.
Referenced by internal_transfer_request().
|
static |
Endpoint create.
See implementation for details.
| [in,out] | ep | See function signature for type and usage. |
| 0 | Success or default value. |
Definition at line 141 of file ux_hcd_ra8_usb.c.
References internal_ep_to_pipe(), k_ra8_ok, k_ra8_usb_ep_dir_in, k_ra8_usb_ep_dir_out, k_ra8_usb_ep_type_bulk, k_ra8_usb_ep_type_intr, k_ra8_usb_ep_type_iso, k_ra8_usb_hcd_ep_addr_dir_in_bit, k_ra8_usb_hcd_ep_addr_num_mask, k_ra8_usb_hcd_pipe_count, RA8_INTERNAL, ra8_usb_configure_endpoint(), and s_hcd.
Referenced by _ux_hcd_ra8_usb_function().
|
static |
Ep to pipe.
See implementation for details.
| [in,out] | ep_addr | See function signature for type and usage. |
| 0 | Success or default value. |
Definition at line 110 of file ux_hcd_ra8_usb.c.
References k_ra8_usb_hcd_ep_addr_num_mask, k_ra8_usb_hcd_pipe_count, and RA8_INTERNAL.
Referenced by internal_endpoint_create(), and internal_transfer_request().
|
static |
Pulse the root-hub port reset (assert then deassert).
USBX leaves the spec-required 10 ms hold between the assert and deassert edges to the caller (it issues two separate UX_HCD_RESET_PORT calls with the hold in between for some hosts, or expects the HCD to short-circuit it for others). Here we just trampoline both edges into ra8_usb_host_bus_reset.
| UX_SUCCESS | Both edges accepted. |
| UX_ERROR | Either edge rejected by the controller. |
Definition at line 351 of file ux_hcd_ra8_usb.c.
References k_ra8_ok, RA8_INTERNAL, ra8_usb_host_bus_reset(), and s_hcd.
Referenced by _ux_hcd_ra8_usb_function().
|
static |
Enable or disable the root-hub port via DVSTCTR0.UACT.
Wraps ra8_usb_host_set_uact so the dispatcher's enable/disable cases collapse to a one-line call. On enable the bridge moves into active; on disable it returns to ready.
| [in] | enable | True to assert UACT (SOF generation, downstream bus activity), false to deassert. |
| UX_SUCCESS | UACT toggled and state updated. |
| UX_ERROR | ra8_usb_host_set_uact rejected the change. |
Definition at line 384 of file ux_hcd_ra8_usb.c.
References k_ra8_ok, k_ux_hcd_ra8_usb_state_active, k_ux_hcd_ra8_usb_state_ready, RA8_INTERNAL, ra8_usb_host_set_uact(), and s_hcd.
Referenced by _ux_hcd_ra8_usb_function().
|
static |
Transfer request.
See implementation for details.
| [in,out] | tr | See function signature for type and usage. |
| 0 | Success or default value. |
Definition at line 308 of file ux_hcd_ra8_usb.c.
References internal_bulk_xfer(), internal_control_xfer(), internal_ep_to_pipe(), k_ra8_usb_hcd_pipe_count, and RA8_INTERNAL.
Referenced by _ux_hcd_ra8_usb_function().
|
nodiscard |
Ux hcd ra usb initialize.
Register the ra8_usb host bridge as the active USBX HCD.
See implementation for details.
| [in,out] | speed | See function signature for type and usage. |
| 0 | Success or default value. |
Definition at line 501 of file ux_hcd_ra8_usb.c.
References _ux_hcd_ra8_usb_function(), k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_ok, k_ra8_usb_hcd_controller_id, k_ra8_usb_speed_hs, k_ux_hcd_ra8_usb_state_ready, ra8_log_info, RA8_RETURN_ON_ERROR, ra8_usb_host_init(), s_hcd, and s_tag.
| ra8_usb_hcd_state_t ux_hcd_ra8_usb_state | ( | void | ) |
Ux hcd ra usb state.
Read the bridge run-state.
See implementation for details.
| 0 | Success or default value. |
Definition at line 586 of file ux_hcd_ra8_usb.c.
References s_hcd.
|
nodiscard |
Ux hcd ra usb uninitialize.
Tear down the ra8_usb HCD bridge.
See implementation for details.
| 0 | Success or default value. |
Definition at line 553 of file ux_hcd_ra8_usb.c.
References k_ra8_err_invalid_state, k_ra8_ok, k_ux_hcd_ra8_usb_state_uninit, ra8_usb_host_deinit(), ra8_usb_host_set_uact(), and s_hcd.
|
static |
Bridge instance.
RA8 has two USB controllers but USBX only ever drives one root-hub-style host at a time in this app.
Definition at line 48 of file ux_hcd_ra8_usb.c.
Referenced by _ux_hcd_ra8_usb_function(), internal_bulk_xfer(), internal_control_xfer(), internal_endpoint_create(), internal_port_reset(), internal_port_set_enabled(), ux_hcd_ra8_usb_initialize(), ux_hcd_ra8_usb_state(), and ux_hcd_ra8_usb_uninitialize().
|
static |
Definition at line 31 of file ux_hcd_ra8_usb.c.