Home

µC/FS

image

Contents

1. cee 93 FS_IDE HW X Geiata 94 FG IDE HW XS Getievice eee 95 FS IDE HW X Geior cc cecceeeeee eee ees 96 FS_IDE_HW_X_GetSectorCount nanonnan0000ne 97 FG IDE HW X GeiGechorho 98 FS IDE HW X GeiGiatus cc ceeeeee eee 99 FS_IDE_HW_X_HWReset anononnnnnnnnannnnnnennnne 90 FS_IDE HW X GetCommand 100 FG IDE HW XN GerCwltigb nnana 101 FG IDE HW XN GerCwllow 102 FG IDE HW SX Gefiata eee ceee eee 103 FS IDE HW X GeiDevControl 104 FS_ IDE HW N Getfievice 105 FS IDE HW_X_SetFeatures cceee 106 FS IDE HW X GetGechortCoumt 107 FS_IDE_HW_X_SetSectorNO s onsnnnnanannaneneana 108 PRT E E 11 14 26 Sen EE 12 KSM EE ge aN 38 FS MMC_HW_X_AdjustFOP 0 ee 76 FS MMC HW XV Busvl edCn 72 FS MMC HW XV Busvl edm 73 FS MMC _HW_X_CheckOCR cc0eeeeee 77 FS MMC HW X ChechkwWb 79 FS MMC HW v ClockCand eee 74 FS_MMC_HW_X_DetectStatus 0000000000000na 80 FS MMC HW XS GetOb 78 FS_MMC_HW_X_ReadByte asnaeeeeeeenennne 82 FS_MMC_HW_X_ReadByteNoSync 83 FS_MMC_HW_X_ReadSingleBlock 84 FS MMC HW NV Gei 75 FS_MMC_HW_X_WaitBusy aannaeeneeneeene eenn 81 FS_MMC_HW_X_WriteByte ee 86 FS_MMC_HW_X_WriteByteSingleBlock 87 FS Open Difisis ccngedesteee ieee deed ge 39 FS OS EMBOS i E a a tn aa iaia en iaa 20 FG OG TIME SUPPOR Tatiana haa 20 FS OS UCOS IN ia A i iatea 20 FS OS WINDOWS neiet oaa aa a
2. FS_ul16 ltime gt tm_mon 1 lt lt FS_u16 ltime gt tm_year 80 lt lt fdate 1 fdate FS_ul16 1 lt lt 5 fdate FS_ul16 0 9 endif return fdate 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 121 123 11 5 2 FS_X OS GetTime Description Get current time Prototype FS_ul6 FS X OS GetTime void Return value Return current time as FS_u16 in a format suitable for the FAT file system Additional information The correct date format is o Bit 0 4 2 second count 0 29 o Bit 5 10 Minutes 0 59 o Bit 11 15 Hours 0 23 Example sample using ANSI C time functions FS_ul6 FS_X_OS_GetTime void if E OG TIME SUPPORT FS_ul6 ftime time_t ce struct tm ltime time amp t ltime ocaltime amp t ftime ftime else FS_ul6 ftime FS_u16 ltime gt tm_min lt lt 5 FS_ul6 ltime gt tm_hour lt lt 11 1 Crime ltime gt tm_sec 2 ftime endif return ftime 2002 Micrium Technologies Corporation 122 123 Index H UC FS add directories ecceeeeeeeeeeeeeeeaaeeeeeeaneeeees 15 AOA ee EE TE 15 API functions Tor 24 36 configuration of 15 17 23 device drivers Tor 43 49 features Ofset aaae raian 7 in multithreaded environments 111 22 INSTANING 2 a a as 10 integrating into your system 15 16 EVT WEE 8 OS integr
3. Additional information If you have a real SPI in your system you can simply send a Oxff for num times Example sample taken from device smc Hardware M16C_137x_IP void FS_MMC_HW_X_ClockCard FS_u32 id int num if id 0 return num 8 SPI_SET_DATAOUT while num SPI_CLR_CLK SPI_DELAY SPI_SET_ SPI_DEL num 2002 Micrium Technologies Corporation 74 123 User s amp reference manual for uC FS 9 1 4 ES MMC_HW_X SetCS Description Sets CS signal of the specified card reader Prototype void FS_MMC_HW_X_SetCS FS_u32 id char high Parameter ID of card reader 0 N 1 means high 0 means low Return value Void Additional information CS signal is used to address a specific card reader connected to the SPI Example sample taken from device smc Hardware M16C_137x_IP void FS_MMC_HW_X_SetCS FS_u32 id char high if id 0 return if high SPL SET CS else SPI_CLR_CS 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 75 123 9 2 Operation condition detection and adjusting functions 9 2 1 FS_MMC_HW_X_AdjustFOP Description Adjusts host to card clock frequency according to tran_speed Prototype char FS_MMC_HW_X_AdjustFOP FS_u32 id FS_u32 tran_speed Parameter Meng o O ID of card reader 0 N Lower 8 bits contain TRAN SPEED parameter of the C
4. FileView e Address 0x00000000 7 all data written if x int strlen txt check why not all data was written Si x FS _FError myfile S sprintf mybuf fer Hot all bytes written because of error d n x _error mybuf fer Oe eege S e txt 1 strlen txt myfile with FS_FWrite close file FS_FClose myfile 3 oe eee sprintf mybuf fer le to create file s n name _error mybuf fer 3 Closing the file with FS_FClose e AAA JE JE JE JE JE JE JE JE JE JE JE JE JE JE IE JE JE JE JE JE JE JE JE JE JE JE JE JE JE AAA JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE AAA JE JEJEJEJE dumn file sl lu i x Context _write_file const char const char 4 Value 00000000 2 7 2 00000006 2 7 27 oooon00C 27 27 27 2 72 22 00000012 2 2 00000018 7 OOOOOO1E 7 2 2 2 2 F4 3 2 F4 3 3 722 27772 A Name Value E 2777 277929 DI name Ox0042b3be 22 A 222222 default Let 22 2 222727 Thi 2292 922979 D txt Ee P 22 2 22227 S LL Auto Locals A this 7 N watent_ Watch2 A Watch Watcha 7 Ln 85 Col 1 Figure 4 3 You should get to the uC FS function call FS_FOpen This function creates a file named default txt in the root directory of your default device which is the RAM disk in this example Step over F10 this function which should return the address of a
5. Full qualified file name Return value 0 if the file has been removed In case of an error the return value is 1 Additional information Values for name are the same as for FS_FOpen Please refer FS_FOpen for examples of valid names Example void foo void FS_Remove test txt 2002 Micrium Technologies Corporation 36 123 User s amp reference manual for uC FS 6 7 Directory functions 6 7 1 FS_CloseDir Close a directory Description This functions closes a directory referred by parameter dirp Prototype int FS_CloseDir FS_DIR dirp Parameter Meaning o O o O Pointer to directory structure Return value 0 if the directory has been closed In case of any error the return value is 1 Example void foo void FS_DIR dirp struct FS_DIRENT direntp dirp FS_OpenDir Open root directory of the default device if dirp do direntp FS_ReadDir dirp if direntp sprintf mybuffer s n direntp gt d_name _log mybuffer while direntp FS_CloseDir dirp else _error Unable to open directory n 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 37 123 6 7 2 FS_MkDir Create a directory Description Creates a new directory Prototype int FS_MkDir const char dirname Parameter Meaning o Fully qualified directory name Return value Retu
6. If you are using a big endian system or a totally different architecture you may have to modify the file fs port p Version Date Author Explanation 1 00 00 20020815 First release Known problems or limitations with current version None Sas END OF HEADER xf tt define constants KKK KKK KKK KKK KK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KKK KKK KKK KKK Zi KKK KK I I I I A A AA IA A A A I I A AAA RA A A A HO OK Number of file handles Set the maximum number of simultaneously open files in your system Please be aware that the file system requires one FS_FILE structure for each open file If you are using FAT each file will also require two sector buffers Ki define FS_MAXOPE Maximum number of file handles 2002 Micrium Technologies Corporation 18 123 User s amp reference manual for uC FS HK IK IK I I RR A A A A I A A I I A AAA RA A A kkk kkk OS Layer Set all to 0 if you do not want OS support St define FS_OS_EMBOS 1 1 use embOS define FS_OS_UCOS_II 0 1 use uC OS II define FS_OS_WINDOWS 0 1 use WINDOWS if FS_OS_WINDOWS 1 amp amp FS_OS_EMBOS 1 FS_OS_UCOS_II 1 error You must not use Windows at the same time as embOS or uC OS ITI endif KK IK IK I I A RR A A A A A A I I I I A A A A A kk kkk kkk Time Date support If your system does support ANSI C library
7. data __IDE_SC return data 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 97 123 10 2 8 FS_IDE HW_X_GetSectorNo Description Read the Sector Number register Prototype unsigned char FS_IDE_HW_X_GetSectorNo FS_u32 id Parameter Meaning U U O ID of card reader 0 N Return value Value of the Sector Number register Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 unsigned char FS_IDE_HW_X_GetSectorNo FS_u32 id unsigned char data __MEMCFG2 0x1f13 CS5 8 bit data __IDE_SN return data 2002 Micrium Technologies Corporation 98 123 User s amp reference manual for uC FS 10 2 9 FS_ IDE HW_X_GetStatus Description Read the Status register Prototype unsigned char FS_IDE_HW_X_GetStatus FS_u32 id Parameter Meaning U O ID of card reader 0 N Return value Value of the Status register Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 unsigned char FS_IDE_HW_X_GetStatus FS_u32 id unsigned char data __MEMCFG2 0x1f13 CS5 8 bit data __IDE_CMD return data 2002 Micrium T
8. 2 Software and manual versions u sccastetses deaecsateexan avbindeettanestisv cierto avbddedatarest neiaiwlsinhiees 3 Eeer Ee eene 4 1 About this document gebei Secteure geegent 6 Wee et LE E 6 1 2 How to use this SEET chs dats Stat wen hese nieces EE 6 1 3 Typographic Conventions for Gvnmtan e 6 2 NMP OGUCTOMSOGL C E Sao s ais Saeed eis ce eat EE 7 Pe WBE IS CRS EE 7 PAA CALUNOS eebe Eed 7 Oe Basic CONCCDIS avert Sco ere ieee eee eae abe esate aia lata Ne nee tee lanes 8 a ars E 8 3 2 File System Layer E 8 eS Logical Block EE 9 SE RIDIA DIVER ET 9 Elie Ee WEE 10 Ae Tis e EE EE 10 4 2 Use the Windows sample c cescecesceeeeseeceeeeceeeseeeceanseeaceaneeeseeaeeesatseeeseaneeeeeeanees 10 4 3 Integrating UC FS into your system ceecseceeecseeseeeceeeeeeeeeeeseeeseeeaeeeseaeeesateaneeeaeeatees 15 EE ee Lee E 17 BTS COMI E 17 Dees ISOM i EE 21 6ZAPIf UNCHON E 24 6 1 File system Control functions eeeeeceeseseeeeeceeeeeeeeeseeeceaeseeaceanseeaceaneesseeseeeteatseeetiaes 25 GEN ene 27 6 0 Direct inp t outp t FUNCTIONS eege 30 24 File eege elle e TING er EE 32 6 5 EEGEN cee to 34 6 6 Opera tions om E 36 SEENEN ee e EE 37 EIERE 43 7 1 DEVICE driver ee E 43 7 2 Device driver function Lallenger reegen 48 7 3 Integrate a new device ENEE 48 8 SmartMedia Card Device Driver EE 50 This chapter describes all hardware access functions required by uC FS s generic SmartMedia NIV EE EEN 50 8 1 Contro
9. CLE else if id 1 ___PBDR 0x9f nCE low CLE 2002 Micrium Technologies Corporation 54 123 User s amp reference manual for uC FS 8 1 5 FS_SMC_HW_X_SetData Description Set CE low CLE low and ALE low for the specified card reader Prototype void FS_SMC_HW_X_SetData FS_u32 id Parameter Meaning O S O Id of card reader 0 N Return value void Additional information The generic SMC driver calls this function to start data transfer Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_SetData FS_u32 id if id 0 ___PBDR 0x4f nCE E low ALE else if id 1 Ox8f nCE E low ALE 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 55 123 8 1 6 FS SMC _HW_X_SetStandby Description Set CE high CLE low and ALE low for the specified card reader Prototype void FS__X_SMC_HW_SetStandby FS_u32 id Parameter Meaning id of card reader 0 N Return value void Additional information The generic SMC driver calls this function to set the specified card reader into standby mode Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_SetStandby FS_u32 id __PBDR Ox0f nCE high CLE low ALE 2002 Micrium Technologies Corporation 56 123 User s amp reference manua
10. FS FAT File System 1 1 Assumptions This guide assumes that you already have a solid knowledge of the following e The software tools used to build your application assembler linker C compiler e The C language e The target processor e DOS command line If you feel your knowledge of C is not good enough we recommend The C Programming Language by Kernighan and Richie ISBN 0 13 1103628 which describes the standard in Cprogramming and in newer editions also covers ANSI C 1 2 How to use this manual This manual explains all the functions and macros that uC FS offers It assumes you have a working knowledge of the CLanguage knowledge of assembly programming is not required 1 3 Typographic Conventions for Syntax This manual uses the following typographic conventions Body EE O S Text that you enter at the command prompt or that appears on eyword i the display i e system functions file or pathnames Parameters in API functions Sample code in program examples Very important sections Term Important terms 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 7 123 2 Introduction to uC FS 2 1 What is uC FS LC FS is a FAT file system which can be used on any media for which you can provide basic hardware access functions UC FS is a high performance library that has been optimized for speed versatility and memory footprint 2 2 Features
11. IDE device driver for details 5 2 fs_port h 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 Example ifndef FG PORT_ define E PORT EE Micrium Inc 949 Crestview Circle Weston FL 33327 1848 Ka fe uC FS 2002 Micrium Technologies Corporation 22 123 User s amp reference manual for uC FS c Copyright 2002 Micrium Inc All rights reserved KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KK KKK KKK File fs_port h Purpose Architecture dependend defines for the file system This header defines basic data types and access macros used by the file system Depending on your CPU compiler you may have to modify this file Version Dat Author Explanation 1 00 00 20020815 First release Known problems or limitations with current version None SC KK IK IK I I I I A RR A A A A A A I I I I A AA A A A A I OK define constants KKK KKK KKK KKK KKK KKK KK KKK KK KKK KKK KK KKK KKK KK KKK KKK KKK KKK KKK KK KKK KKK KKK KKK S7 define FS_LITTLE_ 1 little endian 0 big endian KK IK IK I RR A A A A A A A I I I I AAA A A A A A I OK define global data types KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK
12. LUC FS is written in ANSI C and can be used on virtually any CPU Some features of uC FS are MS DOS MS Windows compatible FAT12 and FAT16 support Multiple device driver support You can use different device drivers with LUC 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 uC 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 uC FS Very simple device driver structure uC 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 amp SD cards using SPI mode which can be easily integrated 2002 Micrium Technologies Corporation 8 123 User s amp reference manual for uC FS 3 Basic concepts UC FS is organized in different layers In this chapter you will find a short description of the functionality of each layer 3 1 API Layer The API layer is the interface between uC FS and the user application It does contain a library of ANSI C oriented file functions
13. Microsoft Visual C break c FS sample main c BEE File Edit View Insert Project Debug Tools Window Help l8 x GA CIR Rae wl z n Globals y All global members x _dump_file si e ES t sl di ll EE EE EE JE JE JE JE JE E E JE EE EE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE JE EE E RS Workspace 186_MS_start 1 project s _dump_file SIE MS stat files 5 1 Source Files This routine demonstrates how to open and read from a file using v DES Ap the file system FS_DEV_WINDRIVE oz Git Fe CES LL e Dit De sample lt 3 ClassView FileView DEV_RAM Header Files Resource Files External Dependencies if myfile 7 read until EQ do x FS FRead mybuffer 1 sizeof mybuffer 1 myfile mybuf fer x 0 if x Lo 1 Opening default txt gt btatic ne egte int x Ee fil i Pola Fe Fopen nane cre 2 Read the file een reached H H j H SS _log mybuf fer while x check if there is no more data because of EOF x FS _FError myfile if xT ERR_EOF there a problem during read operation Si sprintf mybu Error d during read operation n x _error mybuf fer vs close file FS_FClose myfile 3 Check for End Of File EOF else sprintf Omhuffer Unable to open file zen name error nybuf Pes x ID 4 4 Closing the file a Address 0x00000000 4 Context _dump_file const c
14. clocks 8 before timeout Return value The next byte with bit 7 0 or Oxff if timeout occurred Additional information This function is used to receive card responses which have the highest bit set to 0 Example sample taken from device smc Hardware M16C_137x_IP unsigned char FS_MMC_HW_X_ReadByte FS_u32 id FS_u32 maxwait unsigned char a bpos if id 0 return Oxff SPI_SET_DATAOUT maxwait 8 sync on 1st 0 bit do SPI_CIR SPI_DEL SPI_SET_ SPI_DELAY if lay break if maxwait maxwait while maxwait if a return Oxff get 7 remaining bits bpos 7 do bpos SPI_CLR_CLK SPI_DELAY a SPI_DATAIN lt lt bpos SPI_ SET CLK SPI_DELAY while posi return a 2002 Micrium Technologies Corporation 82 123 User s amp reference manual for uC FS 9 4 2 FS MMC _HW_X_ReadByteNoSync Description Reads the next byte from the SPI Prototype unsigned char FS_MMC_HW_X_ReadByteNoSync FS_u32 id Parameter Meaning U U OO ID of card reader 0 N Return value The next byte received from the SPI Additional information This function is used to read normal data from the card If your system has a usual SPI you can simply read from it Example sample taken from device smc Hardware M16C_137x_IP unsigned char FS_MMC_HW_X_ReadByteNoSync FS_u32
15. data structure of type FS_FILE Return value Current position of file pointer in the file On failure the return value is 1 Additional information Currently this function does simply return the file pointer element of the file s FS_FILE structure Nevertheless you should not access the FS_FILE structure by yourself because that data structure might change in future Example const char welcome hello world n void foo void FS_FILE myfile FS_i32 pos myfile FS_FOpen test txt w if myfile 0 FS_FWrite welcome 1 strlen welcome myfile Pos FS_FTell myfile FS_FClose myfile 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 33 123 6 5 Error handling functions 6 5 1 FS_ClearErr Clear error status Description Clears the error status of a file Prototype void FS_ClearErr FS_FILE fp Pointer to a data structure of type FS_F ILE Return value void Additional information Call this routine after you have detected an error so you can check for success of the next file operations Example void foo void FS_FILE myfile FS_i16 err myfile FS_FOpen test txt r if myfile 0 err FS_FError myfile if err FS_ERR_OK FS_ClearErr myfile FS_FClose myfile 2002 Micrium Technologies Corporation 34 123 User s amp reference manual for uC FS 6 5 2 FS_F
16. functions for time date you can set this to 1 If it is set to 0 functions FS_OS_Get_Date and FS_OS_Get_Time will return the date 1 01 1980 0 00 unless you modify them EJ define FS_OS_TIME_SUPPORT 1 time date supported KK IK IK I I I A A A A A A A A I I A A A KKK kkk kkk kkk File System Layer You can turn on off the file system layers used in your system At least one layer has to be active Because currently there is only one file system layer supported FAT you will usually not change this setting Ki define FS_USE_FAT_ FSL FAT12 FAT16 file system KK IK IK I I A A A A A A A A A I I A I A AA A A A A HO OK Device Driver Support You can turn on off device driver supported in your system If you turn on a driver please check also its settings in this file below a define FS_USE_SMC_DRIVER SmartMedia card driver define FS_USE_WINDRIVE_DRIVER 0 Windows Logical Drive driver define FS_USE_RAMDISK_DRIVER 1 RAM Disk driver ae if defined _WIN32 amp amp FS_USE_WINDRIVE_DRIVER error Windows Logical Drive driver needs Windows API endif KK IK KK RK A I I A I I I A A AAR RAR A A A A I kkk kkk Ka pi FAT File System Layer defines if FS_USE_FAT_FSL For each media in your system using FAT the file system reserves memory to keep required information of the boot sector of that media FS_MAXDEV is the nu
17. lline TUN CUNO EE 51 8 2 Power control leede 57 8 3 Status detection functions EE 59 8 4 Data transfer functions eeerdzertergtereek ereeu eegeeeeuEEgGeEEEeEEEEgedEedCeeeEueEeENsterktenH 66 8 5 EE Set EtEEechEtgbebeetedbetegee enee Eege 68 9 MultiMedia amp SD Card device driver E 72 Oi Ae Gontrol line TUMCUOMS edel EE 72 9 2 Operation condition detection and adjusting functions cece eeeeeeeteeeteeeeeeees 76 9 3 Status detection functions EE 79 9 4 MEET 82 10 CompactFlash card amp IDE device driver ne ceeceeeececceceeeeecesteeeeceseeeeseeseeeseeseeeseaneesaeeateees 88 10 1 Control line lte 88 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 5 123 10 2 ATA I O register ACCESS functions 0 ceceeeeeecceeeeeeeeeseeeeeeeeeeeteeeeeseeeatieseseateetaeeateees 91 10 3 Status detection functions enee et cna en Sol Tuatha ott Sie al leslie 109 AT DS WMC OPANOM cca eet tetas dasa aaclc at fat diet teh ah salt 111 11 1 OS layer control functions EE 111 11 2 Internal data structure protection cecceceeccsceceeececeseeeeeceseeeesceaeeeeeeeseeeteetseeaseaees 113 11 3 File access protection ec ert A ok a eel ihe ht eR Re anenee een 117 11 4 DEVICE ACEESS ere e EE 119 11 5 Time Date functions tege eege 121 tel E E 123 2002 Micrium Technologies Corporation 6 123 User s amp reference manual for uC FS 1 About this document This guide describes the functionality and user API of uC
18. s amp reference manual for uC FS 89 123 10 1 3 FS_IDE_HW_X_HWReset Description Reset the bus interface Prototype void FS_IDE HW _X_ HWReset FS_u32 id Parameter Meaning U OO ID of card reader 0 N Return value Void Additional information This function is called if FS_IDE_HW_X_DetectStatus detects that a new device or card is present For usual ATA devices the function can be empty If you are going to use a CompactFlash card make sure that the bus is power cycled in this function while OE is grounded so that the card operates in true IDE mode This is important because a CF card inserted in a normal card reader will be provided with VCC and GND before OE is connected That will cause the card to run in PC Card ATA mode which is not supported by the driver Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_HWReset FS_u32 id 2002 Micrium Technologies Corporation 90 123 User s amp reference manual for uC FS 10 2 ATA I O register access functions 10 2 1 FS_ IDE HW_X_GetAltStatus Description Read the Alternate Status register Prototype unsigned char FS_IDE_HW_X_GetAl1tStatus FS_u32 id Parameter Meaning T ID of card reader 0 N Return value Value of the Alternate Status register Additional information Please check AT Attachment interface specification or CompactFlash specificat
19. standard http www t13 org To use the driver with your specific hardware you will have to provide basic I O functions for accessing the ATA I O registers This chapter describes all these routines 10 1 Control line functions 10 1 1 FS_IDE_HW_X_BusyLedOff Description Turns off busy LED of the card reader Prototype void FS_IDE_HW_X_BusyLedoOff FS_u32 id ID of card reader 0 N Return value Void Additional information Please see FS_IDE_HW_X_BusyLedOn Example sample taken from device ide Hardware EP7312 void FS_IDE_HW_X_BusyLedOff FS_u32 id no LED available 2002 Micrium Technologies Corporation 88 123 User s amp reference manual for uC FS 10 1 2 FS_IDE_HW_X_BusyLedOn Description Turns on busy LED of the card reader Prototype void FS_IDE_HW_X_BusyLedOn FS_u32 id Parameter Meanmg U O ID of card reader 0 N Return value Void Additional information If your system can lock the card reader or device you should also see that this is done here because a call of this function means that an pC FS operation is pending and the card or device should not be removed until FS_IDE_HW_X_BusyLedoOff is called Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_BusyLedOn FS_u32 id no LED available 2002 Micrium Technologies Corporation User
20. structure of type FS_FILE Return value Number of elements transferred Additional Information If there is less data transferred than specified you should check for possible errors by calling the FS_FError function Example Char buffer 100 void foo void FS_FILE myfile myfile FS_FOpen test txt r if myfile 0 do i FS_FRead buffer 1 sizeof buffer 1 myfile buffer i 0 if i printf s buffer while i FS_FClose myfile 2002 Micrium Technologies Corporation 30 123 User s amp reference manual for uC FS 6 3 2 FS_FWrite Write data to a file Description Writes data to an open file Prototype FS_size_t FS_FWrite void ptr FS_size_t size FS_size_t n FS_FILE fp Pointer to data which should be written to the file Size of an element to be transferred from buffer to the file Number of elements to be transferred to the file Pointer to a data structure of type FS_FILE Return value Number of elements written Additional Information If there is less data transferred than specified you should check for possible errors by calling the FS_FError function Example const char welcome hello world n void foo void FS_FILE myfile myfile FS_FOpen test txt w if myfile 0 FS_FWrite welcome 1 strlen welcome myfile FS_FClose myfile 2002 Micrium Technologies Corp
21. 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 uC 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 uC FS 3 2 File System Layer The file system ayer 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 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 9 123 3 3 Logical Block Layer The main purpose of the ogical 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 3 4 Device Driver 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 hardware 2002 Micrium Technologies Corporation 10 123 User s amp reference manual for uC FS 4 Getting started This chapter gives you a step by step introduction on how to use UC FS 4 1 Installation UC FS is shipped on CD ROM or as a zip file in electronic form In order to install it proceed as follows If you received a CD copy the entire contents to
22. this function and your screen should look as shown in Figure 4 2 I 6_MS_start Micrsoft Visual C break fe _ PSsamplenaia c Rob Gi zen Inert Datt Gang Loos wirden Dr lgjx D rug po MMS wis osmo jW Gre Vl Aotbinst s zl Mantak a eE SR DCL E Warps IO ger 1 reel mm v sien files D D KainTask D 1 Call to FS_Ioct1 to G Soa fies 3 Ta D An S void Meintesk void 3 format the RAM disk GIS DE MORVE SE FS_FSL format y RAN disk wi G GES LL Ss F amp _IoCtl ran PS_CHD_FORMAT_MEDIA PS_MEDI amp _RAM_16KB 0 Ga Fs_05 tt xi 0 E e Die s _error Cennot format RAM dizk n 2 Call pee Tet G DEV BAN el SE O Holu Fis creata TIT txt on your default device gi BD Puros fh _write_filet default Let der_default_asg fuer d Dependencies create file rem Let cn your RAM disk _write_filet ren Can txt dev ran Isy gt dusp tile default _duap_filet default Lei you default device 3 Call _write_file to tet Ce you default RAM diek e H i SE ty g write to another file e duap tile rad _duap_filef ran 4 Call to _dump_file to display the contents of default txt 5 Displaying the contents of ram txt Dn D0D0Dn 00000006 HD D0 DC aqoaoao12 00000016 00000018 Frosty int62 Cat AET ico ove 2002 Micri
23. 0 return Oxff SPI_SET_DATAOUT maxwait 8 sync on 1st 0 bit LSB in data token Start Block do SPI_CLR_CLK SPI_DELAY a SPI_DATAIN SPI_SE K SPI_DELAY if l a break if maxwait maxwait while maxwait if a return Oxff read data 16 bit CRC for 1 0 i lt len 2 i bpos 8 a 0 2002 Micrium Technologies Corporation 84 123 User s amp reference manual for uC FS do bpos SPI_CLR_CLK SPI_DELAY a SPI_DATAIN lt lt bpos SPI_SET_CLK SPI_DELAY while bpos if ix lt len buf i a return 0 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 85 123 9 4 4 FS_MMC_HW_X_WriteByte Description Sends data to the card Prototype void FS_MMC_HW_X_WriteByte FS_u32 id unsigned char data Parameter ID of card reader 0 N Data to send Return value Void Additional information When using a real SPI you can simply send the data Example sample taken from device smc Hardware M16C_137x_IP void FS_MMC_HW_X_WriteByte FS_u32 id unsigned char data if id 0 return _FS_MMC_HW_Send1 data 2002 Micrium Technologies Corporation 86 123 User s amp reference manual for uC FS 9 4 5 FS MMC_HW_X_WriteByteSingleBlock Description Sends a data block to the card Prototype voi
24. DRIVE_DRIVER defines 2002 Micrium Technologies Corporation 20 123 User s amp reference manual for uC FS This driver does allow to use any Windows logical driver ona Windows NT system with the file system Please be aware that Win9X is not supported because it cannot access logical drives with CreateFile ZS if FS_USE_WINDRIVE_DRIVER The following define tells WINDRIVE how many logical drives of your NT system you are going to access with the file system if your are going to use more than 2 logical drives you will have to modify function _FS_wd_devstatus of module device windriver wd_misc c bed define FS_WD_MAXUNIT 2 number of windows drives Specify names of logical Windows drives used with the file system For example A is usually the floppy of your computer FS_WD_DEVONAME WANA A Age A Bet Windows drive name for windrv 0 define FS_WD_DEV1NAME WAV Ae AS Windows drive name for windrv 1 To improve performance of WINDRIVE it does use sector caches for read write operations to avoid real device operations for each read write access The number of caches can be specified below and must not be smaller than 1 define FS _WD_CACHENUM 40 number of read caches per drive define FS_WD_WBUFFNUM 20 number of write caches per drive Do not change following define It may become configurable in future versions of the file s
25. Error Return error code Description Returns current error status of a file Prototype FS_il6 FS_FError FS_FILE fp Pointer to a data structure of type FS_FILE Return value Returns value not equal to FS_ERR_OK in case a file operation caused an error Additional information The return value is not FS_ERR_OK only in case a file operation caused an error and the error was not cleared by calling FS_ClearErr or any other operation that clears the previous error status The following error codes have specific meanings ES ERR OR Noeror S FS_ERR_ EOF End of file has been reached space on media illegal parameter A read operation has been made on a file open for writing only An error occurred during write operation FS_ERR_DISKCHANGED Media has been changed although the file was still open ES ERR CLOSE An error occurred during close operation FS_ERR_READONLY A write operation has been made on a file open for reading only FS_ERR_READERROR An error occurred during read operation Example void foo void FS_FILE myfile FS_i16 err myfile FS_FOpen test txt r if myfile 0 err FS_FError myfile FS_FClose myfile 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 35 123 6 6 Operations on files 6 6 1 FS_Remove Delete a file Description Removes file from the media Prototype int FS Remove const char name
26. KKK KKK KKK KKK KK KK KKK KKK KKK KKK KKK KKK KKK These defines will work for most 8 16 32 bit CPUs Please check your compiler manual if you are not sure my define FS_size_t unsigned long 32 bit unsigned define FS_u32 unsigned long 32 bit unsigned define FS_i32 signed long 32 bit signed define FS_ul6 unsigned short 16 bit unsigned define FS_il16 signed short 16 bit signed KK KK KK RR RR KK KK k k k K K K I I I k k k k k k A k k k k k k A k A k k IA k kK k k define access macros KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK Following macros are used to access data of a FAT file system Systems using little endian can access data as it is but big endian systems have to swap SCH if FS_LITTLE_ENDIAN 1 define FS__r_u32 value value define FS__w_u32 value value define FS__r_ul6 value value define FS__w_ul6 value value else define FS__r_u32 value value gt gt 24 value lt lt 24 value amp Ox00ffO0000ulL gt gt 8 value amp 0x0000ff00ul lt lt 8 define FS__w_u32 value _FS_r_u32 value define FS__r_ul6 value u_short value gt gt 8 u_short value lt lt 8 define FS__w_ul6 value _FS_r_ul6 value endif endif _FS_PORT_H_ 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 23 123 6 API functions In this chapter you
27. SD Return value 0 if no problem occurs If the host cannot adjust a communication speed lower than or equal to what is specified with the TRAN SPEED parameter a non zero value will be returned Please refer the MultiMedia amp SD card specifications on how to interpret the TRANS_SPEED parameter Additional information UC FS s generic MultiMedia amp SD card driver calls this function after reading TRAN_SPEED of the card s CSD register allowing the host to adjust the communication speed according to the card s limitations Before this function is called you should not access a card faster than 400KHz Example sample taken from device smc Hardware M16C_137x_IP char FS_MMC_HW_X_AdjustFOP FS_u32 id FS_u32 tran_speed return 0 2002 Micrium Technologies Corporation 76 123 User s amp reference manual for uC FS 9 2 2 FS MMC_HW_X_CheckOCR Description Checks and adjusts operation voltage Prototype char FS_MMC_HW_X_CheckOCR FS_u32 id FS_u32 ocr Parameter ID of card reader 0 N Value of the OCR register Return value 0 if the host can operate the card at requested voltage Any other value means that the host cannot work at the requested voltage Additional information Please check the MultiMedia amp SD card specifications for details Example sample taken from device smc Hardware M16C_137x_IP char FS_MMC_HW_X_CheckOCR FS_u32 id FS_u32
28. UC FS File System Software Version 1 26 CPU independent User amp Reference manual Micrium Technologies Corporation www micrium com Empowering Embedded Systems 2 123 User s amp reference manual for uC FS Disclaimer The information in this document is subject to change without notice While the information herein is assumed to be accurate Micrium Technologies Corporation the vendor assumes no responsibility for any errors or omissions The vendor makes and you receive no warranties or conditions express implied statutory or in any communications with you The vendor specifically disclaims any implied warranty of merchantability or fitness for a particular purpose Copyright notice No part of this publication may be reproduced stored in a retrieval system or transmitted in any form or by any means electronic mechanical photocopying recording or otherwise without the prior written permission of the vendor The Software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license If you have received this product as trial version for evaluation you are entitled to evaluate it but you may under no circumstances use it in a product If you want to do so you need to obtain a fully licensed version from the vendor 2002 Micrium Technologies Corporation http www micrium com Trademarks Names mentioned in this manual may be tradem
29. _u32 id Parameter Meaning o O id of card reader 0 N Return value Data received from the card reader Additional information Usually you will not have to take care about handling of the RE line because it is done automatically by hardware If you have to control RE line make sure that timing is according to SmartMedia card specification Example sample taken from device smc Hardware EP7312 char FS_SMC_HW_X_InData FS_u32 id return _ SMCPORT 2002 Micrium Technologies Corporation 66 123 User s amp reference manual for uC FS 8 4 2 FS SMC_HW_X OutData Description For the selected card reader set lines O7 O8 to the value specified with data and then set WE to low After a write pulse width set WE back to high Prototype void FS_SMC_HW_X_OutData FS_u32 id unsigned char data Parameter Meaning S O id of card reader 0 N value to be set on lines O1 I 08 Return value void Additional information Usually you will not have to take care about handling of the WE line because it is done automatically by hardware If you have to control WE line make sure that timing is according to the SmartMedia card specification Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_OutData FS_u32 id unsigned char data __SMCPORT char data 2002 Micrium Technologies Corporation User s a
30. aa 20 fS POrth filer ales 15 21 23 FS READ If a aeeti A aae 40 ESA ue EE raa aa 36 Fo Rewimglbg uggutues euer eege 41 FS ul 42 FG GMC HW X Busvl edCOn 51 FS_SMC_HW_X_BusyLedOn ssnaenneeneenneeenn 52 FS_SMC_HW_X_ChkBusy 0eeeeeeeees 59 FS SMC HW v ChkCGardln 60 FS OMC HW v Chkbower sssonsnsnnnensnnnnens1ne 61 FS OMC HW X Chk tatus eee 62 FS SMC HW vX Chkiimer 68 FS SMC HW X ChkWb 0 ceceec cece scenes 63 User s amp reference manual for uC FS FS SMC_HW_X_DetectStatus ee 64 FS SMC HW XS Infata ees 66 FS SMC HW v OutfData eee 67 FS SMC HW XS Get ddr cena es 53 FS OMC HW SX GeiCmd 54 FS OMC HW X Geiata ce eee scenes 55 FS SMC HW XV GetGtandiny 56 FS SMC HW X Getflmer 69 FS SMC HW v Gioptimer 70 FS SMC HW X VeeOnt es 57 FS SMC HW N Vee mn eee eeee es 58 FS SMC HW NV WaitTimer aeee 71 FS USE EAR tte ENEE EN FS USE RAMDIGk DRIVER eeen EN FS USE GMC DRIVER EN FS USE WINDRIVE DRIVER EN FS X OS NIE tee EENEG 111 FS X OS Geiiaie ccc ceccecceeeeeceeeeeees 121 FS2X LOS Getlime oria eege 122 BS Elle TEE 112 FS X_OS_LockDeviceOp ceeeeeeeee ee 119 FS XS OG LockFileHandle ccceceeeees 113 FS_X_OS_LockFileOp sssssesssesssenesenrenrennene 117 FS X OG LockMem a a iu 114 EG X OS Unlockevicep 120 FS SX OG Unlocktietande aaanonnnnnnnnannnnn 115 FS X OS UnlocktieCp eee 118 FS SX OS UnlockMem ccccceceeeceee scene 116 Fun
31. ake sure that only one thread allocates a memory block at any given time Example sample for pC OS II void FS SX OS LockMem void INT8U err OSSemPend FS_SemMemManager 0 amp err 2002 Micrium Technologies Corporation 114 123 User s amp reference manual for uC FS 11 2 3 FS XS OS UnlockFileHandle Description Unlock file handle table Prototype void FS_X_OS_UnlockFileHandle void Return value void Additional information LUC FS has a table for all open files The OS integration has to make sure that only one task can access this table at any given time This function releases the binary semaphore used for that purpose Example sample for pC OS II void PS SX _OS_UnlockFileHandle void OSSemPost FS_SemFileHandle 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 115 123 11 2 4 FS X OS UnlockMem Description Unlock FAT memory block table Prototype void FS_X_OS_UnlockMem void Return value void Additional information The FAT file system layer of uC FS has a memory manager This function releases access to the memory manager Example sample for pC OS II void FS_X_OS_UnlockMem void OSSemPost FS_SemMemManager 2002 Micrium Technologies Corporation 116 123 User s amp reference manual for uC FS 11 3 File access protection 11 3 1 FS_X_OS_LockFileOp Description Lock file
32. arks of their respective companies Brand and product names are trademarks or registered trademarks of their respective holders Contact Micrium Technologies Corporation 949 Crestview Circle Weston FL 33327 1848 U S A Phone 1 954 217 2036 FAX 1 954 217 2037 Email support micrium com Web http www micrium com 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 3 123 Software and manual versions This manual describes the software version 1 10 If any error occurs please inform us and we will try to assist you as soon as possible For further information on topics or routines not yet specified please contact us Print date 1 13 2003 Software Manual Date By Explanation 2 1 030113 TB Support for trial version added FS __fat_malloc returns cleared buffer E MMC driver deactivates CS whenever allowed by specification 021205 FAT32 amp POSIX like directory functions added 021010 IDE amp CompactFlash driver added 020927 MultiMedia amp SD card driver added 020830 KG Revised for language grammar Version control table added Typographic conventions section 1 3 changed into table Index added 2002 Micrium Technologies Corporation 4 123 User s amp reference manual for uC FS Contents Bisclaime Roe eee Ne eebe A a eT ne Oe ROR er 2 EE TONIC enee Reegele ee eelere eng 2 REES het EEEE eee ee ahead eater wna E A E EE E E EEST 2 87 0 9 le EE
33. as been reached Finally default txt is closed by calling FS_FClose Continue stepping over F10 until you get back toMainTask See Figure 4 2 The second call to _dump_file inMainTask does the same thing as the previous call except that it displays the contents of ram txt the second file we wrote Continue stepping over F10 until you get back to the function main in Figure 4 1 If your application terminates and thus you don t need to use the file system you can close the whole file system by calling FS_Exit This function call stops UC FS and you MUST NOT call any uC FS functions except FS_Init which is used to re initialize the file system Congratulations you have successfully built and debugged your first application using LC FS 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 15 123 4 3 Integrating uC FS into your system In this chapter you will learn how to add uC FS to your system We assume that you are familiar with the tools you have selected for your project compiler project manager linker etc You must thus be able to add files directories to the include search path etc It is also assumed that you are familiar with the OS you will be using in your target system if you are using one 4 3 1 Create a simple project without uC FS We recommend that you create a small hello world program for your system That project should already use you
34. ation wii 111 22 sample projet 10 14 using with SMC device driver 00010014 50 71 A ANS reaa a a adedetny eaten 6 7 All Rue e EE 24 36 direct input OUtput eee eeeeeeeeee eaters 30 31 CrrOr Nandling senera E AE 34 35 WUERT 27 29 file POSITIONING eee E ees 32 33 file system Control 25 26 Operations on files a e 36 API layer Of UC FS AA 8 B Building your applcation ee 15 CG C programming language eeeeeeeeee eneee 6 Configuration of UCIEB eee 17 23 D Device driver functions FS Devon 44 E ebe agesin 45 WPS DeVStatus 1 ien idinaan ni deaan edita 46 FS Dev Witas an EE 47 Device drivers oiie eiennenn 9 21 43 49 d faults TOF iriserai anaa a ee EE 48 function table Tor 48 integrating vour OWN ss ssssssssssresserrreserrreesrreee 48 E End Of File EOF 14 F FAT file evetenmt ENEE eed 7 File system layer Of HC FS e 20 File system layer of CIE 8 FS Kleber fedex cieesecsndatian sesteacanntens 34 Eleng et ageseent end 37 fs_conf h fie 15 17 21 17 21 17 21 IG EE 14 25 le 12 14 27 2002 Micrium Technologies Corporation User s amp reference manual for uC FS STEE 12 14 35 Keren ue 12 13 28 FS EReagd enden 14 30 EE 32 E belge ge 33 FS EWYiitey ang ENEE 4 12 31 FG IDE HW X BusvledCn 88 FG IDE HW X Busvtedcm 89 FS IDE _HW_X_DetectStatus 0 109 FS IDE HW X GeiAltGtaius eee 91 FS_IDE_HW_X_GetCylHigh eee 92 FS_IDE_HW_X_GetCylLow
35. busy Any other value does mean that an operation is pending Additional information If your hardware allows you to monitor the RY BY line you can use the status of that line In case your hardware needs to make a device operation to detect if the card reader is busy you must make sure that the macro FS_SMC_HW_SUPPORT_BSYLINE_CHECK is set to zero in your fs_conf h This allows you to tell the generic driver not to use FS_SMC_HW_X_ChkBusy when a device operation is pending Instead it will wait for the maximum allowed time for that operation Example sample taken from device smc Hardware EP7312 char FS_SMC_HW_X_ChkBusy FS_u32 id char x hardware cannot check RY BY therefore we use read status FS_SMC_HW_X_SetCmd id nCE low CLE high ALE low ___SMCPORT 0x70 cmd read status A ff FS_SMC_HW_X_SetData id nCE low CLE low ALE low x __SMCPORT FS_SMC_HW_X_SetStandby id nCE high CLE low ALE low if x amp 0x40 return 0 return 1 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 59 123 8 3 2 FS_SMC_HW_X_ChkCardIn Description The generic SMC driver uses this function to detect if there is a card in the reader Prototype char FS_SMC_HW_X_ChkCardiIn FS_u32 id id of card reader 0 N Return value Return 0 if there is no card in the reader Any othe
36. ck your include path and your 2002 Micrium Technologies Corporation 16 123 User s amp reference manual for uC FS configuration Usually puC FS s source code builds without any compiler warning Once you can build the application you should be able to use it with your target s debugger environment just like we did with the Visual C sample project Congratulations you have successfully integrated uC FS into your system 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 17 123 5 Configuration of uC FS In your configuration directory for UC FS you will find two files which allow you to configure the file system according to your requirements In this chapter you will find a description of each of these files 5 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 Example ifndef _FS_CONF_H_ define _FS_CONF_H_ ZS KKKKKKK kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk Micrium Inc 949 Crestview Circle Weston FL 33327 1848 uC FS c Copyright 2002 Micrium Inc All rights reserved KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KKK KKK KKK KKK KKK KKK KKK KK fs_conf h File system configuration Usually all configuration of the file system for your system can be done by changing this file
37. ction table for device divers 48 H Hardware access functions an0r0000000a 50 71 eet gel Ile 51 56 data transt t ne a a o EUR 66 67 Power Control 57 58 status deteclon 59 64 TIMER uniana E weave aed 68 71 Hardware access aver 50 l Inelude fles nrn ege Ee 15 2002 Micrium Technologies Corporation 123 123 L Logical block layer Of UC FS seeeeeeeee eters 9 M Microsoft Compiler ceeeeeeeeeeeeeeeeeeeeeanee ees 10 MMC device driver nne 72 110 MultiMedia amp SD card device driver See MMC device driver O OS integration functions cee 111 22 device access protection ceeeee 119 20 file access protection s 117 18 internal data structure protection 113 16 Wl 121 22 Ee 20 R RAM disk driver cccccecceeeeeceeeeeceeeeeeeees 10 21 S Sample code generic eceeeeeeeeeeeeneeeeeenneeees 15 Sample Project AAA 10 14 DUIIGING E 10 CEDUGGING AA 10 14 Search path configuration of 15 SmartMedia card device driver See SMC device driver SMC device driver 21 50 71 Source Code generic ssssssrsrnrssrrerrrrerrrerreen 15 T Testing UC FS integration n 15 Time date support rasi aseena aas Eara 20 W Windows driver rrene 21
38. d FS_MMC_HW_X_WriteSingleBlock FS_u32 id unsigned char buf int len Parameter Po Meaning OE ID of card reader 0 N Pointer to data to send Number of bytes to send Return value Void Additional information This function is used to send a complete data block to the card A data block starts with a data token and ends with a CRC By default the CAC is ignored in SPI mode and any value can be sent instead Example sample taken from device smc Hardware M16C_137x_IP void FS_MMC_HW_X_WriteSingleBlock FS_u32 id unsigned char buf int len int i if id 0 return SPI_SET_DATAOUT _FS_MMC_HW_Send1 Oxfe Start Block Single Block Write for i O0 i lt len i t _FS_MMC_HW_Sendl1 buf i Send dummy CRC by default not checked in SPI mode _FS_MMC_HW_Send1 Oxff _FS_MMC_HW_Send1 Oxff SPI_SET_DATAOUT 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 87 123 10 CompactFlash card amp IDE device driver LUC FS s generic CompactFlash amp IDE device driver can be used to access usual ATA HD drives or CompactFlash storage cards also known as CF using true IDE mode For details on CompactFlash please check the specification which is available at http www compactflash org Information about the AT Attachment interface can be found at the Technical Committee T13 who is responsible for the ATA
39. de basic hardware access functions Please check device smc hardware XXX smc_hw c and device smc hardware XXX smc_hw h for samples e if FS_USE_SMC_DRIVER Number of card readers in your system Please note that even if your system does have more than one SMC slot it might be unable to access them both at the same time because they share resources e g same data port If that is true for your system you must ensure that your implementation of FS_OS_Lock_deviceop amp _FS_smcdevice_driver id blocks the device driver for all values of id the default implementation of the file system s OS Layer does so define FS_SMC_MAXUNIT 2 EP7312 SMC on board NAND ST The following define does tell the generic driver if your system can directly check the SMC RY BY line Wi define FS_SMC_HW_SUPPORT_BSYLINE_CHECK D EP7312 does not support FS_SMC_HW_NEEDS_POLL has to be set if your SMC hardware driver needs to be called periodically for status check e g diskchange In such a case the generic driver does provide a function void FS_smc_check_card FS_u32 id which has to be called periodically by your system for each card reader Wi define FS_SMC_HW_NEEDS_POLL 1 EP7312 needs poll for diskchange endif FS_USE_SMC_DRIVER RK HK KK KK RR A A A A A A A A A A A A kkk kk A k k k k k kk k k k k k k kk k k k k si WIN
40. e timer is sufficient because you will have to avoid simultaneous card reader operations Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_WaitTimer FS_u32 id unsigned short time short x __INTMR1 amp 0x200ul disable TC2 underflow interrupt __SYSCON1 0x80ul Set clock in 512kHz mode __SYSCON1 amp 0x40ul free running TC2D time 50 Load counter do x __ TC2D while x gt 0 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 71 123 9 MultiMedia amp SD card device driver LUC FS includes a generic driver for MultiMedia amp SD cards The driver accesses cards using SPI mode For details on MultiMedia amp SD cards please check their specifications which are available at the following websites http Awww mmca org http www sdcard org To use the driver in your system you will have to provide basic I O functions for accessing your card reader hardware You can find samples of these routines in the directory device mmc_sd hardware This chapter describes all hardware access functions required by pC FS s generic MultitMedia amp SD card driver The sample code which can be found in the description uses normal port pins instead of a real SPI Therefore data transfer functions look a bit complex 9 1 Control line functions 9 1 1 FS_MMC_HW_X_BusyLedOff Description Turns off busy LED of
41. echnologies Corporation User s amp reference manual for uC FS 99 123 10 2 10 FS_IDE HW_X_SetCommand Description Set the Command register Prototype void FS_IDE_HW_X_SetCommand FS_u32 id unsigned char data Parameter ID of card reader 0 N Value to write to the Command register Return value Void Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_SetCommand FS_u32 id unsigned char data EMCFG2 0x1f13 Jr CS5 8 bit DE_CMD data 2002 Micrium Technologies Corporation 100 123 User s amp reference manual for uC FS 10 2 11 FS_IDE_HW_X_SetCylHigh Description Set the Cylinder High register Prototype void FS_IDE_HW_X_SetCylHigh FS_u32 id unsigned char data Parameter ID of card reader 0 N Value to write to the Cylinder High register Return value Void Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_SetCylHigh FS_u32 id unsigned char data MEMCFG2 x1f13 CS5 8 bit 0 __IDE_CH data 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 101 123 10 2 12 FS_IDE_HW_X SetCylL
42. eter Meaning oo O ID of card reader 0 N Value to write to the Device Control register Return value Void Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_SetDevControl FS_u32 id unsigned char data MEMCFG2 Ox1f13 CS5 8 bit ___IDE_DC data 2002 Micrium Technologies Corporation 104 123 User s amp reference manual for uC FS 10 2 15 FS_ IDE HW_X_SetDevice Description Set the Device Head register Prototype void FS_IDE_HW_X_SetDevice FS_u32 id unsigned char data Parameter ID of card reader 0 N Value to write to the Device Head register Return value Void Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 void E ID MEMCFG2 __IDE_DH 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 105 123 10 2 16 FS_ IDE _HW_X_SetFeatures Description Set the Features register Prototype void FS_IDE_HW_X_SetFeatures FS_u32 id unsigned char data Parameter Meaning oo O ID of card reader 0 N Value to write to the Features register Return value Void Additional informati
43. evice_driver 0 FO_DEVSMC define EG Di endif if FS_USE_WINDRIVE_ EVINFO_DEVSMC DRIVER define FS_D windrive_driver 0 else define FS_D endif if FS_USE_RAMDISK_ DRIVER EVINFO_DEVWI else define FS_DEVI ramdevice_driver 0 FO_DEVRA define EG Di endif EVINFO_DEVRA EVINFO_DEVWINDRV sme windrv ram User s amp reference manual for uC FS kb fat_functable k fat_functable kb fat_functable define FS_DEVINFO FS_DEVI FS_DEVINFO dif DEVSMC ES Di EVINFO_DEVWINDRV FS_DEVINFO_DEVRAM The SMC driver will be used as default if it is enabled since it is first in the table The last device in the table is the RAM disk driver which will be the only default device if the SMC and Windows drivers are both disabled 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 49 123 8 SmartMedia Card Device Driver LC FS includes a generic driver for SmartMedia cards To use it in your system you will have to provide basic I O functions for accessing your card reader hardware You can find samples for such routines in the directory device smc hardware The SMC driver is split up into different layers In the diagram below there is an overview of these layers To use the SMC driver with a custom hardware only a suitable hardware access layer i
44. fer to the ANSI C documentation regarding the fopen function Note that uC FS does not distinguish between binary and text mode files are always accessed in binary mode Example FS_FILE myfile void fool void open file for reading default driver on default device myfile FS_FOpen test txt r void foo2 void create new file for writing default driver on default device myfile FS_FOpen test txt w void foo3 void open file for reading in folder mysub default driver on default device myfile FS_FOpen mysub test txt r void foo4 void open file for reading RAM device driver on default device myfile FS_FOpen ram test txt r void foo5 void open file for reading RAM device driver on device number 2 myfile FS_FOpen ram 1l test txt r 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 29 123 6 3 Direct input output functions 6 3 1 FS_FRead Read data from file Description Reads data from an open file Prototype FS_size_t FS_FRead void ptr FS_size_t size k size_t pn FS_FILE fp Parameter Meaning Pointer to a data buffer for storing data transferred from file Size of an element to be transferred from file to the data buffer Number of elements to be transferred Pointer to a data
45. har 00000000 7 2 2 22 2 227222 a 00000006 7 7 2 22 2 22222 nane 0x0042b3be QOODOO0C 7 7 2 22 22 22 27722 default Let 00000012 7 2 2 22 22 22722 00000018 72 27 72 22 22 22 222272 OCOOOOLE 7 22 22 2 222777 m f Auto Locals this 7 H Watent_ Watch 3 Watch3 A Watcha 7 Ready Ln 118 Col 1 Figure 4 4 F4 4 1 The sample application opens the previously created file default txt for read operation by using the puC FS function FS_FOpen If the file does not exist or cannot be opened for any reason FS_FOpen will return O instead of a valid pointer to an FS_FILE structure 2002 Micrium Technologies Corporation 14 123 F4 4 2 F4 4 3 F4 4 4 F4 2 5 F4 1 3 User s amp reference manual for uC FS Continue stepping over F10 until you get to the pC FS function call FS_FRead Watch the contents of mybuffer and the return value when stepping over F10 the function You should see that FS_FRead loads the contents of the file default txt into mybuffer and returns the length of the string If FS_FRead returned data it would be displayed on the console window with help of the sample application function _log Continue stepping over F10 until you get to the second call to FS_FRead This time FS_FRead returns 0 because the file pointer has reached the end of file default txt The sample application calls FS_FError to see if EOF i e the End Of File h
46. he RAM device driver const FS__device_type FS__ramdevice_driver RAMDISK device _FS_DevStatus _FS_DevRead _FS_DevWrite _FS_DevIocCtl 1 7 3 Integrate a new device driver If you want to use your own device driver you have to tell uC FS which device name you woud 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 uwC FS s global device information table The first parameter is a device name which you want to use for C FS s API calls 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 Example Default device is smc because it is first in the list mydev uses FAT and device driver function table FS__mydevice_driver define FS_DEVINFO Deech amp FS__fat_functable amp FS_smcdevice_driver mydev amp FS__fat_functable amp FS__omydevice_driver If you do not specify a value for FS_DEVINFO UC FS will use the following values as default ifndef FS_DEVINFO if FS_USE_SMC_DRIVE 2002 Micrium Technologies Corporation 48 123 amp FS SES en else define FS_DEVI _ smcd
47. he return value is 0 Upon failure the return value is 1 Additional information The function should transfer 0x0200 i e 512 bytes which is the default value for an MS DOS MS Windows compatible FAT file systems uC FS can support any block size but if you use the FAT file system layer you have to use this default block size Example sample taken from the RAM device driver static int _FS_DevRead FS_u32 id FS_u32 block void buffer memcpy buffer char _FS_rr_devdata id data block _FS_rr_devdata id bpu _FS_rr_devdata id bpu return 0 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 45 123 7 1 3 FS DevStatus Description Return current status of your device Prototype static int _FS DevStatus FS_u32 id Parameter Meaning Number of media 0 N Return value 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 lt 0 is interpreted as an error Additional information The main purpose of this function is to detect a media change All uC FS file operation calls this function to check if the device can be accessed Example sample taken from the RAM device driver static int _FS DevStatus FS_u32 id static int online RR_DEVNUM if online id online
48. heck AT Attachment interface specification or CompactFlash specification Example sample taken from device ide Hardware ep7312 char FS_IDE_HW_X_DetectStatus FS_u32 id static char init unsigned char a b af Chante 4 init 1 MEMCEGZ Ox1f13 CS5 8 bit __SYSCON1 0x40000ul1 enable expansion clock if id 0 FS_IDE_HW_X_SetDevice id 0xa0 else FS_IDE_HW_X_SetDevice id 0xe0 HW__DELAY400NS FS_IDE_HW_X_SetSectorCount id 0x55 FS_IDE_HW_X_SetSectorNo id 0xaa 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 109 123 FS_ID FS_ID _HW_X_SetSectorCount id 0xaa _HW_X_SetSectorNo id 0x55 FS_IDE_HW_X_SetSectorCount id 0x55 FS_IDE_HW_X_SetSectorNo id 0xaa HW_X_GetSectorCount id a FS_IDI b FS_IDE_HW_X_GetSectorNo id 1 Di Di Fl L P P if a 0x55 amp amp b 0Oxaa _HW_DevicePresent id 1 else _HW_DevicePresent id 0 return _HW_DevicePresent id 2002 Micrium Technologies Corporation 110 123 User s amp reference manual for uC FS 11 OS integration UC FS is suitable for usage with just about any multithreaded environment To ensure that different tasks can access the file system concurrently you have to implement a few operating system dependent functions For embOS uC OS II and MS Windows you will find impleme
49. ice ide Hardware ep7312 unsigned char FS_IDE_HW_X_GetCylLow FS_u32 id unsigned char data __MEMCFG2 0x1f13 CS5 8 bit data __IDE_CL return data 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 93 123 10 2 4 FS_IDE HW_X_GetData Description Read the AD Data register Prototype FS_ul6 FS_IDE DW NM _GetData FS_u32 id Parameter Meanmg OO ID of card reader 0 N Return value Value of the RD Data register Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 FS_ul6 FS_IDE_HW_X_GetData FS_u32 id FS_ul6 data __MEMCFG2 0xlcl13 CS5 16 bit data DE DATA return data 2002 Micrium Technologies Corporation 94 123 User s amp reference manual for uC FS 10 2 5 FS_ IDE HW_X_GetDevice Description Read the Device Head register Prototype unsigned char FS_IDE_HW_X_GetDevice FS_u32 id Parameter Meaning o O ra IDofcard reader 0 N Return value Value of the Device Head register Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 unsigned char FS_IDE_HW_X_GetDevice FS_u32 id
50. id unsigned char a bpos if id 0 return Oxff _DATAOUT bits K DH _DATAIN lt lt bpos K ELAY while bpos return a 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 83 123 9 4 3 FS_MMC_HW_X_ReadSingleBlock Description Reads a data block from the SPI Prototype unsigned char FS_MMC_HW_X_ReadSingleBlock FS_u32 id unsigned char buf int len FS_u32 maxwait Parameter Menn ooo y y oO id ID of card reader 0 N Number of bytes to receive Maximum number of clocks 8 before timeout Return value Pointer to a buffer for data to receive 0 on success Oxff in case of a problem Additional information This function is used to read a complete data block starting with a data token and ending with a CRC Only the data in between is stored to the data buffer By default the CRC is not checked in SPI mode please also see the MultiMedia amp SD card specifications for details When using a real SPI you can simply read from it until you get a valid data token or timeout occurs Then read the real data and the CRC Make sure that you do not store the data token or the CRC to the buffer Example sample taken from device smc Hardware M16C_137x_IP unsigned char FS_MMC_HW_X_ReadSingleBlock FS_u32 id unsigned char buf int len FS_u32 maxwait unsigned char a bpos int i if id
51. id 1 init memory create BPB return FS_LBL MEDIACHANGED return 0 2002 Micrium Technologies Corporation 46 123 User s amp reference manual for uC FS 7 1 4 FS DevWrite Description Write block to media Prototype static int P DevWrite FS_u32 id FS_u32 block void buffer Parameter Meaning O S O Number of media 0 N Block number to be written on media Pointer to data for transfer to the media Return value In case of success the return value is 0 Upon failure the return value is 1 Additional information The function should transfer 0x0200 i e 512 bytes which is the default value for an MS DOS MS Windows compatible FAT file systems uC FS can support any block size but if you use the FAT file system layer you have to use this default block size Example sample taken from the RAM device driver static int _FS DevWrite FS_u32 id FS_u32 block void buffer memcpy char _FS_rr_devdata id data block _FS_rr_devdata id bpu buffer _FS_rr_devdata id bpu return 0 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 47 123 7 2 Device driver function table To use a device driver with uC 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 Example sample taken from t
52. id FS_SMC_HW_X_Set_Timer FS_u32 id unsigned short time __INTMR1 amp 0x200ul disable TC2 underflow interrupt __SYSCON1 0x80ul Set clock in 512kHz mode __SYSCON1 amp 0x40ul free running __TC2D time 50 Load counter 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 69 123 8 5 3 FS_SMC_HW_X_StopTimer Description Stop the countdown timer of the specified reader id Prototype void FS_SMC_HW_X_StopTimer FS_u32 id Parameter Meaning S O id of card reader 0 N Return value void Additional information See FS_SMC_HW_X _SetTimer Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_StopTimer FS_u32 id 2002 Micrium Technologies Corporation 70 123 User s amp reference manual for uC FS 8 5 4 FS_SMC_HW_X_WaitTimer Description Wait for a time of time 0 1 msec and return Prototype void FS_SMC_HW_X_WaitTimer FS_u32 id unsigned short time Parameter Meaning O S O id of card reader 0 N time in 0 1msec units Return value void Additional information The generic SmartMedia card driver uses this function to wait for a device operation to complete If you have more than one card reader in your system and you can access them simultaneously you will need a separate timer for each reader If your card readers share resources e g the same I O pins on
53. id FS_X_OS_UnlockFileOp FS_FILE d OSSemPost FS_SemFileOps 2002 Micrium Technologies Corporation 118 123 User s amp reference manual for uC FS 11 4 Device access protection 11 4 1 FS_X_OS_LockDeviceOp Description Lock device operation for a specific driver and media Prototype void FS_X_OS_LockDeviceOp const _FS_device_type driver FS_u32 id Parameter Meaning Pointer to device driver Number of media 0 N Return value void Additional information LUC FS allows you to make concurrent device operations To ensure that only one tasks makes an access to a specific media via a device driver at any given time this function has to lock an operation by looking to the driver and id This is done via another binary semaphore If your application never accesses multiple devices concurrently then you don t need this locking mechanism However we recommend that you implement this functionality Example sample for pC OS II void FS SX OS LockDeviceOp const FS__device_type driver FS_u32 id INT8U err OSSemPend FS_SemDeviceOps 0 amp err 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 119 123 11 4 2 FS_X OS UnlockDeviceOp Description Unlock device operation for a specific driver and media Prototype void FS_X_OS_UnlockDeviceOp const _FS_device_type driver FS_u32 id Parameter Pointe
54. ify UnitNum if DevName has not been specified DirPathList means a complete path to an already existing subdirectory FS_Fopen does not create directories The path must start and end with a V character Directory names in the path are separated by NV If DirPathList is not specified the root directory on the device will be used FileName and all directory names have to follow the standard FAT naming conventions i e 8 3 notation long file names are not supported The parameter mode points to a string If the string is one of the following LUC FS will open the file in the indicated mode 2002 Micrium Technologies Corporation 28 123 User s amp reference manual for uC FS z Opentextfile forreading w Truncate to zero length or create text file for wring a Append open or create text file for writing at end of le _ b Open binary file for reading wb Truncate to zero length or create binary fle for writing Append open or create binary file for writing at end of file Open text file for update reading and writing Truncate to zero length or create text file for update a Append open or create text file for update writing at end of file Open binary file for update reading and writing Truncate to zero length or create binary file for update a b orab Append open or create bin file for update writing at end of file For more details on the FS_FOpen function please also re
55. ion for details Example sample taken from device ide Hardware ep7312 unsigned char FS_IDE_HW_X_GetAltStatus FS_u32 id unsigned char data ___MEMCFG2 0x1f13 CS5 8 bit data __IDE_DC return data 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 91 123 10 2 2 FS_IDE_HW_X_GetCylHigh Description Read the Cylinder High register Prototype unsigned char FS_IDE_HW_X_GetCylHigh FS_u32 id Parameter Meaning U U O ID of card reader 0 N Return value Value of the Cylinder High register Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 unsigned char FS_IDE_HW_X_GetCylHigh FS_u32 id unsigned char data __MEMCFG2 0x1f13 CS5 8 bit data __IDE_CH return data 2002 Micrium Technologies Corporation 92 123 User s amp reference manual for uC FS 10 2 3 FS_IDE_HW_X_GetCylLow Description Read the Cylinder Lowregister Prototype unsigned char FS_IDE_HW_X_GetCylLow FS_u32 id Parameter Meaning U U O ID of card reader 0 N Return value Value of the Cylinder Lowregister Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from dev
56. irectory which is not empty Example void fool void remove mydir in directory test default driver on default device err FS_RmDir test mydir void foo2 void remove directory mydir RAM device driver on default device err FS_RmDir ram mydir 2002 Micrium Technologies Corporation 42 123 User s amp reference manual for uC FS 7 Device drivers LUC FS has been designed to cooperate with any kind of hardware To use a specific hardware with uC FS a so called device driver for that hardware is required The device driver consists of basic I O functions for accessing the hardware and a global table which holds pointers to these functions If you are going to use uC FS with you own hardware you may have to write your own device driver This chapter describes which functions are required and how to integrate your own device driver into uC FS Called with pointer to a device driver function table as parameter Call function in table Device Driver Function Table FS_DevStatus FS_DevRead _FS_DevWrite mg Geet 7 1 Device driver functions In this chapter you will find a detailed description of the device driver functions required by uC FS Please note that the names used for these functions are not really relevant for uC FS because the file system accesses those functions through a function table 2002 Micrium Technologies Corporation Use
57. l for uC FS 8 2 Power control functions 8 2 1 FS_SMC_HW_X_VccOff Description Turn off VCC for the specified card reader Prototype void FS_SMC_HW_X_VccOff FS_u32 id Parameter Meaning id of card reader 0 N Return value void Additional information If your hardware cannot control VCC for the card reader you can simply leave that function empty In such case VCC should always be on Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_VccOff FS_u32 id 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 57 123 8 2 2 FS_SMC_HW_X VccOn Description Turn on VCC for the specified card reader Prototype void FS_SMC_HW_X VccOn FS_u32 id Parameter Meaning O S O id of card reader 0 N Return value void Additional information If your hardware cannot control VCC for the card reader you can simply leave that function empty In such case VCC should always be on Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_VccOn FS_u32 id 2002 Micrium Technologies Corporation 58 123 User s amp reference manual for uC FS 8 3 Status detection functions 8 3 1 FS_SMC_HW_X_ChkBusy Description Check if card reader is busy Prototype char FS_SMC_HW_X_ChkBusy FS_u32 id id of card reader 0 N Return value Return 0 if the card reader is not
58. mber of device drivers in your system used with FAT FS_FAT_MAXUNIT is the maximum number of logical units supported by one of the activated drivers define FS_MAXDEV FS_USE_SMC_DRIVER FS_USE_WINDRIVE_DRIV FS_USE_RAMDISK_DRIVER 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 19 123 define FS_FAT_MAXUNIT max number of medias per devic Si Do not change following defines They may become configurable in future versions of the file system Wi define FS_FAT_SEC_SIZ 0x200 do not change for FAT define FS_FAT_MAXCLST 100000 max cluster number do not change endif FS_USE_FAT_FSL S EEKE KK k k K k k k K K k K K K k k II k K k k k K k k I K k k K K k k kK K k IO I k k k kk k kkk I AO kk KK kk k k E RAMDISK_DRIVER defines Si if FS_USE_RAMDISK_DRIVER Define size of your RAM disk here You specify the number of sectors 512 bytes here me define FS_RR_BLOCKNU 32 16KB RAM Do not change following define It may become configurable in future versions of the file system KE define FS_RR_BLOCKSIZI 0x200 do not change for FAT endif FS_USE_RAMDISK_DRIVER KK IK IK IK I I RRR A A A A A A I I I I AAA AA A A kk kkk kkk SMC_DRIVER defines Settings of the generic Smartmedia Card driver For using SMC in your system you will have to provi
59. mp reference manual for uC FS 67 123 8 5 Timer functions 8 5 1 FS_SMC_HW_X_ChkTimer Description Check the current status of the countdown timer for the specified reader id Prototype int FS_SMC_HW_X_ChkTimer FS_u32 id Parameter Meaning id of card reader 0 N Return value Return 0 if the time set with FS_SMC_HW_X_SetTimer for the specified reader id has expired and any non zero value if it has not expired Additional information See FS_SMC_HW_X _SetTimer Example sample taken from device smc Hardware EP7312 int FS_SMC_HW_X_ChkTimer FS_u32 id short int x x __TC2D if x lt 0 x x 0 return xX 2002 Micrium Technologies Corporation 68 123 User s amp reference manual for uC FS 8 5 2 FS SMC _HW_X_SetTimer Description Set the countdown timer of reader id to a time of time 0 1 msec and return Prototype void FS_SMC_HW_X_SetTimer FS_u32 id unsigned short time Parameter id of card reader 0 N time in 0 1msec units Return value void Additional information Unlike FS_SMC_HW_X_WaitTimer this function does not wait until the time has elapsed before returning Instead it returns immediately and the driver can check with FS_SMC_HW_X_ChkTimer to see if the time has elapsed See also FS_SMC_HW_X_WaitTimer for additional information Example sample taken from device smc Hardware EP7312 vo
60. n FS_FILE structure In case of any error it would return 0 indicating that the file could not be created f FS_FOpen returns a valid pointer to an FS_FILE structure the sample application will write a small ASCII string to this file by calling the uC FS function FS_FWrite Step over F10 this function and watch the return value If no problem occurs it should match with the length of the text In case there have been less characters written the sample project checks for an error code by calling the uC FS function FS_FError Continue stepping over F10 until you reach the call to pC FS function FS_FClose This will close the file default txt Step over F10 this function and continue stepping over F10 until you are back to MainTask see Figure 4 2 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 13 123 F4 2 3 F4 2 4 You will get to the next call of _write_file which creates another file called Tram DU on your RAM disk The difference between this and the first call is that this time the RAM disk is specified explicitly So the file will be created on your RAM disk even if you use a different default device Continue stepping over F10 until you reach the call to _dump_file Note that this function is also part of the example and not uC FS After stepping into F11 the function your screen should look as shown in Figure 4 4 186_MS_start
61. ndDir Reset position in directory stream Description This function sets pointer for reading the next directory entry to the first entry in the directory Prototype void FS_RewindDir FS_DIR dirp Parameter Meaning Pointer to directory structure Return value Void Example void foo void FS_DIR dirp struct FS_DIRENT direntp Open root directory of the RAM device dirp FS_OpenDir ram if dirp display directory do direntp FS_ReadDir dirp if direntp sprintf mybuffer s n direntp gt d_name _log mybuffer while direntp rewind to 1st entry FS_RewindDir dirp display directory again do direntp FS_ReadDir dirp if direntp sprintf mybuffer s n direntp gt d_name _log mybuffer while direntp FS_CloseDir dirp else _error Unable to open directory n 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 41 123 6 7 6 FS_RmDir Remove a directory Description Deletes a directory Prototype int FS _RmDir const char dirname Parameter Meaning O Fully qualified directory name Return value Returns 0 if the directory has been successfully removed In case of any error the return value is 1 Additional information A fully qualified directory name has the same meaning as for function FS_OpenDir FS_RmDir will not delete a d
62. ntations of these functions in the file system s source code In this chapter you will find a description of all the functions that are required to fully support wC FS in multithreaded environments If you do not use an OS or if you do not make file access from different tasks you can implement these functions as empty routines You will also add date and time support functions for use by the FAT file system The example implementations provided with wC FS use ANSI C standard functions to get the correct date and time 11 1 OS layer control functions 11 1 1 FS_X_OS_Exit Description Delete OS resources Specifically you need to delete the binary semaphores used by the file system Prototype int FS_X_OS_Exit void Return value In case of success return value is 0 On failure return value is 1 Additional information This function is called by FS_Exit You should delete all resources required by the OS to support multithreading of the file system Example sample for pC OS II int FS_X OS Exit void INT8U err OSSemDel FS_SemFileHandle OSSemDel FS_SemFileOps OSSemDel FS_SemMemManager OSSemDel FS_SemDeviceOps return 0 FS FS 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 111 123 11 1 2 FS X OS Init Description Initializes the OS resources Specifically you will need to create four binary semaphores Prototy
63. ny other value means that the media is write protected Additional information If your hardware allows to monitor write protect status of a media directly you can use this status In case your hardware has to execute a status read command for checking write protect status of a card you must not do that operation inside this function because it is called during other device operations that would be interrupted Instead use a variable to keep track of the current status instead and return the value of that variable Example sample taken from device smc Hardware EP7312 char FS_SMC_HW_X_ChkWP FS_u32 id return _Hw_card_wprotect id 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 63 123 8 3 6 FS SMC _HW_X_DetectStatus Description Check if card is present Prototype char FS_SMC_HW_X DetectStatus FS_u32 id Parameter Meaning S O id of card reader 0 N Return value Return 0 if there is a card present and a non zero value if there is no card in reader or the card cannot be accessed Additional information In contrast to FS_SMC_HW_X_ChkCardIn this function is not called when a device operation is pending and therefore it is allowed to use a device command for status detection The generic SmartMedia driver calls this function in two cases 1 Before a uC FS operation takes place the file system asks the device driver for curren
64. ocr if id 0 return 1 if ocr amp 0x003c0000 we support 3 0 3 4 Volt return 0 return 1 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 77 123 9 2 3 FS_MMC_HW_X_GetFOP Description Returns current host to card clock frequency Prototype FS_u32 FS_MMC_HW_X_GetFOP FS_u32 id Parameter Meaning ID of card reader 0 N Return value Current host to card clock frequency Additional information This value is used to calculate the absolute time dependent part of card access timing Please also check the MultiMedia amp SD card specifications for details Example sample taken from device smc Hardware M16C_137x_IP FS_u32 FS_MMC_HW_X_GetFOP FS_u32 id return FS MMC _CLOCK_FREQ 2002 Micrium Technologies Corporation 78 123 User s amp reference manual for uC FS 9 3 Status detection functions 9 3 1 FS_MMC_HW_X_CheckWP Description Checks the status of the mechanical write protect switch of an SD card Prototype char FS_MMC_HW_X_CheckWP FS_u32 id Parameter Meann y ID of card reader 0 N Return value 0 if the card is not write protected Any other value means that the card is write protected Additional information MultiMedia cards do not have a mechanical write protect switch and should return 0 If you are using an SD card please be aware that the mechanical switch d
65. oes not really protect the card it is the responsibility of the host to respect the status of that switch Example sample taken from device smc Hardware M16C_137x_IP char FS_MMC_HW_X_CheckWP FS_u32 id return 0 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 79 123 9 3 2 FS MMC _HW_X_DetectStatus Description Checks whether a card is present Prototype char FS_MMC_HW_X DetectStatus FS_u32 id Parameter Meaning U U O ID of card reader 0 N Return value 0 if there is a card present Any other value means there is no card in the reader or the card cannot be accessed Additional information Usually a card reader provides a hardware signal which can be used The sample code below is for a specific hardware which does not have such a signal Therefore the presence of a card is checked by executing a card command Example sample taken from device smc Hardware M16C_137x_IP char FS_MMC_HW_X_DetectStatus FS_u32 id static int init if id 0 return 1 af Init 4 PD6 Oxb0 Direction register O IN 1 OUT P6 Oxb0 init 1 FS_MMC_HW_X_SetCS id 0 if FS__MMC_CheckCardCSD id 0 Reading card parameters failed try complete RESET sequence if FS__MMC_Init id 0 FS_MMC_HW_X_SetCS id 1 return 1 FS_MMC_HW_X_SetCS id 1 return 0 2002 Micrium Technologies Cor
66. on Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_SetFeatures FS_u32 id unsigned char data MEMCFG2 x1f13 CS5 8 bit 0 IDE F data 2002 Micrium Technologies Corporation 106 123 User s amp reference manual for uC FS 10 2 17 FS_IDE_HW_X_SetSectorCount Description Set the Sector Count register Prototype void FS_IDE_HW_X_SetSectorCount FS_u32 id unsigned char data Parameter Meaning o O ID of card reader 0 N Value to write to the Sector Count register Return value Void Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_SetSectorCount FS_u32 id unsigned char data MEMCFG2 x1f13 CS5 8 bit 0 __ IDE SC data 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 107 123 10 2 18 FS_IDE_ HW_X_SetSectorNo Description Set the Sector Number register Prototype void FS_IDE_HW_X_SetSectorNo FS_u32 id unsigned char data Parameter Po Meaning OE ID of card reader 0 N Value to write to the Sector Number register Return value Void Additional information Please check AT Attachment inte
67. operation on a specific file Prototype void FS_X_OS_LockFileOp FS_FILE fp Parameter Meanmg O Pointer to a data structure of type FS_F ILE Return value void Additional information Different tasks could access the same file Therefore an OS implementation which wants to support concurrent file operations has to lock a file operation However if you only allow one file operation at any given time in your application then you wouldn t need this semaphore In a multitasking environment it is however recommended to use the semaphore mechanism Example sample for pC OS II void FS_X_OS_LockFileOp FS_FILE INT8U err OSSemPend FS_SemFileOps 0 amp err 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 117 123 11 3 2 FS_X_OS_UnlockFileOp Description Unlock file operation on a specific file Prototype void FS_X_OS_UnlockFileOp FS_FILE fp Pointer to a data structure of type FS_F ILE Return value void Additional information Different tasks could access the same file Therefore an OS implementation which wants to support concurrent file operations has to lock a file operation However if you only allow one file operation at any given time in your application then you wouldn t need this semaphore In a multitasking environment it is however recommended to use the semaphore mechanism Example sample for pC OS II vo
68. or uC FS 61 123 8 3 4 FS_SMC_HW_X_ChkStatus Description This function detects if the status of the card reader has changed since its last call It is used by the generic driver to detect a disk change Prototype char FS_SMC_HW_X_ChkStatus FS_u32 id 0 id of card reader 0 N Return value Return 0 if there is no status change since last call Any other value does means that status has changed since the last call Additional information For hardware that remembers a disk change you can simply return that status If your hardware does not remember a disk change you will have to check periodically if a card is present in your reader Whenever you detect a change during that periodic check you have to make sure that next call of FS_SMC_HW_X_ChkStatus returns a non zero value See also FS_SMC_HW_X_DetectStatus for more information about disk change detection Example sample taken from device smc Hardware EP7312 char FS_SMC_HW_X_ChkStatus FS_u32 id if _Hw_card_changed id _Hw_card_changed id 0 return 1 return 0 2002 Micrium Technologies Corporation 62 123 User s amp reference manual for uC FS 8 3 5 FS_SMC_HW_X_ChkWP Description Check if the current media is write protected Prototype char FS _SMC_HW_X_ChkWP FS_u32 id Boss Ct Ita sf id of card reader 0 N Return value Returns 0 if the media is not write protected A
69. oration User s amp reference manual for uC FS 31 123 6 4 File positioning functions 6 4 1 FS_FSeek Set position of file pointer Description Sets current position of the file pointer Prototype Int FS_FSeek FS_FILE fp FS_i32 offset int whence Pointer to a data structure of type FS_F ILE Offset for setting the file pointer position Mode for positioning file pointer Return value If file pointer has been positioned according to the parameters the return value is 0 In case of an error the return value is 1 Additional information Valid values for parameter whence are FS_SEEK_SET FS_SEEK_CUR and FS_SEEK_END For details on these parameters please check ANSI C documentation about the fseek function Note that wC FS does not currently support positioning the file pointer after end of a file Example const char welcome some text will be overwritten n void foo void FS_FILE myfile myfile FS_FOpen test txt w if myfile 0 FS_FWrite welcome 1 strlen welcome myfile FS_FSeek myfile 4 FS_SEEK_CUR FS_FWrite welcome 1 strlen welcome myfile FS_FClose myfile 2002 Micrium Technologies Corporation 32 123 User s amp reference manual for uC FS 6 4 2 FS_FTell Return position of file pointer Description Returns current position of the file pointer Prototype FS_i32 FS_FTell FS_FILE fp Pointer to a
70. ow Description Set the Cylinder Low register Prototype void FS_IDE_HW_X_SetCylLow FS_u32 id unsigned char data Parameter ID of card reader 0 N Value to write to the Cylinder Lowregister Return value Void Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_SetCylLow FS_u32 id unsigned char data MEMCFG2 CS5 8 bit 0 IDE CE d 2002 Micrium Technologies Corporation 102 123 User s amp reference manual for uC FS 10 2 13 FS_IDE HW_X_SetData Description Set the WR Data register Prototype void FS_IDE HW_X _SetData FS_u32 id FS_ul6 data Parameter ID of card reader 0 N Value to write to the WR Data register Return value Void Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_SetData FS_u32 id FS_ul6 data EMCFG2 x1c13 CSS 16 pit 0 FE DATA data 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 103 123 10 2 14 FS IDE HW_X_SetDevControl Description Set the Device Control register Prototype void FS_IDE_HW_X_SetDevControl FS_u32 id unsigned char data Param
71. pe int FS_X_OS_Init void Return value In case of success return value is 0 On failure return value is 1 Additional information This function is called by FS_Init You should create all resources required by the OS to support multithreading of the file system Example sample for pC OS II int FS XZ OS Init void FS_SemFileHandle FS_SemFileOps FS_SemMemManager FS_SemDeviceOps return 0 OSSemCreate OSSemCreate OSSemCreate OSSemCreate 2002 Micrium Technologies Corporation 112 123 User s amp reference manual for uC FS 11 2 Internal data structure protection 11 2 1 FS_X_OS_LockFileHandle Description Lock file handle table Prototype void FS_X_OS_LockFileHandle void Return value void Additional information UC FS has a table for all open files The OS integration has to make sure that only one task can access this table at the same time This is done by waiting on a binary semaphore Example sample for pC OS II void FS SX OS _LockFileHandle void INT8U err OSSemPend FS_SemFileHandle 0 amp err 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 113 123 11 2 2 FS_X_OS LockMem Description Lock FAT memory block table Prototype void FS_X_OS_LockMem void Return value void Additional information The FAT file system layer of uC FS has an internal memory manager This function is to m
72. pending and the card should not be removed until FS_SMC_HW_X_BusyLedOff is called Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_BusyLedOn FS_u32 id if id 0 __PDDR 0x01 DIAG LED on 2002 Micrium Technologies Corporation 52 123 User s amp reference manual for uC FS 8 1 3 FS_SMC_HW_X_SetAddr Description Set CE low CLE low and ALE high for the specified card reader Prototype void FS_SMC_HW_X_SetAddr FS_u32 id Parameter Meaning S O id of card reader 0 N Return value void Additional information The generic SMC driver calls this function to start address data transfer Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_SetAddr FS_u32 id if id 0 O0x6f nCE low CLE nCE low CLE 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 53 123 8 1 4 ES SMC _HW_X SetCmd Description Set CE low CLE high and ALE low for the specified card reader Prototype void FS_SMC_HW_X_SetCmd FS_u32 id Parameter Meaning O S O id of card reader 0 N Return value void Additional information The generic SMC driver calls this function to start command transfer Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_SetCmd FS_u32 id if id 0 __PBDR Ox5f nCE low
73. poration 80 123 User s amp reference manual for uC FS 9 3 3 FS_MMC_HW_X_WaitBusy Description Waits for a maximum of 8 maxwait clocks for a card to become ready Prototype unsigned char FS_MMC_HW_X_WaitBusy FS_u32 id FS_u32 maxwait Parameter Meaning o o O ID of card reader 0 N Maximum number of clocks 8 before timeout Return value 0 if the card is no longer busy A non zero value means the card is still busy Additional information When using a real SPI you can simply read from it until you receive a non zero value or a timeout occurred Example sample taken from device smc Hardware M16C_137x_IP unsigned char FS_MMC_HW_X_WaitBusy FS_u32 id FS_u32 maxwait unsigned char a if id 0 return Oxff SPI_SET_DATAOUT maxwait 8 Wait until timeout or data line is high do SPI_CLR_CLK SPI_DELAY a SPI_DATAIN SPI_SET_CLK SPI_DELAY if a break if maxwait maxwait while maxwait if ta still busy return Oxff return 0 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 81 123 9 4 Data transfer functions 9 4 1 FS MMC_HW_X_ReadByte Description Reads the next byte starting with a 0 bit from the SPI Prototype unsigned char FS_MMC_HW_X_ReadByte FS_u32 id FS_u32 maxwait 1D ofcard reader 0 S card reader 0 N Maximum SC of
74. r OS and there should be a way to display text on a screen or serial port 4 3 2 Add your uC FS configuration In order to configure pC FS for your system you should create a new sub directory in wC 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 LUC FS for detailed information about the configuration 4 3 3 Add uC FS generic source code Add all source files in the following directories FS API FS FSL FS LBL FS OS FS DEVICE RAM and their sub directories to your project 4 3 4 Configure the search path In order to build all the files that you added you will have to add the following directories to your path for include files FS API FS CONFIG myconfig FS LBL FS OS 4 3 5 Add generic sample code For a quick and easy test of your uC FS integration you should use the code found in FS sample main c 4 3 6 Build and test your application If everything is configured correctly you should now be able to build an application containing a RAM disk on your target system If you encounter any problem during the build process please che
75. r RAN disk e x PS _IoCtli ras FS CHD FORMAT_MEDIA PS WEDIA RAM 1618 0 i eis errori Cannot foraat RAM disk gt n 1 E Wortpace 1 bp gar 1 Geet Z Imp MS ven Wer Sose fier ERC FSAA e e ca ee 5 x create tile defoult tut ca your default device FS OEV MANOR YVE _write file default txt dev_default_ mmg FSFSL FS_LBL e create tile ran RL ca your RAM dick e ten _vrite_file ran n txt der zappen zl nee ze dump file defoult txt uf 1 Call FS_Init before any other DEN DAN _duap_file default trt calls to uC FS Lp pester Fier g H E Becngce Fier a dump file ron 181 en ycu defoult RA durp_filel ran vor tet D Externe Deperdences BREE REESE RAE ER ER EERE EERE EEE EER ERE EE EE EEE EEE EERE EERE EER 2 Call Maintask see Figure 4 2 x Init the file systes MarnTexk re Call MaanTask darectly if you do not use enk gr FS_Exit End using the file systca 3 Closing the File System Achen 000000010 O dn0nn FF 00000006 gp pg D0C 00000012 0000001 0D0D0DLE H Figure 4 1 F4 1 1 One of the first things called in the sample program is a call to the UC FS function FS_Init This function initializes the file system and must be called before using any other uC FS function You should step over F10 this function F4 1 2 When you reach the call to MainTask you should step into F11
76. r s amp reference manual for uC FS 43 123 7 1 1 FS DevloCtl Description Execute special command on device Prototype static int _FS_DevIoCtl FS_u32 id FS_i32 cmd FS_i32 aux void buffer Parameter Meaning Number of media 0 N Command Parameter for command Pointer to data required by command Return value In case of success the return value is 0 Upon failure the return value is 1 Add information This function can be used to implement special commands for your device driver For uC FS the only command that currently needs to be supported is the command FS_CMD_FLUSH_CACHE This command is used to inform cache logic of the device that all of the cache has to be cleared If you do not have a cache logic in your device driver you can simply do nothing and return 0 Example sample taken from the RAM device driver static int _FS_ DevIoCtl FS_u32 id FS_i32 cmd FS_i32 aux void buffer if cmd FS_CMD_FLUSH_CACHE flush caches return 0 return 1 2002 Micrium Technologies Corporation 44 123 User s amp reference manual for uC FS 7 1 2 FS DevRead Description Read block from media Prototype static int _FS_ DevRead FS_u32 id FS_u32 block void buffer Parameter Meaning o O Number of media 0 N Block number to be read from the media Data buffer to which the data is transferred Return value In case of success t
77. r to device driver Number of media 0 N Return value void Additional information LUC FS allows you to make concurrent device operations To ensure that only one tasks makes an access to a specific media via a device driver at any given time this function has to lock an operation by looking to driver and id This is done via another binary semaphore If your application never accesses multiple devices concurrently then you don t need this locking mechanism However we recommend that you implement this functionality Example sample for pC OS II void FS_X_OS_UnlockDeviceOp const FS_device_type driver FS_u32 id OSSemPost FS_SemDeviceOps 2002 Micrium Technologies Corporation 120 123 User s amp reference manual for uC FS 11 5 Time Date functions 11 5 1 FS XS OS GetDate Description Get current date Prototype FS_ul6 FS _X OS GetDate void Return value Return current date as FS_u16 ina format suitable for the FAT file system Additional information The correct date format is o Bit 0 4 Day of month 1 31 o Bit 5 8 Month of year 1 12 o Bit 9 15 Count of years from 1980 0 127 Example sample using ANSI C time functions FS_ul6 FS_X_OS_GetDate void if FS_OS_TIME SUPPORT 1 FS_ul6 fdate time_t struct tm ltime time amp t ltime fdate fdate fdate else FS_ul6 fdate localtime amp t ltime gt tm_mday
78. r value does mean means that there is a card in your reader Additional information If your hardware can directly check the presence of a card you can use that mechanism and return the proper status In case your hardware has to try to do a device operation for checking the presence of a card you must not do that operation inside this function because it is called during other device operations which would be interrupted Instead use a variable to keep track of the current status and return the value of that variable Example sample taken from device smc Hardware EP7312 char FS_SMC_HW_X_ChkCardIn FS_u32 id return _Hw_card_in id 2002 Micrium Technologies Corporation 60 123 User s amp reference manual for uC FS 8 3 3 FS_SMC_HW_X_ChkPower Description Check power is applied to card reader Prototype char EG OMC Hu SX _ChkPower FS_u32 id Parameter Meaning id of card reader 0 N Return value Return 0 if there is a problem with the power supply Any other value means that the power status is correct Additional information This function is used to detect the result of turning on VCC If your hardware does not support power check you should simply return a non zero value Example sample taken from device smc Hardware EP7312 char FS_SMC_HW_X_ChkPower FS_u32 id return 1 2002 Micrium Technologies Corporation User s amp reference manual f
79. rface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 void FS_IDE_HW_X_SetSectorNo FS_u32 id unsigned char data MEMCFG2 x1f13 CS5 8 bit 0 __IDE_SN data 2002 Micrium Technologies Corporation 108 123 User s amp reference manual for uC FS 10 3 Status detection functions 10 3 1 FS_IDE HW_X_DetectStatus Description Checks whether a CF card or ATA device is present Prototype char FS_IDE_HW_X_DetectStatus FS_u32 id Parameter Meaning ID of card reader 0 N Return value 0 if there is a card or device present and can be accessed Any other value means there is no card in the reader or the device cannot be accessed Additional information The sample below is used for accessing a normal ATA device such as e g an IDE hard disk drive It checks if you can access the Sector Count and Sector Number register When using the driver for accessing CompactFlash cards you should check lines CD1 and CD2 for presence of a card instead There are two reasons for that 1 When a CF card is inserted while VCC is on the card will be in PC Card ATA mode Therefore you cannot access Sector Count and Sector Number registers using true IDE mode 2 Checking the lines is usually faster than selecting the device and accessing the Sector Count and Sector Number registers For further details please c
80. rns 0 if the directory has been successfully created In case of any error the return value is 1 Additional information A fully qualified directory name has the same meaning as for function FS_OpenDir Please note that FS_MkDir will not create the whole DirPathList it will only create a directory in an already existing path Example void fool void create mydir in directory test default driver on default device err FS_MkDir test mydir void foo2 void create directory mydir RAM device driver on default device err FS_MkDir ram mydir 2002 Micrium Technologies Corporation 38 123 User s amp reference manual for uC FS 6 7 3 FS_OpenDir Open a directory Description Opens an existing directory for reading Prototype FS_DIR FS_OpenDir const char dirname Parameter Meaning o Fully qualified directory name Return value Returns the address of an FS_DIR data structure if the directory could be opened In case of any error the return value is 0 Additional information A fully qualified directory name means DevName UnitNum DirPathList DirectoryName e DevName is the name of a device e g smc ram or windrv If not specified the first device in the device table will be used e UnitNum is the number of the unit of the device If not specified unit O will be used Note that it i
81. s not allowed to specify UnitNum if DevName has not been specified e DirPathList means a complete path to an existing subdirectory The path must start and end with a character Directory names in the path are separated by If DirPathList is not specified the root directory on the device will be used e DirectoryName and all directory names have to follow the standard FAT naming conventions e g 8 3 notation long file names are not supported To open the root directory simply use an empty string for Di rectoryName Example FS_DIR dirp void fool void open directory test default driver on default device dirp FS_OpenDir test void foo2 void open root directory RAM device driver on default device dirp FS_OpenDir ram 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 39 123 6 7 4 FS_ReadDir Read from a directory Description Reads next directory entry in directory specified by dirp Prototype struct FS_DIRENT FS_ReadDir FS_DIR dirp Parameter Meaning Pointer to an opened directory Return value Returns a pointer to a directory entry If there is no more entry in the directory or in case of any error 0 is returned Example Please refer toFS_CloseDir 2002 Micrium Technologies Corporation 40 123 User s amp reference manual for uC FS 6 7 5 FS_Rewi
82. s required All other layers are generic and do not depend on a specific card reader hardware Logical Block Layer Device driver functions required by emFile Read Write logical sector routines for SMC Read Write physical sector routines for SMC Hardware low level routines This chapter describes all hardware access functions required by pC FS s generic SmartMedia driver 2002 Micrium Technologies Corporation 50 123 User s amp reference manual for uC FS 8 1 Control line functions 8 1 1 FS_SMC_HW_X_BusyLedOff Description Turn off busy LED of the card reader Prototype void FS_SMC_HW_X_BusyLedOff FS_u32 id Parameter Meaning E id of card reader 0 N Return value void Additional information Please see FS_SMC_HW_X_BusyLedOn Example sample taken from device smc Hardware EP7312 void FS_SMC_HW_X_BusyLedOff FS_u32 id if id 0 __PDDR amp 0x01 DIAG LED off 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 51 123 8 1 2 FS_SMC_HW_X_BusyLedOn Description Turn on busy LED of the card reader Prototype void FS_SMC_HW_X_BusyLedOn FS_u32 id Parameter Meaning Z o o O id of card reader 0 N Return value void Additional information If your system can lock the card reader you should also do this here because a call of this function means that a C FS operation is
83. s the vehicle to store your files However this driver only works with Windows NT or Windows 2000 This driver alows you to access real Windows drives e g floppy or flashcards with the help of the Windows API It is very useful for testing This driver is enabled by setting FS_USE_WINDRIVE_DRIVER to 1 note Please be careful when using this driver because it can destroy data on your hard disk Smart Media Card uC FS can work with Smart Media Cards also known as SMCs You can enable it by setting FS_USE_SMC_DRIVER to 1 In order to use it you will have to provide low level I O functions for your card reader hardware Please check out chapter SmartMedia card device driver for details MultiMedia card u C FS can support MultiMedia amp 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 amp SD card device driver for details CompactFlash card amp IDE uC FS supports CompactFlash storage cards also known as CF The driver uses true IDE mode to access a card You can use the same driver for accessing ATA HD drives To enable the driver set FS_USE_IDE_DRIVER to 1 In order to use it you will have to provide low level I O functions for your card reader or IDE port hardware Please take a look at the chapter CompactFlash card amp
84. t status of the device 2 During the periodic disk change detect if your hardware does not remember disk changes If your hardware cannot check for write protect status and disk presence without a device operation you should also make those detections here and remember their status in variables See also FS_SMC_HW_X_ChkCardIn FS_SMC_HW_X_ChkStatus and FS_SMC_HW_X_ChkWP Example sample taken from device smc Hardware EP7312 char FS_SMC_HW_X_DetectStatus FS_u32 id char x FS_SMC_HW_X_SetCmd id nCE low CLE high ALE low ___SMCPORT 0x70 cmd read status Z FS_SMC_HW_X_SetData id nCE low CLE low ALE low x SMCPORT HW_X_Set Standby id nCE high CLE low ALE low if x 0x70 x amp 0x01 FS_SMC_ x amp 0x40 _Hw_card_changed id S _Hw_card_wprotect id _Hw_card_in id return 1 _Hw_card_in id if x amp 0x80 _Hw_card_wprotect id else _Hw_card_wprotect id return 0 1 1 D 0 f f f 2002 Micrium Technologies Corporation 64 123 User s amp reference manual for uC FS 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 65 123 8 4 Data transfer functions 8 4 1 FS_SMC_HW_X_InData Description For the specified card reader set RE to low read the lines O7 I O8 and set RE to high Prototype char FS_SMC_HW_X_InData FS
85. the card reader Prototype void FS_MMC_HW_X_BusyLedoOff FS_u32 id Faseren H ID of card reader 0 NI Return value Void Additional information Please see FS_MMC_HW_X_BusyLedOn Example sample taken from device smc Hardware M16C_137x_IP void FS_MMC_HW_X_BusyLedOff FS_u32 id no LED available 2002 Micrium Technologies Corporation 72 123 User s amp reference manual for uC FS 9 1 2 FS MMC_HW_X_BusyLedOn Description Turns on busy LED of the card reader Prototype void FS_MMC_HW_X_BusyLedOn FS_u32 id Parameter Meaning O o O ra IDofcard reader 0 N Return value Void Additional information If your system can lock the card reader you should also see that this is done here because a call of this function means that an uC FS operation is pending and the card should not be removed until FS_MMC_HW_X_BusyLedOff is called Example sample taken from device smc Hardware M16C_137x_IP void FS_MMC_HW_X_BusyLedOn FS_u32 id no LED available 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 73 123 9 1 3 FS MMC _HW_X_ClockCard Description Clocks the card 8 num times while data line is high Prototype void FS_MMC_HW_X_ClockCard FS_u32 id int num Parameter 1 Meaning ID of card reader 0 N num Number of clocks 8 Return value Void
86. um Technologies Corporation 12 123 F4 2 1 F4 2 2 User s amp reference manual for uC FS Figure 4 2 There is a call to the uC FS function FS_Toct1 This call is used to format your RAM disk in order to be able to write data to it Formatting your RAM disk should not cause any problem You should get to the call of function _write_file without any error message Please note that _write_file is nota uC FS function it is part of the sample application After stepping into F11 that function your screen should look as shown in Figure 4 3 186_MS_start Microsoft Visual C break c FS sample main c File Edit View Insert Project Debug Tools Window Help l x asugi pe Rae wl EE Globals sl All global members zl _write_file Ry e amp 1 sl di Jl A HEHH HEHE IE IE JE JE JE JE HE IE EE EE JE JE JE JE JE JE JE JE JE JE JE JE JE JE E JE JE JE JE JE JE JE JE JE JE JE AAA AAA HER R a Workspace 186_MS_start 1 project s _write_file EI 186_MS_start files Eq Source Files This routine demonstrates how to create and write to a file v DES Ap using the file system QQ FS_DEV_WINDRIVE FS_FSL gery void _write_file const char sp H 1 Call to FS_FOpen FS_LBL rz Oe eege sample myfile FS Toan nane w re R DEV_RAM if myfile 2 Writing an ASCII string Header Files E E Resource Files External Dependencies lt ma ClassView
87. unsigned char data __MEMCFG2 0x1f13 CS5 8 bit data __IDE_DH return data 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 95 123 10 2 6 FS_IDE HW_X_GetError Description Read the Error register Prototype unsigned char FS_IDE_HW_X_GetError FS_u32 id Parameter Meaning U OO ID of card reader 0 N Return value Value of the Error register Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 unsigned char FS_IDE_HW_X_GetError FS_u32 id unsigned char data MEMCEGZ 0x1f13 CS5 8 bit data __IDE_FC return data 2002 Micrium Technologies Corporation 96 123 User s amp reference manual for uC FS 10 2 7 FS_IDE HW_X_GetSectorCount Description Read the Sector Count register Prototype unsigned char FS_IDE_HW_X_GetSectorCount FS_u32 id Parameter Meaning O U O ID of card reader 0 N Return value Value of the Sector Count register Additional information Please check AT Attachment interface specification or CompactFlash specification for details Example sample taken from device ide Hardware ep7312 unsigned char FS_IDE_HW_X_GetSectorCount FS_u32 id unsigned char data __MEMCFG2 0x1f13 CS5 8 bit
88. will find a description of each uC FS API functions An application should only access uC FS by these functions The table below lists the available API functions within their respective categories FS_Exit O FS_Init FS_FClose FS_FOpen FS_FRead FS_FWrite FS_FSeek Set position of file pointer FS_FTell Return position of file pointer FS_ClearErr FS_FError FS_Remove 2002 Micrium Technologies Corporation 24 123 User s amp reference manual for uC FS 6 1 File system control functions 6 1 1 FS_Exit Stop file system Description Stop the file system Prototype void FS_Exit void Return value void Additional information FS_Exit removes e g resources required for an OS integration of uC FS and stops the file system After calling this function you must not call any other LUC FS function except FS_Init Example See FS Init 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 25 123 6 1 2 FS_Init Start file system Description Start the file system Prototype void FS_Init void Return value void Additional information FS_Init initializes the file system and creates resources required for an OS integration of uC FS This function has to be called before calling any other LUC FS function Example include fs_api h void main void FS Inve access file system ff FS E
89. xit 3 2002 Micrium Technologies Corporation 26 123 User s amp reference manual for uC FS 6 2 File access functions 6 2 1 FS_FClose Close a file Description Close an open file Prototype void FS_FClose FS_FILE fp Pointer to a data structure of type FS_FILE Return value void Additional information Close an open file Example void foo void FS_FILE myfile myfile FS_FOpen test txt r if myfile 0 access file FS_FClose myfile 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 27 123 6 2 2 FS _FOpen Open a file Description Opens an existing file or creates a new file depending on parameters Prototype FS_FILE FS_FOpen const char name const char mode Peiireiiinesie Sic Meaning Fully qualified file name Mode for opening the file Return value It returns the address of a FS_FILE structure if the file could be opened in the requested mode In case of any error the return value is 0 Additional information A fully qualified file name means DevName UnitNum DirPathList FileName DI Di DevName is the name of a device e g smc the first device in the device table will be used ram or windrv H not specified UnitNum is the number of the unit of the device If not specified unit 0 will be used Note that it is not allowed to spec
90. your hard drive into any folder of your choice When copying please keep all files in their respective sub directories Make sure the files are not read only after copying If you received zip file please extract it to any folder of your choice preserving the directory structure of the zip file 4 2 Use the Windows sample If you have MS Visual C 6 00 or later version available you will be able to work with a Windows sample project using uC FS Even if you do not have the Microsoft compiler you should read this chapter to understand how an application can use uC FS 4 2 1 Building the sample program Open the Workspace I186_MS_Start dsw with MS Visual Studio by e g double clicking it There is no further configuration necessary You should be able to build the application without any error or warning message 4 2 2 Stepping through the sample The sample project uses the RAM disk driver for demonstration It will create two files in the RAM disk and then dump contents of these files to the console window After starting the debugger by stepping into the application your screen should look as shown in Figure 4 1 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 11 123 ISa MS start Microsett Visual C braak eh Skoamoniekuan Dob tat yew eet Eost Dag Tools Windom Die stet eg ge mr o w ers fo SA otitis vind Sie SHA ET ajaj a format you
91. ystem ef define FS_WD_BLOCKSIZE 0x200 do not change for FAT endif FS_USE_WINDRIVE_DRIVER endif _FS_CONF_H_ 5 1 1 0S support You can specify whether you are using uC OS ll 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 5 1 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 5 1 3 File System Layer Support LUC 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 uC FS only supports the FAT file system so you will need to set FS_USE_FAT_FSL tol 2002 Micrium Technologies Corporation User s amp reference manual for uC FS 21 123 5 1 4 Device Driver Support and configuration LUC FS is shipped with three device drivers RAM Disk uC FS allows you to create any number of RAM disk drives To support these types of drives simply set FS_USE_RAMDISK_DRIVER to 1 By default uC FS implements a RAM disks with 16Kbytes of storage Windows Driver This driver allows you to use Microsoft Windows a

Download Pdf Manuals

image

Related Search

Related Contents

TECH 2 Ver el PDF - Auto Diagnosis Ochoa  Manual de instrucciones Balanza compacta  cln)tot) - File Management  Sun Network QDR InfiniBand Gateway Switch Administration Guide  - Vacuubrand.com  

Copyright © All rights reserved.
Failed to retrieve file