µC/FS is written in ANSI C and can be used on virtually any CPU. Some
features of µC/FS are:
· MS-DOS/MS-Windows compatible FAT12 and FAT16 support.
· Multiple device driver support. You can use different device drivers with µC/FS, which allows you to access different types of hardware with the file system at the same time. 在该文件系统中可同时支持多个设备驱动
· Multiple media support. A device driver does allow you to access different medias at the same time.
· OS support. µC/FS can easily be integrated into any OS. In that way you can make file operations in a multithreaded environment.
· ANSI C stdio.h like API for user applications. An application using standard C I/O library can easily be ported to use µC/FS.
· Very simple device driver structure. µC/FS device drivers need only very basic functions for reading and writing blocks. Therefore it is very simple to support your custom hardware.
· Generic device driver for SmartMedia cards, which can easily be used with any kind of card reader hardware.
· Generic device driver for MultitMedia & SD cards using SPI mode, which can be easily integrated.
3: uC/FS结构
µC/FS 由不同的分层构成。
上面的图是FATFS,但与UC/FS的是一样的
1:API层类似于linux的VFS层
The API layer is the interface between µC/FS and the user application. It does contain a library of ANSI C oriented file functions, such as FS_FOpen, FS_FWrite etc. The API layer does transfer these calls to the file system layer. Currently there is only a FAT file system layer available for µC/FS, but the API layer can deal with different file system layers at the same time. So it is possible to use FAT and any other file system at the same time with µC/FS.
API层是µC/FS提供给用户使用的接口层(fs_api.h),API层将各种调用传输到file system layer(文件系统层),目前对µC/FS(文件管理实现机制)来说 只有一个 FAT文件系统层被使用,API层可以处理不同的文件系统层,因此µC/FS可同时支持多种文件系统(API层类似于linux中的虚拟文件系统VFS,他的功能是提供给童用户标准的系统调用接口,VFS层下面才是具体实际的文件系统层,有FAT、EXT2等等,这个根据硬件的情况(格式化时使用什么文件系统)来调用具体的文件系统)。
2:File System Layer 文件系统层这层与linux是一样的,是具体的管理文件所用的文件系统
The file system layer translates file operations to logical block operations. After such a translation, the file system calls the logical block layer and specifies the corresponding device driver for a device.
the main purpose of the logical block layer is to synchronize accesses to a device driver and to have an easy interface for the file system layer. The logical block layer does call a device driver to make a block operation.
逻辑块层的主要目的是同步访问设备驱动与文件系统的简易接口,逻辑块层调用设备驱动来实现设备的块操作。
4:Device DriverLayer设备驱动层
Device drivers are low level routines that are used to access your hardware.
The structure of the device driver is simple to allow easy integration of your own
We recommend, that you create a small “hello world” program for your system. That project should already use your OS and there should be a way to display text on a screen or serial port.
2: Add your µC/FS configuration
In order to configure µC/FS for your system, you should create a new sub-directory in µC/FS’s config directory and copy the files fs_conf.h and fs_port.h from one of the other sub-directories to your directory. For the following chapters, we assume that you have created a directory FS\CONFIG\myconfig. Usually, the only file you have to modify is fs_conf.h. For an easy startup, we recommend, that you disable all drivers except the RAM disk driver. Please check out the chapter “Configuration of µC/FS” for detailed information about the configuration.
3: Add µC/FS generic source code
Add all source files in the following directories:
FS\API: µC/FS提供给用户的接口函数
FS\FSL: 具体的文件系统层
FS\LBL: 逻辑块层
FS\OS :
FS\DEVICE\RAM
and their sub-directories to your project.
4: Configure the search path[为开发环境添加所以代码的路径]
FS\API
FS\CONFIG\myconfig
FS\LBL
FS\OS
5: Add generic sample code
For a quick and easy test of your µC/FS integration, you should use the code
found in FS\sample\main.c.
6: uC/FS配置
1:fs_conf.h
This is the main configuration file for the file system. You define which drivers you want to use and, the configurations for these drivers.
用户手册中列出了一个配置样本,包括下面的各个配置项目
1:OS support
You can specify whether you are using uC/OS-II, embOS, Windows or no OS support at all. Please set FS_OS_UCOS_II, FS_OS_EMBOS, FS_OS_WINDOWS to 1, respectively. For no OS support at all, set all of them to 0. If you need support for an additional OS, you will have to provide functions described in the chapter “OS integration”.
2:Time/Date support
If you want to be able to add date and times to your files, you will need to set
FS_OS_TIME_SUPPORT to 1.
3:File System Layer Support
µC/FS can support different file system at the same time. You can enable them by setting FS_USE_XXX_FSL, where XXX is the name of the file system layer. The current version of µC/FS only supports the FAT file system, so you will need to set FS_USE_FAT_FSL to 1.
4:Device Driver Support and configuration
IRAM Disk:
FS_USE_RAMDISK_DRIVER
to 1
Windows Driver: FS_USE_WINDRIVE_DRIVER to 1
Smart Media Card(SMCs):
FS_USE_SMC_DRIVER to 1
MultiMedia card:
µC/FS can support MultiMedia & SD cards. You can enable the driver by setting FS_USE_MMC_DRIVER to 1. In order to use it, you will have to provide low-level I/O functions for your card reader hardware. Please take a look at the chapter “MultiMedia & SD card device driver” for details.
CompactFlash card & IDE:FS_USE_IDE_DRIVER to 1
2:fs_port.h一般是与CPU相关的数据类型
Usually this file only requires minor modifications, if you are using a very specific CPU. Please also check the type declarations in this file to ensure that they fit with your target processor and compiler.
6: API函数说明
FS_IoCtl:执行命令(SD卡等可以通过电脑格式化)
x = FS_IoCtl("ram:",FS_CMD_FORMAT_MEDIA,FS_MEDIA_RAM_16KB,0);
In this chapter, you will find a detailed description of the device driver functions required by µC/FS. Please note that the names used for these functions are not really relevant for µC/FS because the file system accesses those functions through a function table.
因为是通过一张全局表来管理各个设备驱动函数,所以各设备驱动函数的名称与µC/FS没有太多的关联性。
_FS_DevIoCtl():Execute special command on device.
static int _FS_DevIoCtl(FS_u32 id, FS_i32 cmd, FS_i32 aux,void *buffer);
static int _FS_DevRead(FS_u32 id, FS_u32 block, void *buffer);
id Number of media (0…N)
block Block number to be read from the media
buffer Data buffer to which the data is transferred
The function should transfer 0x0200 (i.e. 512) bytes, which is the default value for an MS-DOS/MS-Windows compatible FAT file systems. µC/FS can support any block size but, if you use the FAT file system layer, you have to use this default block size.
The function returns 0 if the device can be accessed. If the media has changed (e.g. a card removed or replaced) and the device can be accessed, the return value has to be FS_LBL_MEDIACHANGED. Any value < 0 is interpreted as an error.
_FS_DevWrite():Write block to media
static int _FS_DevWrite(FS_u32 id, FS_u32 block,void *buffer);
id Number of media (0…N)
block Block number to be written on media
buffer Pointer to data for transfer to the media.
The function should transfer 0x0200 (i.e. 512) bytes, which is the default value for an MS-DOS/MS-Windows compatible FAT file systems. µC/FS can support any block size but, if you use the FAT file system layer, you have to use this default block size.
Device driver function table
To use a device driver with µC/FS, a global function table is required, which
holds pointers to the device driver functions. Each entry in the table contains
five values as shown in the example below.
const FS__device_type FS__ramdevice_driver = {
"RAMDISK device",
_FS_DevStatus,
_FS_DevRead,
_FS_DevWrite,
_FS_DevIoCtl
};
If you want to use your own device driver, you have to tell µC/FS, which device
name you would like to use for your device and which File System Layer
(currently only FAT is supported) you want to use.
You do this by setting appropriate value for FS_DEVINFO in your FS_conf.h ,
which is used to initialize µC/FS’s global device information table.