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

examples/ek_ra8d2/hil_needs_revalidation/usb_selftest_wlun/src/usb_selftest_wlun_host.c More...

#include <stdint.h>
#include <string.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_err.h"
#include "ra8_usb_hmsc.h"
#include "tx_api.h"
#include "usb_selftest_wlun_steps.h"
Include dependency graph for usb_selftest_wlun_host.c:

Go to the source code of this file.

Functions

static ra8_err_t wlun_write_disk (uint32_t lun)
 WRITE(10) the per-LBA pattern across the whole RAM disk.
static ra8_err_t wlun_verify_one (uint32_t lun)
 Read + verify one LUN's full sector range against its pattern.
static ra8_err_t wlun_print_lun_ok (uint32_t lun)
 Print "LUN n OK" for the verified writable unit.
static ra8_err_t wlun_host_enumerate (ra8_usb_hmsc_device_t *device)
 Enumerate the looped device and print its PID + GET_MAX_LUN.
static ra8_err_t wlun_host_pass (void)
 One full host-side pass: enumerate, WRITE(10) then verify.
VOID wlun_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 (wlun_phase_t).
static volatile uint32_t s_dbg_luns_ok
 Sectors that read back correctly after the write pass.
static volatile uint32_t s_dbg_max_lun
 Device-reported GET_MAX_LUN value (expect 0, single LUN).
static volatile uint32_t s_dbg_mismatch = (uint32_t)k_wlun_no_mismatch
 First mismatching sector, or k_wlun_no_mismatch.
static volatile uint32_t s_dbg_pass_count
 Completed full passes (sticky success counter).

Detailed Description

examples/ek_ra8d2/hil_needs_revalidation/usb_selftest_wlun/src/usb_selftest_wlun_host.c

Host-side MSC ladder: enumerate, WRITE(10) the disk, read-verify it

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

The polled host-side worker of the writable-LUN self-loop. It enumerates the looped-back FS device, WRITE(10)s a deterministic per-LBA pattern across the whole RAM disk, then READ(10)s it back and byte-checks every sector – proving the device bulk-OUT WRITE data phase round-trips intact. Streams its verdicts over SCI8 via the shared console formatters and mirrors host-ladder progress in J-Link-readable probes (s_dbg_*). Split out of main.c so each translation unit stays under the per-file line cap. The wlun_host_worker contract lives in usb_selftest_wlun_steps.h.

Author
Brighton Sikarskie
Date
2026-06-13
Since
0.1.0

Definition in file usb_selftest_wlun_host.c.

Function Documentation

◆ wlun_host_enumerate()

ra8_err_t wlun_host_enumerate ( ra8_usb_hmsc_device_t * device)
staticnodiscard

Enumerate the looped device and print its PID + GET_MAX_LUN.

Sets the enum phase, runs ra8_usb_hmsc_enumerate, records the reported max-LUN in s_dbg_max_lun, and streams the enumerated pid=... GET_MAX_LUN=... banner. On enumerate failure the host controller is closed so the next retry re-attaches clean.

Parameters
[out]deviceReceives the enumerated descriptor snapshot.
Returns
First failing step's error, or k_ra8_ok.
Return values
k_ra8_okDevice enumerated and the banner printed.
Precondition
device is non-null.
ra8_usb_hmsc_init has succeeded on this pass.
Postcondition
s_dbg_max_lun mirrors the device's GET_MAX_LUN.
On failure the host controller is deinitialized.
Note
Blocking; runs on the low-priority host thread.
Since
0.1.0

Definition at line 203 of file usb_selftest_wlun_host.c.

References k_ra8_ok, k_wlun_hex_chars_u16, k_wlun_phase_enum, ra8_usb_hmsc_device_t::max_lun, ra8_usb_hmsc_device_t::product_id, ra8_usb_hmsc_close(), ra8_usb_hmsc_enumerate(), s_dbg_max_lun, s_dbg_phase, wlun_print(), wlun_print_dec(), wlun_print_fail(), and wlun_print_hex().

Referenced by wlun_host_pass().

◆ wlun_host_pass()

ra8_err_t wlun_host_pass ( void )
staticnodiscard

One full host-side pass: enumerate, WRITE(10) then verify.

Phases mirror wlun_phase_t. On any failure the host controller is closed 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 WRITABLE-LUN PASS.
Precondition
Device-side class is registered and attached (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 again.
Note
Blocking; runs on the low-priority host thread.
Since
0.1.0

Definition at line 249 of file usb_selftest_wlun_host.c.

References k_ra8_board_led2, k_ra8_ok, k_ra8_usb_speed_hs, k_wlun_count, k_wlun_phase_init, k_wlun_phase_pass, k_wlun_phase_verify, ra8_board_led_on(), ra8_usb_hmsc_close(), ra8_usb_hmsc_init(), s_dbg_luns_ok, s_dbg_pass_count, s_dbg_phase, wlun_host_enumerate(), wlun_print(), wlun_print_fail(), wlun_print_lun_ok(), wlun_verify_one(), and wlun_write_disk().

Referenced by wlun_host_worker().

◆ wlun_host_worker()

VOID wlun_host_worker ( ULONG arg)

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

Waits for the device side to attach, then loops the full enumerate / WRITE(10) / verify pass with a retry pause until the writable LUN verifies; afterwards parks so the verdict stays on the wire.

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 298 of file usb_selftest_wlun_host.c.

References k_ra8_ok, k_wlun_boot_wait_ticks, k_wlun_idle_ticks, k_wlun_retry_ticks, tx_thread_sleep, and wlun_host_pass().

Referenced by tx_application_define().

◆ wlun_print_lun_ok()

ra8_err_t wlun_print_lun_ok ( uint32_t lun)
staticnodiscard

Print "LUN n OK" for the verified writable unit.

Parameters
[in]lunThe LUN that just verified.
Returns
ra8_err_t propagated from the SCI helpers.
Return values
k_ra8_okThe line is queued.
Precondition
wlun_verify_one returned k_ra8_ok for lun.
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 169 of file usb_selftest_wlun_host.c.

References k_ra8_ok, wlun_print(), and wlun_print_dec().

Referenced by wlun_host_pass().

◆ wlun_verify_one()

ra8_err_t wlun_verify_one ( uint32_t lun)
staticnodiscard

Read + verify one LUN's full sector range against its pattern.

READ_CAPACITY (must report k_wlun_sectors), then a raw multi-block READ(10) sweep in 8-block bursts, checking each sector against wlun_pattern_fill for this lun.

Parameters
[in]lunLogical unit to verify (0..1).
Returns
ra8_err_t verdict.
Return values
k_ra8_okThe whole LUN matched its pattern.
k_ra8_err_invalid_sizeREAD_CAPACITY reported wrong geometry.
k_ra8_err_invalid_stateA byte differed from the pattern.
Precondition
The host has enumerated the device.
lun is below k_wlun_count.
Postcondition
s_dbg_mismatch records (lun<<24 | sector) on mismatch.
Nothing is retained between LUNs.
Note
Blocking; 32 four-KiB READ(10) bursts over the self-loop.
Since
0.1.0

Definition at line 118 of file usb_selftest_wlun_host.c.

References k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_ok, k_wlun_block_size, k_wlun_burst_blocks, k_wlun_burst_bytes, k_wlun_mismatch_lun_shift, k_wlun_sectors, memcmp(), ra8_usb_hmsc_read10(), ra8_usb_hmsc_read_capacity(), s_dbg_mismatch, wlun_pattern_fill(), and wlun_print_fail().

Referenced by wlun_host_pass().

◆ wlun_write_disk()

ra8_err_t wlun_write_disk ( uint32_t lun)
staticnodiscard

WRITE(10) the per-LBA pattern across the whole RAM disk.

Fills an 8-block burst from wlun_pattern_fill and pushes it with raw ra8_usb_hmsc_write10 until every sector is written. This is the host data-OUT phase that drives the device bulk-OUT receive path (the gating mechanism for every writable / repeated-bulk matrix item).

Parameters
[in]lunLogical unit to write (0).
Returns
ra8_err_t verdict.
Return values
k_ra8_okThe whole disk was written.
k_ra8_err_hw_timeoutA WRITE(10) data-OUT phase did not complete.
Precondition
The host has enumerated the device.
The LUN is writable (read_only_flag = UX_FALSE).
Postcondition
The device RAM disk holds the pattern on success.
On failure the offending step printed its error.
Note
Blocking; 8 four-KiB WRITE(10) bursts over the self-loop.
Since
0.1.0

Definition at line 79 of file usb_selftest_wlun_host.c.

References k_ra8_ok, k_wlun_block_size, k_wlun_burst_blocks, k_wlun_burst_bytes, k_wlun_sectors, ra8_usb_hmsc_write10(), wlun_pattern_fill(), and wlun_print_fail().

Referenced by wlun_host_pass().

Variable Documentation

◆ s_dbg_luns_ok

volatile uint32_t s_dbg_luns_ok
static

Sectors that read back correctly after the write pass.

Definition at line 45 of file usb_selftest_wlun_host.c.

Referenced by microsd_host_pass(), mlun_host_pass(), ospirw_host_pass(), and wlun_host_pass().

◆ s_dbg_max_lun

volatile uint32_t s_dbg_max_lun
static

Device-reported GET_MAX_LUN value (expect 0, single LUN).

Definition at line 47 of file usb_selftest_wlun_host.c.

Referenced by microsd_host_enumerate(), mlun_host_enumerate(), ospirw_host_enumerate(), and wlun_host_enumerate().

◆ s_dbg_mismatch

volatile uint32_t s_dbg_mismatch = (uint32_t)k_wlun_no_mismatch
static

◆ s_dbg_pass_count

volatile uint32_t s_dbg_pass_count
static

◆ s_dbg_phase