版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、uC/FS詳解(開發(fā)文檔)1: uC/FS簡(jiǎn)介 µ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)是一種由微軟發(fā)明的并帶有部分專件系統(tǒng)。FAT文件系統(tǒng)考慮當(dāng)時(shí)計(jì)算機(jī)效能有限,所以未被復(fù)雜化,因而被幾乎所有個(gè)人計(jì)算機(jī)的操作系統(tǒng)支持。這特性使它成為理想的軟盤和記憶卡文件系統(tǒng),也適合用作不同操作系統(tǒng)中的數(shù)據(jù)交流。但FAT有一個(gè)嚴(yán)重的缺點(diǎn):當(dāng)文件被刪除并且在同一位置被寫入新數(shù)據(jù),他們的片段通常是分散的,減慢了讀寫速度。磁盤碎片重整是一種解決方法,但必須經(jīng)常重組來保持FAT文件系統(tǒng)的效率。 FAT文件系統(tǒng)遵行已用了多年的軟件方法來進(jìn)行規(guī)范。它在1977年由比爾&
3、#183;蓋茨和馬斯·麥當(dāng)勞為了管理磁盤而發(fā)明。2: uC/FS特點(diǎn)µ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. 【在該文件系統(tǒng)中可同時(shí)支持多個(gè)設(shè)備驅(qū)動(dòng)】· 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結(jié)構(gòu) µC/FS 由不同的分層構(gòu)成。 上面的圖是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層將各種調(diào)用傳輸?shù)絝ile system layer(文件系統(tǒng)層),目前對(duì)µC/FS(文件管理實(shí)現(xiàn)機(jī)制)來說 只有一個(gè) FAT文件系統(tǒng)層被使用,API層可以處理不同的文件系統(tǒng)層,因此µC/FS可同時(shí)支持多種文件系統(tǒng)(API層類似于linux中的虛擬文件系統(tǒng)VFS,他的功能是提供給童用戶標(biāo)準(zhǔn)的系統(tǒng)調(diào)用接口,VFS層下面才
12、是具體實(shí)際的文件系統(tǒng)層,有FAT、EXT2等等,這個(gè)根據(jù)硬件的情況(格式化時(shí)使用什么文件系統(tǒng))來調(diào)用具體的文件系統(tǒng))。 2:File System Layer 文件系統(tǒng)層【這層與linux是一樣的,是具體的管理文件所用的文件系統(tǒng)】 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. 文件系統(tǒng)層將文件操作轉(zhuǎn)換為邏輯塊操作,之后,具體的文件系統(tǒng)調(diào)用邏輯塊層函數(shù)并指定設(shè)備相應(yīng)的驅(qū)動(dòng);【linux中,文件系統(tǒng)將各種系統(tǒng)調(diào)用轉(zhuǎn)換為各種IO請(qǐng)求(系統(tǒng)請(qǐng)求即是對(duì)底層相應(yīng)的扇區(qū)、柱面、等操作),IO請(qǐng)求被放到對(duì)應(yīng)設(shè)備的IO請(qǐng)求隊(duì)列中去,再由一個(gè)系統(tǒng)內(nèi)核線程一直讀取請(qǐng)求隊(duì)列中的請(qǐng)求,沒有請(qǐng)求時(shí)就睡眠,拿到請(qǐng)求就通過設(shè)備驅(qū)動(dòng)實(shí)現(xiàn)具體的操作】 uC_FSFSLfat 下面就是F
14、AT文件系統(tǒng)的各個(gè)文件。 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. 邏輯塊層的主要目的是同步訪問設(shè)備驅(qū)動(dòng)與文件系統(tǒng)的簡(jiǎn)易接口,邏輯塊層調(diào)用設(shè)備驅(qū)動(dòng)來實(shí)現(xiàn)設(shè)備的塊操作。 4: Device Driver Layer 設(shè)備驅(qū)動(dòng)層 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. 設(shè)備驅(qū)動(dòng)是一些訪問硬件的底層操作,µC/FS的設(shè)備驅(qū)動(dòng)的架構(gòu)很簡(jiǎn)單,不像linux架構(gòu)非常復(fù)雜。 4: uC/FS的使用 下面的流程是參考uC/FS用戶手冊(cè)上的例程來寫的,可以參考。 1:調(diào)用FS_Init()初始化文件系統(tǒng),在使用uC/FS的任何功能函數(shù)之前須要首先調(diào)用該函數(shù)進(jìn)行初始 化; &
17、#160; 2:進(jìn)入MainTask() 1:調(diào)用FS_IoCtl()【格式化:使硬件按指定的文件系統(tǒng)來管理文件】 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:調(diào)用應(yīng)用程序中的函數(shù)_write_file()【非uc/fs的函數(shù)】
19、160; _write_file()中又依次調(diào)用: FS_FOpen(), FS_FWrite(),F(xiàn)S_FClose() FS_FOpen():在這個(gè)例程中FS_FOpen()創(chuàng)建了一個(gè)叫default.txt的文件,如果創(chuàng)建成功,函數(shù)
20、0; 將返回一個(gè)FS_FILE結(jié)構(gòu)體的指針,如果出錯(cuò)將返回0 FS_FWrite():文件創(chuàng)建成功之后,將一串字符串寫入該文件中,如果寫入時(shí)出錯(cuò),例
21、程中調(diào) 用FS_FError()處理錯(cuò)誤。 FS_FClose():關(guān)閉上面打開的文件
22、,返回主任務(wù)中 【大致過程就是如上過程】 讀: FS_FOpen()->FS_FRead()->FS_FClose() 3:不使用uC/FS文件管理系統(tǒng)時(shí)調(diào)用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提供給用戶的接口函數(shù)
27、60; FSFSL: 具體的文件系統(tǒng)層 FSLBL: 邏輯塊層 FSOS : FSDEVICERAM and their sub-directories to your project. &
28、#160; 4: Configure the search path為開發(fā)環(huán)境添加所以代碼的路徑 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. 【用戶手冊(cè)中列出了一個(gè)配置樣本】,包括下面的各個(gè)配置項(xiàng)目 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相關(guān)的數(shù)據(jù)類型】 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函數(shù)說明 FS_IoCtl:執(zhí)行命令(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: 設(shè)備驅(qū)動(dòng)Device drivers µC/FS可以與任何種類的硬件配合工作;µC/FS需要配備與硬件設(shè)備對(duì)應(yīng)的設(shè)備驅(qū)動(dòng)程序,這些設(shè)備驅(qū)動(dòng)程序包含 基本的訪問硬件的I
41、/O函數(shù) 以及 一張全局表,這張表中存放各個(gè)函數(shù)的指針?!韭?lián)想到LINUX中系統(tǒng)調(diào)用的系統(tǒng)調(diào)用號(hào)】 要使你的µC/FS支持特定的硬件設(shè)備,你必須寫好該設(shè)備的驅(qū)動(dòng),本節(jié)告訴你需要實(shí)現(xiàn)哪些函數(shù)以及怎么樣將驅(qū)動(dòng)整合到µC/FS中去。 【下面是ramdisk的設(shè)備驅(qū)動(dòng)函數(shù)表的例子:設(shè)備驅(qū)動(dòng)函數(shù)表中的各個(gè)函數(shù),在PDF中已給出具體的代碼,其他的設(shè)備,如MMC&SD也是類似的,需要提供這相關(guān)的幾個(gè)函數(shù),名字可以不同,在功能函數(shù)的次序要一樣】 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、;因?yàn)槭峭ㄟ^一張全局表來管理各個(gè)設(shè)備驅(qū)動(dòng)函數(shù),所以各設(shè)備驅(qū)動(dòng)函數(shù)的名稱與µC/FS沒有太多的關(guān)聯(lián)性。 _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 該函數(shù)被用來完成一些設(shè)備驅(qū)動(dòng)中特殊的命令,對(duì)uc/FS來說目前需要支持的這類特殊命令有:FS_CMD_FLUSH_CACHE,這個(gè)命
48、令用來告訴設(shè)備的緩沖邏輯 所有的緩沖必須清零,如果你的設(shè)備沒有緩沖邏輯,該函數(shù)不需要做任何事情。 _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、 函數(shù)應(yīng)該傳送0x0200(512)個(gè)字節(jié),這個(gè)是兼容FAT文件系統(tǒng)的MS-DOS/MS-Windows系統(tǒng)的默認(rèn)值,µC/FS能支持任何大小的塊,但是如果你的文件系統(tǒng)層使用FAT,那么你必須使用這個(gè)默認(rèn)的塊大小。 _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. 該函數(shù)的主要目的是檢測(cè)一個(gè)介質(zhì)的改變。如果一個(gè)設(shè)備能夠被訪問,所有的µC/FS 文件操作都調(diào)用這個(gè)函數(shù)進(jìn)行檢測(cè), 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. 如果你想要使用自己的設(shè)備驅(qū)動(dòng),你必須要告訴C/FS,你的設(shè)備使用的是哪一個(gè)設(shè)備名稱以及使用哪一個(gè)文件系統(tǒng)來管理(目前只支持FAT)。 可以將&
63、#160;FS_conf.h中的FS_DEVINFO 設(shè)置一個(gè)合適的值來完成上面的動(dòng)作,F(xiàn)S_DEVINFO被用來初始化C/FS的全局設(shè)備信息表。 【上面是ramdisk的設(shè)備驅(qū)動(dòng)函數(shù)表的例子,_FS_DevStatus, _FS_DevRead, _FS_DevWrite, _FS_DevIoCtl,就是ramdisk所需的底層驅(qū)動(dòng)函數(shù)】 這里如果是MMC&SD存儲(chǔ)設(shè)備,下面是源碼。#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,系統(tǒng)會(huì)自動(dòng)以FS_DEVINFO_DEVSMC,即采用系統(tǒng)默認(rèn)的設(shè)備驅(qū)動(dòng)。我們可以在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,系統(tǒng)也會(huì)有一個(gè)默認(rèn)的定義。FS_fat_functable:這個(gè)表不用填充,因?yàn)檫@里面的函數(shù)在API層已經(jīng)實(shí)現(xiàn),且系統(tǒng)已經(jīng)設(shè)置好。用戶只需更改FS_mmcdevice_driver里面的各個(gè)函數(shù)即可。 【這里支持多個(gè)設(shè)備"smc"和"mydev"】#define FS_DEVINFO "smc", &FS_fat_functable,
68、 &FS_smcdevice_driver, 0, "mydev", &FS_fat_functable, &FS_mydevice_driver , 0 【如果不指定,系統(tǒng)將使用默認(rèn)值】 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包含的就是文件系統(tǒng)需要使用的最底層的操作硬
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- GB/T 44887.10-2024IPv6演進(jìn)技術(shù)要求 第10部分:支持IP網(wǎng)絡(luò)切片的增強(qiáng)型虛擬專用網(wǎng)(VPN+)
- 2025年教學(xué)檢查通報(bào) 教學(xué)計(jì)劃?rùn)z查通報(bào)
- 開咖啡屋的創(chuàng)業(yè)計(jì)劃書
- 基層派出所宣傳工作計(jì)劃行政工作計(jì)劃
- 2025年急診護(hù)理工作計(jì)劃024年門急診工作計(jì)劃
- 初二數(shù)學(xué)教學(xué)計(jì)劃
- 醫(yī)院業(yè)務(wù)宣傳年度工作計(jì)劃范文
- 2025年中小學(xué)課件中心組活動(dòng)計(jì)劃
- 企業(yè)經(jīng)理工作計(jì)劃報(bào)告大全
- 《歐美簡(jiǎn)約美模板》課件
- 四川省南充市2023-2024學(xué)年高一上學(xué)期期末考試 政治 含解析
- 【MOOC】土木工程制圖-同濟(jì)大學(xué) 中國(guó)大學(xué)慕課MOOC答案
- 人教版5年級(jí)上冊(cè)音樂測(cè)試(含答案)
- 數(shù)智時(shí)代的商業(yè)變革智慧樹知到期末考試答案章節(jié)答案2024年山東大學(xué)(威海)
- 生物化學(xué)實(shí)驗(yàn)智慧樹知到期末考試答案2024年
- 2024年職業(yè)衛(wèi)生技術(shù)人員評(píng)價(jià)方向考試題庫附答案
- 《經(jīng)絡(luò)及任督二脈》課件
- 在建鋼結(jié)構(gòu)工程危險(xiǎn)源辨識(shí)評(píng)價(jià).doc
- 托兒所、幼兒園建筑設(shè)計(jì)規(guī)范 JGJ 39-2016
- 螺栓螺母理論重量表
- 微生物鑒定藥敏分析系統(tǒng)說明書48頁
評(píng)論
0/150
提交評(píng)論