47#include "ux_device_class_storage.h"
48#include "ux_device_stack.h"
67static const UCHAR
s_fat_oem_name[8] = {
'R',
'A',
'8',
'D',
'2',
'F',
'W',
' '};
70static const UCHAR
s_fat_volume_label[11] = {
'R',
'A',
'8',
'D',
'2',
' ',
'M',
'R',
'A',
'M',
' '};
73static const UCHAR
s_fat_fs_type[8] = {
'F',
'A',
'T',
'1',
'6',
' ',
' ',
' '};
76static const UCHAR
s_fat_file_name[11] = {
'M',
'R',
'A',
'M',
' ',
' ',
' ',
' ',
'B',
'I',
'N'};
430 const uint32_t entry = first_entry + j;
434 }
else if (entry == 1U) {
437 value = (uint16_t)(entry + 1U);
467 if (root_sector != 0U) {
517 const uint32_t offset =
519 const UCHAR* mram = (
const UCHAR*)(uintptr_t)((uint32_t)
k_mram_base_addr + offset);
573 for (
ULONG i = 0UL; i < number_blocks; i++) {
710 UX_SLAVE_CLASS_STORAGE_PARAMETER msc_params;
711 (void)
memset(&msc_params, 0,
sizeof(msc_params));
712 msc_params.ux_slave_class_storage_parameter_number_lun = 1UL;
713 msc_params.ux_slave_class_storage_parameter_vendor_id =
s_msc_vendor_id;
717 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_last_lba =
719 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_block_length =
721 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_type =
722 UX_SLAVE_CLASS_STORAGE_MEDIA_FAT_DISK;
723 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_removable_flag =
724 UX_SLAVE_CLASS_STORAGE_MEDIA_IS_REMOVABLE;
725 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_read_only_flag =
727 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_read =
729 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_write =
731 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_status =
734 static UCHAR s_class_name[] =
"ux_slave_class_storage";
736 return _ux_device_stack_class_register(s_class_name,
737 _ux_device_class_storage_entry,
784 s_dbg_dev_state = (uint32_t)_ux_system_slave->ux_system_slave_device.ux_slave_device_state;
785 s_dbg_ux_speed = (uint32_t)_ux_system_slave->ux_system_slave_speed;
786 s_dbg_framework = (uint32_t)(uintptr_t)_ux_system_slave->ux_system_slave_device_framework;
787 s_dbg_fw_len = (uint32_t)_ux_system_slave->ux_system_slave_device_framework_length;
788 s_dbg_thr_state = (uint32_t)_ux_system_slave->ux_system_slave_class_array[0]
789 .ux_slave_class_thread.tx_thread_state;
790 s_dbg_thr_runs = (uint32_t)_ux_system_slave->ux_system_slave_class_array[0]
791 .ux_slave_class_thread.tx_thread_run_count;
795 (void)tx_thread_resume(
796 &_ux_system_slave->ux_system_slave_class_array[0].ux_slave_class_thread);
static UCHAR s_msc_product_id[]
static UCHAR s_string_framework[]
USBX string descriptor table (vendor / product / serial).
@ k_scsi_ascq_none
ASCQ: none.
@ k_scsi_asc_write_protected
ASC: WRITE PROTECTED.
@ k_scsi_sense_illegal_request
Sense key: ILLEGAL REQUEST.
@ k_scsi_sense_data_protect
Sense key: DATA PROTECT.
@ k_scsi_asc_lba_out_of_range
ASC: LBA out of range.
static UCHAR s_usbx_pool[k_wlun_usbx_pool_bytes]
USBX memory pool (USBX uses tx_byte_pool internally).
@ k_usb_langid_en_us_lo
LANGID 0x0409 low byte.
@ k_usb_langid_en_us_hi
LANGID 0x0409 high byte.
static UCHAR s_device_framework_fs[]
static UCHAR s_msc_product_rev[]
static UCHAR s_language_id_framework[]
USBX language-id table – US English.
static volatile uint32_t s_dbg_read_calls
Device-side media_read invocations.
static UCHAR s_msc_vendor_id[]
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
@ k_dir_off_attr
MS FAT spec sec 6 "DIR_Attr".
Native USB controller driver public API (device + host modes).
ra8_err_t ra8_usb_device_attach(ra8_usb_speed_t speed, bool attached)
Raise / drop the D+ pull-up to advertise the device to the host.
@ k_ra8_usb_speed_hs
High-Speed controller (USBHS @ 0x40351000).
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
static const UCHAR s_fat_oem_name[8]
Boot-sector OEM name (8 bytes, space padded).
static const UCHAR s_fat_fs_type[8]
Filesystem-type tag, 8 bytes space padded.
static const UCHAR s_fat_volume_label[11]
Volume label, 11 bytes space padded (also the root entry).
@ k_boot_sig_hi_off
Signature high-byte offset.
@ k_boot_jmp0
Short JMP opcode.
@ k_boot_num_heads
Geometry filler.
@ k_boot_sig_lo_off
Signature low-byte offset.
@ k_boot_sig_hi
Boot signature high byte.
@ k_boot_jmp1
JMP displacement.
@ k_boot_sig_lo
Boot signature low byte.
@ k_boot_media
Fixed-disk media byte.
@ k_boot_sec_per_trk
Geometry filler.
@ k_boot_ext_sig
Extended boot signature.
@ k_boot_drive_num
BIOS drive number.
@ k_boot_volume_id
Arbitrary volume serial.
static const UCHAR s_fat_file_name[11]
8.3 directory name of the exposed file: "MRAM.BIN".
@ k_word_shift
Bits per half-word.
UINT selftest_msc_status(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
Storage media-status callback.
@ k_fat_root_entries
Root directory entries.
@ k_fat_eoc
End-of-chain marker.
@ k_fat_data_lba
First data sector (cluster 2).
@ k_fat_root_lba
First root-directory sector.
@ k_fat_fat_sectors
FAT16 size for 4098 entries.
@ k_fat_fat_lba
First FAT sector.
@ k_fat_first_cluster
FAT data area starts at cluster 2.
@ k_fat_entry0
FAT[0]: media F8 + filler.
@ k_fat_reserved_sectors
Boot sector only.
@ k_fat_entries_per_sec
FAT16 entries per 512-byte sector.
@ k_fat_total_sectors
1 + 17 + 32 + 4096.
@ k_fat_last_mram_clus
Last cluster of MRAM.BIN.
@ k_fat_num_fats
Single FAT copy.
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.
@ k_dir_entry_bytes
Directory entry size.
@ k_bpb_off_spt
Sectors per track.
@ k_bpb_off_label
Volume label (11 bytes).
@ k_dir_attr_volume
Volume-label attribute.
@ k_bpb_off_media
Media descriptor.
@ k_bpb_off_bps
Bytes per sector.
@ k_dir_off_size
File size (32-bit LE).
@ k_bpb_off_jmp
Jump instruction.
@ k_bpb_off_heads
Head count.
@ k_bpb_off_oem
OEM name (8 bytes).
@ k_bpb_off_volid
Volume serial (4 bytes).
@ k_bpb_off_bootsig
Extended boot signature.
@ k_bpb_off_fatsz16
Sectors per FAT.
@ k_bpb_off_rsvd
Reserved sector count.
@ k_bpb_off_drvnum
Drive number.
@ k_bpb_off_fstype
Filesystem type (8 bytes).
@ k_bpb_off_rootent
Root entry count.
@ k_dir_name_bytes
8.3 name field length.
@ k_byte_shift
Bits per byte for LE packing.
@ k_dir_off_cluster_lo
First cluster (low word).
@ k_bpb_off_nfats
Number of FATs.
@ k_bpb_off_spc
Sectors per cluster.
@ k_bpb_off_totsec16
Total sectors (16-bit).
@ k_dir_attr_read_only
Read-only attribute.
@ k_mram_bytes
1 MiB window size.
@ k_mram_base_addr
MRAM code window base address.
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).
@ k_selftest_block_size
SCSI logical block size (bytes).
@ k_selftest_usbx_pool_bytes
USBX memory pool (bytes).
static volatile uint32_t s_dbg_thr_state
Storage class thread ThreadX state (see tx_api TX_* states).
static volatile uint32_t s_dbg_thr_runs
Storage class thread ThreadX run-count (0 = never scheduled).
UINT selftest_msc_status(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
Storage media-status callback.
static void selftest_put16(UCHAR *dst, uint16_t value)
Write a 16-bit value little-endian into a byte buffer.
static volatile uint32_t s_dbg_fw_hs_addr
Address of the HS framework array (compare vs s_dbg_framework).
VOID selftest_device_worker(ULONG arg)
Device-side worker: bring the HS device stack up, then park.
static void selftest_fat_fill_root(uint32_t root_sector, UCHAR *out)
Synthesize one root-directory sector.
static volatile uint32_t s_dbg_fw_fs_addr
Address of the FS framework array (compare vs s_dbg_framework).
static UCHAR s_device_framework_hs[]
static volatile uint32_t s_dbg_state3_seen
Times the device sampler observed UX_DEVICE_CONFIGURED.
static volatile uint32_t s_dbg_ux_speed
Device-side USBX negotiated speed (0 = HS, 1 = FS in UX terms).
static void selftest_fat_fill_sector(uint32_t lba, UCHAR *out)
Synthesize one 512-byte sector of the read-only volume.
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.
static volatile uint32_t s_dbg_dev_state
Device-side ux_slave_device_state sample (3 = CONFIGURED).
static void selftest_fat_fill_boot(UCHAR *out)
Synthesize the FAT16 boot sector (MS FAT spec 1.03 sec 3.1).
static volatile uint32_t s_dbg_fw_len
Current device framework length (32 = FS cfg, 42 = HS cfg).
static UINT selftest_usbx_stack_up(void)
Brings USBX system + FS device stack up.
static void selftest_fat_fill_fat(uint32_t fat_sector, UCHAR *out)
Synthesize one FAT16 sector of the cluster chain.
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).
static void selftest_put32(UCHAR *dst, uint32_t value)
Write a 32-bit value little-endian into a byte buffer.
static volatile uint32_t s_dbg_framework
Current device framework pointer (HS vs FS array address).
static UINT selftest_msc_class_register(void)
Registers the Mass-Storage class with the read-only MRAM LUN.
examples/ek_ra8d2/hw_validated/hil/usb_selftest_fs_host/inc/usb_selftest_fs_host_steps....
USBX device-controller-driver (DCD) bridge to ra8_usb.
ra8_err_t ux_dcd_ra8_usb_initialize(ra8_usb_speed_t speed)
Register the ra8_usb bridge as the active USBX DCD.