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

Shared constants + cross-TU prototypes for usb_selftest_mlun. More...

#include <stdint.h>
#include "tx_api.h"
#include "ux_api.h"
Include dependency graph for usb_selftest_mlun_steps.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  mlun_config_t : uint32_t {
  k_mlun_thread_stack = 4096U ,
  k_mlun_host_stack = 8192U ,
  k_mlun_usbx_pool_bytes = 32768U ,
  k_mlun_idle_ticks = 50U ,
  k_mlun_boot_wait_ticks = 500U ,
  k_mlun_retry_ticks = 3000U ,
  k_mlun_baud = 115200U ,
  k_mlun_print_cap = 160U ,
  k_mlun_dev_priority = 8U ,
  k_mlun_host_priority = 24U
}
 Compile-time settings: threads, pool, console, cadence. More...
enum  mlun_hex_t : uint8_t {
  k_mlun_hex_chars_u16 = 4U ,
  k_mlun_hex_chars_u32 = 8U ,
  k_mlun_dec_chars_u32 = 10U ,
  k_mlun_nibble_bits = 4U ,
  k_mlun_hex_digit_split = 10U
}
 Hex/decimal text-formatter sizing constants. More...
enum  mlun_mask_t : uint32_t {
  k_mlun_nibble_mask = 0xFU ,
  k_mlun_dec_radix = 10U
}
 Bit-mask constants used by the text formatters. More...
enum  mlun_geom_t : uint32_t {
  k_mlun_count = 2U ,
  k_mlun_sectors = 256U ,
  k_mlun_block_size = 512U ,
  k_mlun_burst_blocks = 8U ,
  k_mlun_burst_bytes = 4096U ,
  k_mlun_target_lun0 = 0U ,
  k_mlun_no_mismatch = 0xFFFFFFFFU ,
  k_mlun_pat_lun_mul = 97U ,
  k_mlun_pat_lba_mul = 7U ,
  k_mlun_pat_bias = 0x5AU ,
  k_mlun_byte_mask = 0xFFU ,
  k_mlun_mismatch_lun_shift = 24U
}
 LUN geometry + verification constants. More...
enum  mlun_phase_t : uint32_t {
  k_mlun_phase_boot = 0U ,
  k_mlun_phase_init = 1U ,
  k_mlun_phase_enum = 2U ,
  k_mlun_phase_verify = 3U ,
  k_mlun_phase_pass = 4U
}
 J-Link probe values marking host-ladder progress. More...

Functions

void mlun_pattern_fill (uint32_t lun, uint32_t lba, UCHAR *out)
 Fill one 512-byte sector with this LUN/LBA's deterministic bytes.
VOID mlun_host_worker (ULONG arg)
 Host-side worker: retry the full pass until it succeeds.

Detailed Description

Shared constants + cross-TU prototypes for usb_selftest_mlun.

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

The multi-LUN USB self-loop app is split into two translation units to keep each one under the per-file line cap: main.c owns boot, pin/clock bring-up, the device-side USBX MSC class, and the ThreadX entry hooks; the steps TU (usb_selftest_mlun_steps.c) owns the shared per-(LUN,LBA) pattern, the SCI8 console + text formatters, and the host-side enumerate / per-LUN verify / retry worker.

This header holds the typed-enum constants both TUs share (thread + pool sizing, the text-formatter widths, the LUN geometry, the host-ladder probe phases) plus prototypes for the two symbols that cross the TU boundary: mlun_pattern_fill (the device media-read in main.c calls it) and mlun_host_worker (tx_application_define in main.c spawns it). Every other moved helper stays file-static in the steps TU.

Author
Brighton Sikarskie
Date
2026-06-13
Since
0.1.0

Definition in file usb_selftest_mlun_steps.h.

Enumeration Type Documentation

◆ mlun_config_t

enum mlun_config_t : uint32_t

Compile-time settings: threads, pool, console, cadence.

Enumerator
k_mlun_thread_stack 

Device worker stack (bytes).

k_mlun_host_stack 

Host worker stack (bytes).

k_mlun_usbx_pool_bytes 

USBX memory pool (bytes).

k_mlun_idle_ticks 

Parked-loop back-off (ticks).

k_mlun_boot_wait_ticks 

Host start delay (1 ms ticks).

k_mlun_retry_ticks 

Pause between ladder retries.

k_mlun_baud 

J-Link OB CDC log baud.

k_mlun_print_cap 

Bound for console-string scans.

k_mlun_dev_priority 

Device bring-up worker priority.

k_mlun_host_priority 

Host worker priority (below USBX).

Definition at line 38 of file usb_selftest_mlun_steps.h.

◆ mlun_geom_t

enum mlun_geom_t : uint32_t

LUN geometry + verification constants.

Enumerator
k_mlun_count 

Logical units exposed (UX_MAX_SLAVE_LUN).

k_mlun_sectors 

512-byte sectors per LUN.

k_mlun_block_size 

SCSI logical block size.

k_mlun_burst_blocks 

Blocks per READ(10) burst.

k_mlun_burst_bytes 

8 x 512 B burst buffer.

k_mlun_target_lun0 

First LUN index.

k_mlun_no_mismatch 

Probe: no mismatch.

k_mlun_pat_lun_mul 

Per-LUN pattern multiplier.

k_mlun_pat_lba_mul 

Per-LBA pattern multiplier.

k_mlun_pat_bias 

Pattern constant bias.

k_mlun_byte_mask 

Byte mask.

k_mlun_mismatch_lun_shift 

s_dbg_mismatch: LUN in bits 31:24.

Definition at line 76 of file usb_selftest_mlun_steps.h.

◆ mlun_hex_t

enum mlun_hex_t : uint8_t

Hex/decimal text-formatter sizing constants.

Enumerator
k_mlun_hex_chars_u16 

16-bit value -> "ABCD".

k_mlun_hex_chars_u32 

32-bit value -> "ABCDEF01".

k_mlun_dec_chars_u32 

Max digits for a 32-bit count.

k_mlun_nibble_bits 

Bits per hex nibble.

k_mlun_hex_digit_split 

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

Definition at line 55 of file usb_selftest_mlun_steps.h.

◆ mlun_mask_t

enum mlun_mask_t : uint32_t

Bit-mask constants used by the text formatters.

Enumerator
k_mlun_nibble_mask 

4-bit nibble mask.

k_mlun_dec_radix 

Base for decimal conversion.

Definition at line 67 of file usb_selftest_mlun_steps.h.

◆ mlun_phase_t

enum mlun_phase_t : uint32_t

J-Link probe values marking host-ladder progress.

Enumerator
k_mlun_phase_boot 

Host thread not started.

k_mlun_phase_init 

ra8_usb_hmsc_init issued.

k_mlun_phase_enum 

Enumerating.

k_mlun_phase_verify 

Reading + checking LUNs.

k_mlun_phase_pass 

All LUNs verified.

Definition at line 95 of file usb_selftest_mlun_steps.h.

Function Documentation

◆ mlun_host_worker()

VOID mlun_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 + per-LUN verify pass with a retry pause until both LUNs verify; 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. Defined in usb_selftest_mlun_steps.c; tx_application_define spawns it.
Since
0.1.0

Definition at line 497 of file usb_selftest_mlun_steps.c.

References k_mlun_boot_wait_ticks, k_mlun_idle_ticks, k_mlun_retry_ticks, k_ra8_ok, mlun_host_pass(), and tx_thread_sleep.

Referenced by tx_application_define().

◆ mlun_pattern_fill()

void mlun_pattern_fill ( uint32_t lun,
uint32_t lba,
UCHAR * out )

Fill one 512-byte sector with this LUN/LBA's deterministic bytes.

Byte i = (lun*97 + lba*7 + i + 0x5A) & 0xFF. Distinct per LUN and per LBA so the host can prove it addressed the right logical unit and sector. The device media-read and the host verifier compute it identically.

Parameters
[in]lunThe logical unit (0..1).
[in]lbaThe logical block address within the LUN.
[out]out512-byte destination buffer.
Precondition
out has k_mlun_block_size writable bytes.
lun and lba are within the exposed geometry.
Postcondition
out holds the sector's pattern bytes.
No global state changes.
Note
Pure function. Defined in usb_selftest_mlun_steps.c; the device media-read in main.c shares it with the host verifier.
Since
0.1.0

Definition at line 65 of file usb_selftest_mlun_steps.c.

References k_mlun_block_size, k_mlun_byte_mask, k_mlun_pat_bias, k_mlun_pat_lba_mul, and k_mlun_pat_lun_mul.

Referenced by mlun_msc_read(), and mlun_verify_one().