1 | /*#######################################################################################
|
2 | Connect ARM to MMC/SD
|
3 |
|
4 | Copyright (C) 2004 Ulrich Radig
|
5 | #######################################################################################*/
|
6 |
|
7 | #ifndef _FAT_H_
|
8 | #define _FAT_H_
|
9 |
|
10 | #include <string.h>
|
11 | #include <avr/pgmspace.h>
|
12 | #include "mmc.h"
|
13 | #include "usart.h"
|
14 |
|
15 | #define FAT_DEBUG usart_writePC
|
16 | //#define FAT_DEBUG(...)
|
17 |
|
18 |
|
19 | //Prototypes
|
20 | extern unsigned int fat_root_dir_addr (unsigned char *);
|
21 | extern unsigned int fat_read_dir_ent (unsigned int,unsigned char,unsigned long*,unsigned char *,unsigned char *);
|
22 | extern void fat_load (unsigned int,unsigned long *,unsigned char *);
|
23 | extern void fat_read_file (unsigned int,unsigned char *,unsigned long);
|
24 | extern void fat_write_file (unsigned int,unsigned char *,unsigned long);
|
25 | extern void fat_init (void);
|
26 | extern unsigned char fat_search_file (unsigned char *,unsigned int *,unsigned long *,unsigned char *,unsigned char *);
|
27 |
|
28 | //Block Size in Bytes
|
29 | #define BlockSize 512
|
30 |
|
31 | //Master Boot Record
|
32 | #define MASTER_BOOT_RECORD 0
|
33 |
|
34 | //Volume Boot Record location in Master Boot Record
|
35 | #define VBR_ADDR 0x1C6
|
36 |
|
37 | //define ASCII
|
38 | #define SPACE 0x20
|
39 | #define DIR_ENTRY_IS_FREE 0xE5
|
40 | #define FIRST_LONG_ENTRY 0x01
|
41 | #define SECOND_LONG_ENTRY 0x42
|
42 |
|
43 | //define DIR_Attr
|
44 | #define ATTR_LONG_NAME 0x0F
|
45 | #define ATTR_READ_ONLY 0x01
|
46 | #define ATTR_HIDDEN 0x02
|
47 | #define ATTR_SYSTEM 0x04
|
48 | #define ATTR_VOLUME_ID 0x08
|
49 | #define ATTR_DIRECTORY 0x10
|
50 | #define ATTR_ARCHIVE 0x20
|
51 |
|
52 | struct BootSec
|
53 | {
|
54 | unsigned char BS_jmpBoot[3];
|
55 | unsigned char BS_OEMName[8];
|
56 | unsigned int BPB_BytesPerSec; //2 bytes
|
57 | unsigned char BPB_SecPerClus;
|
58 | unsigned int BPB_RsvdSecCnt; //2 bytes
|
59 | unsigned char BPB_NumFATs;
|
60 | unsigned int BPB_RootEntCnt; //2 bytes
|
61 | unsigned int BPB_TotSec16; //2 bytes
|
62 | unsigned char BPB_Media;
|
63 | unsigned int BPB_FATSz16; //2 bytes
|
64 | unsigned int BPB_SecPerTrk; //2 bytes
|
65 | unsigned int BPB_NumHeads; //2 bytes
|
66 | unsigned long BPB_HiddSec; //4 bytes
|
67 | unsigned long BPB_TotSec32; //4 bytes
|
68 | };
|
69 |
|
70 | //FAT12 and FAT16 Structure Starting at Offset 36
|
71 | #define BS_DRVNUM 36
|
72 | #define BS_RESERVED1 37
|
73 | #define BS_BOOTSIG 38
|
74 | #define BS_VOLID 39
|
75 | #define BS_VOLLAB 43
|
76 | #define BS_FILSYSTYPE 54
|
77 |
|
78 | //FAT32 Structure Starting at Offset 36
|
79 | #define BPB_FATSZ32 36
|
80 | #define BPB_EXTFLAGS 40
|
81 | #define BPB_FSVER 42
|
82 | #define BPB_ROOTCLUS 44
|
83 | #define BPB_FSINFO 48
|
84 | #define BPB_BKBOOTSEC 50
|
85 | #define BPB_RESERVED 52
|
86 |
|
87 | #define FAT32_BS_DRVNUM 64
|
88 | #define FAT32_BS_RESERVED1 65
|
89 | #define FAT32_BS_BOOTSIG 66
|
90 | #define FAT32_BS_VOLID 67
|
91 | #define FAT32_BS_VOLLAB 71
|
92 | #define FAT32_BS_FILSYSTYPE 82
|
93 | //End of Boot Sctor and BPB Structure
|
94 |
|
95 | struct DirEntry {
|
96 | unsigned char DIR_Name[11]; //8 chars filename
|
97 | unsigned char DIR_Attr; //file attributes RSHA, Longname, Drive Label, Directory
|
98 | unsigned char DIR_NTRes; //set to zero
|
99 | unsigned char DIR_CrtTimeTenth; //creation time part in milliseconds
|
100 | unsigned int DIR_CrtTime; //creation time
|
101 | unsigned int DIR_CrtDate; //creation date
|
102 | unsigned int DIR_LastAccDate; //last access date
|
103 | unsigned int DIR_FstClusHI; //first cluster high word
|
104 | unsigned int DIR_WrtTime; //last write time
|
105 | unsigned int DIR_WrtDate; //last write date
|
106 | unsigned int DIR_FstClusLO; //first cluster low word
|
107 | unsigned long DIR_FileSize;
|
108 | };
|
109 |
|
110 | #endif //_FAT_H_
|