Oops - ensure that only the relevant/available interrupts are defined and used on...
[pub/USBasp.git] / Projects / Incomplete / StandaloneProgrammer / Lib / PetiteFATFs / pff.h
1 /*---------------------------------------------------------------------------/
2 / Petit FatFs - FAT file system module include file R0.02a (C)ChaN, 2010
3 /----------------------------------------------------------------------------/
4 / Petit FatFs module is an open source software to implement FAT file system to
5 / small embedded systems. This is a free software and is opened for education,
6 / research and commercial developments under license policy of following trems.
7 /
8 / Copyright (C) 2010, ChaN, all right reserved.
9 /
10 / * The Petit FatFs module is a free software and there is NO WARRANTY.
11 / * No restriction on use. You can use, modify and redistribute it for
12 / personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
13 / * Redistributions of source code must retain the above copyright notice.
14 /
15 /----------------------------------------------------------------------------*/
16
17 #include "integer.h"
18
19 /*---------------------------------------------------------------------------/
20 / Petit FatFs Configuration Options
21 /
22 / CAUTION! Do not forget to make clean the project after any changes to
23 / the configuration options.
24 /
25 /----------------------------------------------------------------------------*/
26 #ifndef _FATFS
27 #define _FATFS
28
29 #define _USE_READ 1 /* 1:Enable pf_read() */
30
31 #define _USE_DIR 0 /* 1:Enable pf_opendir() and pf_readdir() */
32
33 #define _USE_LSEEK 0 /* 1:Enable pf_lseek() */
34
35 #define _USE_WRITE 0 /* 1:Enable pf_write() */
36
37 #define _FS_FAT12 1 /* 1:Enable FAT12 support */
38 #define _FS_FAT32 0 /* 1:Enable FAT32 support */
39
40
41 #define _CODE_PAGE 1
42 /* Defines which code page is used for path name. Supported code pages are:
43 / 932, 936, 949, 950, 437, 720, 737, 775, 850, 852, 855, 857, 858, 862, 866,
44 / 874, 1250, 1251, 1252, 1253, 1254, 1255, 1257, 1258 and 1 (ASCII only).
45 / SBCS code pages except for 1 requiers a case conversion table. This
46 / might occupy 128 bytes on the RAM on some platforms, e.g. avr-gcc. */
47
48
49 #define _WORD_ACCESS 0
50 /* The _WORD_ACCESS option defines which access method is used to the word
51 / data in the FAT structure.
52 /
53 / 0: Byte-by-byte access. Always compatible with all platforms.
54 / 1: Word access. Do not choose this unless following condition is met.
55 /
56 / When the byte order on the memory is big-endian or address miss-aligned
57 / word access results incorrect behavior, the _WORD_ACCESS must be set to 0.
58 / If it is not the case, the value can also be set to 1 to improve the
59 / performance and code efficiency. */
60
61
62 /* End of configuration options. Do not change followings without care. */
63 /*--------------------------------------------------------------------------*/
64
65
66
67 #if _FS_FAT32
68 #define CLUST DWORD
69 #else
70 #define CLUST WORD
71 #endif
72
73
74 /* File system object structure */
75
76 typedef struct {
77 BYTE fs_type; /* FAT sub type */
78 BYTE flag; /* File status flags */
79 BYTE csize; /* Number of sectors per cluster */
80 BYTE pad1;
81 WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
82 CLUST n_fatent; /* Number of FAT entries (= number of clusters + 2) */
83 DWORD fatbase; /* FAT start sector */
84 DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
85 DWORD database; /* Data start sector */
86 DWORD fptr; /* File R/W pointer */
87 DWORD fsize; /* File size */
88 CLUST org_clust; /* File start cluster */
89 CLUST curr_clust; /* File current cluster */
90 DWORD dsect; /* File current data sector */
91 } FATFS;
92
93
94
95 /* Directory object structure */
96
97 typedef struct {
98 WORD index; /* Current read/write index number */
99 BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
100 CLUST sclust; /* Table start cluster (0:Static table) */
101 CLUST clust; /* Current cluster */
102 DWORD sect; /* Current sector */
103 } DIR;
104
105
106
107 /* File status structure */
108
109 typedef struct {
110 DWORD fsize; /* File size */
111 WORD fdate; /* Last modified date */
112 WORD ftime; /* Last modified time */
113 BYTE fattrib; /* Attribute */
114 char fname[13]; /* File name */
115 } FILINFO;
116
117
118
119 /* File function return code (FRESULT) */
120
121 typedef enum {
122 FR_OK = 0, /* 0 */
123 FR_DISK_ERR, /* 1 */
124 FR_NOT_READY, /* 2 */
125 FR_NO_FILE, /* 3 */
126 FR_NO_PATH, /* 4 */
127 FR_NOT_OPENED, /* 5 */
128 FR_NOT_ENABLED, /* 6 */
129 FR_NO_FILESYSTEM /* 7 */
130 } FRESULT;
131
132
133
134 /*--------------------------------------------------------------*/
135 /* Petit FatFs module application interface */
136
137 FRESULT pf_mount (FATFS*); /* Mount/Unmount a logical drive */
138 FRESULT pf_open (const char*); /* Open a file */
139 FRESULT pf_read (void*, WORD, WORD*); /* Read data from the open file */
140 FRESULT pf_write (const void*, WORD, WORD*); /* Write data to the open file */
141 FRESULT pf_lseek (DWORD); /* Move file pointer of the open file */
142 FRESULT pf_opendir (DIR*, const char*); /* Open a directory */
143 FRESULT pf_readdir (DIR*, FILINFO*); /* Read a directory item from the open directory */
144
145
146
147 /*--------------------------------------------------------------*/
148 /* Flags and offset address */
149
150 /* File status flag (FATFS.flag) */
151
152 #define FA_OPENED 0x01
153 #define FA_WPRT 0x02
154 #define FA__WIP 0x40
155
156
157 /* FAT sub type (FATFS.fs_type) */
158
159 #define FS_FAT12 1
160 #define FS_FAT16 2
161 #define FS_FAT32 3
162
163
164 /* File attribute bits for directory entry */
165
166 #define AM_RDO 0x01 /* Read only */
167 #define AM_HID 0x02 /* Hidden */
168 #define AM_SYS 0x04 /* System */
169 #define AM_VOL 0x08 /* Volume label */
170 #define AM_LFN 0x0F /* LFN entry */
171 #define AM_DIR 0x10 /* Directory */
172 #define AM_ARC 0x20 /* Archive */
173 #define AM_MASK 0x3F /* Mask of defined bits */
174
175
176 /*--------------------------------*/
177 /* Multi-byte word access macros */
178
179 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
180 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
181 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
182 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
183 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
184 #else /* Use byte-by-byte access to the FAT structure */
185 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
186 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
187 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
188 #define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
189 #endif
190
191
192 #endif /* _FATFS */