|
|
@ -94,10 +94,7 @@ static void WriteBlock(const uint16_t BlockNumber)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint8_t BlockBuffer[SECTOR_SIZE_BYTES];
|
|
|
|
uint8_t BlockBuffer[SECTOR_SIZE_BYTES];
|
|
|
|
|
|
|
|
|
|
|
|
/* Wait until endpoint is ready before continuing */
|
|
|
|
/* Buffer the entire block to be written from the host */
|
|
|
|
if (Endpoint_WaitUntilReady())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Endpoint_Read_Stream_LE(BlockBuffer, sizeof(BlockBuffer), NULL);
|
|
|
|
Endpoint_Read_Stream_LE(BlockBuffer, sizeof(BlockBuffer), NULL);
|
|
|
|
Endpoint_ClearOUT();
|
|
|
|
Endpoint_ClearOUT();
|
|
|
|
|
|
|
|
|
|
|
@ -139,12 +136,12 @@ static void ReadBlock(const uint16_t BlockNumber)
|
|
|
|
|
|
|
|
|
|
|
|
switch (BlockNumber)
|
|
|
|
switch (BlockNumber)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 0: /* Block 0: Boot block sector */
|
|
|
|
memcpy(BlockBuffer, &BootBlock, sizeof(FATBootBlock_t));
|
|
|
|
memcpy(BlockBuffer, &BootBlock, sizeof(FATBootBlock_t));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
case 1: /* Block 1: First FAT12 cluster chain copy */
|
|
|
|
case 2:
|
|
|
|
case 2: /* Block 2: Second FAT12 cluster chain copy */
|
|
|
|
/* Cluster 0: Media type/Reserved */
|
|
|
|
/* Cluster 0: Media type/Reserved */
|
|
|
|
UpdateFAT12ClusterEntry(BlockBuffer, 0, 0xF00 | BootBlock.MediaDescriptor);
|
|
|
|
UpdateFAT12ClusterEntry(BlockBuffer, 0, 0xF00 | BootBlock.MediaDescriptor);
|
|
|
|
|
|
|
|
|
|
|
@ -159,11 +156,11 @@ static void ReadBlock(const uint16_t BlockNumber)
|
|
|
|
UpdateFAT12ClusterEntry(BlockBuffer, FILE_CLUSTERS(FIRMWARE_FILE_SIZE) + 1, 0xFFF);
|
|
|
|
UpdateFAT12ClusterEntry(BlockBuffer, FILE_CLUSTERS(FIRMWARE_FILE_SIZE) + 1, 0xFFF);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
case 3: /* Block 3: Root file entries */
|
|
|
|
memcpy(BlockBuffer, &FirmwareFileEntry, sizeof(FATDirectoryEntry_t));
|
|
|
|
memcpy(BlockBuffer, &FirmwareFileEntry, sizeof(FATDirectoryEntry_t));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default: /* Blocks 4 onwards: Data allocation section */
|
|
|
|
if ((BlockNumber >= 4) && (BlockNumber < (4 + (FIRMWARE_FILE_SIZE / SECTOR_SIZE_BYTES))))
|
|
|
|
if ((BlockNumber >= 4) && (BlockNumber < (4 + (FIRMWARE_FILE_SIZE / SECTOR_SIZE_BYTES))))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32_t ReadFlashAddress = (uint32_t)(BlockNumber - 4) * SECTOR_SIZE_BYTES;
|
|
|
|
uint32_t ReadFlashAddress = (uint32_t)(BlockNumber - 4) * SECTOR_SIZE_BYTES;
|
|
|
@ -175,10 +172,7 @@ static void ReadBlock(const uint16_t BlockNumber)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Wait until endpoint is ready before continuing */
|
|
|
|
/* Write the entire read block Buffer to the host */
|
|
|
|
if (Endpoint_WaitUntilReady())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Endpoint_Write_Stream_LE(BlockBuffer, sizeof(BlockBuffer), NULL);
|
|
|
|
Endpoint_Write_Stream_LE(BlockBuffer, sizeof(BlockBuffer), NULL);
|
|
|
|
Endpoint_ClearIN();
|
|
|
|
Endpoint_ClearIN();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -190,7 +184,7 @@ void VirtualFAT_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
|
|
|
uint16_t CurrentBlock = (uint16_t)BlockAddress;
|
|
|
|
uint16_t CurrentBlock = (uint16_t)BlockAddress;
|
|
|
|
|
|
|
|
|
|
|
|
/* Emulated FAT is performed per-block, pass each requested block index
|
|
|
|
/* Emulated FAT is performed per-block, pass each requested block index
|
|
|
|
* to the emulation function */
|
|
|
|
* to the emulated FAT block write function */
|
|
|
|
while (TotalBlocks--)
|
|
|
|
while (TotalBlocks--)
|
|
|
|
WriteBlock(CurrentBlock++);
|
|
|
|
WriteBlock(CurrentBlock++);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -202,7 +196,7 @@ void VirtualFAT_ReadBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
|
|
|
|
uint16_t CurrentBlock = (uint16_t)BlockAddress;
|
|
|
|
uint16_t CurrentBlock = (uint16_t)BlockAddress;
|
|
|
|
|
|
|
|
|
|
|
|
/* Emulated FAT is performed per-block, pass each requested block index
|
|
|
|
/* Emulated FAT is performed per-block, pass each requested block index
|
|
|
|
* to the emulation function */
|
|
|
|
* to the emulated FAT block read function */
|
|
|
|
while (TotalBlocks--)
|
|
|
|
while (TotalBlocks--)
|
|
|
|
ReadBlock(CurrentBlock++);
|
|
|
|
ReadBlock(CurrentBlock++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|