31static const char*
const s_tag =
"ux_hcd_ra8_usb";
62typedef enum : uint8_t {
75typedef enum : uint8_t {
83typedef enum : uint8_t {
146 const uint8_t ep_addr = (uint8_t)ep->ux_endpoint_descriptor.bEndpointAddress;
161 switch ((uint8_t)ep->ux_endpoint_descriptor.bmAttributes & 0x03U) {
180 (uint16_t)ep->ux_endpoint_descriptor.wMaxPacketSize) ==
215 .bm_request_type = (uint8_t)tr->ux_transfer_request_function,
216 .b_request = (uint8_t)tr->ux_transfer_request_type,
217 .w_value = (uint16_t)tr->ux_transfer_request_value,
218 .w_index = (uint16_t)tr->ux_transfer_request_index,
219 .w_length = (uint16_t)tr->ux_transfer_request_requested_length,
222 return UX_TRANSFER_ERROR;
224 if (tr->ux_transfer_request_requested_length != 0U &&
225 tr->ux_transfer_request_data_pointer !=
nullptr) {
226 uint16_t len = (uint16_t)tr->ux_transfer_request_requested_length;
230 return UX_TRANSFER_ERROR;
232 tr->ux_transfer_request_actual_length = len;
236 return UX_TRANSFER_ERROR;
238 tr->ux_transfer_request_actual_length = len;
272 uint16_t len = (uint16_t)tr->ux_transfer_request_requested_length;
275 return UX_TRANSFER_ERROR;
277 tr->ux_transfer_request_actual_length = len;
279 const uint16_t len = (uint16_t)tr->ux_transfer_request_requested_length;
282 return UX_TRANSFER_ERROR;
284 tr->ux_transfer_request_actual_length = len;
310 if (tr ==
nullptr || tr->ux_transfer_request_endpoint ==
nullptr) {
311 return UX_TRANSFER_ERROR;
313 UX_ENDPOINT* ep = tr->ux_transfer_request_endpoint;
314 const uint8_t ep_addr = (uint8_t)ep->ux_endpoint_descriptor.bEndpointAddress;
321 return UX_TRANSFER_ERROR;
431 return UX_CONTROLLER_UNKNOWN;
435 case UX_HCD_CREATE_ENDPOINT:
438 case UX_HCD_DESTROY_ENDPOINT:
439 case UX_HCD_RESET_ENDPOINT:
442 case UX_HCD_TRANSFER_REQUEST:
445 case UX_HCD_TRANSFER_ABORT:
448 case UX_HCD_RESET_PORT:
451 case UX_HCD_ENABLE_PORT:
454 case UX_HCD_DISABLE_PORT:
455 case UX_HCD_POWER_DOWN_PORT:
458 case UX_HCD_POWER_ON_PORT:
461 case UX_HCD_GET_PORT_STATUS:
462 case UX_HCD_GET_FRAME_NUMBER:
463 if (parameter !=
nullptr) {
464 *(
unsigned long*)parameter = 0UL;
468 case UX_HCD_PROCESS_DONE_QUEUE:
469 case UX_HCD_DISABLE_CONTROLLER:
470 case UX_HCD_UNINITIALIZE:
474 return UX_FUNCTION_NOT_SUPPORTED;
508 if (_ux_system_host == UX_NULL || _ux_system_host->ux_system_host_hcd_array == UX_NULL) {
514 UX_HCD* slot = _ux_system_host->ux_system_host_hcd_array;
515 const UINT max_hcds = UX_SYSTEM_HOST_MAX_HCD_GET();
516 for (
UINT i = 0; i < max_hcds; i++) {
517 if (slot->ux_hcd_status == UX_HCD_STATUS_UNUSED) {
522 slot->ux_hcd_status = UX_HCD_STATUS_OPERATIONAL;
524 slot->ux_hcd_nb_root_hubs = 1U;
526 slot->ux_hcd_controller_hardware = (
void*)&
s_hcd;
560 if (
s_hcd.owner !=
nullptr) {
561 s_hcd.owner->ux_hcd_status = UX_HCD_STATUS_HALTED;
562 s_hcd.owner->ux_hcd_entry_function =
nullptr;
565 s_hcd.owner =
nullptr;
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.
@ 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(tag, message)
RA8 log info.
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.
ra8_usb_ep_type_t
Transfer type for a non-control endpoint.
@ k_ra8_usb_ep_type_bulk
Bulk transfer.
@ k_ra8_usb_ep_type_iso
Isochronous transfer.
@ k_ra8_usb_ep_type_intr
Interrupt transfer.
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.
ra8_usb_ep_dir_t
Endpoint direction.
@ 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_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.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
struct UX_HCD_STRUCT * owner
Back-pointer into USBX.
ra8_usb_hcd_state_t state
Bridge run-state.
ra8_usb_speed_t speed
Controller this drives.
Decoded 8-byte USB SETUP packet.
uint8_t bm_request_type
Request direction / type / recipient.
static unsigned int internal_endpoint_create(struct UX_ENDPOINT_STRUCT *ep)
Endpoint create.
ra8_err_t ux_hcd_ra8_usb_initialize(ra8_usb_speed_t speed)
Ux hcd ra usb initialize.
static unsigned int internal_control_xfer(struct UX_TRANSFER_STRUCT *tr)
Drive the EP0 control transfer SETUP + optional data stage.
unsigned int _ux_hcd_ra8_usb_function(struct UX_HCD_STRUCT *hcd, unsigned int function, void *parameter)
USBX host-side HCD function dispatcher.
ra8_usb_hcd_ctrl_id_t
Private USBX controller-type id reported by this HCD bridge.
@ k_ra8_usb_hcd_controller_id
RA-USB private controller id.
static ra8_usb_hcd_t s_hcd
Bridge instance.
static unsigned int internal_transfer_request(struct UX_TRANSFER_STRUCT *tr)
Transfer request.
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.
ra8_err_t ux_hcd_ra8_usb_uninitialize(void)
Ux hcd ra usb uninitialize.
ra8_usb_hcd_pipe_t
Pipe-index bounds for the host bridge.
@ k_ra8_usb_hcd_pipe_count
Valid pipes 0..9; 10 == out-of-range.
ra8_usb_hcd_ep_addr_field_t
Bit fields of a USB endpoint address (bEndpointAddress).
@ 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).
ra8_usb_hcd_state_t ux_hcd_ra8_usb_state(void)
Ux hcd ra usb state.
static uint8_t internal_ep_to_pipe(uint8_t ep_addr)
Ep to pipe.
static unsigned int internal_port_set_enabled(bool enable)
Enable or disable the root-hub port via DVSTCTR0.UACT.
static unsigned int internal_port_reset(void)
Pulse the root-hub port reset (assert then deassert).
USBX host-controller-driver (HCD) bridge to ra8_usb.
unsigned int _ux_hcd_ra8_usb_function(struct UX_HCD_STRUCT *hcd, unsigned int function, void *parameter)
ux hcd ra usb function.
ra8_usb_hcd_state_t
Run-state of the HCD bridge.
@ k_ux_hcd_ra8_usb_state_uninit
Bridge not yet initialized.
@ k_ux_hcd_ra8_usb_state_ready
Bridge installed; bus idle.
@ k_ux_hcd_ra8_usb_state_active
SOF generation enabled.