ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_usb_dev.c File Reference

USBFS register + CFIFO model (see board_usb_internal.h). More...

#include <stdio.h>
#include <string.h>
#include "board_usb_internal.h"
#include "ra8_elc_regs.h"
#include "ra8_usb_regs.h"
Include dependency graph for board_usb_dev.c:

Go to the source code of this file.

Functions

uint16_t priv_usb_intsts0 (void)
 INTSTS0 value the device reads: event bits OR computed fields.
void priv_usb_intsts0_set (uint8_t bit)
 Set an INTSTS0 event bit in the shadow (host asserts it).
void priv_usb_raise_irq (uc_engine *uc)
 Raise the device controller interrupt (USBFS_INT, or USBHS after a role swap).
static uint8_t internal_cfifo_pipe (void)
 Currently-selected CFIFO pipe number (CFIFOSEL.CURPIPE[3:0]).
static bool internal_cfifo_is_in (void)
 True when CFIFOSEL selects the IN direction (device writes / fills).
static usb_in_buf_tinternal_cfifo_in_buf (void)
 The device-IN staging buffer CFIFOSEL currently points at.
static usb_out_buf_tinternal_cfifo_out_buf (void)
 The device-OUT staging buffer CFIFOSEL currently points at.
static uint16_t internal_cfifo_dtln (void)
 Bytes still available for the device to read on the selected OUT buf.
static uint32_t internal_cfifo_read_port (unsigned size)
 Service a CFIFO data-port read: drain one unit (1..4 bytes) from the OUT buffer.
static void internal_cfifo_write_port (uint32_t value, unsigned size)
 Service a CFIFO data-port write: append one unit (1..4 bytes) to the IN buffer.
static void internal_cfifoctr_write (uint16_t value)
 Apply a CFIFOCTR write: BCLR clears the buffer, BVAL commits an IN.
static uint16_t internal_cfifoctr_read (void)
 CFIFOCTR read value: FRDY always ready, DTLN = OUT bytes available.
uint32_t priv_usb_reg_read (uint64_t off, unsigned size)
 Read one device-controller register; off is the byte offset into the window.
void priv_usb_reg_write (uint64_t off, uint32_t value, unsigned size)
 Write one device-controller register; off is the byte offset into the window.
uint64_t board_usb_read (uc_engine *uc, uint64_t addr, unsigned size, bool *handled)
 Dispatch an MMIO read inside the USBFS register window.
void board_usb_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value, bool *handled)
 Dispatch an MMIO write inside the USBFS register window.

Detailed Description

USBFS register + CFIFO model (see board_usb_internal.h).

The 16-bit reflect-on-read register shadow, the INTSTS0 composition, the CFIFO port/CFIFOCTR staging model and the MMIO window entry points – moved verbatim out of board_usb.c.

Since
0.1.0

Definition in file board_usb_dev.c.

Function Documentation

◆ board_usb_read()

uint64_t board_usb_read ( uc_engine * uc,
uint64_t addr,
unsigned size,
bool * handled )

Dispatch an MMIO read inside the USBFS register window.

Parameters
[in,out]ucUnicorn engine (unused today; kept for symmetry).
[in]addrAbsolute peripheral address being read.
[in]sizeAccess width in bytes (1 / 2 / 4).
[out]handledTrue iff addr is inside the USBFS window.
Returns
The register value when *handled is true, else 0.
Since
0.1.0

Dispatch an mmio read inside the usbfs register window; this step is contained within the board USB model and uses bounded caller or module-owned storage.

Return values
valueThe operation-specific board USB read value.
Precondition
Arguments satisfy the ranges documented for board USB read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 282 of file board_usb_dev.c.

References board_usbhs_host_reg_read(), k_usb_base, k_usb_span, priv_usb_reg_read(), and s_roles_swapped.

Referenced by board_periph_read().

◆ board_usb_write()

void board_usb_write ( uc_engine * uc,
uint64_t addr,
unsigned size,
uint64_t value,
bool * handled )

Dispatch an MMIO write inside the USBFS register window.

Parameters
[in,out]ucUnicorn engine (unused today; kept for symmetry).
[in]addrAbsolute peripheral address being written.
[in]sizeAccess width in bytes (1 / 2 / 4).
[in]valueValue being written.
[out]handledTrue iff addr is inside the USBFS window.
Returns
Nothing.
Since
0.1.0

Dispatch an mmio write inside the usbfs register window; this step is contained within the board USB model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for board USB write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 297 of file board_usb_dev.c.

References board_usb_roles_swap(), board_usbhs_host_reg_write(), k_ra8_syscfg_bit_dcfm, k_ra8_usb_off_syscfg, k_usb_base, k_usb_span, priv_usb_reg_write(), s_external_host, and s_roles_swapped.

Referenced by board_periph_write().

◆ internal_cfifo_dtln()

uint16_t internal_cfifo_dtln ( void )
static

Bytes still available for the device to read on the selected OUT buf.

Bytes still available for the device to read on the selected out buf; this step is contained within the board USB dev model and uses bounded caller or module-owned storage.

Returns
The cfifo dtln result produced by the board USB dev model.
Return values
valueThe operation-specific cfifo dtln value.
Precondition
Arguments satisfy the ranges documented for cfifo dtln.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB dev model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 115 of file board_usb_dev.c.

References internal_cfifo_is_in(), internal_cfifo_out_buf(), and RA8_INTERNAL.

Referenced by internal_cfifoctr_read().

◆ internal_cfifo_in_buf()

usb_in_buf_t * internal_cfifo_in_buf ( void )
static

The device-IN staging buffer CFIFOSEL currently points at.

Definition at line 92 of file board_usb_dev.c.

References internal_cfifo_pipe(), k_usb_pipe_count, RA8_INTERNAL, and s_usb.

Referenced by internal_cfifo_write_port(), and internal_cfifoctr_write().

◆ internal_cfifo_is_in()

bool internal_cfifo_is_in ( void )
static

True when CFIFOSEL selects the IN direction (device writes / fills).

True when cfifosel selects the in direction (device writes / fills); this step is contained within the board USB dev model and uses bounded caller or module-owned storage.

Returns
The cfifo is in result produced by the board USB dev model.
Return values
trueThe cfifo is in condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for cfifo is in.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB dev model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 85 of file board_usb_dev.c.

References internal_usb_word(), k_ra8_fifosel_isel, k_ra8_usb_off_cfifosel, RA8_INTERNAL, and s_usb.

Referenced by internal_cfifo_dtln(), and internal_cfifoctr_write().

◆ internal_cfifo_out_buf()

usb_out_buf_t * internal_cfifo_out_buf ( void )
static

The device-OUT staging buffer CFIFOSEL currently points at.

Definition at line 99 of file board_usb_dev.c.

References internal_cfifo_pipe(), k_usb_pipe_count, RA8_INTERNAL, and s_usb.

Referenced by internal_cfifo_dtln(), internal_cfifo_read_port(), and internal_cfifoctr_write().

◆ internal_cfifo_pipe()

uint8_t internal_cfifo_pipe ( void )
static

Currently-selected CFIFO pipe number (CFIFOSEL.CURPIPE[3:0]).

Currently-selected cfifo pipe number (cfifosel.curpipe[3:0]); this step is contained within the board USB dev model and uses bounded caller or module-owned storage.

Returns
The cfifo pipe result produced by the board USB dev model.
Return values
valueThe operation-specific cfifo pipe value.
Precondition
Arguments satisfy the ranges documented for cfifo pipe.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB dev model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 69 of file board_usb_dev.c.

References internal_usb_word(), k_ra8_fifosel_curpipe, k_ra8_usb_off_cfifosel, RA8_INTERNAL, and s_usb.

Referenced by internal_cfifo_in_buf(), and internal_cfifo_out_buf().

◆ internal_cfifo_read_port()

uint32_t internal_cfifo_read_port ( unsigned size)
static

Service a CFIFO data-port read: drain one unit (1..4 bytes) from the OUT buffer.

Service a cfifo data-port read: drain one unit (1..4 bytes) from the out buffer; this step is contained within the board USB dev model and uses bounded caller or module-owned storage.

Parameters
[in]sizeSize of the requested region or access in bytes.
Returns
The cfifo read port result produced by the board USB dev model.
Return values
valueThe operation-specific cfifo read port value.
Precondition
Arguments satisfy the ranges documented for cfifo read port.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB dev model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 135 of file board_usb_dev.c.

References internal_cfifo_out_buf(), k_usb_byte_bits, and RA8_INTERNAL.

Referenced by priv_usb_reg_read().

◆ internal_cfifo_write_port()

void internal_cfifo_write_port ( uint32_t value,
unsigned size )
static

Service a CFIFO data-port write: append one unit (1..4 bytes) to the IN buffer.

Service a cfifo data-port write: append one unit (1..4 bytes) to the in buffer; this step is contained within the board USB dev model and uses bounded caller or module-owned storage.

Parameters
[in]valueRegister or payload value involved in the operation.
[in]sizeSize of the requested region or access in bytes.
Precondition
Arguments satisfy the ranges documented for cfifo write port.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB dev model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 156 of file board_usb_dev.c.

References internal_cfifo_in_buf(), k_usb_byte_bits, k_usb_byte_mask, and RA8_INTERNAL.

Referenced by priv_usb_reg_write().

◆ internal_cfifoctr_read()

uint16_t internal_cfifoctr_read ( void )
static

CFIFOCTR read value: FRDY always ready, DTLN = OUT bytes available.

Cfifoctr read value: frdy always ready, dtln = out bytes available; this step is contained within the board USB dev model and uses bounded caller or module-owned storage.

Returns
The cfifoctr read result produced by the board USB dev model.
Return values
valueThe operation-specific cfifoctr read value.
Precondition
Arguments satisfy the ranges documented for cfifoctr read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB dev model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 208 of file board_usb_dev.c.

References internal_cfifo_dtln(), k_ra8_fifoctr_dtln, k_ra8_fifoctr_frdy, and RA8_INTERNAL.

Referenced by priv_usb_reg_read().

◆ internal_cfifoctr_write()

void internal_cfifoctr_write ( uint16_t value)
static

Apply a CFIFOCTR write: BCLR clears the buffer, BVAL commits an IN.

Apply a cfifoctr write: bclr clears the buffer, bval commits an in; this step is contained within the board USB dev model and uses bounded caller or module-owned storage.

Parameters
[in]valueRegister or payload value involved in the operation.
Precondition
Arguments satisfy the ranges documented for cfifoctr write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board USB dev model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 174 of file board_usb_dev.c.

References internal_cfifo_in_buf(), internal_cfifo_is_in(), internal_cfifo_out_buf(), k_ra8_fifoctr_bclr, k_ra8_fifoctr_bval, RA8_INTERNAL, and usb_in_buf_t::valid.

Referenced by priv_usb_reg_write().

◆ priv_usb_intsts0()

uint16_t priv_usb_intsts0 ( void )

INTSTS0 value the device reads: event bits OR computed fields.

INTSTS0 value the device reads: event bits OR computed fields (dev).

Definition at line 23 of file board_usb_dev.c.

References internal_usb_word(), 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_intsts0_mask_ctsq, k_ra8_intsts0_mask_dvsq, k_ra8_intsts0_mask_valid, k_ra8_intsts0_mask_vbsts, k_ra8_usb_off_intsts0, and s_usb.

Referenced by priv_usb_reg_read().

◆ priv_usb_intsts0_set()

◆ priv_usb_raise_irq()

◆ priv_usb_reg_read()

uint32_t priv_usb_reg_read ( uint64_t off,
unsigned size )

◆ priv_usb_reg_write()

void priv_usb_reg_write ( uint64_t off,
uint32_t value,
unsigned size )

Write one device-controller register; off is the byte offset into the window.

USBFS window register write dispatch (dev).

Definition at line 253 of file board_usb_dev.c.

References internal_cfifo_write_port(), internal_cfifoctr_write(), internal_usb_word(), k_ra8_intsts0_mask_valid, k_ra8_usb_off_cfifo, k_ra8_usb_off_cfifoctr, k_ra8_usb_off_intsts0, k_usb_cfifo_h, k_usb_cfifo_hh, and s_usb.

Referenced by board_usb_dev_reg_write(), and board_usb_write().