




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、uC/FS详解(开发文档)1: uC/FS简介 µC/FS is a FAT file system which can be used on any media, for which you can provide basic hardware access functions. . µC/FS is a high performance library that has been optimized for speed, versatility and memory footp
2、rint. 文件配置表(英文:File Allocation Table,首字母缩略字:FAT)是一种由微软发明的并带有部分专件系统。FAT文件系统考虑当时计算机效能有限,所以未被复杂化,因而被几乎所有个人计算机的操作系统支持。这特性使它成为理想的软盘和记忆卡文件系统,也适合用作不同操作系统中的数据交流。但FAT有一个严重的缺点:当文件被删除并且在同一位置被写入新数据,他们的片段通常是分散的,减慢了读写速度。磁盘碎片重整是一种解决方法,但必须经常重组来保持FAT文件系统的效率。 FAT文件系统遵行已用了多年的软件方法来进行规范。它在1977年由比尔&
3、#183;盖茨和马斯·麦当劳为了管理磁盘而发明。2: uC/FS特点µ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 devi
4、ce 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&
5、#160;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.
6、· 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 driver
7、s 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
8、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/F
9、S结构 µ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
10、;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 an
11、y 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层下面才
12、是具体实际的文件系统层,有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 l
13、ayer and specifies the corresponding device driver for a device. 文件系统层将文件操作转换为逻辑块操作,之后,具体的文件系统调用逻辑块层函数并指定设备相应的驱动;【linux中,文件系统将各种系统调用转换为各种IO请求(系统请求即是对底层相应的扇区、柱面、等操作),IO请求被放到对应设备的IO请求队列中去,再由一个系统内核线程一直读取请求队列中的请求,没有请求时就睡眠,拿到请求就通过设备驱动实现具体的操作】 uC_FSFSLfat 下面就是F
14、AT文件系统的各个文件。 3:Logical Block Layer 逻辑块层 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 blo
15、ck operation. 逻辑块层的主要目的是同步访问设备驱动与文件系统的简易接口,逻辑块层调用设备驱动来实现设备的块操作。 4: Device Driver Layer 设备驱动层 Device drivers are low level routines that are used to access your hardware. The structure of the device driver is simple to allow
16、 easy integration of your own hardware. 设备驱动是一些访问硬件的底层操作,µC/FS的设备驱动的架构很简单,不像linux架构非常复杂。 4: uC/FS的使用 下面的流程是参考uC/FS用户手册上的例程来写的,可以参考。 1:调用FS_Init()初始化文件系统,在使用uC/FS的任何功能函数之前须要首先调用该函数进行初始 化; &
17、#160; 2:进入MainTask() 1:调用FS_IoCtl()【格式化:使硬件按指定的文件系统来管理文件】 This call is used to format your RAM disk in order to be able to write data to
18、; it. Formatting your RAM disk should not cause any problem. 2:调用应用程序中的函数_write_file()【非uc/fs的函数】
19、160; _write_file()中又依次调用: FS_FOpen(), FS_FWrite(),FS_FClose() FS_FOpen():在这个例程中FS_FOpen()创建了一个叫default.txt的文件,如果创建成功,函数
20、0; 将返回一个FS_FILE结构体的指针,如果出错将返回0 FS_FWrite():文件创建成功之后,将一串字符串写入该文件中,如果写入时出错,例
21、程中调 用FS_FError()处理错误。 FS_FClose():关闭上面打开的文件
22、,返回主任务中 【大致过程就是如上过程】 读: FS_FOpen()->FS_FRead()->FS_FClose() 3:不使用uC/FS文件管理系统时调用FS_Exit().5: uC/FS加入到工程中 1:Create a simple project without µC/FS We recom
23、mend, 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
24、 configure µC/FS for your system, you should create a new sub-directory in µC/FSs 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
25、you have created a directory FSCONFIGmyconfig. 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 informa
26、tion about the configuration. 3: Add µC/FS generic source code Add all source files in the following directories: FSAPI: µC/FS提供给用户的接口函数
27、60; FSFSL: 具体的文件系统层 FSLBL: 逻辑块层 FSOS : FSDEVICERAM and their sub-directories to your project. &
28、#160; 4: Configure the search path为开发环境添加所以代码的路径 FSAPI FSCONFIGmyconfig FSLBL FSOS
29、160; 5: Add generic sample code For a quick and easy test of your µC/FS integration, you should use the code found in FSsamplemain.c. 6: uC/FS配置 1:fs_conf.h &
30、#160; 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
31、160;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 hav
32、e 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.
33、; 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 s
34、ystem, so you will need to set FS_USE_FAT_FSL to 1. 4:Device Driver Support and configurationI RAM Disk: FS_USE_RAMDISK_DRIVER to 1
35、0; Windows Driver: FS_USE_WINDRIVE_DRIVER to 1 Smart Media Card(SMCs):
36、0; 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_D
37、RIVER 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_
38、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 compi
39、ler. 6: API函数说明 FS_IoCtl:执行命令(SD卡等可以通过电脑格式化) x = FS_IoCtl("ram:",FS_CMD_FORMAT_MEDIA,FS_MEDIA_RAM_16KB,0); Directory functions int FS_CloseDir(FS_DIR *dirp); int FS_MkDir(const char *dirname); FS_DIR *F
40、S_OpenDir(const char *dirname); struct FS_DIRENT *FS_ReadDir(FS_DIR *dirp); void FS_RewindDir(FS_DIR *dirp); int FS_RmDir(const char *dirname); 7: 设备驱动Device drivers µC/FS可以与任何种类的硬件配合工作;µC/FS需要配备与硬件设备对应的设备驱动程序,这些设备驱动程序包含 基本的访问硬件的I
41、/O函数 以及 一张全局表,这张表中存放各个函数的指针。【联想到LINUX中系统调用的系统调用号】 要使你的µC/FS支持特定的硬件设备,你必须写好该设备的驱动,本节告诉你需要实现哪些函数以及怎么样将驱动整合到µC/FS中去。 【下面是ramdisk的设备驱动函数表的例子:设备驱动函数表中的各个函数,在PDF中已给出具体的代码,其他的设备,如MMC&SD也是类似的,需要提供这相关的几个函数,名字可以不同,在功能函数的次序要一样】 In thi
42、s 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.
43、;因为是通过一张全局表来管理各个设备驱动函数,所以各设备驱动函数的名称与µC/FS没有太多的关联性。 _FS_DevIoCtl():Execute special command on device. static int _FS_DevIoCtl(FS_u32 id, FS_i32 cmd, FS_i32 aux,void *buffer);
44、0; Parameter Meaning
45、; id Number of media (0N) cmd
46、160;Command aux Parameter for command
47、 buffer Pointer to data required by command 该函数被用来完成一些设备驱动中特殊的命令,对uc/FS来说目前需要支持的这类特殊命令有:FS_CMD_FLUSH_CACHE,这个命
48、令用来告诉设备的缓冲逻辑 所有的缓冲必须清零,如果你的设备没有缓冲逻辑,该函数不需要做任何事情。 _FS_DevRead():Read block from media static int _FS_DevRead(FS_u32 id, FS_u32 block, void *buffer);
49、; id Number of media (0N)
50、 block Block number to be read from the media buffer Data buffer to which the data is transf
51、erred 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.
52、 函数应该传送0x0200(512)个字节,这个是兼容FAT文件系统的MS-DOS/MS-Windows系统的默认值,µC/FS能支持任何大小的块,但是如果你的文件系统层使用FAT,那么你必须使用这个默认的块大小。 _FS_DevStatus():Return current status of your device. static int _FS_DevStatus(FS_u32 id); id Number of media (0N
53、) The main purpose of this function is to detect a media change. All µC/FS file operation calls this function to check, if the device can be accessed. 该函数的主要目的是检测一个介质的改变。如果一个设备能够被访问,所有的µC/FS 文件操作都调用这个函数进行检测, The function re
54、turns 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
55、0; static int _FS_DevWrite(FS_u32 id, FS_u32 block,void *buffer); id
56、; Number of media (0N) block Block number to be written on media
57、0; buffer Pointer to data for transfer to the media. The function should transfer 0x0200 (i.e. 512) byte
58、s, 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
59、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 =
60、160; "RAMDISK device", _FS_DevStatus, _FS_DevRead, _FS_DevWrite,
61、160;_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
62、use. You do this by setting appropriate value for FS_DEVINFO in your FS_conf.h , which is used to initialize µC/FSs global device information table. 如果你想要使用自己的设备驱动,你必须要告诉C/FS,你的设备使用的是哪一个设备名称以及使用哪一个文件系统来管理(目前只支持FAT)。 可以将&
63、#160;FS_conf.h中的FS_DEVINFO 设置一个合适的值来完成上面的动作,FS_DEVINFO被用来初始化C/FS的全局设备信息表。 【上面是ramdisk的设备驱动函数表的例子,_FS_DevStatus, _FS_DevRead, _FS_DevWrite, _FS_DevIoCtl,就是ramdisk所需的底层驱动函数】 这里如果是MMC&SD存储设备,下面是源码。#ifndef FS_DEVINFO #if FS_USE_SMC_DRIVER
64、60;#define FS_DEVINFO_DEVSMC "smc",&FS_fat_functable,&FS_smcdevice_driver,FS_CACHEINFO_SMC_DRIVER 0 , #else #define FS_DEVINFO_DEVSMC #endif #if FS_USE_MMC_DRIVER #def
65、ine FS_DEVINFO_DEVMMC "mmc", &FS_fat_functable,&FS_mmcdevice_driver, FS_CACHEINFO_MMC_DRIVER 0 , #else #define FS_DEVINFO_DEVMMC #endif . #endif从源码中可以看出,如果没有定义 FS_DEVINFO宏,且如果没有定义
66、FS_DEVINFO_DEVSMC,系统会自动以FS_DEVINFO_DEVSMC,即采用系统默认的设备驱动。我们可以在fs_conf.h中配置 FS_USE_MMC_DRIVER = 1;再定义 #define FS_DEVINFO "mmc", &FS_fat_functable, &FS_mmcdevice_driver, 0,FS_USE_MMC_DRIVER = 1,即使
67、没有定义 FS_DEVINFO,系统也会有一个默认的定义。FS_fat_functable:这个表不用填充,因为这里面的函数在API层已经实现,且系统已经设置好。用户只需更改FS_mmcdevice_driver里面的各个函数即可。 【这里支持多个设备"smc"和"mydev"】#define FS_DEVINFO "smc", &FS_fat_functable,
68、 &FS_smcdevice_driver, 0, "mydev", &FS_fat_functable, &FS_mydevice_driver , 0 【如果不指定,系统将使用默认值】 The first parameter is a device name, which you want to use for µC/FSs API calls.
69、60; The second parameter is a pointer to a File System Layer function table; currently only FAT is supported. The third parameter is a pointer to a Device Driver function table. The last parameter is reserved for future use and should be zero. 8: 各目录介绍 在工程中添加上面的文件组:API层、FAT层、LBL层、DEV层、OS、CLIBDEV包含的就是文件系统需要使用的最底层的操作硬
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 浙江药科职业大学《定向越野》2023-2024学年第二学期期末试卷
- 江门职业技术学院《审计沟通》2023-2024学年第二学期期末试卷
- 唐山学院《全面预算管理》2023-2024学年第二学期期末试卷
- 武汉航海职业技术学院《医学美容技术》2023-2024学年第二学期期末试卷
- 黄山职业技术学院《药品分析》2023-2024学年第一学期期末试卷
- 2025届河南省许汝平九校联盟高三第三次模性考试英语试题试卷含解析
- 上海工商外国语职业学院《艺术管理学(一)》2023-2024学年第二学期期末试卷
- 东乡族自治县2025年数学五下期末教学质量检测模拟试题含答案
- 财务反欺诈培训课件
- 餐饮酒楼服务语言技巧大全
- 医院临床医学带教老师培训
- 2024年03月浙江南浔银行春季招考笔试历年参考题库附带答案详解
- HPE-DL380-Gen10-服务器用户手册
- Unit6Beautifullandscapes-Reading教学设计译林版七年级英语下册
- 金刚石行业分析报告
- 2024版家庭资产配置与财富传承规划合同3篇
- 2025届高考地理 二轮复习课件-专题35 生态脆弱区的综合治理
- 幼儿园体育游戏对幼儿社交能力的影响
- 《STP营销战略概述》课件
- 英语语法点点通(新疆交通职业技术学院)知到智慧树答案
- 2024年四川省绵阳市中考语文试卷(附真题答案)
评论
0/150
提交评论