當前位置:編程學習大全網 - 源碼下載 - sd卡怎麽修改文件目錄和分配表 fatfs

sd卡怎麽修改文件目錄和分配表 fatfs

SD的優勢之壹是它的便攜性,它可以自由插拔,可以在嵌入式設備和PC機之間交換數據。如果使用FAT(File Allocation Table)文件系統,它便可以方便在安裝windows的PC和嵌入式設備之間交換數據。壹個完整的FAT文件系統代碼量非常龐大,不適合資源較少的嵌入式系統,於是就需要壹個微型的FAT文件系統,FatFs就是基於這樣的目的而開發的。

FatFS是壹個專為小型嵌入式系統設計的通用FAT文件系統模塊。FatFs具有較高的可配置性,最小配置僅使用1K的RAM空間,非常適用於嵌入式系統。FatFs 的編寫遵循ANSI C,並且完全與磁盤I/O層分開。因此,它獨立(不依賴)於硬件架構。它可以被嵌入到低成本的微控制器中,如AVR, 8051, PIC, ARM, Z80, 68K 等等,而不需要做任何修改。

特點

Windows兼容的FAT文件系統

不依賴於平臺,易於移植

代碼和工作區占用空間非常小

多種配置選項:

多卷(物理驅動器和分區)

多ANSI/OEM代碼頁,包括DBCS

在ANSI/OEM或Unicode中長文件名的支持

RTOS的支持

多扇區大小的支持

只讀,最少API,I/O緩沖區等等

FatFs的源代碼只有幾個文件:diskio.c,ff.c,ff_util.c,tff.c及頭文件。diskio.c是磁盤操作的代碼文件(這個文件是移植時要實現的),ff.c是壹般FatFs的代碼文件,tff.c是微型FatFs的代碼文件,ff_util.c是幾個輔助函數。integer.h是內部基本類型的定義,ff.h是壹般FatFs包含的頭文件,tff.h是微型FatFs包含的頭文件。

[cpp] view plaincopy在CODE上查看代碼片派生到我的代碼片

#if _FATFS_TINY != 1

#include <fatfs/src/ff.h>

#else

#include <fatfs/src/tff.h>

#endif

#include <fatfs/src/ff_util.h>

微型FatFs配置最小時僅占用內存1KB,但它是壹個只讀的FAT系統。

FatFs的配置文件是fatfs_config.h:

[cpp] view plaincopy在CODE上查看代碼片派生到我的代碼片

//------------------------------------------------------------------------------

// General Definitions (previously in ff.h)

//------------------------------------------------------------------------------

#define _FATFS_TINY 0

/* When _FATFS_TINY is set to 1, fatfs is compiled in Tiny mode

/ Else, it is compiled in normal mode

/ Tiny FatFs feature : Very low memory consumption, suitable for small memory

/ system. (1KB RAM) : Supports only single drive, no disk format,

/ only read functions, no write functions */

//------------------------------------------------------------------------------

// Definitions for normal FATFS (previously in ff.h)

//------------------------------------------------------------------------------

#if _FATFS_TINY == 0

#define _MCU_ENDIAN 2

/* The _MCU_ENDIAN defines which access method is used to the FAT structure.

/ 1: Enable word access.

/ 2: Disable word access and use byte-by-byte access instead.

/ When the architectural byte order of the MCU is big-endian and/or address

/ miss-aligned access results incorrect behavior, the _MCU_ENDIAN must be set to 2.

/ If it is not the case, it can also be set to 1 for good code efficiency. */

#define _FS_READONLY 0

/* Setting _FS_READONLY to 1 defines read only configuration. This removes

/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,

/ f_truncate and useless f_getfree. */

#define _FS_MINIMIZE 0

/* The _FS_MINIMIZE option defines minimization level to remove some functions.

/ 0: Full function.

/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename are removed.

/ 2: f_opendir and f_readdir are removed in addition to level 1.

/ 3: f_lseek is removed in addition to level 2. */

#define _USE_STRFUNC 0

/* To enable string functions, set _USE_STRFUNC to 1 or 2. */

#define _USE_FSINFO 1

/* To enable FSInfo support on FAT32 volume, set _USE_FSINFO to 1. */

#define _USE_SJIS 1

/* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise

/ only US-ASCII(7bit) code can be accepted as file/directory name. */

#define _USE_NTFLAG 1

/* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved.

/ Note that the files are always accessed in case insensitive. */

#define _USE_MKFS 1

/* When _USE_MKFS is set to 1 and _FS_READONLY is set to 0, f_mkfs function is

/ enabled. */

#define _DRIVES 2

/* Number of logical drives to be used. This affects the size of internal table. */

#define _MULTI_PARTITION 0

/* When _MULTI_PARTITION is set to 0, each logical drive is bound to same

/ physical drive number and can mount only 1st primaly partition. When it is

/ set to 1, each logical drive can mount a partition listed in Drives[]. */

//------------------------------------------------------------------------------

// Definitions for normal FATFS TINY (previously in tff.h)

//------------------------------------------------------------------------------

#else

#define _MCU_ENDIAN 2

/* The _MCU_ENDIAN defines which access method is used to the FAT structure.

/ 1: Enable word access.

/ 2: Disable word access and use byte-by-byte access instead.

/ When the architectural byte order of the MCU is big-endian and/or address

/ miss-aligned access results incorrect behavior, the _MCU_ENDIAN must be set to 2.

/ If it is not the case, it can also be set to 1 for good code efficiency. */

#define _FS_READONLY 1

/* Setting _FS_READONLY to 1 defines read only configuration. This removes

/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,

/ f_truncate, f_getfree and internal writing codes. */

#define _FS_MINIMIZE 0

/* The _FS_MINIMIZE option defines minimization level to remove some functions.

/ 0: Full function.

/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename are removed.

/ 2: f_opendir and f_readdir are removed in addition to level 1.

/ 3: f_lseek is removed in addition to level 2. */

#define _USE_STRFUNC 0

/* To enable string functions, set _USE_STRFUNC to 1 or 2. */

#define _USE_FSINFO 1

/* To enable FSInfo support on FAT32 volume, set _USE_FSINFO to 1. */

#define _USE_SJIS 1

/* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise

/ only US-ASCII(7bit) code can be accepted as file/directory name. */

#define _USE_NTFLAG 1

/* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved.

/ Note that the files are always accessed in case insensitive. */

#define _USE_FORWARD 0

/* To enable f_forward function, set _USE_FORWARD to 1. */

#define _FAT32 1

/* To enable FAT32 support in addition of FAT12/16, set _FAT32 to 1. */

#endif

//------------------------------------------------------------------------------

// Other definitions

//------------------------------------------------------------------------------

/*-----------------------------------------------------------------------*/

/* Correspondence between drive number and physical drive */

/* Note that Tiny-FatFs supports only single drive and always */

/* accesses drive number 0. */

#define DRV_MMC 0

#define DRV_SDRAM 1

#define DRV_ATA 2

#define DRV_USB 3

#define SECTOR_SIZE_SDRAM 512

#define SECTOR_SIZE_SDCARD 512

  • 上一篇:比如比較源代碼
  • 下一篇:類似於DNF 的遊戲
  • copyright 2024編程學習大全網