123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- #ifndef _VIRTUALFAT_H_
- #define _VIRTUALFAT_H_
-
- #include <avr/io.h>
- #include <avr/pgmspace.h>
- #include <LUFA/Drivers/USB/USB.h>
- #include "../BootloaderAPI.h"
-
-
- #define FLASH_FILE_SIZE_BYTES (FLASHEND - (FLASHEND - BOOT_START_ADDR) - AUX_BOOT_SECTION_SIZE)
-
- #define EEPROM_FILE_SIZE_BYTES E2END
-
- #define SECTOR_PER_CLUSTER 4
-
- #define SECTOR_SIZE_BYTES 512
-
- #define CLUSTER_SIZE_BYTES (SECTOR_PER_CLUSTER * SECTOR_SIZE_BYTES)
-
- #define FILE_SECTORS(size) ((size / SECTOR_SIZE_BYTES) + ((size % SECTOR_SIZE_BYTES) ? 1 : 0))
-
- #define FILE_CLUSTERS(size) ((size / CLUSTER_SIZE_BYTES) + ((size % CLUSTER_SIZE_BYTES) ? 1 : 0))
-
- #define LUN_MEDIA_BLOCKS (FILE_SECTORS(FLASH_FILE_SIZE_BYTES) + FILE_SECTORS(EEPROM_FILE_SIZE_BYTES) + 32)
-
- #define FAT_TIME(hh, mm, ss) ((hh << 11) | (mm << 5) | (ss >> 1))
-
- #define FAT_DATE(dd, mm, yyyy) (((yyyy - 1980) << 9) | (mm << 5) | (dd << 0))
-
- #define ROT8(x) ((((x) & 0xFE) >> 1) | (((x) & 1) ? 0x80 : 0x00))
-
- #define FAT_CHECKSUM(n0, n1, n2, n3, n4, n5, n6, n7, e0, e1, e2) \
- (uint8_t)(ROT8(ROT8(ROT8(ROT8(ROT8(ROT8(ROT8(ROT8(ROT8(ROT8(n0)+n1)+n2)+n3)+n4)+n5)+n6)+n7)+e0)+e1)+e2)
-
-
-
- #define FAT_FLAG_READONLY (1 << 0)
-
- #define FAT_FLAG_HIDDEN (1 << 1)
-
- #define FAT_FLAG_SYSTEM (1 << 2)
-
- #define FAT_FLAG_VOLUME_NAME (1 << 3)
-
- #define FAT_FLAG_DIRECTORY (1 << 4)
-
- #define FAT_FLAG_ARCHIVE (1 << 5)
-
- #define FAT_FLAG_LONG_FILE_NAME 0x0F
-
- #define FAT_ORDINAL_LAST_ENTRY (1 << 6)
-
-
-
- enum
- {
-
- DISK_FILE_ENTRY_VolumeID = 0,
-
- DISK_FILE_ENTRY_FLASH_LFN = 1,
-
- DISK_FILE_ENTRY_FLASH_MSDOS = 2,
-
- DISK_FILE_ENTRY_EEPROM_LFN = 3,
-
- DISK_FILE_ENTRY_EEPROM_MSDOS = 4,
- };
-
- enum
- {
-
- DISK_BLOCK_BootBlock = 0,
-
- DISK_BLOCK_FATBlock1 = 1,
-
- DISK_BLOCK_FATBlock2 = 2,
-
- DISK_BLOCK_RootFilesBlock = 3,
-
- DISK_BLOCK_DataStartBlock = 4,
- };
-
-
- typedef struct
- {
- uint8_t Bootstrap[3];
- uint8_t Description[8];
- uint16_t SectorSize;
- uint8_t SectorsPerCluster;
- uint16_t ReservedSectors;
- uint8_t FATCopies;
- uint16_t RootDirectoryEntries;
- uint16_t TotalSectors16;
- uint8_t MediaDescriptor;
- uint16_t SectorsPerFAT;
- uint16_t SectorsPerTrack;
- uint16_t Heads;
- uint32_t HiddenSectors;
- uint32_t TotalSectors32;
- uint16_t PhysicalDriveNum;
- uint8_t ExtendedBootRecordSig;
- uint32_t VolumeSerialNumber;
- uint8_t VolumeLabel[11];
- uint8_t FilesystemIdentifier[8];
-
-
- } FATBootBlock_t;
-
- typedef union
- {
-
- struct
- {
- uint8_t Ordinal;
- uint16_t Unicode1;
- uint16_t Unicode2;
- uint16_t Unicode3;
- uint16_t Unicode4;
- uint16_t Unicode5;
- uint8_t Attribute;
- uint8_t Reserved1;
- uint8_t Checksum;
- uint16_t Unicode6;
- uint16_t Unicode7;
- uint16_t Unicode8;
- uint16_t Unicode9;
- uint16_t Unicode10;
- uint16_t Unicode11;
- uint16_t Reserved2;
- uint16_t Unicode12;
- uint16_t Unicode13;
- } VFAT_LongFileName;
-
- struct
- {
- uint8_t Filename[8];
- uint8_t Extension[3];
- uint8_t Attributes;
- uint8_t Reserved[10];
- uint16_t CreationTime;
- uint16_t CreationDate;
- uint16_t StartingCluster;
- uint32_t FileSizeBytes;
- } MSDOS_File;
-
- struct
- {
- uint8_t Name[11];
- uint8_t Attributes;
- uint8_t Reserved[10];
- uint16_t CreationTime;
- uint16_t CreationDate;
- uint16_t StartingCluster;
- uint32_t Reserved2;
- } MSDOS_Directory;
- } FATDirectoryEntry_t;
-
- #if defined(INCLUDE_FROM_VIRTUAL_FAT_C)
- static uint8_t ReadEEPROMByte(const uint8_t* const Address) ATTR_NO_INLINE;
- static void WriteEEPROMByte(uint8_t* const Address,
- const uint8_t Data) ATTR_NO_INLINE;
- static void UpdateFAT12ClusterEntry(uint8_t* const FATTable,
- const uint16_t Index,
- const uint16_t ChainEntry) AUX_BOOT_SECTION;
- static void UpdateFAT12ClusterChain(uint8_t* const FATTable,
- const uint16_t StartIndex,
- const uint8_t ChainLength) AUX_BOOT_SECTION;
- static void ReadWriteFLASHFileBlock(const uint16_t BlockNumber,
- uint8_t* BlockBuffer,
- const bool Read) AUX_BOOT_SECTION;
- static void ReadWriteEEPROMFileBlock(const uint16_t BlockNumber,
- uint8_t* BlockBuffer,
- const bool Read) AUX_BOOT_SECTION;
- #endif
- void VirtualFAT_WriteBlock(const uint16_t BlockNumber) AUX_BOOT_SECTION;
- void VirtualFAT_ReadBlock(const uint16_t BlockNumber) AUX_BOOT_SECTION;
- #endif
|