35static const char*
s_tag =
"USB";
189 if (reg ==
nullptr) {
237 if (reg ==
nullptr) {
270 if (reg ==
nullptr) {
345 if (reg ==
nullptr) {
370 if (reg ==
nullptr) {
396 if (reg ==
nullptr) {
421 if (reg ==
nullptr) {
481 if (reg ==
nullptr) {
597 const uint8_t ctr_idx = (uint8_t)(pipe_num - 1U);
598 const uint16_t pipe_bit = (uint16_t)(1U << pipe_num);
602 reg->
BRDYSTS = (uint16_t)(~pipe_bit);
603 reg->
BEMPSTS = (uint16_t)(~pipe_bit);
630 const uint16_t pipe_bit = (uint16_t)(1U << pipe_num);
669 if (reg ==
nullptr) {
719 if (reg ==
nullptr) {
725 if (pipe_num == 0U) {
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.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ 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_val(tag, message, value)
RA8 log info val.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
void priv_dcp_pid(volatile r_usb_regs_t *reg, ra8_usb_pid_t pid)
Set DCPCTR PID field to a specific value while preserving the rest of the register.
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.
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_mstp_t priv_mstp(ra8_usb_speed_t speed)
Resolve the per-speed MSTP id.
volatile r_usb_regs_t * priv_pick(ra8_usb_speed_t speed)
Resolve the per-speed register pointer.
uint16_t priv_pipebuf_word(uint8_t pipe_num, uint16_t max_packet)
Compute the PIPEBUF word for a bulk pipe (2*MPS region).
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_pipe_quiesce(volatile r_usb_regs_t *reg, uint8_t pipe_num)
Quiesce the pipe so PIPECFG/PIPEMAXP/PIPEPERI become writable.
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.
Native USB controller driver public API (device + host modes).
static ra8_err_t internal_check_ep_args(uint8_t pipe_num, uint8_t ep_addr, ra8_usb_ep_dir_t dir, ra8_usb_ep_type_t type, uint16_t max_packet)
Validate the argument set for ra8_usb_configure_endpoint.
ra8_err_t ra8_usb_device_init(ra8_usb_speed_t speed)
Implementation of ra8_usb_device_init().
static ra8_usb_dev_state_t internal_decode_dvsq(uint16_t intsts0)
Translate INTSTS0.DVSQ[2:0] into the public state enum.
volatile uint16_t g_syscfg_after_attach
SYSCFG snapshot captured at the end of ra8_usb_device_attach(true).
static void internal_pipe_arm_irq(volatile r_usb_regs_t *reg, uint8_t pipe_num, ra8_usb_ep_dir_t dir)
Re-arm the per-pipe interrupt the dispatcher routes off of.
volatile uint16_t g_syscfg_before_dprpu
SYSCFG snapshot captured immediately BEFORE the DPRPU write.
volatile uint16_t g_lpsts_after_attach
LPSTS snapshot at the end of ra8_usb_device_attach(true).
static void internal_dcp_reset_defaults(volatile r_usb_regs_t *reg)
Reset DCP defaults + clear DCP FIFO on bus-reset rearm.
ra8_err_t ra8_usb_device_busreset_rearm(ra8_usb_speed_t speed)
Implementation of ra8_usb_device_busreset_rearm (see header).
ra8_err_t ra8_usb_set_address(ra8_usb_speed_t speed, uint8_t address)
Implementation of ra8_usb_set_address().
ra8_err_t ra8_usb_get_device_state(ra8_usb_speed_t speed, ra8_usb_dev_state_t *out_state)
Implementation of ra8_usb_get_device_state().
ra8_err_t ra8_usb_device_deinit(ra8_usb_speed_t speed)
Implementation of ra8_usb_device_deinit().
static void internal_pipe_finalize(volatile r_usb_regs_t *reg, uint8_t pipe_num, ra8_usb_ep_dir_t dir)
Finalize the pipe after PIPECFG/PIPEMAXP/PIPEPERI have landed.
ra8_err_t ra8_usb_stall_endpoint(ra8_usb_speed_t speed, uint8_t pipe_num)
Implementation of ra8_usb_stall_endpoint().
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)
Implementation of ra8_usb_configure_endpoint().
ra8_err_t ra8_usb_device_attach(ra8_usb_speed_t speed, bool attached)
Implementation of ra8_usb_device_attach().
volatile uint16_t g_syscfg_after_phy_bringup
SYSCFG snapshot captured at the end of ra8_usb_device_init.
volatile uint16_t g_lpsts_after_phy_bringup
LPSTS snapshot at the end of ra8_usb_device_init.
volatile uint16_t g_syssts0_after_attach
SYSSTS0 snapshot captured at the end of ra8_usb_device_attach(true).
ra8_err_t ra8_usb_get_status(ra8_usb_speed_t speed, uint16_t *out_mask)
Implementation of ra8_usb_get_status().
ra8_err_t ra8_usb_clear_status(ra8_usb_speed_t speed, uint16_t mask)
Implementation of ra8_usb_clear_status().
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.
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).
ra8_usb_dev_state_t
Decoded INTSTS0.DVSQ[2:0] device-state values.
@ k_ra8_usb_dev_state_suspended
Suspended.
@ k_ra8_usb_dev_state_default
Default (post reset).
@ k_ra8_usb_dev_state_address
Address assigned.
@ k_ra8_usb_dev_state_configured
Configured.
@ k_ra8_usb_dev_state_powered
Powered, no reset yet.
Cross-TU surface for the ra8_usb driver split.
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).
@ k_ra8_usb_max_address
7-bit USB address.
@ k_ra8_usb_pipe_max_packet
Max packet ceiling for pipes.
@ k_ra8_usb_max_pipe_num
PIPE1..PIPE9 + DCP at 0.
@ k_ra8_usb_max_ep_addr
USB EP number is 4 bits.
@ k_ra8_usb_dcp_max_packet
EP0 default packet size.
ra8_err_t priv_usbfs_module_bringup(volatile r_usb_regs_t *reg)
USBFS module bring-up (FSP hw_usb_pmodule_init IP0 branch).
USB Full-Speed + High-Speed controller layout for the Renesas RA8D2.
static volatile uint16_t * ra8_usbhs_lpsts(void)
Get pointer to USBHS LPSTS register.
@ k_ra8_pipectr_aclrm
Auto buffer clear mode.
@ k_ra8_pipectr_sqclr
Toggle clear.
@ k_ra8_pid_buf
BUF response (transmit/receive).
@ k_ra8_pid_nak
NAK response.
@ k_ra8_pid_stall
STALL response.
@ k_ra8_syscfg_bit_dprpu
D+ pull-up enable (device).
@ k_ra8_syscfg_bit_cnen
Single-end receiver enable.
@ k_ra8_fifoctr_bclr
Buffer clear.
@ k_ra8_usbaddr_addr_mask
7-bit USB address [6:0].
@ k_ra8_intsts0_mask_dvsq
Device state.
@ k_ra8_int0_bit_bemp
Buffer-empty interrupt.
@ k_ra8_int0_bit_dvst
Device-state transition.
@ k_ra8_int0_bit_brdy
Buffer-ready interrupt.
@ k_ra8_int0_bit_ctrt
Control-transfer-stage transition.
@ k_ra8_int0_bit_vbse
VBUS change.
@ k_ra8_int0_bit_nrdy
Buffer-not-ready interrupt.
@ k_ra8_dvsq_suspend
Suspended (any sub-state).
@ k_ra8_dvsq_address
Address assigned.
@ k_ra8_dvsq_default
Default (post bus reset).
@ k_ra8_dvsq_configured
Configured.
@ k_ra8_usb_pipectr_count
PIPECTR[9] = PIPE1..PIPE9.
USB FS / HS register window (device-mode subset).
volatile uint16_t NRDYENB
+0x038 NRDY Interrupt Enable.
volatile uint16_t CFIFOCTR
+0x022 Control FIFO control.
volatile uint16_t DCPMAXP
+0x05E DCP Max Packet.
volatile uint16_t USBADDR
+0x050 USB Address.
volatile uint16_t PIPECTR[k_ra8_usb_pipectr_count]
+0x070 PIPE1..9 ctrl.
volatile uint16_t INTENB0
+0x030 Interrupt Enable 0.
volatile uint16_t INTSTS0
+0x040 Interrupt Status 0.
volatile uint16_t PIPEPERI
+0x06E Selected pipe period.
volatile uint16_t SYSCFG
+0x000 System Configuration.
volatile uint16_t SYSSTS0
+0x004 System Status 0.
volatile uint16_t BRDYENB
+0x036 BRDY Interrupt Enable.
volatile uint16_t PIPEMAXP
+0x06C Selected pipe max packet.
volatile uint16_t BEMPSTS
+0x04A BEMP Interrupt Status.
volatile uint16_t PIPEBUF
+0x06A Selected pipe buffer.
volatile uint16_t PIPECFG
+0x068 Selected pipe config.
volatile uint16_t INTENB1
+0x032 Interrupt Enable 1.
volatile uint16_t DCPCFG
+0x05C DCP Configuration.
volatile uint16_t NRDYSTS
+0x048 NRDY Interrupt Status.
volatile uint16_t BEMPENB
+0x03A BEMP Interrupt Enable.
volatile uint16_t PIPESEL
+0x064 Pipe window select.
volatile uint16_t BRDYSTS
+0x046 BRDY Interrupt Status.