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

Shared geometry constants + FAT16 sector-synthesis prototype. More...

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

Go to the source code of this file.

Enumerations

enum  demo_config_t : uint32_t {
  k_demo_thread_stack = 4096U ,
  k_demo_usbx_pool_bytes = 32768U ,
  k_demo_block_size = 512U ,
  k_demo_idle_ticks = 50U
}
 Compile-time settings for the worker thread + USBX pool + RAM-disk geometry. More...
enum  demo_mram_t : uint32_t {
  k_mram_base_addr = 0x02000000U ,
  k_mram_bytes = 0x00100000U
}
 The MRAM window this volume exposes (RA8D2 HUM memory map). More...
enum  demo_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  demo_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 = 0x52A8D200U ,
  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  demo_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  demo_word_pack_t : uint32_t {
  k_word_shift = 16U ,
  k_word_mask = 0xFFFFU
}
 32-bit little-endian split constants. More...

Functions

void demo_fat_fill_sector (uint32_t lba, UCHAR *out)
 Synthesize one 512-byte sector of the read-only volume.

Detailed Description

Shared geometry constants + FAT16 sector-synthesis prototype.

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

Declares the compile-time FAT16 volume-geometry / boot-sector / offset enums plus the read-only sector-synthesizer that main.c and usb_msc_mram_steps.c share. The enums live here so the on-the-fly volume image stays a single source of truth: the worker thread in main.c reads geometry constants such as k_fat_total_sectors and k_demo_block_size to size the LUN, while the synthesis helpers in usb_msc_mram_steps.c consume the same byte-offset and field-value constants to build each 512-byte sector.

Author
Brighton Sikarskie
Date
2026-05-02
Since
0.1.0

Definition in file usb_msc_mram_steps.h.

Enumeration Type Documentation

◆ demo_config_t

enum demo_config_t : uint32_t

Compile-time settings for the worker thread + USBX pool + RAM-disk geometry.

Enumerator
k_demo_thread_stack 

Worker thread stack (bytes).

k_demo_usbx_pool_bytes 

USBX memory pool (bytes).

k_demo_block_size 

SCSI logical block size (bytes).

k_demo_idle_ticks 

Heartbeat back-off (ThreadX ticks).

Definition at line 34 of file usb_msc_mram_steps.h.

◆ demo_fat_boot_t

enum demo_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 84 of file usb_msc_mram_steps.h.

◆ demo_fat_geom_t

enum demo_fat_geom_t : uint32_t

Synthesized FAT16 volume geometry (MS FAT spec 1.03).

One 512-byte sector per cluster. The data region is padded to 4096 clusters so the cluster count crosses the 4085 FAT16 threshold; only the first 2048 clusters (1 MiB) are backed by MRAM, and nothing references the rest. FAT16 needs 2 bytes per entry for 4098 entries = 8196 bytes = 17 sectors. The root directory holds 512 entries = 32 sectors.

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 61 of file usb_msc_mram_steps.h.

◆ demo_fat_off_t

enum demo_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 104 of file usb_msc_mram_steps.h.

◆ demo_mram_t

enum demo_mram_t : uint32_t

The MRAM window this volume exposes (RA8D2 HUM memory map).

Enumerator
k_mram_base_addr 

MRAM code window base address.

k_mram_bytes 

1 MiB window size.

Definition at line 45 of file usb_msc_mram_steps.h.

◆ demo_word_pack_t

enum demo_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 137 of file usb_msc_mram_steps.h.

Function Documentation

◆ demo_fat_fill_sector()

void demo_fat_fill_sector ( uint32_t lba,
UCHAR * out )

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.

Parameters
[in]lbaLogical block address inside the volume.
[out]out512-byte destination buffer.
Precondition
lba is below k_fat_total_sectors (caller-checked).
out has 512 writable bytes.
Postcondition
out holds the synthesized sector content.
No other state changes.
Note
Reads chip MRAM directly; no caching.
Since
0.1.0

Definition at line 199 of file usb_msc_mram_steps.c.

References demo_fat_fill_boot(), demo_fat_fill_fat(), demo_fat_fill_root(), k_demo_block_size, 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, memcpy(), and memset().

Referenced by demo_msc_read().