3 Copyright (C) Dean Camera, 2013.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2013 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
31 #ifndef _VIRTUALFAT_H_
32 #define _VIRTUALFAT_H_
36 #include <avr/pgmspace.h>
38 #include <LUFA/Drivers/USB/USB.h>
41 #define FIRMWARE_FILE_SIZE (FLASHEND + 1UL)
42 #define FILE_CLUSTERS(size) ((size / CLUSTER_SIZE_BYTES) + ((size % CLUSTER_SIZE_BYTES) ? 1 : 0))
44 #define SECTOR_SIZE_BYTES 512
45 #define SECTOR_PER_CLUSTER 4
46 #define CLUSTER_SIZE_BYTES (SECTOR_PER_CLUSTER * SECTOR_SIZE_BYTES)
48 #define LUN_MEDIA_BLOCKS ((FIRMWARE_FILE_SIZE / SECTOR_SIZE_BYTES) + 32)
50 #define FAT_TIME(h, m, s) ((h << 11) | (m << 5) | (s >> 1))
51 #define FAT_DATE(d, m, y) (((y - 1980) << 9) | (m << 5) | (d << 0))
53 /* Type Definitions: */
57 uint8_t Description
[8];
59 uint8_t SectorsPerCluster
;
60 uint16_t ReservedSectors
;
62 uint16_t RootDirectoryEntries
;
63 uint16_t TotalSectors16
;
64 uint8_t MediaDescriptor
;
65 uint16_t SectorsPerFAT
;
66 uint16_t SectorsPerTrack
;
68 uint32_t HiddenSectors
;
69 uint32_t TotalSectors32
;
70 uint16_t PhysicalDriveNum
;
71 uint8_t ExtendedBootRecordSig
;
72 uint32_t VolumeSerialNumber
;
73 uint8_t VolumeLabel
[11];
74 uint8_t FilesystemIdentifier
[8];
75 uint8_t BootstrapProgram
[448];
76 uint16_t MagicSignature
;
85 uint16_t CreationTime
;
86 uint16_t CreationDate
;
87 uint16_t StartingCluster
;
88 uint32_t FileSizeBytes
;
89 } FATDirectoryEntry_t
;
91 /* Function Prototypes: */
92 void VirtualFAT_WriteBlocks(USB_ClassInfo_MS_Device_t
* const MSInterfaceInfo
,
93 const uint32_t BlockAddress
,
94 uint16_t TotalBlocks
);
96 void VirtualFAT_ReadBlocks(USB_ClassInfo_MS_Device_t
* const MSInterfaceInfo
,
97 const uint32_t BlockAddress
,
98 uint16_t TotalBlocks
);