tff.h

00001 /*--------------------------------------------------------------------------/
00002 /  Tiny-FatFs - FAT file system module include file  R0.04b   (C)ChaN, 2007
00003 /---------------------------------------------------------------------------/
00004 / FatFs module is an experimenal project to implement FAT file system to
00005 / cheap microcontrollers. This is a free software and is opened for education,
00006 / research and development under license policy of following trems.
00007 /
00008 /  Copyright (C) 2007, ChaN, all right reserved.
00009 /
00010 / * The FatFs module is a free software and there is no warranty.
00011 / * You can use, modify and/or redistribute it for personal, non-profit or
00012 /   profit use without any restriction under your responsibility.
00013 / * Redistributions of source code must retain the above copyright notice.
00014 /
00015 /---------------------------------------------------------------------------*/
00016 
00017 #ifndef _FATFS
00018 
00019 #define _MCU_ENDIAN             2
00020 /* The _MCU_ENDIAN defines which access method is used to the FAT structure.
00021 /  1: Enable word access.
00022 /  2: Disable word access and use byte-by-byte access instead.
00023 /  When the architectural byte order of the MCU is big-endian and/or address
00024 /  miss-aligned access is prohibited, the _MCU_ENDIAN must be set to 2.
00025 /  If it is not the case, it can be set to 1 for good code efficiency. */
00026 
00027 #define _FS_READONLY    0
00028 /* Setting _FS_READONLY to 1 defines read only configuration. This removes
00029 /  writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename
00030 /  and useless f_getfree. */
00031 
00032 #define _FS_MINIMIZE    0
00033 /* The _FS_MINIMIZE option defines minimization level to remove some functions.
00034 /  0: Full function.
00035 /  1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod and f_rename are removed.
00036 /  2: f_opendir and f_readdir are removed in addition to level 1.
00037 /  3: f_lseek is removed in addition to level 2. */
00038 
00039 #define _FAT32  1
00040 /* To enable FAT32 support in addition of FAT12/16, set _FAT32 to 1. */
00041 
00042 #define _USE_FSINFO     0
00043 /* To enable FSInfo support on FAT32 volume, set _USE_FSINFO to 1. */
00044 
00045 #define _USE_SJIS       1
00046 /* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise
00047 /  only US-ASCII(7bit) code can be accepted as file/directory name. */
00048 
00049 #define _USE_NTFLAG     1
00050 /* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved.
00051 /  Note that the files are always accessed in case insensitive. */
00052 
00053 
00054 #include "integer.h"
00055 
00056 
00057 /* Type definition for cluster number */
00058 #if _FAT32
00059 typedef DWORD   CLUST;
00060 #else
00061 typedef WORD    CLUST;
00062 #undef _USE_FSINFO
00063 #define _USE_FSINFO     0
00064 #endif
00065 
00066 
00067 /* File system object structure */
00068 typedef struct _FATFS {
00069         WORD    id;                             /* File system mount ID */
00070         WORD    n_rootdir;              /* Number of root directory entries */
00071         DWORD   winsect;                /* Current sector appearing in the win[] */
00072         DWORD   fatbase;                /* FAT start sector */
00073         DWORD   dirbase;                /* Root directory start sector */
00074         DWORD   database;               /* Data start sector */
00075         CLUST   sects_fat;              /* Sectors per fat */
00076         CLUST   max_clust;              /* Maximum cluster# + 1 */
00077 #if !_FS_READONLY
00078         CLUST   last_clust;             /* Last allocated cluster */
00079         CLUST   free_clust;             /* Number of free clusters */
00080 #if _USE_FSINFO
00081         DWORD   fsi_sector;             /* fsinfo sector */
00082         BYTE    fsi_flag;               /* fsinfo dirty flag (1:must be written back) */
00083         BYTE    pad1;
00084 #endif
00085 #endif
00086         BYTE    fs_type;                /* FAT sub type */
00087         BYTE    sects_clust;    /* Sectors per cluster */
00088         BYTE    n_fats;                 /* Number of FAT copies */
00089         BYTE    winflag;                /* win[] dirty flag (1:must be written back) */
00090         BYTE    win[512];               /* Disk access window for Directory/FAT/File */
00091 } FATFS;
00092 
00093 
00094 /* Directory object structure */
00095 typedef struct _DIR {
00096         WORD    id;                     /* Owner file system mount ID */
00097         WORD    index;          /* Current index */
00098         FATFS*  fs;                     /* Pointer to the owner file system object */
00099         CLUST   sclust;         /* Start cluster */
00100         CLUST   clust;          /* Current cluster */
00101         DWORD   sect;           /* Current sector */
00102 } DIR;
00103 
00104 
00105 /* File object structure */
00106 typedef struct _FIL {
00107         WORD    id;                             /* Owner file system mount ID */
00108         BYTE    flag;                   /* File status flags */
00109         BYTE    sect_clust;             /* Left sectors in cluster */
00110         FATFS*  fs;                             /* Pointer to owner file system */
00111         DWORD   fptr;                   /* File R/W pointer */
00112         DWORD   fsize;                  /* File size */
00113         CLUST   org_clust;              /* File start cluster */
00114         CLUST   curr_clust;             /* Current cluster */
00115         DWORD   curr_sect;              /* Current sector */
00116 #if !_FS_READONLY
00117         DWORD   dir_sect;               /* Sector containing the directory entry */
00118         BYTE*   dir_ptr;                /* Ponter to the directory entry in the window */
00119 #endif
00120 } FIL;
00121 
00122 
00123 /* File status structure */
00124 typedef struct _FILINFO {
00125         DWORD fsize;                    /* Size */
00126         WORD fdate;                             /* Date */
00127         WORD ftime;                             /* Time */
00128         BYTE fattrib;                   /* Attribute */
00129         char fname[8+1+3+1];    /* Name (8.3 format) */
00130 } FILINFO;
00131 
00132 
00133 /* File function return code (FRESULT) */
00134 
00135 typedef enum {
00136         FR_OK = 0,                      /* 0 */
00137         FR_NOT_READY,           /* 1 */
00138         FR_NO_FILE,                     /* 2 */
00139         FR_NO_PATH,                     /* 3 */
00140         FR_INVALID_NAME,        /* 4 */
00141         FR_INVALID_DRIVE,       /* 5 */
00142         FR_DENIED,                      /* 6 */
00143         FR_EXIST,                       /* 7 */
00144         FR_RW_ERROR,            /* 8 */
00145         FR_WRITE_PROTECTED,     /* 9 */
00146         FR_NOT_ENABLED,         /* 10 */
00147         FR_NO_FILESYSTEM,       /* 11 */
00148         FR_INVALID_OBJECT       /* 12 */
00149 } FRESULT;
00150 
00151 
00152 
00153 /*-----------------------------------------------------*/
00154 /* FatFs module application interface                  */
00155 
00156 FRESULT f_mount (BYTE, FATFS*);                                         /* Mount/Unmount a logical drive */
00157 FRESULT f_open (FIL*, const char*, BYTE);                       /* Open or create a file */
00158 FRESULT f_read (FIL*, void*, WORD, WORD*);                      /* Read data from a file */
00159 FRESULT f_write (FIL*, const void*, WORD, WORD*);       /* Write data to a file */
00160 FRESULT f_lseek (FIL*, DWORD);                                          /* Move file pointer of a file object */
00161 FRESULT f_close (FIL*);                                                         /* Close an open file object */
00162 FRESULT f_opendir (DIR*, const char*);                          /* Open an existing directory */
00163 FRESULT f_readdir (DIR*, FILINFO*);                                     /* Read a directory item */
00164 FRESULT f_stat (const char*, FILINFO*);                         /* Get file status */
00165 FRESULT f_getfree (const char*, DWORD*, FATFS**);       /* Get number of free clusters on the drive */
00166 FRESULT f_sync (FIL*);                                                          /* Flush cached data of a writing file */
00167 FRESULT f_unlink (const char*);                                         /* Delete an existing file or directory */
00168 FRESULT f_mkdir (const char*);                                          /* Create a new directory */
00169 FRESULT f_chmod (const char*, BYTE, BYTE);                      /* Change file/dir attriburte */
00170 FRESULT f_rename (const char*, const char*);            /* Rename/Move a file or directory */
00171 
00172 
00173 /* User defined function to give a current time to fatfs module */
00174 
00175 DWORD get_fattime (void);       /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */
00176                                                         /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
00177 
00178 
00179 
00180 /* File access control and file status flags (FIL.flag) */
00181 
00182 #define FA_READ                         0x01
00183 #define FA_OPEN_EXISTING        0x00
00184 #if !_FS_READONLY
00185 #define FA_WRITE                        0x02
00186 #define FA_CREATE_NEW           0x04
00187 #define FA_CREATE_ALWAYS        0x08
00188 #define FA_OPEN_ALWAYS          0x10
00189 #define FA__WRITTEN                     0x20
00190 #endif
00191 #define FA__ERROR                       0x80
00192 
00193 
00194 /* FAT sub type (FATFS.fs_type) */
00195 
00196 #define FS_FAT12        1
00197 #define FS_FAT16        2
00198 #define FS_FAT32        3
00199 
00200 
00201 /* File attribute bits for directory entry */
00202 
00203 #define AM_RDO  0x01    /* Read only */
00204 #define AM_HID  0x02    /* Hidden */
00205 #define AM_SYS  0x04    /* System */
00206 #define AM_VOL  0x08    /* Volume label */
00207 #define AM_LFN  0x0F    /* LFN entry */
00208 #define AM_DIR  0x10    /* Directory */
00209 #define AM_ARC  0x20    /* Archive */
00210 
00211 
00212 
00213 /* Offset of FAT structure members */
00214 
00215 #define BS_jmpBoot                      0
00216 #define BS_OEMName                      3
00217 #define BPB_BytsPerSec          11
00218 #define BPB_SecPerClus          13
00219 #define BPB_RsvdSecCnt          14
00220 #define BPB_NumFATs                     16
00221 #define BPB_RootEntCnt          17
00222 #define BPB_TotSec16            19
00223 #define BPB_Media                       21
00224 #define BPB_FATSz16                     22
00225 #define BPB_SecPerTrk           24
00226 #define BPB_NumHeads            26
00227 #define BPB_HiddSec                     28
00228 #define BPB_TotSec32            32
00229 #define BS_55AA                         510
00230 
00231 #define BS_DrvNum                       36
00232 #define BS_BootSig                      38
00233 #define BS_VolID                        39
00234 #define BS_VolLab                       43
00235 #define BS_FilSysType           54
00236 
00237 #define BPB_FATSz32                     36
00238 #define BPB_ExtFlags            40
00239 #define BPB_FSVer                       42
00240 #define BPB_RootClus            44
00241 #define BPB_FSInfo                      48
00242 #define BPB_BkBootSec           50
00243 #define BS_DrvNum32                     64
00244 #define BS_BootSig32            66
00245 #define BS_VolID32                      67
00246 #define BS_VolLab32                     71
00247 #define BS_FilSysType32         82
00248 
00249 #define FSI_LeadSig                     0
00250 #define FSI_StrucSig            484
00251 #define FSI_Free_Count          488
00252 #define FSI_Nxt_Free            492
00253 
00254 #define MBR_Table                       446
00255 
00256 #define DIR_Name                        0
00257 #define DIR_Attr                        11
00258 #define DIR_NTres                       12
00259 #define DIR_CrtTime                     14
00260 #define DIR_CrtDate                     16
00261 #define DIR_FstClusHI           20
00262 #define DIR_WrtTime                     22
00263 #define DIR_WrtDate                     24
00264 #define DIR_FstClusLO           26
00265 #define DIR_FileSize            28
00266 
00267 
00268 
00269 /* Multi-byte word access macros  */
00270 
00271 #if _MCU_ENDIAN == 1    /* Use word access */
00272 #define LD_WORD(ptr)            (WORD)(*(WORD*)(BYTE*)(ptr))
00273 #define LD_DWORD(ptr)           (DWORD)(*(DWORD*)(BYTE*)(ptr))
00274 #define ST_WORD(ptr,val)        *(WORD*)(BYTE*)(ptr)=(WORD)(val)
00275 #define ST_DWORD(ptr,val)       *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
00276 #else
00277 #if _MCU_ENDIAN == 2    /* Use byte-by-byte access */
00278 #define LD_WORD(ptr)            (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
00279 #define LD_DWORD(ptr)           (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr))
00280 #define ST_WORD(ptr,val)        *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
00281 #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)
00282 #else
00283 #error Do not forget to set _MCU_ENDIAN properly!
00284 #endif
00285 #endif
00286 
00287 
00288 
00289 #define _FATFS
00290 #endif /* _FATFS */

Generated on Sun Dec 9 17:17:10 2007 for Sample MSP430-4619LCD Project by  doxygen 1.5.1