Skip to content

Commit 614da97

Browse files
committed
More descriptive names for some defines
1 parent 00669e8 commit 614da97

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/usb/uf2/ghostfat.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct TextFile {
7979
#define BPB_SECTORS_PER_FAT ( (BPB_TOTAL_SECTORS / FAT_ENTRIES_PER_SECTOR) + \
8080
((BPB_TOTAL_SECTORS % FAT_ENTRIES_PER_SECTOR) ? 1 : 0))
8181
#define DIRENTRIES_PER_SECTOR (BPB_SECTOR_SIZE/sizeof(DirEntry))
82-
#define ROOT_DIR_SECTORS (BPB_ROOT_DIR_ENTRIES/DIRENTRIES_PER_SECTOR)
82+
#define ROOT_DIR_SECTOR_COUNT (BPB_ROOT_DIR_ENTRIES/DIRENTRIES_PER_SECTOR)
8383

8484
STATIC_ASSERT(BPB_SECTOR_SIZE == 512); // GhostFAT does not support other sector sizes (currently)
8585
STATIC_ASSERT(BPB_SECTORS_PER_CLUSTER == 1); // GhostFAT presumes one sector == one cluster (for simplicity)
@@ -125,8 +125,8 @@ STATIC_ASSERT(ARRAY_SIZE(indexFile) < BPB_SECTOR_SIZE);
125125
#define NUM_DIRENTRIES (NUM_FILES + 1) // Code adds volume label as first root directory entry
126126
#define REQUIRED_ROOT_DIRECTORY_SECTORS ( ((NUM_DIRENTRIES+1) / DIRENTRIES_PER_SECTOR) + \
127127
(((NUM_DIRENTRIES+1) % DIRENTRIES_PER_SECTOR) ? 1 : 0))
128-
STATIC_ASSERT(NUM_DIRENTRIES < (DIRENTRIES_PER_SECTOR * ROOT_DIR_SECTORS)); // Need at least one terminating (unused) entry
129-
STATIC_ASSERT(ROOT_DIR_SECTORS >= REQUIRED_ROOT_DIRECTORY_SECTORS); // Ensures BPB reserves sufficient entries for files
128+
STATIC_ASSERT(ROOT_DIR_SECTOR_COUNT >= REQUIRED_ROOT_DIRECTORY_SECTORS); // Ensures BPB reserves sufficient entries for files
129+
STATIC_ASSERT(NUM_DIRENTRIES < (DIRENTRIES_PER_SECTOR * ROOT_DIR_SECTOR_COUNT)); // Need at least one terminating (unused) entry
130130
STATIC_ASSERT(NUM_DIRENTRIES < BPB_ROOT_DIR_ENTRIES);
131131
// all directory entries must fit in a single sector
132132
// because otherwise current code overflows buffer
@@ -143,10 +143,10 @@ STATIC_ASSERT(TRUE_USER_FLASH_SIZE % UF2_FIRMWARE_BYTES_PER_SECTOR == 0);
143143
#define UF2_FIRST_SECTOR ((NUM_FILES + 1) * BPB_SECTORS_PER_CLUSTER) // WARNING -- code presumes each non-UF2 file content fits in single sector
144144
#define UF2_LAST_SECTOR ((UF2_FIRST_SECTOR + UF2_SECTORS - 1) * BPB_SECTORS_PER_CLUSTER)
145145

146-
#define START_FAT0 BPB_RESERVED_SECTORS
147-
#define START_FAT1 (START_FAT0 + BPB_SECTORS_PER_FAT)
148-
#define START_ROOTDIR (START_FAT1 + BPB_SECTORS_PER_FAT)
149-
#define START_CLUSTERS (START_ROOTDIR + ROOT_DIR_SECTORS)
146+
#define FS_START_FAT0_SECTOR BPB_RESERVED_SECTORS
147+
#define FS_START_FAT1_SECTOR (FS_START_FAT0_SECTOR + BPB_SECTORS_PER_FAT)
148+
#define FS_START_ROOTDIR_SECTOR (FS_START_FAT1_SECTOR + BPB_SECTORS_PER_FAT)
149+
#define FS_START_CLUSTERS_SECTOR (FS_START_ROOTDIR_SECTOR + ROOT_DIR_SECTOR_COUNT)
150150

151151

152152
static FAT_BootBlock const BootBlock = {
@@ -156,7 +156,7 @@ static FAT_BootBlock const BootBlock = {
156156
.SectorsPerCluster = BPB_SECTORS_PER_CLUSTER,
157157
.ReservedSectors = BPB_RESERVED_SECTORS,
158158
.FATCopies = BPB_NUMBER_OF_FATS,
159-
.RootDirectoryEntries = (ROOT_DIR_SECTORS * DIRENTRIES_PER_SECTOR),
159+
.RootDirectoryEntries = (ROOT_DIR_SECTOR_COUNT * DIRENTRIES_PER_SECTOR),
160160
.TotalSectors16 = NUM_FAT_BLOCKS - 2,
161161
.MediaDescriptor = BPB_MEDIA_DESCRIPTOR_BYTE,
162162
.SectorsPerFAT = BPB_SECTORS_PER_FAT,
@@ -252,8 +252,8 @@ void read_block(uint32_t block_no, uint8_t *data) {
252252
data[510] = 0x55; // Always at offsets 510/511, even when BPB_SECTOR_SIZE is larger
253253
data[511] = 0xaa; // Always at offsets 510/511, even when BPB_SECTOR_SIZE is larger
254254
// logval("data[0]", data[0]);
255-
} else if (block_no < START_ROOTDIR) { // Requested FAT table sector
256-
sectionIdx -= START_FAT0;
255+
} else if (block_no < FS_START_ROOTDIR_SECTOR) { // Requested FAT table sector
256+
sectionIdx -= FS_START_FAT0_SECTOR;
257257
// logval("sidx", sectionIdx);
258258
if (sectionIdx >= BPB_SECTORS_PER_FAT) {
259259
sectionIdx -= BPB_SECTORS_PER_FAT; // second FAT is same as the first...
@@ -273,9 +273,9 @@ void read_block(uint32_t block_no, uint8_t *data) {
273273
if (UF2_FIRST_SECTOR <= v && v <= UF2_LAST_SECTOR)
274274
((uint16_t *)(void *)data)[i] = v == UF2_LAST_SECTOR ? 0xffff : v + 1;
275275
}
276-
} else if (block_no < START_CLUSTERS) { // Requested root directory sector
276+
} else if (block_no < FS_START_CLUSTERS_SECTOR) { // Requested root directory sector
277277

278-
sectionIdx -= START_ROOTDIR;
278+
sectionIdx -= FS_START_ROOTDIR_SECTOR;
279279

280280
DirEntry *d = (void *)data;
281281
int remainingEntries = DIRENTRIES_PER_SECTOR;
@@ -309,7 +309,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
309309
}
310310

311311
} else {
312-
sectionIdx -= START_CLUSTERS;
312+
sectionIdx -= FS_START_CLUSTERS_SECTOR;
313313
if (sectionIdx < NUM_FILES - 1) {
314314
memcpy(data, info[sectionIdx].content, strlen(info[sectionIdx].content));
315315
} else { // generate the UF2 file data on-the-fly

0 commit comments

Comments
 (0)