annotate ff.h @ 91:231662c6690c

handle new next_wake format
author Matt Johnston <matt@ucc.asn.au>
date Mon, 16 Jul 2012 21:24:43 +0800
parents 888be1b234b6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*---------------------------------------------------------------------------/
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 / FatFs - FAT file system module include file R0.09 (C)ChaN, 2011
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 /----------------------------------------------------------------------------/
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 / FatFs module is a generic FAT file system module for small embedded systems.
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 / This is a free software that opened for education, research and commercial
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 / developments under license policy of following trems.
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 /
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 / Copyright (C) 2011, ChaN, all right reserved.
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 /
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 / * The FatFs module is a free software and there is NO WARRANTY.
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 / * No restriction on use. You can use, modify and redistribute it for
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 / personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 / * Redistributions of source code must retain the above copyright notice.
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 /
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 /----------------------------------------------------------------------------*/
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 #ifndef _FATFS
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 #define _FATFS 6502 /* Revision ID */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 #ifdef __cplusplus
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 extern "C" {
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 #include "integer.h" /* Basic integer types */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 #include "ffconf.h" /* FatFs configuration options */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #if _FATFS != _FFCONF
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #error Wrong configuration file (ffconf.h).
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 /* Definitions of volume management */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 #if _MULTI_PARTITION /* Multiple partition configuration */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 typedef struct {
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 BYTE pd; /* Physical drive number */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 } PARTITION;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 #else /* Single partition configuration */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 #define LD2PD(vol) (vol) /* Each logical drive is bound to the same physical drive number */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 #define LD2PT(vol) 0 /* Always mounts the 1st partition or in SFD */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 /* Type of path name strings on FatFs API */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 #if _LFN_UNICODE /* Unicode string */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 #if !_USE_LFN
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 #error _LFN_UNICODE must be 0 in non-LFN cfg.
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 #ifndef _INC_TCHAR
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 typedef WCHAR TCHAR;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 #define _T(x) L ## x
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 #define _TEXT(x) L ## x
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 #else /* ANSI/OEM string */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 #ifndef _INC_TCHAR
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 typedef char TCHAR;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 #define _T(x) x
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 #define _TEXT(x) x
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 /* File system object structure (FATFS) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 typedef struct {
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 BYTE fs_type; /* FAT sub-type (0:Not mounted) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 BYTE drv; /* Physical drive number */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 BYTE csize; /* Sectors per cluster (1,2,4...128) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 BYTE n_fats; /* Number of FAT copies (1,2) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 BYTE wflag; /* win[] dirty flag (1:must be written back) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 WORD id; /* File system mount ID */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 #if _MAX_SS != 512
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 #if _FS_REENTRANT
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 _SYNC_t sobj; /* Identifier of sync object */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 #if !_FS_READONLY
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 DWORD last_clust; /* Last allocated cluster */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 DWORD free_clust; /* Number of free clusters */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 DWORD fsi_sector; /* fsinfo sector (FAT32) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 #if _FS_RPATH
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 DWORD cdir; /* Current directory start cluster (0:root) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 DWORD n_fatent; /* Number of FAT entries (= number of clusters + 2) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 DWORD fsize; /* Sectors per FAT */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 DWORD fatbase; /* FAT start sector */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 DWORD database; /* Data start sector */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 DWORD winsect; /* Current sector appearing in the win[] */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 } FATFS;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 /* File object structure (FIL) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 typedef struct {
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 FATFS* fs; /* Pointer to the owner file system object */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 WORD id; /* Owner file system mount ID */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 BYTE flag; /* File status flags */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 BYTE pad1;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 DWORD fptr; /* File read/write pointer (0 on file open) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 DWORD fsize; /* File size */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 DWORD sclust; /* File start cluster (0 when fsize==0) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 DWORD clust; /* Current cluster */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 DWORD dsect; /* Current data sector */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 #if !_FS_READONLY
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 DWORD dir_sect; /* Sector containing the directory entry */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 BYTE* dir_ptr; /* Ponter to the directory entry in the window */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 #if _USE_FASTSEEK
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 #if _FS_SHARE
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 UINT lockid; /* File lock ID (index of file semaphore table) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 #if !_FS_TINY
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 BYTE buf[_MAX_SS]; /* File data read/write buffer */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 } FIL;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 /* Directory object structure (DIR) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 typedef struct {
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 FATFS* fs; /* Pointer to the owner file system object */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 WORD id; /* Owner file system mount ID */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 WORD index; /* Current read/write index number */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 DWORD sclust; /* Table start cluster (0:Root dir) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 DWORD clust; /* Current cluster */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 DWORD sect; /* Current sector */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 BYTE* dir; /* Pointer to the current SFN entry in the win[] */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 #if _USE_LFN
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 WCHAR* lfn; /* Pointer to the LFN working buffer */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 } DIR;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 /* File status structure (FILINFO) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 typedef struct {
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162 DWORD fsize; /* File size */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 WORD fdate; /* Last modified date */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 WORD ftime; /* Last modified time */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 BYTE fattrib; /* Attribute */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 TCHAR fname[13]; /* Short file name (8.3 format) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 #if _USE_LFN
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 TCHAR* lfname; /* Pointer to the LFN buffer */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 UINT lfsize; /* Size of LFN buffer in TCHAR */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 } FILINFO;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 /* File function return code (FRESULT) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 typedef enum {
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178 FR_OK = 0, /* (0) Succeeded */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 FR_DISK_ERR, /* (1) A hard error occured in the low level disk I/O layer */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180 FR_INT_ERR, /* (2) Assertion failed */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 FR_NOT_READY, /* (3) The physical drive cannot work */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 FR_NO_FILE, /* (4) Could not find the file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 FR_NO_PATH, /* (5) Could not find the path */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184 FR_INVALID_NAME, /* (6) The path name format is invalid */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185 FR_DENIED, /* (7) Acces denied due to prohibited access or directory full */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 FR_EXIST, /* (8) Acces denied due to prohibited access */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188 FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 FR_NOT_ENABLED, /* (12) The volume has no work area */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191 FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 FR_LOCKED, /* (16) The operation is rejected according to the file shareing policy */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
196 FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197 FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 } FRESULT;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202 /*--------------------------------------------------------------*/
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
203 /* FatFs module application interface */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205 FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206 FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
207 FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
208 FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209 FRESULT f_close (FIL*); /* Close an open file object */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210 FRESULT f_opendir (DIR*, const TCHAR*); /* Open an existing directory */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211 FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
212 FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213 FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214 FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215 FRESULT f_truncate (FIL*); /* Truncate file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
216 FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
218 FRESULT f_mkdir (const TCHAR*); /* Create a new directory */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
219 FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
220 FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change timestamp of the file/dir */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
221 FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
222 FRESULT f_chdrive (BYTE); /* Change current drive */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223 FRESULT f_chdir (const TCHAR*); /* Change current directory */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
224 FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
225 FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
226 FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
227 FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
228 int f_putc (TCHAR, FIL*); /* Put a character to the file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229 int f_puts (const TCHAR*, FIL*); /* Put a string to the file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
230 int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 TCHAR* f_gets (TCHAR*, int, FIL*); /* Get a string from the file */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
232
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
234 #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
235 #define f_tell(fp) ((fp)->fptr)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236 #define f_size(fp) ((fp)->fsize)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238 #ifndef EOF
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239 #define EOF (-1)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
242
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
245 /*--------------------------------------------------------------*/
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246 /* Additional user defined functions */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248 /* RTC function */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 #if !_FS_READONLY
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 DWORD get_fattime (void);
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
251 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
252
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 /* Unicode support functions */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254 #if _USE_LFN /* Unicode - OEM code conversion */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 WCHAR ff_convert (WCHAR, UINT); /* OEM-Unicode bidirectional conversion */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 WCHAR ff_wtoupper (WCHAR); /* Unicode upper-case conversion */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 #if _USE_LFN == 3 /* Memory functions */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258 void* ff_memalloc (UINT); /* Allocate memory block */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 void ff_memfree (void*); /* Free memory block */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
261 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
263 /* Sync functions */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
264 #if _FS_REENTRANT
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
265 int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
266 int ff_req_grant (_SYNC_t); /* Lock sync object */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
267 void ff_rel_grant (_SYNC_t); /* Unlock sync object */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
268 int ff_del_syncobj (_SYNC_t); /* Delete a sync object */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
269 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
271
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
272
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
273
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
274 /*--------------------------------------------------------------*/
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275 /* Flags and offset address */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
276
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
277
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
278 /* File access control and file status flags (FIL.flag) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
279
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
280 #define FA_READ 0x01
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
281 #define FA_OPEN_EXISTING 0x00
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
282 #define FA__ERROR 0x80
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284 #if !_FS_READONLY
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285 #define FA_WRITE 0x02
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286 #define FA_CREATE_NEW 0x04
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287 #define FA_CREATE_ALWAYS 0x08
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
288 #define FA_OPEN_ALWAYS 0x10
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289 #define FA__WRITTEN 0x20
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290 #define FA__DIRTY 0x40
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
291 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
292
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
293
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
294 /* FAT sub type (FATFS.fs_type) */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
295
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
296 #define FS_FAT12 1
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
297 #define FS_FAT16 2
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
298 #define FS_FAT32 3
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
301 /* File attribute bits for directory entry */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
303 #define AM_RDO 0x01 /* Read only */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
304 #define AM_HID 0x02 /* Hidden */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
305 #define AM_SYS 0x04 /* System */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 #define AM_VOL 0x08 /* Volume label */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307 #define AM_LFN 0x0F /* LFN entry */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
308 #define AM_DIR 0x10 /* Directory */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
309 #define AM_ARC 0x20 /* Archive */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
310 #define AM_MASK 0x3F /* Mask of defined bits */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
311
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
312
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
313 /* Fast seek feature */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314 #define CREATE_LINKMAP 0xFFFFFFFF
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
316
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
317
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
318 /*--------------------------------*/
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
319 /* Multi-byte word access macros */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
320
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
321 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
322 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
323 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
324 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
326 #else /* Use byte-by-byte access to the FAT structure */
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
327 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
328 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
329 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
330 #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)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
331 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
332
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
333 #ifdef __cplusplus
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
334 }
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
335 #endif
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
336
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
337 #endif /* _FATFS */