|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Cross-TU surface for the ra8_usb driver split. More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_err.h"#include "ra8_mstp.h"#include "ra8_usb.h"#include "ra8_usb_regs.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_usb_internal_lim_t : uint16_t { k_ra8_usb_max_pipe_num = 9U , k_ra8_usb_max_ep_addr = 15U , k_ra8_usb_max_address = 127U , k_ra8_usb_dcp_max_packet = 64U , k_ra8_usb_pipe_max_packet = 1024U } |
| Driver-wide bounds that aren't part of the public API. More... | |
| enum | ra8_usb_byte_mask_t : uint16_t { k_ra8_usb_byte_mask = 0x00FFU , k_ra8_usb_byte_bits = 8U } |
| Byte-extraction masks shared across the FIFO byte path. More... | |
| enum | ra8_usb_host_ctrl_bits_t : uint16_t { k_ra8_usb_dcp_pipe0_bit = 0x0001U , k_ra8_usb_setup_dir_in = 0x0080U , k_ra8_usb_dcpmaxp_mxps = 0x007FU , k_ra8_usb_rhst_mask = 0x0007U , k_ra8_usb_lnst_mask = 0x0003U } |
| Bit masks used by the host control-transfer engine. More... | |
| enum | ra8_usb_host_devadd_t : uint32_t { k_ra8_usb_devadd0_off = 0x00D0U , k_ra8_usb_usbspd_shift = 6U , k_ra8_usb_devadd_stride = 2U , k_ra8_usb_dev_addr_max = 10U } |
| Offsets / shifts for the device-address (DEVADDn) registers. More... | |
| enum | ra8_usb_host_addr_bits_t : uint16_t { k_ra8_usb_devsel_shift = 12U , k_ra8_usb_devsel_field_mask = 0x000FU , k_ra8_usb_pipemaxp_mxps = 0x07FFU , k_ra8_usb_pid_stall_bit = 0x0002U } |
| Field layout helpers for host-mode device addressing. More... | |
Functions | |
| volatile r_usb_regs_t * | priv_pick (ra8_usb_speed_t speed) |
| Resolve the per-speed register pointer. | |
| ra8_mstp_t | priv_mstp (ra8_usb_speed_t speed) |
| Resolve the per-speed MSTP id. | |
| void | priv_rmw16 (volatile uint16_t *reg, uint16_t set_mask, uint16_t clr_mask) |
| Apply a generic read-modify-write to a 16-bit register. | |
| bool | priv_is_hs (volatile const r_usb_regs_t *reg) |
| Detect whether reg points at the USBHS (IP1) register block. | |
| void | priv_select_cfifo (volatile r_usb_regs_t *reg, uint16_t pipe_num, bool is_in_dir) |
| Set CFIFOSEL.MBW + CURPIPE + ISEL for the given pipe / direction. | |
| ra8_err_t | priv_wait_frdy (volatile r_usb_regs_t *reg) |
| Spin until CFIFOCTR.FRDY asserts or a deadline elapses. | |
| void | priv_dcp_pid (volatile r_usb_regs_t *reg, ra8_usb_pid_t pid) |
| Set DCPCTR PID field while preserving the rest of the register. | |
| void | priv_pipe_pid (volatile r_usb_regs_t *reg, uint8_t pipe_num, ra8_usb_pid_t pid) |
| Set PIPECTR[idx] PID field. | |
| void | priv_fifo_write (volatile r_usb_regs_t *reg, const uint8_t *data, uint16_t len) |
| Push a byte buffer into the CFIFO data port. | |
| void | priv_fifo_read (volatile r_usb_regs_t *reg, uint8_t *data, uint16_t len) |
| Drain the CFIFO data port into a buffer. | |
| ra8_err_t | priv_dcp_push_chunk (volatile r_usb_regs_t *reg, const uint8_t *p, uint16_t n) |
| Push a single DCP IN chunk: wait FRDY, write FIFO, pulse BVAL. | |
| uint16_t | priv_pipebuf_word (uint8_t pipe_num, uint16_t max_packet) |
| Compute the PIPEBUF word for a bulk pipe (2*MPS region). | |
| uint16_t | priv_pipecfg_word (uint8_t ep_addr, ra8_usb_ep_dir_t dir, ra8_usb_ep_type_t type, bool dblb_in) |
| Pack PIPECFG fields for a configured non-control pipe. | |
| void | priv_pipe_quiesce (volatile r_usb_regs_t *reg, uint8_t pipe_num) |
| Quiesce the pipe so PIPECFG/PIPEMAXP/PIPEPERI become writable. | |
| ra8_err_t | priv_usbhs_phy_bringup (volatile r_usb_regs_t *reg) |
| USBHS embedded-PHY bring-up (HUM Figure 37.2 p 2121). | |
| void | priv_usb_init_common (volatile r_usb_regs_t *reg) |
| Programme the post-SYSCFG common registers (FIFO, DCP, INTENB). | |
| ra8_err_t | priv_usbfs_module_bringup (volatile r_usb_regs_t *reg) |
| USBFS module bring-up (FSP hw_usb_pmodule_init IP0 branch). | |
| void | priv_host_program_devadd (volatile r_usb_regs_t *reg, uint8_t dev_addr) |
| Program DEVADDn.USBSPD with the connected device's link speed. | |
Cross-TU surface for the ra8_usb driver split.
Not part of the public API. The native USB controller driver (HUM Ch 36 USBFS, Ch 37 USBHS) was partitioned across several translation units so every file stays under the 1000-line cap:
This header declares every symbol referenced by more than one of those TUs: the shared bound enums, the byte-mask helpers, the host addressing-field enums, and the promoted register helpers (which were TU-private statics before the split). Production code keeps calling the public ra8_usb_* API in ra8_usb.h; the symbols here are an implementation detail of the driver split only. See CLAUDE.md "Test access to internal symbols (MC/DC scope)".
Definition in file ra8_usb_internal.h.
| enum ra8_usb_byte_mask_t : uint16_t |
Byte-extraction masks shared across the FIFO byte path.
| Enumerator | |
|---|---|
| k_ra8_usb_byte_mask | Low byte of a 16-bit FIFO word. |
| k_ra8_usb_byte_bits | Bits per byte (shift constant). |
Definition at line 70 of file ra8_usb_internal.h.
| enum ra8_usb_host_addr_bits_t : uint16_t |
Field layout helpers for host-mode device addressing.
Definition at line 93 of file ra8_usb_internal.h.
| enum ra8_usb_host_ctrl_bits_t : uint16_t |
Bit masks used by the host control-transfer engine.
Definition at line 76 of file ra8_usb_internal.h.
| enum ra8_usb_host_devadd_t : uint32_t |
Offsets / shifts for the device-address (DEVADDn) registers.
Definition at line 85 of file ra8_usb_internal.h.
| enum ra8_usb_internal_lim_t : uint16_t |
Driver-wide bounds that aren't part of the public API.
Definition at line 58 of file ra8_usb_internal.h.
| void priv_dcp_pid | ( | volatile r_usb_regs_t * | reg, |
| ra8_usb_pid_t | pid ) |
Set DCPCTR PID field while preserving the rest of the register.
Promoted from a TU-private static so the device, control, and host engines drive the DCP PID through one accessor.
| [in,out] | reg | DCP register block. |
| [in] | pid | PID encoding to write (NAK / BUF / STALL). |
Set DCPCTR PID field while preserving the rest of the register.
See implementation.
| [in] | reg | See implementation. |
| [in] | pid | See implementation. |
Definition at line 288 of file ra8_usb.c.
References r_usb_regs_t::DCPCTR, k_ra8_pid_mask, and priv_rmw16().
Referenced by internal_dcp_in_payload(), internal_dcp_in_zlp(), internal_host_ctrl_data_arm(), internal_host_ctrl_data_in(), internal_host_ctrl_data_out(), internal_host_ctrl_setup(), internal_host_ctrl_status(), internal_host_dcp_in_wait(), ra8_usb_control_response(), ra8_usb_dcp_out_arm(), ra8_usb_dcp_out_read(), and ra8_usb_stall_endpoint().
| ra8_err_t priv_dcp_push_chunk | ( | volatile r_usb_regs_t * | reg, |
| const uint8_t * | p, | ||
| uint16_t | n ) |
Push a single DCP IN chunk: wait FRDY, write FIFO, pulse BVAL.
Promoted from a TU-private static so both the device DCP-IN data path and the host control-write data path share one chunk push.
| [in,out] | reg | DCP register block (chip or host shim). |
| [in] | p | Source byte pointer; must hold at least n bytes. |
| [in] | n | Chunk size in bytes; must be > 0 and <= the DCP MPS. |
| k_ra8_ok | Chunk queued; BVAL pulsed. |
| k_ra8_err_hw_timeout | FRDY never asserted within the bound. |
Push a single DCP IN chunk: wait FRDY, write FIFO, pulse BVAL.
Bounded helper extracted from ra8_usb_dcp_in_data so the top-level function stays under the clang-tidy readability-function-size threshold. Performs exactly one controller-buffer transfer cycle.
| [in,out] | reg | DCP register block (chip or host shim). |
| [in] | p | Source byte pointer; must hold at least n bytes. |
| [in] | n | Chunk size in bytes; must be > 0 and <= the DCP MPS. |
| k_ra8_ok | Chunk queued; BVAL pulsed. |
| k_ra8_err_timeout | FRDY never asserted within the bound. |
Definition at line 770 of file ra8_usb.c.
References r_usb_regs_t::CFIFOCTR, k_ra8_fifoctr_bval, k_ra8_ok, priv_fifo_write(), priv_wait_frdy(), RA8_RETURN_ON_ERROR, and s_tag.
Referenced by internal_dcp_in_payload(), and internal_host_ctrl_data_out().
| void priv_fifo_read | ( | volatile r_usb_regs_t * | reg, |
| uint8_t * | data, | ||
| uint16_t | len ) |
Drain the CFIFO data port into a buffer.
Promoted from a TU-private static. Dispatches to the speed-appropriate access width (USBHS 32-bit, USBFS 16-bit).
| [in] | reg | USB instance register block. |
| [out] | data | Destination byte pointer (may be NULL when len == 0). |
| [in] | len | Number of bytes to drain. |
Dispatches to the speed-appropriate access width: USBHS requires 32-bit reads (MBW=32) – a 16-bit read does not advance the FIFO read pointer (HUM Ch 37.2.7 p 2070, FSP hw_usb_read_fifo32). USBFS keeps MBW=16. Mirrors FSP usb_pstd_read_fifo for IP1/IP0.
| [in] | reg | USB instance register block. |
| [out] | data | Destination byte pointer (may be NULL when len == 0). |
| [in] | len | Number of bytes to drain. |
Definition at line 712 of file ra8_usb.c.
References r_usb_regs_t::CFIFO, r_usb_regs_t::CFIFOSEL, internal_fifo_read_hs_head(), internal_fifo_read_hs_tail(), k_ra8_fifosel_mbw_8, k_ra8_fifosel_mbw_msk, k_ra8_usb_byte_bits, k_ra8_usb_byte_mask, and priv_is_hs().
Referenced by internal_host_bulk_rx_packet(), internal_host_ctrl_data_in(), ra8_usb_dcp_out_read(), and ra8_usb_queue_out().
| void priv_fifo_write | ( | volatile r_usb_regs_t * | reg, |
| const uint8_t * | data, | ||
| uint16_t | len ) |
Push a byte buffer into the CFIFO data port.
Promoted from a TU-private static. Dispatches to the speed-appropriate access width (USBHS 32-bit, USBFS 16-bit).
| [in] | reg | USB instance register block. |
| [in] | data | Source byte pointer (may be NULL when len == 0). |
| [in] | len | Number of bytes to push. |
Dispatches to the speed-appropriate access width: USBHS uses 32-bit writes (with FSP-style 16/8 narrowing for the trailing 0..3 bytes), USBFS uses 16-bit writes with a single-byte tail. Mirrors FSP usb_pstd_write_fifo for IP1 / IP0 respectively.
| [in] | reg | USB instance register block. |
| [in] | data | Source byte pointer (may be NULL when len == 0). |
| [in] | len | Number of bytes to push. |
Definition at line 592 of file ra8_usb.c.
References r_usb_regs_t::CFIFO, r_usb_regs_t::CFIFOSEL, internal_fifo_write_hs_head(), internal_fifo_write_hs_tail(), k_ra8_fifosel_mbw_8, k_ra8_fifosel_mbw_msk, k_ra8_usb_byte_bits, and priv_is_hs().
Referenced by priv_dcp_push_chunk(), and ra8_usb_queue_in().
| void priv_host_program_devadd | ( | volatile r_usb_regs_t * | reg, |
| uint8_t | dev_addr ) |
Program DEVADDn.USBSPD with the connected device's link speed.
Promoted from a TU-private static so the host control engine (ra8_usb_host_ctrl.c) and the host bulk engine (ra8_usb_host_bulk.c) share one DEVADDn programmer. The DEVADDn registers sit past the modelled register window, so this addresses the slot by raw offset (0xD0 + 2n) and copies DVSTCTR0.RHST into USBSPD[7:6].
| [in] | reg | Selected controller register block (its base address). |
| [in] | dev_addr | Address slot to program (0..k_ra8_usb_dev_addr_max). |
reg is non-NULL and dev_addr is within the DEVADD range. The RA host SIE will not run transactions to a device address until that address's DEVADDn slot carries the link speed. The DEVADDn registers sit past the modelled register window, so this addresses the slot by raw offset (0xD0 + 2n) and copies DVSTCTR0.RHST (01=LS, 10=FS, 11=HS) into USBSPD[7:6].
| [in] | reg | Selected controller register block (its base address). |
| [in] | dev_addr | Address slot to program (0..k_ra8_usb_dev_addr_max). |
reg is non-NULL and dev_addr is within the DEVADD range. Definition at line 91 of file ra8_usb_host_ctrl.c.
References r_usb_regs_t::DVSTCTR0, k_ra8_usb_devadd0_off, k_ra8_usb_devadd_stride, k_ra8_usb_rhst_mask, and k_ra8_usb_usbspd_shift.
Referenced by internal_host_ctrl_setup(), and ra8_usb_host_set_target().
| bool priv_is_hs | ( | volatile const r_usb_regs_t * | reg | ) |
Detect whether reg points at the USBHS (IP1) register block.
Promoted from a TU-private static so the FIFO byte-mover, the host control engine, and the bulk engine share one IP predicate.
| [in] | reg | USB instance register block pointer. |
| true | USBHS (IP1) – caller should use MBW=32 + 32-bit FIFO. |
| false | USBFS (IP0) – caller should use MBW=16 + 16-bit FIFO. |
FSP gates USB1_CFIFO_MBW = USB_MBW_32 on the same predicate (p_utr->ip == USB_CFG_IP1), and the FIFO write helpers below mirror that to keep CFIFOSEL.MBW and the CFIFO write width in agreement on each controller.
| [in] | reg | USB instance register block pointer. |
| true | USBHS (IP1) – caller should use MBW=32 + 32-bit FIFO. |
| false | USBFS (IP0) – caller should use MBW=16 + 16-bit FIFO. |
Definition at line 179 of file ra8_usb.c.
References ra8_usb_hs().
Referenced by internal_host_ctrl_setup(), priv_fifo_read(), priv_fifo_write(), and priv_select_cfifo().
| ra8_mstp_t priv_mstp | ( | ra8_usb_speed_t | speed | ) |
Resolve the per-speed MSTP id.
Promoted from a TU-private static so the lifecycle and power TUs share one speed-to-MSTP mapping.
| [in] | speed | Controller selector (FS / HS). |
| k_ra8_mstp_usbhs | speed == k_ra8_usb_speed_hs. |
| k_ra8_mstp_usbfs | Any other speed value. |
See implementation.
| [in] | speed | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 135 of file ra8_usb.c.
References k_ra8_mstp_usbfs, k_ra8_mstp_usbhs, and k_ra8_usb_speed_hs.
Referenced by ra8_usb_device_deinit(), ra8_usb_device_init(), ra8_usb_enter_stop(), ra8_usb_exit_stop(), ra8_usb_host_deinit(), and ra8_usb_host_init().
| volatile r_usb_regs_t * priv_pick | ( | ra8_usb_speed_t | speed | ) |
Resolve the per-speed register pointer.
Promoted from a TU-private static so every TU in the driver split can map a ra8_usb_speed_t to its controller register block.
| [in] | speed | Controller selector (FS / HS). |
| nullptr | speed is neither FS nor HS. |
Definition at line 110 of file ra8_usb.c.
References k_ra8_usb_speed_fs, k_ra8_usb_speed_hs, ra8_usb_fs(), and ra8_usb_hs().
Referenced by ra8_usb_clear_status(), ra8_usb_configure_endpoint(), ra8_usb_control_response(), ra8_usb_dcp_in_data(), ra8_usb_dcp_out_arm(), ra8_usb_dcp_out_read(), ra8_usb_device_attach(), ra8_usb_device_busreset_rearm(), ra8_usb_device_deinit(), ra8_usb_device_init(), ra8_usb_dispatch(), ra8_usb_get_device_state(), ra8_usb_get_status(), ra8_usb_host_bulk_in(), ra8_usb_host_bulk_out(), ra8_usb_host_bus_reset(), ra8_usb_host_control_xfer(), ra8_usb_host_deinit(), ra8_usb_host_init(), ra8_usb_host_line_state(), ra8_usb_host_pipe_setup(), ra8_usb_host_set_target(), ra8_usb_host_set_uact(), ra8_usb_host_setup_request(), ra8_usb_intsts0_snapshot(), ra8_usb_park_out_pipe(), ra8_usb_queue_in(), ra8_usb_queue_out(), ra8_usb_read_setup_if_valid(), ra8_usb_read_setup_unconditional(), ra8_usb_rearm_out_pipe(), ra8_usb_set_address(), and ra8_usb_stall_endpoint().
| void priv_pipe_pid | ( | volatile r_usb_regs_t * | reg, |
| uint8_t | pipe_num, | ||
| ra8_usb_pid_t | pid ) |
Set PIPECTR[idx] PID field.
Promoted from a TU-private static so the pipe-config, device-data, and host engines share one pipe PID accessor.
| [in,out] | reg | Controller register block. |
| [in] | pipe_num | Pipe index 1..9. |
| [in] | pid | PID encoding to write (NAK / BUF / STALL). |
See implementation.
| [in] | reg | See implementation. |
| [in] | pipe_num | See implementation. |
| [in] | pid | See implementation. |
Definition at line 308 of file ra8_usb.c.
References k_ra8_pid_mask, r_usb_regs_t::PIPECTR, and priv_rmw16().
Referenced by internal_pipe_finalize(), priv_pipe_quiesce(), ra8_usb_host_bulk_in(), ra8_usb_host_bulk_out(), ra8_usb_park_out_pipe(), ra8_usb_queue_in(), ra8_usb_queue_out(), ra8_usb_rearm_out_pipe(), and ra8_usb_stall_endpoint().
| void priv_pipe_quiesce | ( | volatile r_usb_regs_t * | reg, |
| uint8_t | pipe_num ) |
Quiesce the pipe so PIPECFG/PIPEMAXP/PIPEPERI become writable.
Promoted from a TU-private static so both the device-side and host-side pipe configurators park a pipe at PID=NAK before re-programming.
| [in,out] | reg | Controller register window. |
| [in] | pipe_num | Pipe index 1..9. |
Clears BRDYENB/NRDYENB/BEMPENB for this pipe and forces PID=NAK (HUM Ch 36.2.24 NOTE 1, p 1996; mirrors STAR rx_usb_hw.c::internal_usb_quiesce_pipe).
| [in,out] | reg | Controller register window. |
| [in] | pipe_num | Pipe index 1..9. |
Definition at line 447 of file ra8_usb.c.
References r_usb_regs_t::BEMPENB, r_usb_regs_t::BRDYENB, k_ra8_pid_nak, r_usb_regs_t::NRDYENB, and priv_pipe_pid().
Referenced by ra8_usb_configure_endpoint(), and ra8_usb_host_pipe_setup().
| uint16_t priv_pipebuf_word | ( | uint8_t | pipe_num, |
| uint16_t | max_packet ) |
Compute the PIPEBUF word for a bulk pipe (2*MPS region).
Promoted from a TU-private static so the device-side and host-side pipe configurators pack PIPEBUF the same way.
| [in] | pipe_num | PIPE number 1..9. |
| [in] | max_packet | Pipe MPS (bytes). |
| 0..0xFFFF | Packed BUFNMB/BUFSIZE word (no error condition). |
Statically partition the controller's internal FIFO RAM among the bulk pipes. Reserve blocks 0..7 (64-byte units) for the DCP (per FSP/Renesas examples), then pack user pipes in pipe-number order with 2*MPS per pipe – IN bulk pipes use both as a double-buffer (PIPECFG.DBLB set), OUT bulk pipes use only the first block (DBLB clear). Uniform 2*MPS keeps the BUFNMB arithmetic simple and wastes at most one block per OUT pipe.
BUFNMB = 8 + (pipe_num - 1) * (2 * mps_blocks) BUFSIZE = (2 * mps_blocks) - 1
HS MPS=512 -> 2*mps_blocks = 16, BUFSIZE = 15 FS MPS=64 -> 2*mps_blocks = 2, BUFSIZE = 1
| [in] | pipe_num | PIPE number 1..9. |
| [in] | max_packet | Pipe MPS (bytes). |
| 0..0xFFFF | Packed BUFNMB/BUFSIZE word (no error condition; the helper is total over its enum-checked inputs). |
Definition at line 353 of file ra8_usb.c.
References k_ra8_pipebuf_block_bytes, k_ra8_pipebuf_bufnmb_mask, and k_ra8_pipebuf_bufsize_shift.
Referenced by ra8_usb_configure_endpoint(), and ra8_usb_host_pipe_setup().
| uint16_t priv_pipecfg_word | ( | uint8_t | ep_addr, |
| ra8_usb_ep_dir_t | dir, | ||
| ra8_usb_ep_type_t | type, | ||
| bool | dblb_in ) |
Pack PIPECFG fields for a configured non-control pipe.
Promoted from a TU-private static so the device-side and host-side pipe configurators encode PIPECFG the same way.
| [in] | ep_addr | Endpoint address (low nibble = EP number). |
| [in] | dir | Pipe direction (k_ra8_usb_ep_dir_in or _out). |
| [in] | type | Pipe type (bulk / interrupt / iso). |
| [in] | dblb_in | Double-bank bulk IN pipes (host mode true, device mode false; ignored for OUT / non-bulk). |
| 0..0xFFFF | Packed configuration word; no error condition. |
Encodes endpoint number, direction (DIR), pipe type (TYPE), and for bulk pipes the SHTNAK flag plus (optionally, IN only) the DBLB flag into the PIPECFG word. HUM Ch 36.2.24 PIPECFG. Bulk OUT is always single-buffered, otherwise the controller fills both banks with host data and the one-bank-per-call ra8_usb_queue_out drainer wedges the data phase (GitHub issue #6). Bulk IN double-banking is the caller's choice: HOST mode wants it so queue_in can push a data + ZLP pair back-to-back without the second push hitting a full-bank FRDY stall; DEVICE mode must run single-banked because the free-bank handshake after an MPS-exact fill is unreliable (staging the BOT CSW behind a 512-byte data phase on a 512-MPS HS pipe FRDY-times-out and the transport wedges, observed live vs macOS).
| [in] | ep_addr | Endpoint address (low nibble = EP number; bit 7 direction; the helper reads only the EP number). |
| [in] | dir | Pipe direction (k_ra8_usb_ep_dir_in or _out). |
| [in] | type | Pipe type (bulk / interrupt / iso). |
| [in] | dblb_in | Double-bank bulk IN pipes (host mode true, device mode false; ignored for OUT / non-bulk). |
| 0..0xFFFF | Packed configuration word; no error condition. |
Definition at line 401 of file ra8_usb.c.
References k_ra8_pipecfg_dblb, k_ra8_pipecfg_dir_in, k_ra8_pipecfg_epnum_mask, k_ra8_pipecfg_shtnak, k_ra8_pipecfg_type_bulk, k_ra8_pipecfg_type_intr, k_ra8_pipecfg_type_iso, k_ra8_usb_ep_dir_in, k_ra8_usb_ep_dir_out, k_ra8_usb_ep_type_bulk, and k_ra8_usb_ep_type_intr.
Referenced by ra8_usb_configure_endpoint(), and ra8_usb_host_pipe_setup().
| void priv_rmw16 | ( | volatile uint16_t * | reg, |
| uint16_t | set_mask, | ||
| uint16_t | clr_mask ) |
Apply a generic read-modify-write to a 16-bit register.
Promoted from a TU-private static. Clears clr_mask then sets set_mask in one read / modify / store cycle.
| [in,out] | reg | Target register pointer; must not be nullptr. |
| [in] | set_mask | Bits to set. |
| [in] | clr_mask | Bits to clear (applied before the set). |
See implementation.
| [in] | reg | See implementation. |
| [in] | set_mask | See implementation. |
| [in] | clr_mask | See implementation. |
Definition at line 154 of file ra8_usb.c.
Referenced by internal_host_ctrl_data_arm(), internal_host_ctrl_data_out(), internal_host_ctrl_setup(), internal_host_ctrl_status(), internal_host_hs_bringup(), internal_host_setup_wait(), internal_pipe_finalize(), priv_dcp_pid(), priv_pipe_pid(), ra8_usb_control_response(), ra8_usb_dcp_out_arm(), ra8_usb_device_attach(), ra8_usb_host_bus_reset(), ra8_usb_host_init(), ra8_usb_host_pipe_setup(), ra8_usb_host_set_uact(), and ra8_usb_host_setup_request().
| void priv_select_cfifo | ( | volatile r_usb_regs_t * | reg, |
| uint16_t | pipe_num, | ||
| bool | is_in_dir ) |
Set CFIFOSEL.MBW + CURPIPE + ISEL for the given pipe / direction.
Promoted from a TU-private static. Picks MBW=32 for USBHS (FSP USB1_CFIFO_MBW) and MBW=16 for USBFS, then waits for the CURPIPE/ISEL readback to settle.
| [in] | reg | USB instance register block. |
| [in] | pipe_num | CURPIPE value (0 = DCP, 1..n = data pipe). |
| [in] | is_in_dir | true = device-to-host (write), false = the other way. |
Picks MBW=32 for USBHS (FSP USB1_CFIFO_MBW) and MBW=16 for USBFS (FSP USB0_CFIFO_MBW). The CFIFO data-port access width must match the MBW field on subsequent CFIFO accesses.
| [in] | reg | USB instance register block. |
| [in] | pipe_num | CURPIPE value (0 = DCP, 1..n = data pipe). |
| [in] | is_in_dir | true = device-to-host (write), false = host-to-device. |
Definition at line 199 of file ra8_usb.c.
References r_usb_regs_t::CFIFOSEL, k_ra8_fifosel_curpipe, k_ra8_fifosel_isel, k_ra8_fifosel_mbw_16, k_ra8_fifosel_mbw_32, k_ra8_usb_fifosel_settle_limit, and priv_is_hs().
Referenced by internal_dcp_reset_defaults(), internal_host_bulk_rx_packet(), internal_host_ctrl_data_arm(), internal_host_ctrl_data_in(), internal_host_ctrl_data_out(), internal_host_ctrl_status(), ra8_usb_dcp_in_data(), ra8_usb_dcp_out_arm(), ra8_usb_dcp_out_read(), ra8_usb_queue_in(), and ra8_usb_queue_out().
| void priv_usb_init_common | ( | volatile r_usb_regs_t * | reg | ) |
Programme the post-SYSCFG common registers (FIFO, DCP, INTENB).
Promoted from a TU-private static in ra8_usb_phy.c so the device-mode init (ra8_usb_device.c) can apply the shared FS/HS tail of device bring-up.
| [in] | reg | Selected USB instance register block. |
Shared tail of FS and HS device-mode bring-up: CFIFOSEL, DCP defaults, and the device-mode INTENB0 interrupt mask.
| [in] | reg | Selected USB instance register block. |
Definition at line 495 of file ra8_usb_phy.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, r_usb_regs_t::INTSTS0, 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, and r_usb_regs_t::NRDYENB.
Referenced by ra8_usb_device_init().
| ra8_err_t priv_usbfs_module_bringup | ( | volatile r_usb_regs_t * | reg | ) |
USBFS module bring-up (FSP hw_usb_pmodule_init IP0 branch).
Promoted from a TU-private static in ra8_usb_phy.c so the device-mode init (ra8_usb_device.c) can run the FS SYSCFG sequence.
| [in] | reg | FS register block pointer (must be ra8_usb_fs()). |
| k_ra8_ok | USBE asserted. |
| k_ra8_err_hw_timeout | SCKE did not acknowledge within the bounded wait. |
Sets SCKE, polls SCKE-readback, clears DRPD, sets USBE. The FS instance has no PHY-side registers (PHYSET / LPSTS / PLLSTA are HS-only) so this is a pure SYSCFG-driven sequence.
| [in] | reg | FS register block pointer (must be ra8_usb_fs()). |
| k_ra8_ok | USBE asserted. |
Definition at line 566 of file ra8_usb_phy.c.
References k_ra8_err_hw_timeout, k_ra8_ok, k_ra8_syscfg_bit_drpd, k_ra8_syscfg_bit_scke, k_ra8_syscfg_bit_usbe, k_ra8_usbhs_scke_poll_limit, and r_usb_regs_t::SYSCFG.
Referenced by ra8_usb_device_init().
| ra8_err_t priv_usbhs_phy_bringup | ( | volatile r_usb_regs_t * | reg | ) |
USBHS embedded-PHY bring-up (HUM Figure 37.2 p 2121).
Promoted from a TU-private static in ra8_usb_phy.c so both the device-mode init (ra8_usb_device.c) and the host-mode init (ra8_usb_irq.c) can run the UTMI PHY bring-up. Implements the device-mode PHY bring-up flow from HUM Ch 37.3.3 + Figure 37.2.
| [in] | reg | HS register block pointer (must be ra8_usb_hs()). |
| k_ra8_ok | HS PHY locked and ready for DPRPU attach. |
| k_ra8_err_hw_timeout | PLLSTA.PLLLOCK never asserted. |
Implements the device-mode PHY bring-up flow exactly as documented in HUM Ch 37.3.3 + Figure 37.2. The PHY UTMI internal PLL takes EXTAL directly (24 MHz on EK-RA8D2); USB60CLK = 60 MHz is the separate LINK domain clock supplied by ra8_cgc_usbhs_pll_enable.
BUSWAIT = 0x0F04 (4-wait + reserved b11-b8)
The HS instance has no SCKE bit (HUM Ch 37.2.1 "SYSCFG" register layout, p 2060); writing bit 10 there is a no-op.
| [in] | reg | HS register block pointer (must be ra8_usb_hs()). |
| k_ra8_ok | HS PHY locked and ready for DPRPU attach. |
| k_ra8_err_hw_timeout | PLLSTA.PLLLOCK never asserted. |
Definition at line 427 of file ra8_usb_phy.c.
References r_usb_regs_t::BUSWAIT, internal_usbhs_enable_syscfg(), internal_usbhs_try_clksel(), k_ra8_buswait_default, k_ra8_ok, k_ra8_physet_clksel_24, k_ra8_physet_repsel_16, k_ra8_syscfg_bit_hse, k_ra8_usbhs_clksel_no_winner, k_ra8_usbhs_phy_step_clksel_12, k_ra8_usbhs_phy_step_hse_set, k_ra8_usbhs_phy_step_pll_locked, k_ra8_usbhs_phy_step_usbe_set, ra8_log_error, ra8_usbhs_lpsts(), ra8_usbhs_physet(), s_clksel_attempt_pllsta, s_clksel_winner, s_phy_step_probe, s_tag, s_usbhs_init_probe, s_usbhs_pllsta_probe, and r_usb_regs_t::SYSCFG.
Referenced by internal_host_hs_bringup(), and ra8_usb_device_init().
| ra8_err_t priv_wait_frdy | ( | volatile r_usb_regs_t * | reg | ) |
Spin until CFIFOCTR.FRDY asserts or a deadline elapses.
Promoted from a TU-private static. Bounded busy-wait shared by every CFIFO read / write path.
| [in] | reg | USB instance register block. |
| k_ra8_ok | FRDY asserted within the bound. |
| k_ra8_err_hw_timeout | FRDY never asserted. |
Runs the real bounded FRDY poll on every build. On the host unit-test build each poll's loop-exit decision is routed through the ra8_fake_mmio fault seam keyed on CFIFOCTR: first-poll success when no fault is armed, or a test-armed retry / timeout leg (T1-01).
| [in] | reg | Selected controller register block (non-NULL). |
| k_ra8_ok | FRDY observed before the deadline. |
| k_ra8_err_hw_timeout | FRDY never asserted within the budget. |
reg points at a live controller register block. Definition at line 251 of file ra8_usb.c.
References r_usb_regs_t::CFIFOCTR, k_ra8_err_hw_timeout, k_ra8_fifoctr_frdy, k_ra8_ok, and k_ra8_usb_frdy_poll_limit.
Referenced by internal_dcp_in_zlp(), internal_host_bulk_rx_packet(), internal_host_ctrl_data_in(), priv_dcp_push_chunk(), ra8_usb_dcp_out_read(), ra8_usb_queue_in(), and ra8_usb_queue_out().