OSDN Git Service

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