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

USBX device-controller-driver bridge to ra8_usb – endpoint dispatch. More...

#include <stdint.h>
#include <string.h>
#include "ra8_check.h"
#include "ra8_elc_regs.h"
#include "ra8_isr.h"
#include "ra8_log.h"
#include "ra8_usb_regs.h"
#include "tx_api.h"
#include "ux_api.h"
#include "ux_dcd_ra8_usb.h"
#include "ux_dcd_ra8_usb_internal.h"
#include "ux_device_stack.h"
#include "ux_system.h"
#include "ux_utility.h"
Include dependency graph for ux_dcd_ra8_usb_ep.c:

Go to the source code of this file.

Macros

#define UX_SOURCE_CODE

Functions

static void internal_endpoint_arm_out_pid (uint8_t pipe, uint8_t ep_addr)
 Set the power-on PID of a freshly created non-control pipe.
static unsigned int internal_endpoint_create (struct UX_SLAVE_ENDPOINT_STRUCT *ep)
 Translate a USBX endpoint create request into ra8_usb call.
static unsigned int internal_endpoint_stall (struct UX_SLAVE_ENDPOINT_STRUCT *ep)
 Endpoint stall.
static unsigned int internal_endpoint_destroy (struct UX_SLAVE_ENDPOINT_STRUCT *ep)
 Drop the bridge's per-pipe transfer stash for a destroyed endpoint.
static void internal_count_change_state (unsigned long state)
 Count UX_DCD_CHANGE_STATE notifications by target state.
unsigned int _ux_dcd_ra8_usb_function (struct UX_SLAVE_DCD_STRUCT *dcd, unsigned int function, void *parameter)
 USBX device-side DCD function dispatcher.

Detailed Description

USBX device-controller-driver bridge to ra8_usb – endpoint dispatch.

Tag
[Ring 5 / PORT] {World: S}

USBX DCD function trampoline plus the endpoint create / destroy / stall helpers and the CHANGE_STATE accounting.

Split out of ux_dcd_ra8_usb.c to keep each translation unit under the maintainability line cap; the cross-translation-unit contract lives in ux_dcd_ra8_usb_internal.h.

Since
0.1.0

Definition in file ux_dcd_ra8_usb_ep.c.

Macro Definition Documentation

◆ UX_SOURCE_CODE

#define UX_SOURCE_CODE

Definition at line 21 of file ux_dcd_ra8_usb_ep.c.

Function Documentation

◆ _ux_dcd_ra8_usb_function()

unsigned int _ux_dcd_ra8_usb_function ( struct UX_SLAVE_DCD_STRUCT * dcd,
unsigned int function,
void * parameter )

USBX device-side DCD function dispatcher.

ux dcd ra usb function.

Stamped into UX_SLAVE_DCD::ux_slave_dcd_function during ux_dcd_ra8_usb_initialize. The USBX device stack calls this with a UX_DCD_* selector to request endpoint create/destroy, transfer request, transfer abort, stall, and similar primitives; the trampoline routes each to the matching internal_* helper.

Parameters
[in,out]dcdUSBX DCD ownership block (currently unused; the bridge keeps its own static state in g_dcd).
[in]functionUSBX UX_DCD_* selector (e.g. UX_DCD_TRANSFER_REQUEST).
[in,out]parameterSelector-dependent argument (UX_SLAVE_TRANSFER* / UX_SLAVE_ENDPOINT* / opaque).
Returns
USBX result code from the dispatched helper.
Return values
UX_SUCCESSFunction handled.
UX_CONTROLLER_UNKNOWNBridge has not been initialized.
UX_ERRORSelector unsupported, or helper rejected the call.
UX_TRANSFER_ERRORTransfer-request helper failed.
Precondition
Bridge is past ux_dcd_ra8_usb_initialize (or the call returns UX_CONTROLLER_UNKNOWN).
Caller is the USBX device stack.
Postcondition
g_dcd updated per the dispatched selector.
Wire-side state may have been mutated (CREATE / STALL).
Note
Runs on the USBX device task context; not ISR-safe.
Since
0.1.0

Definition at line 281 of file ux_dcd_ra8_usb_ep.c.

References g_dcd, internal_count_change_state(), internal_endpoint_create(), internal_endpoint_destroy(), internal_endpoint_stall(), k_ux_dcd_ra8_usb_state_active, k_ux_dcd_ra8_usb_state_ready, k_ux_dcd_ra8_usb_state_uninit, and priv_transfer_request().

Referenced by internal_init_bind_owner(), and internal_init_setup_ep0().

◆ internal_count_change_state()

void internal_count_change_state ( unsigned long state)
static

Count UX_DCD_CHANGE_STATE notifications by target state.

Diagnostic brackets around the chapter-9 configuration walk: the stack notifies ATTACHED during teardown and CONFIGURED at the end, so the counter pair shows how far configuration processing ran (read via JLink alongside g_diag).

Parameters
[in]stateThe UX device state being announced.
Precondition
Called from the DCD function dispatcher only.
g_diag is single-writer per counter.
Postcondition
The matching counter is incremented (others untouched).
No other state changes.
Note
Diagnostic only; never read by production code.
Since
0.1.0

Definition at line 238 of file ux_dcd_ra8_usb_ep.c.

References g_diag, and RA8_INTERNAL.

Referenced by _ux_dcd_ra8_usb_function().

◆ internal_endpoint_arm_out_pid()

void internal_endpoint_arm_out_pid ( uint8_t pipe,
uint8_t ep_addr )
static

Set the power-on PID of a freshly created non-control pipe.

Called once from internal_endpoint_create after ra8_usb_configure_endpoint. An IN pipe is left as configured – the queue_in path and internal_submit_pipe own its PID. An OUT pipe is armed to PID=BUF only when the in-ISR auto-echo path drains it (CDC loopback); every other OUT pipe is parked at PID=NAK so a host OUT token arriving before internal_submit_pipe arms a real receiver is NAK-flow-controlled rather than ACKed into a FIFO with no waiter – the latter latches BRDYSTS and storms the ISR (GitHub issue #6). Nested ifs keep the auto-echo test out of the MC/DC inventory.

Parameters
[in]pipePipe index (1..max_pipes-1).
[in]ep_addrEndpoint address (bit 7 = direction).
Precondition
ra8_usb_configure_endpoint has run for this pipe.
Bridge speed g_dcd.speed is valid.
Postcondition
OUT pipe PID is BUF (auto-echo pipe) or NAK (all others).
IN pipe PID is left unchanged.
Note
Single-threaded create-path use; not ISR-safe.
Since
0.1.0

Definition at line 64 of file ux_dcd_ra8_usb_ep.c.

References g_dcd, g_dcd_auto_echo_enable, g_dcd_auto_echo_out_pipe, g_orphan_len, k_ra8_usb_ep_addr_dir_in_bit, RA8_INTERNAL, ra8_usb_park_out_pipe(), and ra8_usb_rearm_out_pipe().

Referenced by internal_endpoint_create().

◆ internal_endpoint_create()

unsigned int internal_endpoint_create ( struct UX_SLAVE_ENDPOINT_STRUCT * ep)
static

Translate a USBX endpoint create request into ra8_usb call.

See implementation for details.

Parameters
[in,out]epSee function signature.
Returns
Result code or value; see implementation.
Return values
0Success or default value.
Precondition
Module has been initialized.
Caller has validated arguments.
Postcondition
Side effects bounded to documented state.
State reflects operation result.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 100 of file ux_dcd_ra8_usb_ep.c.

References g_dcd, g_diag, internal_endpoint_arm_out_pid(), k_ra8_ok, k_ra8_usb_ep_addr_dir_in_bit, k_ra8_usb_ep_addr_num_mask, k_ra8_usb_ep_dir_in, k_ra8_usb_ep_dir_out, k_ra8_usb_ep_type_bulk, k_ra8_usb_ep_type_intr, k_ra8_usb_ep_type_iso, k_ux_dcd_ra8_usb_max_pipes, priv_ep_to_pipe(), RA8_INTERNAL, and ra8_usb_configure_endpoint().

Referenced by _ux_dcd_ra8_usb_function().

◆ internal_endpoint_destroy()

unsigned int internal_endpoint_destroy ( struct UX_SLAVE_ENDPOINT_STRUCT * ep)
static

Drop the bridge's per-pipe transfer stash for a destroyed endpoint.

USBX calls UX_DCD_DESTROY_ENDPOINT when a class driver tears down an interface (e.g. SET_CONFIGURATION(0) or device detach). The ra8_usb register layer has no per-pipe destroy primitive, so the cleanup we owe is forgetting any cached UX_SLAVE_TRANSFER* so the IRQ path cannot post a completion against a defunct request.

Parameters
[in]epUSBX endpoint pointer (the parameter from the dispatch).
Returns
UX_SUCCESS, or UX_ERROR if ep is null.
Return values
UX_SUCCESSPipe stash cleared (or pipe was out of range).
UX_ERRORep was null.
Precondition
Bridge is past ux_dcd_ra8_usb_initialize.
Caller is the USBX device-stack dispatcher.
Postcondition
g_dcd.pipes[pipe].xfer is nullptr for the named pipe.
No wire-side state mutated.
Note
Runs on the USBX device task context.
Since
0.1.0

Definition at line 208 of file ux_dcd_ra8_usb_ep.c.

References g_dcd, k_ux_dcd_ra8_usb_max_pipes, priv_ep_to_pipe(), and RA8_INTERNAL.

Referenced by _ux_dcd_ra8_usb_function().

◆ internal_endpoint_stall()

unsigned int internal_endpoint_stall ( struct UX_SLAVE_ENDPOINT_STRUCT * ep)
static

Endpoint stall.

See implementation for details.

Parameters
[in,out]epSee function signature for type and usage.
Returns
Result code or value; see implementation.
Return values
0Success or default value.
Precondition
Caller has validated arguments.
Module has been initialized.
Postcondition
Side effects bounded to documented state.
Returned value reflects current state.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 169 of file ux_dcd_ra8_usb_ep.c.

References g_dcd, k_ra8_ok, k_ux_dcd_ra8_usb_max_pipes, priv_ep_to_pipe(), RA8_INTERNAL, and ra8_usb_stall_endpoint().

Referenced by _ux_dcd_ra8_usb_function().