Lightweight SD card FAT file system. Originaled by chan http://elm-chan.org/fsw/ff/00index_p.html

Petit FAT File System for LPC1114

originaled by elm

If you want to use except LPC1114, you can change pin definitions at mmcPinConfig.h

more detail and original code at http://elm-chan.org/fsw/ff/00index_p.html

This library is NOT compatible with mbed official SDFileSystem

Committer:
hsgw
Date:
Fri May 09 19:41:49 2014 +0000
Revision:
0:845390b117a7
1st commit

Who changed what in which revision?

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