LUFA Library - Mass Storage Class Bootloader
|
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <LUFA/Drivers/USB/USB.h>
#include "../BootloaderAPI.h"
Data Structures | |
struct | FATBootBlock_t |
union | FATDirectoryEntry_t |
Macros | |
#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) |
FAT Filesystem Flags | |
#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) |
Enumerations | |
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 } |
Functions | |
void | VirtualFAT_WriteBlock (const uint16_t BlockNumber) AUX_BOOT_SECTION |
void | VirtualFAT_ReadBlock (const uint16_t BlockNumber) AUX_BOOT_SECTION |
#define _ROT8 | ( | x) | ((((x) & 0xFE) >> 1) | (((x) & 1) ? 0x80 : 0x00)) |
Bit-rotates a given 8-bit value once to the right.
x | Value to rotate right once |
#define CLUSTER_SIZE_BYTES (SECTOR_PER_CLUSTER * SECTOR_SIZE_BYTES) |
Size of a logical cluster on the disk, in bytes
#define EEPROM_FILE_SIZE_BYTES E2END |
Size of the virtual EEPROM.BIN file in bytes.
#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) |
Computes the LFN entry checksum of a MSDOS 8.3 format file entry, to associate a LFN entry with its short file entry.
n0 | MSDOS Filename character 1 |
n1 | MSDOS Filename character 2 |
n2 | MSDOS Filename character 3 |
n3 | MSDOS Filename character 4 |
n4 | MSDOS Filename character 5 |
n5 | MSDOS Filename character 6 |
n6 | MSDOS Filename character 7 |
n7 | MSDOS Filename character 8 |
e0 | MSDOS Extension character 1 |
e1 | MSDOS Extension character 2 |
e2 | MSDOS Extension character 3 |
#define FAT_DATE | ( | dd, | |
mm, | |||
yyyy | |||
) | (((yyyy - 1980) << 9) | (mm << 5) | (dd << 0)) |
Converts a given date in DD/MM/YYYY format to a FAT filesystem date.
[in] | dd | Days in the month (1-31) |
[in] | mm | Months in the year (1-12) |
[in] | yyyy | Year (1980 - 2107) |
#define FAT_FLAG_ARCHIVE (1 << 5) |
FAT attribute flag to indicate a file ready for archiving.
#define FAT_FLAG_DIRECTORY (1 << 4) |
FAT attribute flag to indicate a directory entry.
#define FAT_FLAG_HIDDEN (1 << 1) |
FAT attribute flag to indicate a hidden file.
#define FAT_FLAG_LONG_FILE_NAME 0x0F |
FAT pseudo-attribute flag to indicate a Long File Name entry.
#define FAT_FLAG_READONLY (1 << 0) |
FAT attribute flag to indicate a read-only file.
#define FAT_FLAG_SYSTEM (1 << 2) |
FAT attribute flag to indicate a system file.
#define FAT_FLAG_VOLUME_NAME (1 << 3) |
FAT attribute flag to indicate a Volume name entry.
#define FAT_ORDINAL_LAST_ENTRY (1 << 6) |
Ordinal flag marker for FAT Long File Name entries to mark the last entry.
#define FAT_TIME | ( | hh, | |
mm, | |||
ss | |||
) | ((hh << 11) | (mm << 5) | (ss >> 1)) |
Converts a given time in HH:MM:SS format to a FAT filesystem time.
[in] | hh | Hours (0-23) |
[in] | mm | Minutes (0-59) |
[in] | ss | Seconds (0-59) |
#define FILE_CLUSTERS | ( | size) | ((size / CLUSTER_SIZE_BYTES) + ((size % CLUSTER_SIZE_BYTES) ? 1 : 0)) |
Number of clusters required to store a given size in bytes.
[in] | size | Size of the data that needs to be stored |
#define FILE_SECTORS | ( | size) | ((size / SECTOR_SIZE_BYTES) + ((size % SECTOR_SIZE_BYTES) ? 1 : 0)) |
Number of sectors required to store a given size in bytes.
[in] | size | Size of the data that needs to be stored |
#define FLASH_FILE_SIZE_BYTES (FLASHEND - (FLASHEND - BOOT_START_ADDR) - AUX_BOOT_SECTION_SIZE) |
Size of the virtual FLASH.BIN file in bytes.
#define LUN_MEDIA_BLOCKS (FILE_SECTORS(FLASH_FILE_SIZE_BYTES) + FILE_SECTORS(EEPROM_FILE_SIZE_BYTES) + 32) |
Total number of logical sectors/blocks on the disk.
#define SECTOR_PER_CLUSTER 4 |
Number of sectors that comprise a single logical disk cluster.
#define SECTOR_SIZE_BYTES 512 |
Size of a single logical sector on the disk.
anonymous enum |
Enum for the Root FAT file entry indexes on the disk. This can be used to retrieve the current contents of a known directory entry.
anonymous enum |
Enum for the physical disk blocks of the virtual disk.
void VirtualFAT_ReadBlock | ( | const uint16_t | BlockNumber) |
Reads a block of data from the virtual FAT filesystem, and sends it to the host via the USB Mass Storage interface.
[in] | BlockNumber | Index of the block to read. |
void VirtualFAT_WriteBlock | ( | const uint16_t | BlockNumber) |
Writes a block of data to the virtual FAT filesystem, from the USB Mass Storage interface.
[in] | BlockNumber | Index of the block to write. |