Refactor macros in the VirtualFAT implementation of the incomplete Mass Storage bootl...
[pub/USBasp.git] / Bootloaders / Incomplete / MassStorage / Lib / VirtualFAT.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2013.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2013 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 #ifndef _VIRTUALFAT_H_
32 #define _VIRTUALFAT_H_
33
34 /* Includes: */
35 #include <avr/io.h>
36 #include <avr/pgmspace.h>
37
38 #include <LUFA/Drivers/USB/USB.h>
39
40 /* Macros: */
41 #define FIRMWARE_FILE_SIZE (FLASHEND + 1UL)
42 #define FILE_CLUSTERS(size) ((size / CLUSTER_SIZE_BYTES) + ((size % CLUSTER_SIZE_BYTES) ? 1 : 0))
43
44 #define SECTOR_SIZE_BYTES 512
45 #define SECTOR_PER_CLUSTER 4
46 #define CLUSTER_SIZE_BYTES (SECTOR_PER_CLUSTER * SECTOR_SIZE_BYTES)
47
48 #define LUN_MEDIA_BLOCKS ((FIRMWARE_FILE_SIZE / SECTOR_SIZE_BYTES) + 32)
49
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))
52
53 /* Type Definitions: */
54 typedef struct
55 {
56 uint8_t Bootstrap[3];
57 uint8_t Description[8];
58 uint16_t SectorSize;
59 uint8_t SectorsPerCluster;
60 uint16_t ReservedSectors;
61 uint8_t FATCopies;
62 uint16_t RootDirectoryEntries;
63 uint16_t TotalSectors16;
64 uint8_t MediaDescriptor;
65 uint16_t SectorsPerFAT;
66 uint16_t SectorsPerTrack;
67 uint16_t Heads;
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;
77 } FATBootBlock_t;
78
79 typedef struct
80 {
81 uint8_t Filename[8];
82 uint8_t Extension[3];
83 uint8_t Attributes;
84 uint8_t Reserved[10];
85 uint16_t CreationTime;
86 uint16_t CreationDate;
87 uint16_t StartingCluster;
88 uint32_t FileSizeBytes;
89 } FATDirectoryEntry_t;
90
91 /* Function Prototypes: */
92 void VirtualFAT_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
93 const uint32_t BlockAddress,
94 uint16_t TotalBlocks);
95
96 void VirtualFAT_ReadBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
97 const uint32_t BlockAddress,
98 uint16_t TotalBlocks);
99 #endif