|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
USB IRQ dispatch / event callbacks / power + host-mode bring-up. More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_log.h"#include "ra8_mstp.h"#include "ra8_usb.h"#include "ra8_usb_internal.h"#include "ra8_usb_regs.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_usb_cb_slot_t : uint8_t { k_ra8_usb_cb_slot_fs = 0U , k_ra8_usb_cb_slot_hs = 1U , k_ra8_usb_cb_slot_n = 2U } |
| enum | ra8_usb_dvstctr_bit_t : uint8_t { k_ra8_dvstctr_bit_uact = 4U , k_ra8_dvstctr_bit_vbusen = 9U , k_ra8_dvstctr_bit_resume = 5U , k_ra8_dvstctr_bit_usbrst = 6U , k_ra8_dvstctr_bit_rwupe = 7U } |
| DVSTCTR0 host-mode bit positions (HUM Ch 36.2.5 "DVSTCTR0"). More... | |
Variables | |
| static const char * | s_tag = "USB" |
| static ra8_usb_event_fn_t | s_usb_fn [k_ra8_usb_cb_slot_n] |
| static void * | s_usb_ctx [k_ra8_usb_cb_slot_n] |
USB IRQ dispatch / event callbacks / power + host-mode bring-up.
Two cohesive groups split out of ra8_usb.c to keep every translation unit under the 1000-line cap:
The shared register helpers and the USBHS PHY bring-up it calls are declared in ra8_usb_internal.h. Modelled on FSP r_usb_hreg_access.c; no FSP source ships in this tree.
Definition in file ra8_usb_irq.c.
| enum ra8_usb_cb_slot_t : uint8_t |
| Enumerator | |
|---|---|
| k_ra8_usb_cb_slot_fs | RA8 USB cb slot fs. |
| k_ra8_usb_cb_slot_hs | RA8 USB cb slot hs. |
| k_ra8_usb_cb_slot_n | RA8 USB cb slot n. |
Definition at line 52 of file ra8_usb_irq.c.
| enum ra8_usb_dvstctr_bit_t : uint8_t |
DVSTCTR0 host-mode bit positions (HUM Ch 36.2.5 "DVSTCTR0").
Sourced from CMSIS R_USB_FS0_DVSTCTR0_*_Pos in R7KA8D2KF_core0.h (lines 71382-71389) and confirmed for the HS instance (R_USB_HS0_DVSTCTR0_*_Pos, lines 75228-75235).
Definition at line 238 of file ra8_usb_irq.c.
|
static |
Map a USB speed enum to the per-controller callback slot index.
Two slots exist: k_ra8_usb_cb_slot_fs for the USBFS controller and k_ra8_usb_cb_slot_hs for the USBHS controller. Every code path that indexes s_usb_fn[] or s_usb_ctx[] goes through this helper so we never confuse the two.
| [in] | speed | Controller selector (FS or HS). |
| k_ra8_usb_cb_slot_hs | speed == k_ra8_usb_speed_hs. |
| k_ra8_usb_cb_slot_fs | Any other speed value (FS default). |
Definition at line 84 of file ra8_usb_irq.c.
References k_ra8_usb_cb_slot_fs, k_ra8_usb_cb_slot_hs, and k_ra8_usb_speed_hs.
Referenced by ra8_usb_attach_handler(), and ra8_usb_dispatch().
|
static |
Bring the USBHS instance up in HOST role (PHY + SYSCFG bits).
The HS PHY needs the full UTMI bring-up (CLKSEL, DIRPD and PLLRESET release, SUSPENDM, PLLLOCK) before the module can operate; reuse the device-mode sequence, which ends with USBE=1 and the device-polarity DRPD=0. Then flip the role bits: HUM Ch 37.2.1 requires DCFM to be changed while USBE=0, so drop USBE, set DCFM (host controller) + DRPD (host pull-downs) + CNEN, and re-enable. CNEN (single-ended receiver enable) is required for the HS PHY to report line state / attach at all – without it LNST reads SE0 forever and no ATTCH ever latches (HUM Ch 37.2.1 p 2062).
| [in] | reg | HS register block (must be the USBHS instance). |
| k_ra8_ok | PHY locked; SYSCFG carries the host role. |
| k_ra8_err_hw_timeout | The UTMI PLL never locked. |
Definition at line 346 of file ra8_usb_irq.c.
References k_ra8_ok, k_ra8_syscfg_bit_cnen, k_ra8_syscfg_bit_dcfm, k_ra8_syscfg_bit_drpd, k_ra8_syscfg_bit_usbe, priv_rmw16(), priv_usbhs_phy_bringup(), RA8_RETURN_ON_ERROR, s_tag, and r_usb_regs_t::SYSCFG.
Referenced by ra8_usb_host_init().
|
static |
Program the host-mode FIFO / DCP / interrupt-enable defaults.
Shared tail of host bring-up for both controller instances: 16-bit FIFO port widths (the per-access width is re-selected by priv_select_cfifo), DCP defaults with a 64-byte max packet, USBADDR=0 (newly attached devices answer at the default address), and the host interrupt-enable mask (per-pipe ENB registers stay clear; the transfer engines arm exactly what they wait on).
| [in] | reg | Selected controller register block. |
Definition at line 294 of file ra8_usb_irq.c.
References r_usb_regs_t::BEMPENB, r_usb_regs_t::BRDYENB, r_usb_regs_t::CFIFOSEL, r_usb_regs_t::D0FIFOSEL, r_usb_regs_t::D1FIFOSEL, r_usb_regs_t::DCPCFG, r_usb_regs_t::DCPCTR, r_usb_regs_t::DCPMAXP, r_usb_regs_t::INTENB0, r_usb_regs_t::INTENB1, k_ra8_fifosel_mbw_16, k_ra8_int0_bit_bemp, k_ra8_int0_bit_brdy, k_ra8_int0_bit_ctrt, k_ra8_int0_bit_dvst, k_ra8_int0_bit_nrdy, k_ra8_int0_bit_vbse, k_ra8_usb_dcp_max_packet, r_usb_regs_t::NRDYENB, and r_usb_regs_t::USBADDR.
Referenced by ra8_usb_host_init().
|
static |
Build the host-mode SYSCFG word.
Sets SCKE | DCFM | DRPD | USBE; adds HSE for the HS instance. DPRPU is intentionally not set (device-mode pull-up).
| [in] | speed | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 263 of file ra8_usb_irq.c.
References k_ra8_syscfg_bit_dcfm, k_ra8_syscfg_bit_drpd, k_ra8_syscfg_bit_hse, k_ra8_syscfg_bit_scke, k_ra8_syscfg_bit_usbe, and k_ra8_usb_speed_hs.
Referenced by ra8_usb_host_init().
| void ra8_usb_attach_handler | ( | ra8_usb_speed_t | speed, |
| ra8_usb_event_fn_t | fn, | ||
| void * | ctx ) |
Install (or detach) the per-controller USB event handler.
Each controller (USBFS, USBHS) has its own callback slot, so one firmware image can run different upper-layer drivers on each controller simultaneously (e.g. USBX/DCD bridge on USBHS, a bare-CDC handler on USBFS). The matching ra8_usb_dispatch(speed) only fires the callback registered for that speed.
| [in] | speed | Which controller's callback slot to update. |
| [in] | fn | Callback. NULL detaches. |
| [in] | ctx | Context passed to fn. |
Slot replacement performs no fallible work; callers observe completion when this function returns.
speed is k_ra8_usb_speed_fs or k_ra8_usb_speed_hs. fn. fn prevents subsequent callback invocation for the selected controller.Definition at line 90 of file ra8_usb_irq.c.
References internal_cb_slot(), s_usb_ctx, and s_usb_fn.
Referenced by ra8_usb_pal_deinit(), ra8_usb_pal_init(), ux_dcd_ra8_usb_initialize(), and ux_dcd_ra8_usb_uninitialize().
| void ra8_usb_dispatch | ( | ra8_usb_speed_t | speed | ) |
Implementation of ra8_usb_dispatch().
Snapshot INTSTS0 and fire the installed event handler.
See the public header for the documented contract; this definition implements it.
| [in] | speed | See implementation. |
Definition at line 109 of file ra8_usb_irq.c.
References internal_cb_slot(), r_usb_regs_t::INTSTS0, k_ra8_int0_bit_bemp, k_ra8_int0_bit_brdy, k_ra8_int0_bit_ctrt, k_ra8_int0_bit_dvst, k_ra8_int0_bit_nrdy, k_ra8_int0_bit_rsme, k_ra8_int0_bit_sofr, k_ra8_int0_bit_vbse, priv_pick(), s_usb_ctx, and s_usb_fn.
Referenced by internal_usbfs_isr(), internal_usbhs_isr(), and ns_usb_worker().
|
nodiscard |
Implementation of ra8_usb_enter_stop().
Drop the controller's MSTP gate without touching SYSCFG.
See the public header for the documented contract; this definition implements it.
| [in] | speed | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 192 of file ra8_usb_irq.c.
References k_ra8_err_invalid_arg, k_ra8_usb_speed_fs, k_ra8_usb_speed_hs, priv_mstp(), and ra8_mstp_disable().
|
nodiscard |
Implementation of ra8_usb_exit_stop().
Re-enable the controller's MSTP gate (counterpart to ra8_usb_enter_stop).
See the public header for the documented contract; this definition implements it.
| [in] | speed | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 213 of file ra8_usb_irq.c.
References k_ra8_err_invalid_arg, k_ra8_usb_speed_fs, k_ra8_usb_speed_hs, priv_mstp(), and ra8_mstp_enable().
|
nodiscard |
Implementation of ra8_usb_host_bus_reset().
Drive (or release) the bus reset line.
See the public header for the documented contract; this definition implements it.
| [in] | speed | See implementation. |
| [in] | assert_reset | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 455 of file ra8_usb_irq.c.
References r_usb_regs_t::DVSTCTR0, k_ra8_dvstctr_bit_uact, k_ra8_dvstctr_bit_usbrst, k_ra8_err_invalid_arg, k_ra8_ok, priv_pick(), and priv_rmw16().
Referenced by cdc_enum_hunt(), dfu_enum_hunt(), hid_enum_hunt(), hid_enum_hunt(), internal_do_bus_reset(), internal_do_bus_reset(), internal_do_bus_reset(), internal_do_bus_reset(), internal_do_bus_reset(), internal_do_idle(), internal_do_idle(), internal_do_idle(), internal_do_idle(), internal_do_idle(), internal_enum_hunt(), internal_enum_hunt(), internal_port_reset(), and ns_host_enum_hunt().
|
nodiscard |
Implementation of ra8_usb_host_deinit().
Tear down a host-mode controller and drop its MSTP reference.
See the public header for the documented contract; this definition implements it.
| [in] | speed | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 424 of file ra8_usb_irq.c.
References r_usb_regs_t::BEMPENB, r_usb_regs_t::BRDYENB, r_usb_regs_t::DVSTCTR0, r_usb_regs_t::INTENB0, r_usb_regs_t::INTENB1, k_ra8_err_invalid_arg, r_usb_regs_t::NRDYENB, priv_mstp(), priv_pick(), ra8_mstp_disable(), and r_usb_regs_t::SYSCFG.
Referenced by cdc_host_pass(), dfu_host_enumerate(), dfu_host_pass(), hid_host_pass(), hid_host_pass(), ns_host_worker(), ra8_dfu_host_program(), ra8_dfu_host_run(), ra8_usb_haud_close(), ra8_usb_hcdc_close(), ra8_usb_hcdc_ecm_close(), ra8_usb_hhid_close(), ra8_usb_hhub_close(), ra8_usb_hmsc_close(), and ux_hcd_ra8_usb_uninitialize().
|
nodiscard |
Implementation of ra8_usb_host_init().
Bring up a USB controller in HOST mode.
See the public header for the documented contract; this definition implements it.
| [in] | speed | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 375 of file ra8_usb_irq.c.
References r_usb_regs_t::DVSTCTR0, internal_host_hs_bringup(), internal_host_init_defaults(), internal_host_syscfg_word(), k_ra8_dvstctr_bit_vbusen, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_usb_speed_hs, priv_mstp(), priv_pick(), priv_rmw16(), ra8_log_info_val, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, s_tag, and r_usb_regs_t::SYSCFG.
Referenced by cdc_host_pass(), dfu_host_pass(), hid_host_pass(), hid_host_pass(), ns_host_worker(), ra8_board_usbhs_host_init(), ra8_dfu_host_program(), ra8_dfu_host_run(), ra8_usb_haud_init(), ra8_usb_hcdc_ecm_init(), ra8_usb_hcdc_init(), ra8_usb_hhid_init(), ra8_usb_hhub_init(), ra8_usb_hmsc_init(), and ux_hcd_ra8_usb_initialize().
|
nodiscard |
Implementation of ra8_usb_host_set_uact().
Enable / disable SOF (Start-of-Frame) generation on the bus.
See the public header for the documented contract; this definition implements it.
| [in] | speed | See implementation. |
| [in] | enable | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 487 of file ra8_usb_irq.c.
References r_usb_regs_t::DVSTCTR0, k_ra8_dvstctr_bit_uact, k_ra8_err_invalid_arg, k_ra8_ok, priv_pick(), and priv_rmw16().
Referenced by cdc_enum_hunt(), dfu_enum_hunt(), hid_enum_hunt(), hid_enum_hunt(), internal_enum_hunt(), internal_enum_hunt(), internal_port_set_enabled(), ns_host_enum_hunt(), ra8_usb_haud_close(), ra8_usb_hcdc_close(), ra8_usb_hcdc_ecm_close(), ra8_usb_hhid_close(), ra8_usb_hhub_close(), ra8_usb_hmsc_close(), and ux_hcd_ra8_usb_uninitialize().
|
nodiscard |
Implementation of ra8_usb_host_setup_request().
Issue a SETUP packet through the DCP (host -> peripheral).
See the public header for the documented contract; this definition implements it.
| [in] | speed | See implementation. |
| [in] | setup | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 517 of file ra8_usb_irq.c.
References ra8_usb_setup_t::b_request, ra8_usb_setup_t::bm_request_type, r_usb_regs_t::DCPCTR, k_ra8_dcpctr_bit_sureq, k_ra8_err_busy, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_usb_byte_bits, priv_pick(), priv_rmw16(), RA8_CHECK_NULL_PTR, s_tag, r_usb_regs_t::USBINDX, r_usb_regs_t::USBLENG, r_usb_regs_t::USBREQ, r_usb_regs_t::USBVAL, ra8_usb_setup_t::w_index, ra8_usb_setup_t::w_length, and ra8_usb_setup_t::w_value.
Referenced by internal_control_xfer(), internal_setup_get_descriptor(), internal_setup_get_descriptor(), internal_setup_get_descriptor(), internal_setup_get_descriptor(), internal_setup_get_descriptor(), internal_setup_get_hub_descriptor(), internal_setup_get_report_descriptor(), internal_setup_set_address(), internal_setup_set_address(), internal_setup_set_address(), internal_setup_set_address(), internal_setup_set_address(), internal_setup_set_config(), internal_setup_set_config(), internal_setup_set_config(), internal_setup_set_config(), internal_setup_set_config(), internal_setup_set_interface(), internal_setup_set_interface(), internal_setup_set_interface(), internal_setup_set_interface_data(), internal_setup_set_packet_filter(), ra8_usb_haud_set_format(), ra8_usb_haud_set_mute(), ra8_usb_haud_set_volume(), ra8_usb_hcdc_ecm_get_link_status(), ra8_usb_hcdc_set_line_coding(), ra8_usb_hhid_get_report(), ra8_usb_hhid_set_idle(), ra8_usb_hhid_set_protocol(), ra8_usb_hhid_set_report(), ra8_usb_hhub_clear_port_feature(), ra8_usb_hhub_get_port_status(), and ra8_usb_hhub_set_port_feature().
| uint16_t ra8_usb_intsts0_snapshot | ( | ra8_usb_speed_t | speed | ) |
Implementation of ra8_usb_intsts0_snapshot().
Read INTSTS0 without acking any bits.
Pure MMIO read; no INTSTS0 bits are modified.
| [in] | speed | See header. |
| 0 | Invalid speed or controller not powered. |
Definition at line 170 of file ra8_usb_irq.c.
References r_usb_regs_t::INTSTS0, and priv_pick().
Referenced by internal_usbfs_isr(), internal_usbhs_isr(), and ns_usb_worker().
|
static |
Definition at line 41 of file ra8_usb_irq.c.
|
static |
Definition at line 59 of file ra8_usb_irq.c.
Referenced by ra8_usb_attach_handler(), and ra8_usb_dispatch().
|
static |
Definition at line 58 of file ra8_usb_irq.c.
Referenced by ra8_usb_attach_handler(), and ra8_usb_dispatch().