|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
examples/ek_ra8d2/hw_validated/hil/usb_selftest_fs_host/src/usb_selftest_fs_host_fatdisk.c More...
#include <stdint.h>#include <string.h>#include "usb_selftest_fs_host_steps.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_err.h"#include "ra8_usb.h"#include "tx_api.h"#include "ux_api.h"#include "ux_dcd_ra8_usb.h"#include "ux_device_class_storage.h"#include "ux_device_stack.h"Go to the source code of this file.
Functions | |
| static void | selftest_put16 (UCHAR *dst, uint16_t value) |
| Write a 16-bit value little-endian into a byte buffer. | |
| static void | selftest_put32 (UCHAR *dst, uint32_t value) |
| Write a 32-bit value little-endian into a byte buffer. | |
| static void | selftest_fat_fill_boot (UCHAR *out) |
| Synthesize the FAT16 boot sector (MS FAT spec 1.03 sec 3.1). | |
| static void | selftest_fat_fill_fat (uint32_t fat_sector, UCHAR *out) |
| Synthesize one FAT16 sector of the cluster chain. | |
| static void | selftest_fat_fill_root (uint32_t root_sector, UCHAR *out) |
| Synthesize one root-directory sector. | |
| 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. | |
| 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. | |
| static UINT | selftest_usbx_stack_up (void) |
| Brings USBX system + FS device stack up. | |
| static UINT | selftest_msc_class_register (void) |
| Registers the Mass-Storage class with the read-only MRAM LUN. | |
| VOID | selftest_device_worker (ULONG arg) |
| Device-side worker: bring the HS device stack up, then park. | |
Variables | |
| static UCHAR | s_usbx_pool [k_selftest_usbx_pool_bytes] |
| USBX memory pool (USBX uses tx_byte_pool internally). | |
| static UCHAR | s_msc_vendor_id [] = "RA8D2 " |
| static UCHAR | s_msc_product_id [] = "SELFTEST MRAM RO" |
| static UCHAR | s_msc_product_rev [] = "0001" |
| static const UCHAR | s_fat_oem_name [8] = {'R', 'A', '8', 'D', '2', 'F', 'W', ' '} |
| Boot-sector OEM name (8 bytes, space padded). | |
| static const UCHAR | s_fat_volume_label [11] = {'R', 'A', '8', 'D', '2', ' ', 'M', 'R', 'A', 'M', ' '} |
| Volume label, 11 bytes space padded (also the root entry). | |
| static const UCHAR | s_fat_fs_type [8] = {'F', 'A', 'T', '1', '6', ' ', ' ', ' '} |
| Filesystem-type tag, 8 bytes space padded. | |
| static const UCHAR | s_fat_file_name [11] = {'M', 'R', 'A', 'M', ' ', ' ', ' ', ' ', 'B', 'I', 'N'} |
| 8.3 directory name of the exposed file: "MRAM.BIN". | |
| static volatile uint32_t | s_dbg_read_calls |
| Device-side media_read invocations. | |
| static volatile uint32_t | s_dbg_dev_state |
| Device-side ux_slave_device_state sample (3 = CONFIGURED). | |
| static volatile uint32_t | s_dbg_ux_speed |
| Device-side USBX negotiated speed (0 = HS, 1 = FS in UX terms). | |
| static volatile uint32_t | s_dbg_thr_runs |
| Storage class thread ThreadX run-count (0 = never scheduled). | |
| static volatile uint32_t | s_dbg_thr_state |
| Storage class thread ThreadX state (see tx_api TX_* states). | |
| static volatile uint32_t | s_dbg_state3_seen |
| Times the device sampler observed UX_DEVICE_CONFIGURED. | |
| static volatile uint32_t | s_dbg_framework |
| Current device framework pointer (HS vs FS array address). | |
| static volatile uint32_t | s_dbg_fw_len |
| Current device framework length (32 = FS cfg, 42 = HS cfg). | |
| static volatile uint32_t | s_dbg_fw_fs_addr |
| Address of the FS framework array (compare vs s_dbg_framework). | |
| static volatile uint32_t | s_dbg_fw_hs_addr |
| Address of the HS framework array (compare vs s_dbg_framework). | |
| static UCHAR | s_device_framework_hs [] |
| static UCHAR | s_device_framework_fs [] |
| static UCHAR | s_string_framework [] |
| USBX string descriptor table (vendor / product / serial). | |
| static UCHAR | s_language_id_framework [] = {k_usb_langid_en_us_lo, k_usb_langid_en_us_hi} |
| USBX language-id table – US English. | |
examples/ek_ra8d2/hw_validated/hil/usb_selftest_fs_host/src/usb_selftest_fs_host_fatdisk.c
Device role: synthesized read-only FAT16 MRAM disk + USBX bring-up.
The DEVICE half of the USB self-loop config B example, split out of main.c. The board's USBHS controller exposes the 1 MiB MRAM window at 0x02000000 as a read-only synthesized FAT16 volume with one file MRAM.BIN. This unit owns:
The compile-time geometry and the cross-unit prototypes live in usb_selftest_fs_host_steps.h. The static data and helpers here stay private to this translation unit; only selftest_msc_read, selftest_msc_write, selftest_msc_status, and selftest_device_worker are referenced from main.c.
Definition in file usb_selftest_fs_host_fatdisk.c.
| VOID selftest_device_worker | ( | ULONG | arg | ) |
Device-side worker: bring the HS device stack up, then park.
Device-side worker: bring the FS device MSC 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.
| [in] | arg | ThreadX entry argument (unused). |
Definition at line 761 of file usb_selftest_fs_host_fatdisk.c.
|
static |
Synthesize the FAT16 boot sector (MS FAT spec 1.03 sec 3.1).
BPB for the padded 4146-sector volume plus the 0x55AA signature; geometry constants in selftest_fat_geom_t.
| [out] | out | Zeroed 512-byte sector buffer. |
out is zeroed. out holds the BPB + 0x55AA signature. Definition at line 382 of file usb_selftest_fs_host_fatdisk.c.
References k_boot_drive_num, k_boot_ext_sig, k_boot_jmp0, k_boot_jmp1, k_boot_jmp2, k_boot_media, k_boot_num_heads, k_boot_sec_per_trk, k_boot_sig_hi, k_boot_sig_hi_off, k_boot_sig_lo, k_boot_sig_lo_off, k_boot_volume_id, k_bpb_off_bootsig, k_bpb_off_bps, k_bpb_off_drvnum, k_bpb_off_fatsz16, k_bpb_off_fstype, k_bpb_off_heads, k_bpb_off_jmp, k_bpb_off_label, k_bpb_off_media, k_bpb_off_nfats, k_bpb_off_oem, k_bpb_off_rootent, k_bpb_off_rsvd, k_bpb_off_spc, k_bpb_off_spt, k_bpb_off_totsec16, k_bpb_off_volid, k_fat_fat_sectors, k_fat_num_fats, k_fat_reserved_sectors, k_fat_root_entries, k_fat_total_sectors, k_selftest_block_size, memcpy(), s_fat_fs_type, s_fat_oem_name, s_fat_volume_label, selftest_put16(), and selftest_put32().
Referenced by selftest_fat_fill_sector().
|
static |
Synthesize one FAT16 sector of the cluster chain.
MRAM.BIN occupies clusters 2..2049 as one sequential chain (entry c -> c + 1, last entry -> end-of-chain). Entries 0/1 carry the media descriptor per the FAT spec; everything past the chain reads as free (0x0000).
| [in] | fat_sector | Index of the FAT sector (0-based). |
| [out] | out | Zeroed 512-byte sector buffer. |
out is zeroed. fat_sector is below k_fat_fat_sectors. out holds 256 little-endian FAT16 entries. Definition at line 426 of file usb_selftest_fs_host_fatdisk.c.
References k_fat_entries_per_sec, k_fat_entry0, k_fat_eoc, k_fat_last_mram_clus, and selftest_put16().
Referenced by selftest_fat_fill_sector().
|
static |
Synthesize one root-directory sector.
Sector 0 of the root carries two entries: the volume label and the read-only MRAM.BIN file (start cluster 2, size 1 MiB). Every other root sector is empty.
| [in] | root_sector | Index of the root sector (0-based). |
| [out] | out | Zeroed 512-byte sector buffer. |
out is zeroed. root_sector is below k_fat_root_sectors. out holds the directory entries for that sector. Definition at line 465 of file usb_selftest_fs_host_fatdisk.c.
References k_dir_attr_read_only, k_dir_attr_volume, k_dir_entry_bytes, k_dir_name_bytes, k_dir_off_attr, k_dir_off_cluster_lo, k_dir_off_size, k_fat_first_cluster, k_mram_bytes, memcpy(), s_fat_file_name, s_fat_volume_label, selftest_put16(), and selftest_put32().
Referenced by selftest_fat_fill_sector().
|
static |
Synthesize one 512-byte sector of the read-only volume.
Dispatches on the LBA: boot sector, FAT, root directory, or data region. Data sectors inside the MRAM.BIN chain are copied straight out of the 1 MiB MRAM window; padding clusters past the chain read as zeros.
| [in] | lba | Logical block address inside the volume. |
| [out] | out | 512-byte destination buffer. |
lba is below k_fat_total_sectors (caller-checked). out has 512 writable bytes. out holds the synthesized sector content. Definition at line 500 of file usb_selftest_fs_host_fatdisk.c.
References k_fat_data_lba, k_fat_fat_lba, k_fat_first_cluster, k_fat_last_mram_clus, k_fat_root_lba, k_mram_base_addr, k_selftest_block_size, memcpy(), memset(), selftest_fat_fill_boot(), selftest_fat_fill_fat(), and selftest_fat_fill_root().
Referenced by selftest_msc_read().
|
static |
Registers the Mass-Storage class with the read-only MRAM LUN.
Single LUN, write-protected, FAT16 geometry from selftest_fat_geom_t, media callbacks above.
| UX_SUCCESS | Class registered. |
Definition at line 708 of file usb_selftest_fs_host_fatdisk.c.
References k_fat_total_sectors, k_selftest_block_size, memset(), s_msc_product_id, s_msc_product_rev, s_msc_vendor_id, selftest_msc_read(), selftest_msc_status(), and selftest_msc_write().
Referenced by selftest_device_worker().
| 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 via selftest_fat_fill_sector. LED1 toggles per call so the self-loop traffic is visible on the board.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (must be 0). |
| [out] | data_pointer | USBX-owned destination buffer. |
| [in] | number_blocks | Number of 512-byte blocks to produce. |
| [in] | lba | Starting LBA. |
| [out] | media_status | Filled with sense status word. |
| UX_SUCCESS | Read completed. |
| UX_ERROR | Out-of-range LBA / count. |
Definition at line 557 of file usb_selftest_fs_host_fatdisk.c.
References k_fat_total_sectors, k_ra8_board_led1, k_scsi_asc_lba_out_of_range, k_scsi_ascq_none, k_scsi_sense_illegal_request, k_selftest_block_size, ra8_board_led_toggle(), s_dbg_read_calls, and selftest_fat_fill_sector().
Storage media-status callback.
Always reports media-present.
The synthesized volume cannot go away; status is constant 0.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (unused). |
| [in] | media_id | Media id (unused). |
| [out] | media_status | Filled with 0 (no fault). |
| UX_SUCCESS | Media is present and ready. |
Definition at line 645 of file usb_selftest_fs_host_fatdisk.c.
| 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).
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (unused). |
| [in] | data_pointer | USBX-owned source buffer (unused). |
| [in] | number_blocks | Number of blocks the host tried (unused). |
| [in] | lba | Starting LBA (unused). |
| [out] | media_status | Filled with DATA PROTECT sense. |
| UX_ERROR | The medium is write-protected. |
Definition at line 606 of file usb_selftest_fs_host_fatdisk.c.
References k_scsi_asc_write_protected, k_scsi_ascq_none, and k_scsi_sense_data_protect.
|
static |
Write a 16-bit value little-endian into a byte buffer.
Low byte first, high byte second, per the FAT on-disk layout.
| [out] | dst | Destination (2 bytes). |
| [in] | value | Value to store. |
dst has 2 writable bytes. Definition at line 338 of file usb_selftest_fs_host_fatdisk.c.
References k_byte_mask, and k_byte_shift.
Referenced by selftest_fat_fill_boot(), selftest_fat_fill_fat(), selftest_fat_fill_root(), and selftest_put32().
|
static |
Write a 32-bit value little-endian into a byte buffer.
Two selftest_put16 halves, low half-word first.
| [out] | dst | Destination (4 bytes). |
| [in] | value | Value to store. |
dst has 4 writable bytes. dst holds the four little-endian bytes of value. Definition at line 360 of file usb_selftest_fs_host_fatdisk.c.
References k_word_mask, k_word_shift, and selftest_put16().
Referenced by selftest_fat_fill_boot(), and selftest_fat_fill_root().
|
static |
Brings USBX system + FS device stack up.
One-shot USBX pool + device-stack initialization for the FS-only framework.
| UX_SUCCESS | Stack ready. |
Definition at line 675 of file usb_selftest_fs_host_fatdisk.c.
References k_selftest_usbx_pool_bytes, s_device_framework_fs, s_device_framework_hs, s_language_id_framework, s_string_framework, and s_usbx_pool.
Referenced by selftest_device_worker().
|
static |
Device-side ux_slave_device_state sample (3 = CONFIGURED).
Definition at line 85 of file usb_selftest_fs_host_fatdisk.c.
Referenced by demo_worker(), and selftest_device_worker().
|
static |
Current device framework pointer (HS vs FS array address).
Definition at line 95 of file usb_selftest_fs_host_fatdisk.c.
Referenced by demo_worker(), and selftest_device_worker().
|
static |
Address of the FS framework array (compare vs s_dbg_framework).
Definition at line 99 of file usb_selftest_fs_host_fatdisk.c.
Referenced by selftest_device_worker().
|
static |
Address of the HS framework array (compare vs s_dbg_framework).
Definition at line 101 of file usb_selftest_fs_host_fatdisk.c.
Referenced by selftest_device_worker().
|
static |
Current device framework length (32 = FS cfg, 42 = HS cfg).
Definition at line 97 of file usb_selftest_fs_host_fatdisk.c.
Referenced by demo_worker(), and selftest_device_worker().
|
static |
Device-side media_read invocations.
Definition at line 83 of file usb_selftest_fs_host_fatdisk.c.
|
static |
Times the device sampler observed UX_DEVICE_CONFIGURED.
Definition at line 93 of file usb_selftest_fs_host_fatdisk.c.
Referenced by demo_worker(), and selftest_device_worker().
|
static |
Storage class thread ThreadX run-count (0 = never scheduled).
Definition at line 89 of file usb_selftest_fs_host_fatdisk.c.
Referenced by demo_worker(), and selftest_device_worker().
|
static |
Storage class thread ThreadX state (see tx_api TX_* states).
Definition at line 91 of file usb_selftest_fs_host_fatdisk.c.
Referenced by demo_worker(), and selftest_device_worker().
|
static |
Device-side USBX negotiated speed (0 = HS, 1 = FS in UX terms).
Definition at line 87 of file usb_selftest_fs_host_fatdisk.c.
Referenced by demo_worker(), and selftest_device_worker().
|
static |
Definition at line 185 of file usb_selftest_fs_host_fatdisk.c.
|
static |
Definition at line 114 of file usb_selftest_fs_host_fatdisk.c.
Referenced by demo_usbx_stack_up(), selftest_device_worker(), and selftest_usbx_stack_up().
|
static |
8.3 directory name of the exposed file: "MRAM.BIN".
Definition at line 76 of file usb_selftest_fs_host_fatdisk.c.
|
static |
Filesystem-type tag, 8 bytes space padded.
Definition at line 73 of file usb_selftest_fs_host_fatdisk.c.
|
static |
Boot-sector OEM name (8 bytes, space padded).
Definition at line 67 of file usb_selftest_fs_host_fatdisk.c.
|
static |
Volume label, 11 bytes space padded (also the root entry).
Definition at line 70 of file usb_selftest_fs_host_fatdisk.c.
|
static |
USBX language-id table – US English.
Definition at line 316 of file usb_selftest_fs_host_fatdisk.c.
|
static |
Definition at line 63 of file usb_selftest_fs_host_fatdisk.c.
|
static |
Definition at line 64 of file usb_selftest_fs_host_fatdisk.c.
|
static |
Definition at line 62 of file usb_selftest_fs_host_fatdisk.c.
|
static |
USBX string descriptor table (vendor / product / serial).
Each entry: 2 bytes lang-id, 1 byte string index, 1 byte length, then ASCII bytes.
Definition at line 250 of file usb_selftest_fs_host_fatdisk.c.
|
static |
USBX memory pool (USBX uses tx_byte_pool internally).
Definition at line 59 of file usb_selftest_fs_host_fatdisk.c.