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

examples/ek_ra8d2/hw_validated/hil/usb_selftest_fs_host/inc/usb_selftest_fs_host_steps.h More...

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

Go to the source code of this file.

Enumerations

enum  selftest_config_t : uint32_t {
  k_selftest_thread_stack = 4096U ,
  k_selftest_host_stack = 8192U ,
  k_selftest_usbx_pool_bytes = 32768U ,
  k_selftest_block_size = 512U ,
  k_selftest_idle_ticks = 50U ,
  k_selftest_boot_wait_ticks = 500U ,
  k_selftest_retry_ticks = 5000U ,
  k_selftest_baud = 115200U ,
  k_selftest_print_cap = 160U ,
  k_selftest_dev_priority = 8U ,
  k_selftest_host_priority = 24U
}
 Compile-time settings: threads, pool, console, retry cadence. More...
enum  selftest_hex_t : uint8_t {
  k_selftest_hex_chars_u16 = 4U ,
  k_selftest_hex_chars_u32 = 8U ,
  k_selftest_dec_chars_u32 = 10U ,
  k_selftest_nibble_bits = 4U ,
  k_selftest_hex_digit_split = 10U
}
 Hex/decimal text-formatter sizing constants. More...
enum  selftest_mask_t : uint32_t {
  k_selftest_nibble_mask = 0xFU ,
  k_selftest_dec_radix = 10U
}
 Bit-mask constants used by the text formatters. More...
enum  selftest_verify_t : uint32_t {
  k_selftest_burst_blocks = 8U ,
  k_selftest_burst_bytes = 4096U ,
  k_selftest_target_lun = 0U ,
  k_selftest_wp_probe_lba = 50U ,
  k_selftest_no_mismatch = 0xFFFFFFFFU ,
  k_selftest_ms_per_sec = 1000U ,
  k_selftest_bytes_per_kib = 1024U
}
 Content-verification geometry over the device's FAT16 volume. More...
enum  selftest_phase_t : uint32_t {
  k_selftest_phase_boot = 0U ,
  k_selftest_phase_host_init = 1U ,
  k_selftest_phase_enum = 2U ,
  k_selftest_phase_mount = 3U ,
  k_selftest_phase_verify = 4U ,
  k_selftest_phase_wp = 5U ,
  k_selftest_phase_pass = 6U
}
 J-Link probe values marking host-ladder progress. More...
enum  selftest_mram_t : uint32_t {
  k_mram_base_addr = 0x02000000U ,
  k_mram_bytes = 0x00100000U
}
 The MRAM window the device-side volume exposes. More...
enum  scsi_sense_code_t : uint8_t {
  k_scsi_sense_illegal_request = 0x05U ,
  k_scsi_asc_lba_out_of_range = 0x21U ,
  k_scsi_ascq_none = 0x00U
}
 SCSI sense triple for an unsupported / out-of-range request. More...
enum  scsi_wp_sense_t : uint8_t {
  k_scsi_sense_data_protect = 0x07U ,
  k_scsi_asc_write_protected = 0x27U
}
 SCSI sense triple for a write to the protected medium. More...
enum  selftest_fat_geom_t : uint32_t {
  k_fat_reserved_sectors = 1U ,
  k_fat_num_fats = 1U ,
  k_fat_fat_sectors = 17U ,
  k_fat_root_entries = 512U ,
  k_fat_root_sectors = 32U ,
  k_fat_data_sectors = 4096U ,
  k_fat_fat_lba = 1U ,
  k_fat_root_lba = 18U ,
  k_fat_data_lba = 50U ,
  k_fat_total_sectors = 4146U ,
  k_fat_first_cluster = 2U ,
  k_fat_mram_clusters = 2048U ,
  k_fat_last_mram_clus = 2049U ,
  k_fat_entries_per_sec = 256U ,
  k_fat_eoc = 0xFFFFU ,
  k_fat_entry0 = 0xFFF8U
}
 Synthesized FAT16 volume geometry (MS FAT spec 1.03). More...
enum  selftest_fat_boot_t : uint32_t {
  k_boot_jmp0 = 0xEBU ,
  k_boot_jmp1 = 0x3CU ,
  k_boot_jmp2 = 0x90U ,
  k_boot_media = 0xF8U ,
  k_boot_sec_per_trk = 32U ,
  k_boot_num_heads = 16U ,
  k_boot_drive_num = 0x80U ,
  k_boot_ext_sig = 0x29U ,
  k_boot_volume_id = 0x52A8D20AU ,
  k_boot_sig_lo = 0x55U ,
  k_boot_sig_hi = 0xAAU ,
  k_boot_sig_lo_off = 510U ,
  k_boot_sig_hi_off = 511U
}
 Boot-sector field values (MS FAT spec 1.03 sec 3.1). More...
enum  selftest_fat_off_t : uint8_t {
  k_bpb_off_jmp = 0U ,
  k_bpb_off_oem = 3U ,
  k_bpb_off_bps = 11U ,
  k_bpb_off_spc = 13U ,
  k_bpb_off_rsvd = 14U ,
  k_bpb_off_nfats = 16U ,
  k_bpb_off_rootent = 17U ,
  k_bpb_off_totsec16 = 19U ,
  k_bpb_off_media = 21U ,
  k_bpb_off_fatsz16 = 22U ,
  k_bpb_off_spt = 24U ,
  k_bpb_off_heads = 26U ,
  k_bpb_off_drvnum = 36U ,
  k_bpb_off_bootsig = 38U ,
  k_bpb_off_volid = 39U ,
  k_bpb_off_label = 43U ,
  k_bpb_off_fstype = 54U ,
  k_dir_entry_bytes = 32U ,
  k_dir_off_attr = 11U ,
  k_dir_off_cluster_lo = 26U ,
  k_dir_off_size = 28U ,
  k_dir_attr_volume = 0x08U ,
  k_dir_attr_read_only = 0x01U ,
  k_dir_name_bytes = 11U ,
  k_byte_shift = 8U ,
  k_byte_mask = 0xFFU
}
 Byte offsets inside the boot sector and directory entries. More...
enum  selftest_word_pack_t : uint32_t {
  k_word_shift = 16U ,
  k_word_mask = 0xFFFFU
}
 32-bit little-endian split constants. More...
enum  usb_langid_byte_t : uint8_t {
  k_usb_langid_en_us_lo = 0x09U ,
  k_usb_langid_en_us_hi = 0x04U
}

Functions

UINT selftest_msc_read (VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
 Storage media-read callback: synthesize sectors over MRAM.
UINT selftest_msc_write (VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
 Storage media-write callback: always rejects (write-protected).
UINT selftest_msc_status (VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
 Storage media-status callback.
VOID selftest_device_worker (ULONG arg)
 Device-side worker: bring the HS device stack up, then park.
VOID selftest_host_worker (ULONG arg)
 Host-side worker: retry the full pass until it succeeds.

Detailed Description

examples/ek_ra8d2/hw_validated/hil/usb_selftest_fs_host/inc/usb_selftest_fs_host_steps.h

Shared contract for the USB self-loop config B (FS host) example.

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

Splits the oversized main.c into three translation units while keeping the firmware behaviour byte-for-byte identical:

  • main.c – boot, pins, SysTick, ThreadX tx_application_define, and the synthesized-disk class-registration glue.
  • usb_selftest_fs_host_fatdisk.c – the DEVICE role: the synthesized read-only FAT16 volume over the 1 MiB MRAM window, the USBX storage media callbacks, the device-stack bring-up, and the device worker.
  • usb_selftest_fs_host_host.c – the HOST role: the SCI8 console formatters, the ra8_io USB-MSC block device the ra8_fs mount runs on, the enumerate / mount / verify / write-protect ladder, and the host worker.

This header owns every compile-time constant the three units share, plus the prototypes of the five functions that cross a translation-unit boundary (the two ThreadX workers and the three USBX storage callbacks). All other helpers and file-static state stay private to their unit.

Author
Brighton Sikarskie
Date
2026-06-13
Since
0.1.0

Definition in file usb_selftest_fs_host_steps.h.

Enumeration Type Documentation

◆ scsi_sense_code_t

enum scsi_sense_code_t : uint8_t

SCSI sense triple for an unsupported / out-of-range request.

Enumerator
k_scsi_sense_illegal_request 

Sense key: ILLEGAL REQUEST.

k_scsi_asc_lba_out_of_range 

ASC: LBA out of range.

k_scsi_ascq_none 

ASCQ: none.

Definition at line 129 of file usb_selftest_fs_host_steps.h.

◆ scsi_wp_sense_t

enum scsi_wp_sense_t : uint8_t

SCSI sense triple for a write to the protected medium.

Enumerator
k_scsi_sense_data_protect 

Sense key: DATA PROTECT.

k_scsi_asc_write_protected 

ASC: WRITE PROTECTED.

Definition at line 136 of file usb_selftest_fs_host_steps.h.

◆ selftest_config_t

enum selftest_config_t : uint32_t

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

Enumerator
k_selftest_thread_stack 

Device worker stack (bytes).

k_selftest_host_stack 

Host worker stack (bytes).

k_selftest_usbx_pool_bytes 

USBX memory pool (bytes).

k_selftest_block_size 

SCSI logical block size (bytes).

k_selftest_idle_ticks 

Parked-loop back-off (ticks).

k_selftest_boot_wait_ticks 

Host start delay (1 ms ticks).

k_selftest_retry_ticks 

Pause between ladder retries.

k_selftest_baud 

J-Link OB CDC log baud.

k_selftest_print_cap 

Bound for console-string scans.

k_selftest_dev_priority 

Device bring-up worker priority.

k_selftest_host_priority 

Host worker: BELOW the USBX storage class thread (UX_THREAD_PRIORITY_CLASS = 20).

The polled host loop busy-waits for device data; if it outranked the class thread, that thread could never run selftest_msc_read and every bulk read would time out (enumeration still works – device SETUP is ISR-driven).

Definition at line 47 of file usb_selftest_fs_host_steps.h.

◆ selftest_fat_boot_t

enum selftest_fat_boot_t : uint32_t

Boot-sector field values (MS FAT spec 1.03 sec 3.1).

Enumerator
k_boot_jmp0 

Short JMP opcode.

k_boot_jmp1 

JMP displacement.

k_boot_jmp2 

NOP.

k_boot_media 

Fixed-disk media byte.

k_boot_sec_per_trk 

Geometry filler.

k_boot_num_heads 

Geometry filler.

k_boot_drive_num 

BIOS drive number.

k_boot_ext_sig 

Extended boot signature.

k_boot_volume_id 

Arbitrary volume serial.

k_boot_sig_lo 

Boot signature low byte.

k_boot_sig_hi 

Boot signature high byte.

k_boot_sig_lo_off 

Signature low-byte offset.

k_boot_sig_hi_off 

Signature high-byte offset.

Definition at line 172 of file usb_selftest_fs_host_steps.h.

◆ selftest_fat_geom_t

enum selftest_fat_geom_t : uint32_t

Synthesized FAT16 volume geometry (MS FAT spec 1.03).

Identical to usb_msc_mram: one 512-byte sector per cluster, data region padded to 4096 clusters to cross the FAT16 threshold, MRAM.BIN occupying clusters 2..2049.

Enumerator
k_fat_reserved_sectors 

Boot sector only.

k_fat_num_fats 

Single FAT copy.

k_fat_fat_sectors 

FAT16 size for 4098 entries.

k_fat_root_entries 

Root directory entries.

k_fat_root_sectors 

512 entries x 32 B / 512 B.

k_fat_data_sectors 

Padded data region (>= 4085).

k_fat_fat_lba 

First FAT sector.

k_fat_root_lba 

First root-directory sector.

k_fat_data_lba 

First data sector (cluster 2).

k_fat_total_sectors 

1 + 17 + 32 + 4096.

k_fat_first_cluster 

FAT data area starts at cluster 2.

k_fat_mram_clusters 

Clusters backed by MRAM (1 MiB).

k_fat_last_mram_clus 

Last cluster of MRAM.BIN.

k_fat_entries_per_sec 

FAT16 entries per 512-byte sector.

k_fat_eoc 

End-of-chain marker.

k_fat_entry0 

FAT[0]: media F8 + filler.

Definition at line 149 of file usb_selftest_fs_host_steps.h.

◆ selftest_fat_off_t

enum selftest_fat_off_t : uint8_t

Byte offsets inside the boot sector and directory entries.

Enumerator
k_bpb_off_jmp 

Jump instruction.

k_bpb_off_oem 

OEM name (8 bytes).

k_bpb_off_bps 

Bytes per sector.

k_bpb_off_spc 

Sectors per cluster.

k_bpb_off_rsvd 

Reserved sector count.

k_bpb_off_nfats 

Number of FATs.

k_bpb_off_rootent 

Root entry count.

k_bpb_off_totsec16 

Total sectors (16-bit).

k_bpb_off_media 

Media descriptor.

k_bpb_off_fatsz16 

Sectors per FAT.

k_bpb_off_spt 

Sectors per track.

k_bpb_off_heads 

Head count.

k_bpb_off_drvnum 

Drive number.

k_bpb_off_bootsig 

Extended boot signature.

k_bpb_off_volid 

Volume serial (4 bytes).

k_bpb_off_label 

Volume label (11 bytes).

k_bpb_off_fstype 

Filesystem type (8 bytes).

k_dir_entry_bytes 

Directory entry size.

k_dir_off_attr 

Attribute byte.

k_dir_off_cluster_lo 

First cluster (low word).

k_dir_off_size 

File size (32-bit LE).

k_dir_attr_volume 

Volume-label attribute.

k_dir_attr_read_only 

Read-only attribute.

k_dir_name_bytes 

8.3 name field length.

k_byte_shift 

Bits per byte for LE packing.

k_byte_mask 

Low-byte mask.

Definition at line 192 of file usb_selftest_fs_host_steps.h.

◆ selftest_hex_t

enum selftest_hex_t : uint8_t

Hex/decimal text-formatter sizing constants.

Enumerator
k_selftest_hex_chars_u16 

16-bit value -> "ABCD".

k_selftest_hex_chars_u32 

32-bit value -> "ABCDEF01".

k_selftest_dec_chars_u32 

Max digits for a 32-bit count.

k_selftest_nibble_bits 

Bits per hex nibble.

k_selftest_hex_digit_split 

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

Definition at line 74 of file usb_selftest_fs_host_steps.h.

◆ selftest_mask_t

enum selftest_mask_t : uint32_t

Bit-mask constants used by the text formatters.

Enumerator
k_selftest_nibble_mask 

4-bit nibble mask.

k_selftest_dec_radix 

Base for decimal conversion.

Definition at line 86 of file usb_selftest_fs_host_steps.h.

◆ selftest_mram_t

enum selftest_mram_t : uint32_t

The MRAM window the device-side volume exposes.

Enumerator
k_mram_base_addr 

MRAM code window base address.

k_mram_bytes 

1 MiB window size.

Definition at line 123 of file usb_selftest_fs_host_steps.h.

◆ selftest_phase_t

enum selftest_phase_t : uint32_t

J-Link probe values marking host-ladder progress.

Enumerator
k_selftest_phase_boot 

Host thread not yet started.

k_selftest_phase_host_init 

ra8_usb_hmsc_init issued.

k_selftest_phase_enum 

Enumerating the FS device.

k_selftest_phase_mount 

Mounting the FAT16 volume.

k_selftest_phase_verify 

Streaming + comparing MRAM.BIN.

k_selftest_phase_wp 

Write-protect rejection test.

k_selftest_phase_pass 

Full config B pass.

Definition at line 109 of file usb_selftest_fs_host_steps.h.

◆ selftest_verify_t

enum selftest_verify_t : uint32_t

Content-verification geometry over the device's FAT16 volume.

Enumerator
k_selftest_burst_blocks 

Blocks per READ(10) burst.

k_selftest_burst_bytes 

8 x 512 B burst buffer size.

k_selftest_target_lun 

Single-LUN device.

k_selftest_wp_probe_lba 

Data-region LBA for WP test.

k_selftest_no_mismatch 

Probe: no mismatch found.

k_selftest_ms_per_sec 

Milliseconds per second.

k_selftest_bytes_per_kib 

Bytes per KiB (rate math).

Definition at line 95 of file usb_selftest_fs_host_steps.h.

◆ selftest_word_pack_t

enum selftest_word_pack_t : uint32_t

32-bit little-endian split constants.

Enumerator
k_word_shift 

Bits per half-word.

k_word_mask 

Low half-word mask.

Definition at line 225 of file usb_selftest_fs_host_steps.h.

◆ usb_langid_byte_t

enum usb_langid_byte_t : uint8_t
Enumerator
k_usb_langid_en_us_lo 

LANGID 0x0409 low byte.

k_usb_langid_en_us_hi 

LANGID 0x0409 high byte.

Definition at line 236 of file usb_selftest_fs_host_steps.h.

Function Documentation

◆ selftest_device_worker()

VOID selftest_device_worker ( ULONG arg)

Device-side worker: bring the HS device stack up, then park.

USBX system + device stack + MSC class + DCD bridge on the USBHS controller, then DPRPU attach. The FS host downstream forces a full-speed link, so the stack serves the FS-fallback framework. USBX runs the SCSI/BBB state machine on its own class threads after this. Defined in usb_selftest_fs_host_fatdisk.c; spawned by tx_application_define in main.c.

Parameters
[in]argThreadX entry argument (unused).
Precondition
tx_application_define created this thread.
USB-HS pins + UTMI PLL are up (main did both).
Postcondition
The HS device is attached and serviceable.
On any bring-up failure the thread exits (probes show where).
Note
Runs once; loops forever on success.
Since
0.1.0

USBX system + device stack + MSC class + DCD bridge on the USBHS controller, then DPRPU attach. The FS host downstream forces a full-speed link, so the stack serves the FS-fallback framework. USBX runs the SCSI/BBB state machine on its own class threads after this.

Parameters
[in]argThreadX entry argument (unused).
Precondition
tx_application_define created this thread.
USB-HS pins + UTMI PLL are up (main did both).
Postcondition
The HS device is attached and serviceable.
On any bring-up failure the thread exits (probes show where).
Note
Runs once; loops forever on success.
Since
0.1.0

Device-side worker: bring the HS device stack up, then park.

USBX system + device stack + MSC class + DCD bridge on the USBFS controller, then DPRPU attach. USBX runs the SCSI/BBB state machine on its own class threads after this.

Parameters
[in]argThreadX entry argument (unused).
Precondition
tx_application_define created this thread.
USB-FS pins + 48 MHz clock are up (main did both).
Postcondition
The FS device is attached and serviceable.
On any bring-up failure the thread exits (probes show where).
Note
Runs once; loops forever on success.
Since
0.1.0

Definition at line 761 of file usb_selftest_fs_host_fatdisk.c.

References k_ra8_ok, k_ra8_usb_speed_hs, ra8_usb_device_attach(), s_dbg_dev_state, s_dbg_framework, s_dbg_fw_fs_addr, s_dbg_fw_hs_addr, s_dbg_fw_len, s_dbg_state3_seen, s_dbg_thr_runs, s_dbg_thr_state, s_dbg_ux_speed, s_device_framework_fs, s_device_framework_hs, selftest_msc_class_register(), selftest_usbx_stack_up(), tx_thread_sleep, and ux_dcd_ra8_usb_initialize().

◆ selftest_host_worker()

VOID selftest_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 config B ladder with a retry pause until it passes; afterwards parks so the verdict stays on the wire. Defined in usb_selftest_fs_host_host.c; spawned by tx_application_define.

Parameters
[in]argThreadX entry argument (unused).
Precondition
tx_application_define created this thread (lower priority than the USBX device-side threads).
The FS host pins, VBUSEN, and 48 MHz clock are up (main).
Postcondition
On success the pass counter and LED2 are latched.
Retries forever otherwise; each failure prints its step.
Note
Polled host stack: blocking calls, ms timeouts via ra8_time.
Since
0.1.0

Waits for the device side to attach, then loops selftest_host_pass with a retry pause until the whole config B ladder passes; afterwards parks so the verdict stays on the wire.

Parameters
[in]argThreadX entry argument (unused).
Precondition
tx_application_define created this thread (lower priority than the USBX device-side threads).
The FS host pins, VBUSEN, and 48 MHz clock are up (main).
Postcondition
On success the pass counter and LED2 are latched.
Retries forever otherwise; each failure prints its step.
Note
Polled host stack: blocking calls, ms timeouts via ra8_time.
Since
0.1.0

Definition at line 718 of file usb_selftest_fs_host_host.c.

References k_ra8_ok, k_selftest_boot_wait_ticks, k_selftest_idle_ticks, k_selftest_retry_ticks, selftest_host_pass(), and tx_thread_sleep.

◆ selftest_msc_read()

UINT selftest_msc_read ( VOID * storage,
ULONG lun,
UCHAR * data_pointer,
ULONG number_blocks,
ULONG lba,
ULONG * media_status )

Storage media-read callback: synthesize sectors over MRAM.

Bound checks the request against the volume, then fills each block from the synthesized FAT16 layout. LED1 toggles per call so the self-loop traffic is visible on the board. Defined in usb_selftest_fs_host_fatdisk.c; referenced by main.c when it registers the USBX storage class.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (must be 0).
[out]data_pointerUSBX-owned destination buffer.
[in]number_blocksNumber of 512-byte blocks to produce.
[in]lbaStarting LBA.
[out]media_statusFilled with sense status word.
Returns
UX_SUCCESS if the request fits the volume; otherwise UX_ERROR with media_status set to ILLEGAL REQUEST.
Return values
UX_SUCCESSRead completed.
UX_ERROROut-of-range LBA / count.
Precondition
data_pointer and media_status are non-NULL (USBX guarantee).
lun is 0 (single-LUN device).
Postcondition
Either number_blocks * 512 bytes were synthesized or media_status is non-zero.
The device-side read counter advanced.
Note
Called from the USBX storage class thread.
Since
0.1.0

Bound checks the request against the volume, then fills each block via the FAT16 synthesizer. LED1 toggles per call so the self-loop traffic is visible on the board.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (must be 0).
[out]data_pointerUSBX-owned destination buffer.
[in]number_blocksNumber of 512-byte blocks to produce.
[in]lbaStarting LBA.
[out]media_statusFilled with sense status word.
Returns
UX_SUCCESS if the request fits the volume; otherwise UX_ERROR with media_status set to ILLEGAL REQUEST.
Return values
UX_SUCCESSRead completed.
UX_ERROROut-of-range LBA / count.
Precondition
data_pointer and media_status are non-NULL (USBX guarantee).
lun is 0 (single-LUN device).
Postcondition
Either number_blocks * 512 bytes were synthesized or media_status is non-zero.
The device-side read-call probe advanced.
Note
Called from the USBX storage class thread.
Since
0.1.0

Bound checks the request against the volume, then fills each block via selftest_fat_fill_sector. LED1 toggles per call so the self-loop traffic is visible on the board.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (must be 0).
[out]data_pointerUSBX-owned destination buffer.
[in]number_blocksNumber of 512-byte blocks to produce.
[in]lbaStarting LBA.
[out]media_statusFilled with sense status word.
Returns
UX_SUCCESS if the request fits the volume; otherwise UX_ERROR with media_status set to ILLEGAL REQUEST.
Return values
UX_SUCCESSRead completed.
UX_ERROROut-of-range LBA / count.
Precondition
data_pointer and media_status are non-NULL (USBX guarantee).
lun is 0 (single-LUN device).
Postcondition
Either number_blocks * 512 bytes were synthesized or media_status is non-zero.
s_dbg_read_calls advanced.
Note
Called from the USBX storage class thread.
Since
0.1.0

Bound checks the request against the volume, then fills each block via the FAT16 synthesizer. LED1 toggles per call so the self-loop traffic is visible on the board.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (must be 0).
[out]data_pointerUSBX-owned destination buffer.
[in]number_blocksNumber of 512-byte blocks to produce.
[in]lbaStarting LBA.
[out]media_statusFilled with sense status word.
Returns
UX_SUCCESS if the request fits the volume; otherwise UX_ERROR with media_status set to ILLEGAL REQUEST.
Return values
UX_SUCCESSRead completed.
UX_ERROROut-of-range LBA / count.
Precondition
data_pointer and media_status are non-NULL (USBX guarantee).
lun is 0 (single-LUN device).
Postcondition
Either number_blocks * 512 bytes were synthesized or media_status is non-zero.
The device-side read-call probe advanced.
Note
Called from the USBX storage class thread.
Since
0.1.0

Bound checks the request against the volume, then fills each block via selftest_fat_fill_sector. LED1 toggles per call so the self-loop traffic is visible on the board.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (must be 0).
[out]data_pointerUSBX-owned destination buffer.
[in]number_blocksNumber of 512-byte blocks to produce.
[in]lbaStarting LBA.
[out]media_statusFilled with sense status word.
Returns
UX_SUCCESS if the request fits the volume; otherwise UX_ERROR with media_status set to ILLEGAL REQUEST.
Return values
UX_SUCCESSRead completed.
UX_ERROROut-of-range LBA / count.
Precondition
data_pointer and media_status are non-NULL (USBX guarantee).
lun is 0 (single-LUN device).
Postcondition
Either number_blocks * 512 bytes were synthesized or media_status is non-zero.
s_dbg_read_calls advanced.
Note
Called from the USBX storage class thread.
Since
0.1.0

Definition at line 304 of file usb_host_msc_browse_steps.c.

◆ selftest_msc_status()

UINT selftest_msc_status ( VOID * storage,
ULONG lun,
ULONG media_id,
ULONG * media_status )

Storage media-status callback.

Always reports media-present.

The synthesized volume cannot go away; status is constant 0. Defined in usb_selftest_fs_host_fatdisk.c.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (unused).
[in]media_idMedia id (unused).
[out]media_statusFilled with 0 (no fault).
Returns
Always UX_SUCCESS.
Return values
UX_SUCCESSMedia is present and ready.
Precondition
media_status is non-NULL (USBX guarantee).
The class instance is live.
Postcondition
*media_status is 0.
No other state changes.
Note
Synthesized volume; never reports media-not-present.
Since
0.1.0

Always reports media-present.

The synthesized volume cannot go away; status is constant 0.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (unused).
[in]media_idMedia id (unused).
[out]media_statusFilled with 0 (no fault).
Returns
Always UX_SUCCESS.
Return values
UX_SUCCESSMedia is present and ready.
Precondition
media_status is non-NULL (USBX guarantee).
The class instance is live.
Postcondition
*media_status is 0.
No other state changes.
Note
Synthesized volume; never reports media-not-present.
Since
0.1.0

Definition at line 347 of file usb_host_msc_browse_steps.c.

◆ selftest_msc_write()

UINT selftest_msc_write ( VOID * storage,
ULONG lun,
UCHAR * data_pointer,
ULONG number_blocks,
ULONG lba,
ULONG * media_status )

Storage media-write callback: always rejects (write-protected).

The host side of this very app probes exactly this rejection (WRITE(10) must fail with DATA PROTECT and the transport must keep working afterwards). Defined in usb_selftest_fs_host_fatdisk.c.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (unused).
[in]data_pointerUSBX-owned source buffer (unused).
[in]number_blocksNumber of blocks the host tried (unused).
[in]lbaStarting LBA (unused).
[out]media_statusFilled with DATA PROTECT sense.
Returns
Always UX_ERROR.
Return values
UX_ERRORThe medium is write-protected.
Precondition
media_status is non-NULL (USBX guarantee).
The LUN also reports write-protected via MODE SENSE.
Postcondition
*media_status carries the DATA PROTECT sense triple.
The MRAM window is untouched.
Note
Hosts honouring the MODE SENSE WP bit never call this.
Since
0.1.0

The host side of this very app probes exactly this rejection (WRITE(10) must fail with DATA PROTECT and the transport must keep working afterwards).

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (unused).
[in]data_pointerUSBX-owned source buffer (unused).
[in]number_blocksNumber of blocks the host tried (unused).
[in]lbaStarting LBA (unused).
[out]media_statusFilled with DATA PROTECT sense.
Returns
Always UX_ERROR.
Return values
UX_ERRORThe medium is write-protected.
Precondition
media_status is non-NULL (USBX guarantee).
The LUN also reports write-protected via MODE SENSE.
Postcondition
*media_status carries the DATA PROTECT sense triple.
The MRAM window is untouched.
Note
Hosts honouring the MODE SENSE WP bit never call this.
Since
0.1.0

Definition at line 328 of file usb_host_msc_browse_steps.c.