44#include "ux_device_class_storage.h"
99 return (uint8_t)((uint8_t)
'0' + (uint8_t)nibble);
126 if (text[len] ==
'\0') {
206 out[0] = (uint8_t)
'0';
217 for (uint8_t i = 0U; i < count; i++) {
218 out[i] = scratch[count - 1U - i];
245 uint8_t width = digits;
249 for (uint8_t i = 0U; i < width; i++) {
327 uint32_t block_count = 0U;
328 uint32_t block_size = 0U;
383 return mlun_print(
" OK (256 sectors, pattern verified)\r\n");
417 err =
mlun_print(
"ra8d2 mlun: enumerated pid=0x");
474 for (uint32_t lun = 0U; lun < (uint32_t)
k_mlun_count; lun++) {
489 err =
mlun_print(
"ra8d2 mlun: USB SELFTEST MULTI-LUN PASS\r\n");
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_on(ra8_board_led_id_t led)
Drive led HIGH (light it).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
@ k_ra8_usb_speed_hs
High-Speed controller (USBHS @ 0x40351000).
Native USB host-side MSC (Mass Storage Class) class layer.
ra8_err_t ra8_usb_hmsc_read_capacity(uint8_t target_lun, uint32_t *block_count, uint32_t *block_size)
Issue a SCSI READ CAPACITY(10) (opcode 0x25) over BBB.
ra8_err_t ra8_usb_hmsc_read10(uint8_t target_lun, uint32_t lba, uint16_t block_count, uint8_t *out_buf)
Issue a SCSI READ(10) (opcode 0x28) over BBB.
ra8_err_t ra8_usb_hmsc_enumerate(ra8_usb_hmsc_device_t *out_device)
Enumerate the attached MSC device end to end (polled).
ra8_err_t ra8_usb_hmsc_close(void)
Tear down the host-MSC driver and release the controller.
ra8_err_t ra8_usb_hmsc_init(ra8_usb_speed_t speed)
Bring up the host-MSC driver on a chosen USB controller.
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Snapshot of the attached MSC device, passed to the attach callback.
uint8_t max_lun
Get-Max-LUN response (0..15).
uint16_t product_id
idProduct from device descriptor.
static uint8_t mlun_nibble_to_hex(uint32_t nibble)
Format one nibble (0..15) into an uppercase hex character.
void mlun_pattern_fill(uint32_t lun, uint32_t lba, UCHAR *out)
Fill one 512-byte sector with this LUN/LBA's deterministic bytes.
static ra8_err_t mlun_print_hex(uint32_t value, uint8_t digits)
Print a value as fixed-width uppercase hex.
VOID mlun_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds.
static ra8_err_t mlun_verify_one(uint32_t lun)
Read + verify one LUN's full sector range against its pattern.
static ra8_err_t mlun_sci_write(const uint8_t *data, uint32_t len)
Push a literal block over SCI8 polled.
static ra8_err_t mlun_print_fail(const char *what, ra8_err_t err)
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
static ra8_err_t mlun_host_enumerate(ra8_usb_hmsc_device_t *device)
Enumerate the looped device and print its PID + GET_MAX_LUN.
static ra8_err_t mlun_print_dec(uint32_t value)
Print a uint32_t as ASCII decimal.
static ra8_err_t mlun_host_pass(void)
One full host-side pass: enumerate, verify both LUNs.
static ra8_err_t mlun_print(const char *text)
Print a NUL-terminated ASCII string over the console.
static uint32_t mlun_str_len(const char *text)
Bounded ASCII string length (cap k_mlun_print_cap).
static ra8_err_t mlun_print_lun_ok(uint32_t lun)
Print "LUN n OK (256 sectors)" for a verified logical unit.
Shared constants + cross-TU prototypes for usb_selftest_mlun.
@ k_mlun_byte_mask
Byte mask.
@ k_mlun_pat_bias
Pattern constant bias.
@ k_mlun_count
Logical units exposed (UX_MAX_SLAVE_LUN).
@ k_mlun_no_mismatch
Probe: no mismatch.
@ k_mlun_pat_lun_mul
Per-LUN pattern multiplier.
@ k_mlun_mismatch_lun_shift
s_dbg_mismatch: LUN in bits 31:24.
@ k_mlun_block_size
SCSI logical block size.
@ k_mlun_pat_lba_mul
Per-LBA pattern multiplier.
@ k_mlun_burst_blocks
Blocks per READ(10) burst.
@ k_mlun_sectors
512-byte sectors per LUN.
@ k_mlun_burst_bytes
8 x 512 B burst buffer.
@ k_mlun_dec_radix
Base for decimal conversion.
@ k_mlun_nibble_mask
4-bit nibble mask.
@ k_mlun_nibble_bits
Bits per hex nibble.
@ k_mlun_hex_chars_u16
16-bit value -> "ABCD".
@ k_mlun_dec_chars_u32
Max digits for a 32-bit count.
@ k_mlun_hex_chars_u32
32-bit value -> "ABCDEF01".
@ k_mlun_hex_digit_split
Threshold between '0-9'/'A-F'.
@ k_mlun_phase_verify
Reading + checking LUNs.
@ k_mlun_phase_enum
Enumerating.
@ k_mlun_phase_pass
All LUNs verified.
@ k_mlun_phase_init
ra8_usb_hmsc_init issued.
@ k_mlun_print_cap
Bound for console-string scans.
@ 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.
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_pass_count
Completed full passes (sticky success counter).
static volatile uint32_t s_dbg_mismatch
First mismatching sector, or k_wlun_no_mismatch.
static volatile uint32_t s_dbg_max_lun
Device-reported GET_MAX_LUN value (expect 0, single LUN).