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

Host-side self-test ladder, console formatters, and echo pattern. More...

#include "usb_selftest_cdc_steps.h"
#include <stdint.h>
#include <string.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_err.h"
#include "ra8_time.h"
#include "ra8_usb.h"
Include dependency graph for usb_selftest_cdc_steps.c:

Go to the source code of this file.

Enumerations

enum  cdc_hex_t : uint8_t {
  k_cdc_hex_chars_u16 = 4U ,
  k_cdc_hex_chars_u32 = 8U ,
  k_cdc_dec_chars_u32 = 10U ,
  k_cdc_nibble_bits = 4U ,
  k_cdc_hex_digit_split = 10U
}
 Hex/decimal text-formatter sizing constants. More...
enum  cdc_mask_t : uint32_t {
  k_cdc_nibble_mask = 0xFU ,
  k_cdc_dec_radix = 10U
}
 Bit-mask constants used by the text formatters. More...
enum  cdc_phase_t : uint32_t {
  k_cdc_phase_boot = 0U ,
  k_cdc_phase_init = 1U ,
  k_cdc_phase_enum = 2U ,
  k_cdc_phase_verify = 3U ,
  k_cdc_phase_pass = 4U
}
 J-Link probe values marking host-ladder progress. More...
enum  cdc_usb_req_t : uint16_t {
  k_cdc_bm_std_dev_in = 0x80U ,
  k_cdc_bm_std_dev_out = 0x00U ,
  k_cdc_breq_get_desc = 0x06U ,
  k_cdc_breq_set_addr = 0x05U ,
  k_cdc_breq_set_config = 0x09U ,
  k_cdc_desc_device = 0x01U ,
  k_cdc_dev_desc_len = 18U ,
  k_cdc_off_dev_pid = 10U ,
  k_cdc_byte_bits = 8U ,
  k_cdc_config_value = 1U
}
 Standard chapter-9 request / descriptor constants for the host. More...
enum  cdc_enum_tune_t : uint32_t {
  k_cdc_vbus_settle_ms = 200U ,
  k_cdc_attach_to_ms = 2000U ,
  k_cdc_debounce_ms = 500U ,
  k_cdc_reset_hold_ms = 50U ,
  k_cdc_recovery_ms = 20U ,
  k_cdc_addr_settle_ms = 5U ,
  k_cdc_enum_tries = 8U ,
  k_cdc_attach_spin = 50000000U
}
 Timing / retry tunables for the polled enumeration ladder. More...

Functions

static void cdc_pattern_fill (uint32_t round, uint8_t *out, uint32_t len)
 Fill an echo payload with this round's deterministic bytes.
static uint8_t cdc_nibble_to_hex (uint32_t nibble)
 Format one nibble (0..15) into an uppercase hex character.
static uint32_t cdc_str_len (const char *text)
 Bounded ASCII string length (cap k_cdc_print_cap).
static ra8_err_t cdc_sci_write (const uint8_t *data, uint32_t len)
 Push a literal block over SCI8 polled.
static ra8_err_t cdc_print (const char *text)
 Print a NUL-terminated ASCII string over the console.
static ra8_err_t cdc_print_dec (uint32_t value)
 Print a uint32_t as ASCII decimal.
static ra8_err_t cdc_print_hex (uint32_t value, uint8_t digits)
 Print a value as fixed-width uppercase hex.
static ra8_err_t cdc_print_fail (const char *what, ra8_err_t err)
 Print "FAIL <what> err=0xNNNNNNNN" on its own line.
static ra8_err_t cdc_ctrl_get_dev_desc (uint8_t *desc)
 GET_DESCRIPTOR(DEVICE) over the polled control engine.
static ra8_err_t cdc_enum_hunt (uint8_t *desc)
 Wait for the device to attach, then bus-reset + read its descriptor.
static ra8_err_t cdc_enum_set_address (void)
 SET_ADDRESS to k_cdc_dev_addr, then retarget the DCP.
static ra8_err_t cdc_enum_set_config (void)
 SET_CONFIGURATION(::k_cdc_config_value) on the addressed device.
static ra8_err_t cdc_open_pipes (void)
 Open the host bulk pipes for the device's CDC data endpoints.
static ra8_err_t cdc_enumerate (uint32_t *out_pid)
 Run the full enumeration ladder and open the bulk pipes.
static ra8_err_t cdc_print_enum (uint32_t pid)
 Print "enumerated pid=0xNNNN" for the looped device.
static ra8_err_t cdc_print_pass (void)
 Print "N rounds echoed -- USB SELFTEST CDC-ECHO PASS".
static ra8_err_t cdc_echo_round (uint32_t round)
 One echo round: bulk-OUT a pattern, bulk-IN the echo, compare.
static ra8_err_t cdc_host_pass (void)
 One full host-side pass: enumerate, then run the echo rounds.
VOID cdc_host_worker (ULONG arg)
 Host-side worker: retry the full pass until it succeeds.

Variables

static volatile uint32_t s_dbg_phase
 Host-ladder phase marker (cdc_phase_t).
static volatile uint32_t s_dbg_rounds_ok
 Echo rounds the host confirmed byte-equal (expect k_cdc_rounds).
static volatile uint32_t s_dbg_pid
 Device-reported product id captured at enumeration.
static volatile uint32_t s_dbg_mismatch = (uint32_t)k_cdc_no_mismatch
 First mismatching round, or k_cdc_no_mismatch.
static volatile uint32_t s_dbg_pass_count
 Completed full passes (sticky success counter).

Detailed Description

Host-side self-test ladder, console formatters, and echo pattern.

Tag
[Ring 6 / APP] {World: S}

Companion translation unit for the usb_selftest_cdc HIL example, carved out of main.c so every unit stays under the file-size cap. It holds the SCI8 console formatters, the shared per-round echo pattern, and the self-contained polled CDC host ladder (enumerate -> open bulk pipes -> run the echo rounds) that the host worker drives. main.c retains the device-side USBX worker, the board bring-up, and the entry point, and only reaches in through cdc_host_worker.

The host-side J-Link probes (s_dbg_*) live here because only the host routines write them; the device-side probes stay in main.c.

Author
Brighton Sikarskie
Date
2026-06-13
Since
0.1.0

Definition in file usb_selftest_cdc_steps.c.

Enumeration Type Documentation

◆ cdc_enum_tune_t

enum cdc_enum_tune_t : uint32_t

Timing / retry tunables for the polled enumeration ladder.

Enumerator
k_cdc_vbus_settle_ms 

VBUS settle before probing.

k_cdc_attach_to_ms 

Wait for the D+ pull-up.

k_cdc_debounce_ms 

Post-attach debounce (>=100 ms).

k_cdc_reset_hold_ms 

USB bus-reset hold (>=10 ms).

k_cdc_recovery_ms 

Post-reset recovery (TRSTRCY).

k_cdc_addr_settle_ms 

Post-SET_ADDRESS recovery.

k_cdc_enum_tries 

Reset+probe attempts.

k_cdc_attach_spin 

Attach spin cap (frozen-tick guard).

Definition at line 367 of file usb_selftest_cdc_steps.c.

◆ cdc_hex_t

enum cdc_hex_t : uint8_t

Hex/decimal text-formatter sizing constants.

Enumerator
k_cdc_hex_chars_u16 

16-bit value -> "ABCD".

k_cdc_hex_chars_u32 

32-bit value -> "ABCDEF01".

k_cdc_dec_chars_u32 

Max digits for a 32-bit count.

k_cdc_nibble_bits 

Bits per hex nibble.

k_cdc_hex_digit_split 

Threshold between '0-9'/'A-F'.

Definition at line 43 of file usb_selftest_cdc_steps.c.

◆ cdc_mask_t

enum cdc_mask_t : uint32_t

Bit-mask constants used by the text formatters.

Enumerator
k_cdc_nibble_mask 

4-bit nibble mask.

k_cdc_dec_radix 

Base for decimal conversion.

Definition at line 55 of file usb_selftest_cdc_steps.c.

◆ cdc_phase_t

enum cdc_phase_t : uint32_t

J-Link probe values marking host-ladder progress.

Enumerator
k_cdc_phase_boot 

Host thread not started.

k_cdc_phase_init 

Host controller init.

k_cdc_phase_enum 

Enumerating.

k_cdc_phase_verify 

Running echo rounds.

k_cdc_phase_pass 

All rounds echoed back OK.

Definition at line 64 of file usb_selftest_cdc_steps.c.

◆ cdc_usb_req_t

enum cdc_usb_req_t : uint16_t

Standard chapter-9 request / descriptor constants for the host.

Enumerator
k_cdc_bm_std_dev_in 

bmRequestType: Std | Device | In.

k_cdc_bm_std_dev_out 

bmRequestType: Std | Device | Out.

k_cdc_breq_get_desc 

GET_DESCRIPTOR.

k_cdc_breq_set_addr 

SET_ADDRESS.

k_cdc_breq_set_config 

SET_CONFIGURATION.

k_cdc_desc_device 

DEVICE descriptor type.

k_cdc_dev_desc_len 

DEVICE descriptor length.

k_cdc_off_dev_pid 

idProduct LSB byte offset.

k_cdc_byte_bits 

Bits per byte.

k_cdc_config_value 

bConfigurationValue to select.

Definition at line 350 of file usb_selftest_cdc_steps.c.

Function Documentation

◆ cdc_ctrl_get_dev_desc()

ra8_err_t cdc_ctrl_get_dev_desc ( uint8_t * desc)
staticnodiscard

GET_DESCRIPTOR(DEVICE) over the polled control engine.

Parameters
[out]descReceives the 18-byte device descriptor.
Returns
Read outcome.
Return values
k_ra8_okAll 18 bytes arrived.
k_ra8_err_hw_errorA short descriptor came back.
Precondition
The bus is reset and the DCP targets the device's current address.
desc holds at least k_cdc_dev_desc_len bytes.
Postcondition
desc carries the device descriptor on success.
No global state changes.
Note
Blocking (polled control transfer).
Since
0.1.0

Definition at line 395 of file usb_selftest_cdc_steps.c.

References k_cdc_bm_std_dev_in, k_cdc_breq_get_desc, k_cdc_byte_bits, k_cdc_desc_device, k_cdc_dev_desc_len, k_ra8_err_hw_error, k_ra8_ok, k_ra8_usb_speed_hs, and ra8_usb_host_control_xfer().

Referenced by cdc_enum_hunt().

◆ cdc_echo_round()

ra8_err_t cdc_echo_round ( uint32_t round)
staticnodiscard

One echo round: bulk-OUT a pattern, bulk-IN the echo, compare.

Fills k_cdc_payload bytes from cdc_pattern_fill keyed on round, ships them on the bulk-OUT pipe (one sub-MPS packet), then reads the bulk-IN echo and byte-checks it. A sub-MPS payload returns as a single short packet, so no MPS-exact ZLP is involved.

Parameters
[in]roundThe echo round index (0..k_cdc_rounds-1).
Returns
ra8_err_t verdict.
Return values
k_ra8_okThe echo matched the sent payload.
k_ra8_err_invalid_sizeThe echo length differed.
k_ra8_err_invalid_stateThe echo bytes differed.
Precondition
The bulk pipes were opened by cdc_open_pipes.
The device echo worker is running.
Postcondition
s_dbg_mismatch records round on any mismatch.
Nothing is retained between rounds.
Note
Blocking; one bulk-OUT then one bulk-IN over the self-loop.
Since
0.1.0

Definition at line 687 of file usb_selftest_cdc_steps.c.

References cdc_pattern_fill(), cdc_print_fail(), k_cdc_echo_buf, k_cdc_payload, k_cdc_pipe_in, k_cdc_pipe_out, k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_ok, k_ra8_usb_speed_hs, memcmp(), ra8_usb_host_bulk_in(), ra8_usb_host_bulk_out(), and s_dbg_mismatch.

Referenced by cdc_host_pass().

◆ cdc_enum_hunt()

ra8_err_t cdc_enum_hunt ( uint8_t * desc)
staticnodiscard

Wait for the device to attach, then bus-reset + read its descriptor.

Waits for the D+ pull-up (LNST leaves SE0) plus the spec debounce, then each attempt drives a full bus reset (returns the device to address 0), re-enables SOF, targets address 0, and reads the device descriptor. The first attempt that returns all 18 bytes wins.

Parameters
[out]descReceives the winning 18-byte device descriptor.
Returns
Hunt outcome.
Return values
k_ra8_okThe device answered at address 0.
k_ra8_err_hw_timeoutNothing attached / nothing answered.
Precondition
ra8_usb_host_init ran (host mode up, VBUS supplied).
ra8_time_init has run (ms delays).
Postcondition
On success the DCP targets address 0 with UACT on.
On failure the bus is left in the last attempt's state.
Note
Blocking; worst case a few seconds.
Since
0.1.0

Definition at line 438 of file usb_selftest_cdc_steps.c.

References cdc_ctrl_get_dev_desc(), k_cdc_attach_spin, k_cdc_attach_to_ms, k_cdc_debounce_ms, k_cdc_enum_tries, k_cdc_recovery_ms, k_cdc_reset_hold_ms, k_cdc_vbus_settle_ms, k_ra8_err_hw_timeout, k_ra8_ok, k_ra8_usb_speed_hs, ra8_delay_ms(), ra8_time_ms(), ra8_usb_host_bus_reset(), ra8_usb_host_line_state(), ra8_usb_host_set_target(), and ra8_usb_host_set_uact().

Referenced by cdc_enumerate().

◆ cdc_enum_set_address()

ra8_err_t cdc_enum_set_address ( void )
staticnodiscard

SET_ADDRESS to k_cdc_dev_addr, then retarget the DCP.

Returns
First failing step's error, or k_ra8_ok.
Return values
k_ra8_okThe DCP now targets the operating address.
Precondition
cdc_enum_hunt succeeded (device answering at address 0).
The bus is active (UACT on).
Postcondition
Later transfers carry tokens to k_cdc_dev_addr.
The set-address recovery delay has elapsed.
Note
Blocking (one control transfer + settle).
Since
0.1.0

Definition at line 481 of file usb_selftest_cdc_steps.c.

References k_cdc_addr_settle_ms, k_cdc_bm_std_dev_out, k_cdc_breq_set_addr, k_cdc_dev_addr, k_ra8_ok, k_ra8_usb_speed_hs, ra8_delay_ms(), ra8_usb_host_control_xfer(), and ra8_usb_host_set_target().

Referenced by cdc_enumerate().

◆ cdc_enum_set_config()

ra8_err_t cdc_enum_set_config ( void )
staticnodiscard

SET_CONFIGURATION(::k_cdc_config_value) on the addressed device.

Returns
Control-transfer outcome.
Return values
k_ra8_okThe device entered the Configured state.
Precondition
cdc_enum_set_address succeeded.
The DCP targets k_cdc_dev_addr.
Postcondition
On success the device's endpoints are usable.
No global state changes.
Note
Blocking (one control transfer).
Since
0.1.0

Definition at line 512 of file usb_selftest_cdc_steps.c.

References k_cdc_bm_std_dev_out, k_cdc_breq_set_config, k_cdc_config_value, k_ra8_usb_speed_hs, and ra8_usb_host_control_xfer().

Referenced by cdc_enumerate().

◆ cdc_enumerate()

ra8_err_t cdc_enumerate ( uint32_t * out_pid)
staticnodiscard

Run the full enumeration ladder and open the bulk pipes.

hunt -> SET_ADDRESS -> SET_CONFIGURATION -> open pipes, and extract idProduct from the device descriptor. Each step prints its own failure tag. The caller deinitializes the host controller on error.

Parameters
[out]out_pidReceives the device's idProduct on success.
Returns
First failing step's error, or k_ra8_ok.
Return values
k_ra8_okDevice enumerated; bulk pipes open.
Precondition
ra8_usb_host_init has succeeded on this pass.
out_pid is non-NULL.
Postcondition
out_pid holds the device idProduct on success.
On failure the offending step printed its tag.
Note
Blocking; runs on the low-priority host thread.
Since
0.1.0

Definition at line 581 of file usb_selftest_cdc_steps.c.

References cdc_enum_hunt(), cdc_enum_set_address(), cdc_enum_set_config(), cdc_open_pipes(), cdc_print_fail(), k_cdc_byte_bits, k_cdc_dev_desc_len, k_cdc_off_dev_pid, and k_ra8_ok.

Referenced by cdc_host_pass().

◆ cdc_host_pass()

ra8_err_t cdc_host_pass ( void )
staticnodiscard

One full host-side pass: enumerate, then run the echo rounds.

Phases mirror cdc_phase_t. On any failure the host controller is deinitialized so the next retry starts from a clean attach.

Returns
First failing step's error, or k_ra8_ok.
Return values
k_ra8_okThe pass printed CDC-ECHO PASS.
Precondition
Device-side CDC class is registered and echoing (other thread).
The self-loop cable connects J7 to J11.
Postcondition
On success s_dbg_pass_count advanced and LED2 is on.
On failure the host controller is deinitialized.
Note
Blocking; runs on the low-priority host thread.
Since
0.1.0

Definition at line 740 of file usb_selftest_cdc_steps.c.

References cdc_echo_round(), cdc_enumerate(), cdc_print(), cdc_print_enum(), cdc_print_fail(), cdc_print_pass(), k_cdc_phase_enum, k_cdc_phase_init, k_cdc_phase_pass, k_cdc_phase_verify, k_cdc_rounds, k_ra8_board_led2, k_ra8_ok, k_ra8_usb_speed_hs, ra8_board_led_on(), ra8_usb_host_deinit(), ra8_usb_host_init(), s_dbg_pass_count, s_dbg_phase, s_dbg_pid, and s_dbg_rounds_ok.

Referenced by cdc_host_worker().

◆ cdc_host_worker()

VOID cdc_host_worker ( ULONG arg)

Host-side worker: retry the full pass until it succeeds.

Waits for the device side to attach, then loops the host pass with a retry pause until every echo round verifies; afterwards parks so the verdict stays on the wire. Spawned by tx_application_define in main.c as the host ThreadX entry.

Parameters
[in]argThreadX entry argument (unused).
Precondition
tx_application_define created this thread.
The HS host pins, expander switch, and PLL are up (main).
Postcondition
On success the pass counter and LED2 are latched.
Retries forever otherwise; each failure prints its step.
Note
Blocking calls; ms timeouts via ra8_time.
Since
0.1.0

Definition at line 787 of file usb_selftest_cdc_steps.c.

References cdc_host_pass(), k_cdc_boot_wait_ticks, k_cdc_idle_ticks, k_cdc_retry_ticks, k_ra8_ok, and tx_thread_sleep.

Referenced by tx_application_define().

◆ cdc_nibble_to_hex()

uint8_t cdc_nibble_to_hex ( uint32_t nibble)
static

Format one nibble (0..15) into an uppercase hex character.

Standard '0'-'9' then 'A'-'F' mapping.

Parameters
[in]nibble4-bit value.
Returns
ASCII '0'..'9' or 'A'..'F'.
Return values
'0'For a zero nibble.
Precondition
Caller has masked the value to 4 bits.
None beyond the mask contract.
Postcondition
Returned byte is printable hex.
No state changes.
Note
Pure function.
Since
0.1.0

Definition at line 142 of file usb_selftest_cdc_steps.c.

References k_cdc_hex_digit_split.

Referenced by cdc_print_hex().

◆ cdc_open_pipes()

ra8_err_t cdc_open_pipes ( void )
staticnodiscard

Open the host bulk pipes for the device's CDC data endpoints.

Pipe k_cdc_pipe_out -> device EP2 OUT (host transmits), pipe k_cdc_pipe_in -> device EP1 IN (host receives), both 64-byte MPS. Endpoint numbers come from this app's own device framework.

Returns
First failing pipe-setup error, or k_ra8_ok.
Return values
k_ra8_okBoth bulk pipes configured and parked NAK.
Precondition
cdc_enum_set_config succeeded.
The pipes are not currently armed.
Postcondition
Both pipes target k_cdc_dev_addr with DATA0 forced.
The pipes' status bits are cleared.
Note
Not thread-safe.
Since
0.1.0

Definition at line 542 of file usb_selftest_cdc_steps.c.

References k_cdc_dev_addr, k_cdc_ep_in_num, k_cdc_ep_out_num, k_cdc_mps, k_cdc_pipe_in, k_cdc_pipe_out, k_ra8_ok, k_ra8_usb_speed_hs, and ra8_usb_host_pipe_setup().

Referenced by cdc_enumerate().

◆ cdc_pattern_fill()

void cdc_pattern_fill ( uint32_t round,
uint8_t * out,
uint32_t len )
static

Fill an echo payload with this round's deterministic bytes.

Byte i = (round*97 + i*7 + 0x5A) & 0xFF. Distinct per round so the host proves the bytes it read back are the ones it sent for that round (not a stale buffer). The device merely echoes, so only the host computes this; both the OUT payload and the IN check use it.

Parameters
[in]roundThe echo round index (0..k_cdc_rounds-1).
[out]outDestination buffer.
[in]lenBytes to fill.
Precondition
out has len writable bytes.
len is at most k_cdc_payload.
Postcondition
out[0..len-1] hold the round's pattern bytes.
No global state changes.
Note
Pure function.
Since
0.1.0

Definition at line 111 of file usb_selftest_cdc_steps.c.

References k_cdc_byte_mask, k_cdc_pat_bias, k_cdc_pat_idx_mul, and k_cdc_pat_round_mul.

Referenced by cdc_echo_round().

◆ cdc_print()

ra8_err_t cdc_print ( const char * text)
staticnodiscard

Print a NUL-terminated ASCII string over the console.

Length-bounded by cdc_str_len.

Parameters
[in]textString to print (CR/LF included by the caller).
Returns
ra8_err_t propagated from the SCI helper.
Return values
k_ra8_okAll bytes queued.
Precondition
SCI8 init already ran; text is non-NULL.
text is NUL-terminated within k_cdc_print_cap bytes.
Postcondition
The string bytes are in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 222 of file usb_selftest_cdc_steps.c.

References cdc_sci_write(), and cdc_str_len().

Referenced by cdc_host_pass(), cdc_print_enum(), cdc_print_fail(), and cdc_print_pass().

◆ cdc_print_dec()

ra8_err_t cdc_print_dec ( uint32_t value)
staticnodiscard

Print a uint32_t as ASCII decimal.

Digit-reversal into a bounded scratch buffer.

Parameters
[in]valueValue to print.
Returns
ra8_err_t propagated from the SCI helper.
Return values
k_ra8_okAll bytes queued.
Precondition
SCI8 init already ran.
None beyond console readiness.
Postcondition
One ASCII decimal token is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 245 of file usb_selftest_cdc_steps.c.

References cdc_sci_write(), k_cdc_dec_chars_u32, and k_cdc_dec_radix.

Referenced by cdc_print_pass().

◆ cdc_print_enum()

ra8_err_t cdc_print_enum ( uint32_t pid)
staticnodiscard

Print "enumerated pid=0xNNNN" for the looped device.

Parameters
[in]pidThe device idProduct to report.
Returns
ra8_err_t propagated from the SCI helpers.
Return values
k_ra8_okThe line is queued.
Precondition
cdc_enumerate succeeded.
SCI8 init already ran.
Postcondition
One ASCII line is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 624 of file usb_selftest_cdc_steps.c.

References cdc_print(), cdc_print_hex(), k_cdc_hex_chars_u16, and k_ra8_ok.

Referenced by cdc_host_pass().

◆ cdc_print_fail()

ra8_err_t cdc_print_fail ( const char * what,
ra8_err_t err )
staticnodiscard

Print "FAIL <what> err=0xNNNNNNNN" on its own line.

One-line diagnostic; first failing chunk's code returned.

Parameters
[in]whatShort description of the failed step.
[in]errError code returned by the step.
Returns
ra8_err_t propagated from the SCI helpers.
Return values
k_ra8_okThe diagnostic line is queued.
Precondition
SCI8 init already ran.
what is NUL-terminated within the print cap.
Postcondition
One diagnostic line is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 321 of file usb_selftest_cdc_steps.c.

References cdc_print(), cdc_print_hex(), k_cdc_hex_chars_u32, and k_ra8_ok.

Referenced by cdc_echo_round(), cdc_enumerate(), and cdc_host_pass().

◆ cdc_print_hex()

ra8_err_t cdc_print_hex ( uint32_t value,
uint8_t digits )
staticnodiscard

Print a value as fixed-width uppercase hex.

Width is clamped to 8 hex digits.

Parameters
[in]valueValue to print.
[in]digitsHex digit count (4 for u16, 8 for u32).
Returns
ra8_err_t propagated from the SCI helper.
Return values
k_ra8_okAll bytes queued.
Precondition
SCI8 init already ran.
digits is at most k_cdc_hex_chars_u32.
Postcondition
One fixed-width hex token is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 288 of file usb_selftest_cdc_steps.c.

References cdc_nibble_to_hex(), cdc_sci_write(), k_cdc_hex_chars_u32, k_cdc_nibble_bits, and k_cdc_nibble_mask.

Referenced by cdc_print_enum(), and cdc_print_fail().

◆ cdc_print_pass()

ra8_err_t cdc_print_pass ( void )
staticnodiscard

Print "N rounds echoed -- USB SELFTEST CDC-ECHO PASS".

Returns
ra8_err_t propagated from the SCI helpers.
Return values
k_ra8_okThe verdict line is queued.
Precondition
All k_cdc_rounds echo rounds verified.
SCI8 init already ran.
Postcondition
One ASCII verdict line is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 651 of file usb_selftest_cdc_steps.c.

References cdc_print(), cdc_print_dec(), k_cdc_rounds, and k_ra8_ok.

Referenced by cdc_host_pass().

◆ cdc_sci_write()

ra8_err_t cdc_sci_write ( const uint8_t * data,
uint32_t len )
staticnodiscard

Push a literal block over SCI8 polled.

Thin wrapper fixing the console channel.

Parameters
[in]dataBuffer to send.
[in]lenByte count.
Returns
ra8_err_t passthrough from ra8_board_uart_console_write.
Return values
k_ra8_okAll bytes queued.
Precondition
data is non-NULL; SCI8 init already ran.
len excludes any NUL terminator.
Postcondition
Bytes are in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 199 of file usb_selftest_cdc_steps.c.

References ra8_board_uart_console_write().

Referenced by cdc_print(), cdc_print_dec(), and cdc_print_hex().

◆ cdc_str_len()

uint32_t cdc_str_len ( const char * text)
static

Bounded ASCII string length (cap k_cdc_print_cap).

Linear scan with a hard upper bound.

Parameters
[in]textNUL-terminated string.
Returns
Number of bytes before the NUL, capped.
Return values
0For an empty string.
Precondition
text is non-NULL.
text points to readable storage of at least the length.
Postcondition
No state changes.
Return value never exceeds k_cdc_print_cap.
Note
Bounded scan.
Since
0.1.0

Definition at line 168 of file usb_selftest_cdc_steps.c.

References k_cdc_print_cap.

Referenced by cdc_print().

Variable Documentation

◆ s_dbg_mismatch

volatile uint32_t s_dbg_mismatch = (uint32_t)k_cdc_no_mismatch
static

First mismatching round, or k_cdc_no_mismatch.

Definition at line 83 of file usb_selftest_cdc_steps.c.

◆ s_dbg_pass_count

volatile uint32_t s_dbg_pass_count
static

Completed full passes (sticky success counter).

Definition at line 85 of file usb_selftest_cdc_steps.c.

◆ s_dbg_phase

volatile uint32_t s_dbg_phase
static

Host-ladder phase marker (cdc_phase_t).

Definition at line 77 of file usb_selftest_cdc_steps.c.

◆ s_dbg_pid

volatile uint32_t s_dbg_pid
static

Device-reported product id captured at enumeration.

Definition at line 81 of file usb_selftest_cdc_steps.c.

◆ s_dbg_rounds_ok

volatile uint32_t s_dbg_rounds_ok
static

Echo rounds the host confirmed byte-equal (expect k_cdc_rounds).

Definition at line 79 of file usb_selftest_cdc_steps.c.