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

FAT16 read-only volume image synthesizer for the MSC MRAM demo. More...

#include "usb_msc_mram_steps.h"
#include <stdint.h>
#include <string.h>
#include "ux_api.h"
Include dependency graph for usb_msc_mram_steps.c:

Go to the source code of this file.

Functions

static void demo_put16 (UCHAR *dst, uint16_t value)
 Write a 16-bit value little-endian into a byte buffer.
static void demo_put32 (UCHAR *dst, uint32_t value)
 Write a 32-bit value little-endian into a byte buffer.
static void demo_fat_fill_boot (UCHAR *out)
 Synthesize the FAT16 boot sector (MS FAT spec 1.03 sec 3.1).
static void demo_fat_fill_fat (uint32_t fat_sector, UCHAR *out)
 Synthesize one FAT16 sector of the cluster chain.
static void demo_fat_fill_root (uint32_t root_sector, UCHAR *out)
 Synthesize one root-directory sector.
void demo_fat_fill_sector (uint32_t lba, UCHAR *out)
 Synthesize one 512-byte sector of the read-only volume.

Variables

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".

Detailed Description

FAT16 read-only volume image synthesizer for the MSC MRAM demo.

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

Holds the on-the-fly FAT16 volume builder used by main.c's storage media-read callback: the little-endian packing primitives (demo_put16 / demo_put32), the per-region sector synthesizers (boot sector, FAT chain, root directory), and the LBA dispatcher demo_fat_fill_sector that ties them together and copies data sectors straight out of the chip's 1 MiB MRAM window at 0x02000000. Geometry, boot-field, and offset constants are shared with main.c through usb_msc_mram_steps.h; the FAT name / label / OEM byte strings are private to this translation unit.

Author
Brighton Sikarskie
Date
2026-05-02
Since
0.1.0

Definition in file usb_msc_mram_steps.c.

Function Documentation

◆ demo_fat_fill_boot()

void demo_fat_fill_boot ( UCHAR * out)
static

◆ demo_fat_fill_fat()

void demo_fat_fill_fat ( uint32_t fat_sector,
UCHAR * out )
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).

Parameters
[in]fat_sectorIndex of the FAT sector (0-based).
[out]outZeroed 512-byte sector buffer.
Precondition
out is zeroed.
fat_sector is below k_fat_fat_sectors.
Postcondition
out holds 256 little-endian FAT16 entries.
No other state changes.
Note
Pure function.
Since
0.1.0

Definition at line 144 of file usb_msc_mram_steps.c.

References demo_put16(), k_fat_entries_per_sec, k_fat_entry0, k_fat_eoc, and k_fat_last_mram_clus.

Referenced by demo_fat_fill_sector().

◆ demo_fat_fill_root()

void demo_fat_fill_root ( uint32_t root_sector,
UCHAR * out )
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.

Parameters
[in]root_sectorIndex of the root sector (0-based).
[out]outZeroed 512-byte sector buffer.
Precondition
out is zeroed.
root_sector is below k_fat_root_sectors.
Postcondition
out holds the directory entries for that sector.
No other state changes.
Note
Pure function.
Since
0.1.0

Definition at line 183 of file usb_msc_mram_steps.c.

References demo_put16(), demo_put32(), 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, and s_fat_volume_label.

Referenced by demo_fat_fill_sector().

◆ 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.

◆ demo_put16()

void demo_put16 ( UCHAR * dst,
uint16_t value )
static

Write a 16-bit value little-endian into a byte buffer.

Parameters
[out]dstDestination (2 bytes).
[in]valueValue to store.
Precondition
dst has 2 writable bytes.
None beyond the buffer contract.
Postcondition
dst[0] holds the low byte, dst[1] the high byte.
No other state changes.
Note
Pure function.
Since
0.1.0

Definition at line 61 of file usb_msc_mram_steps.c.

References k_byte_mask, and k_byte_shift.

Referenced by demo_fat_fill_boot(), demo_fat_fill_fat(), demo_fat_fill_root(), and demo_put32().

◆ demo_put32()

void demo_put32 ( UCHAR * dst,
uint32_t value )
static

Write a 32-bit value little-endian into a byte buffer.

Parameters
[out]dstDestination (4 bytes).
[in]valueValue to store.
Precondition
dst has 4 writable bytes.
None beyond the buffer contract.
Postcondition
dst holds the four little-endian bytes of value.
No other state changes.
Note
Pure function.
Since
0.1.0

Definition at line 81 of file usb_msc_mram_steps.c.

References demo_put16(), k_word_mask, and k_word_shift.

Referenced by demo_fat_fill_boot(), and demo_fat_fill_root().

Variable Documentation

◆ s_fat_file_name

const UCHAR s_fat_file_name[11] = {'M', 'R', 'A', 'M', ' ', ' ', ' ', ' ', 'B', 'I', 'N'}
static

8.3 directory name of the exposed file: "MRAM.BIN".

Definition at line 45 of file usb_msc_mram_steps.c.

◆ s_fat_fs_type

const UCHAR s_fat_fs_type[8] = {'F', 'A', 'T', '1', '6', ' ', ' ', ' '}
static

Filesystem-type tag, 8 bytes space padded.

Definition at line 42 of file usb_msc_mram_steps.c.

◆ s_fat_oem_name

const UCHAR s_fat_oem_name[8] = {'R', 'A', '8', 'D', '2', 'F', 'W', ' '}
static

Boot-sector OEM name (8 bytes, space padded).

Definition at line 36 of file usb_msc_mram_steps.c.

◆ s_fat_volume_label

const UCHAR s_fat_volume_label[11] = {'R', 'A', '8', 'D', '2', ' ', 'M', 'R', 'A', 'M', ' '}
static

Volume label, 11 bytes space padded (also the root entry).

Definition at line 39 of file usb_msc_mram_steps.c.