Using an Ez80 Flash Memory File System
Total Page:16
File Type:pdf, Size:1020Kb
Application Note Using an eZ80® Flash Memory File System AN017303-0908 Abstract you have the performance necessary to execute complex applications quickly and efficiently. Com- This Application Note demonstrates a method for bining Flash and SRAM, eZ80Acclaim! devices creating a file system that can be stored within the provide the memory required to implement com- external Flash memory space connected to Zilog’s munication protocol stacks and achieve flexibility eZ80® microprocessors. This file system is used when performing in-system updates of application with the Zilog TCP/IP (ZTP) Software Suite that firmware. runs on the XINU operating system. The Applica- tions Programming Interface (API) functions The eZ80Acclaim! Flash MCU can operate in full developed for this file system can be used to 24-bit linear mode addressing 16 MB without a develop applications with minimum effort. An Memory Management Unit (MMU). Additionally, eZ80 Development Module features 1 MB of Flash support for the Z80®-compatible mode allows Z80/ Memory, which is large enough to accommodate Z180 legacy code execution within multiple 64 KB the application data and Flash file system storage. memory blocks with minimum modification. With an external bus supporting eZ80, Z80, Intel, and The file system proposed in this Application Note Motorola bus modes and a rich set of serial com- cannot be used for HTTP implementation. HTTP munications peripherals, you have several options uses sequentially stored files and does not support when interfacing to external devices. the file system API discussed in this Application Note. Some of the applications suitable for eZ80Acclaim! devices include vending machines, Note: The source code file associated with point-of-sale (POS) terminals, security systems, this application note, AN0173- automation, communications, industrial control SC01.zip is available for down- and facility monitoring, and remote control. load at www.zilog.com. eZ80® General-Purpose Product Overview Microprocessors The Application Note supports the eZ80 family of The eZ80 has revolutionized the communication microprocessing devices, which includes eZ80 industry. It executes Zilog’s Z80 code four times microprocessors and eZ80Acclaim!® Flash micro- faster at the same clock speed of traditional Z80s controllers unit (MCU). Both product lines are and can operate at frequencies up to 50 MHz. briefly described in this section. Unlike most 8-bit microprocessors, which can only address 64 KB, the eZ80 can address 16 MB eZ80Acclaim! Flash MCU without a MMU. eZ80Acclaim! on-chip Flash MCU are an excep- Designed with over 25 years of experience with the tional value for designing high performance, 8-bit Z80, this microprocessor is best suited for embed- MCU-based systems. With speeds up to 50 MHz ded internet appliances, industrial control, automa- and an on-chip Ethernet MAC (for eZ80F91 only), tion, web management, modem controller, Copyright ©2008 by Zilog®, Inc. All rights reserved. www.zilog.com Using an eZ80® Flash Memory File System electronic games, and personal digital assistant types, there are certain specific terms used when (PDA) applications. describing nearly all file systems. First, the term file is used to define a file system unit, which is Discussion considered to be a sequence of records with the same structure or type. Second, the term disk is File systems offer a common way to store data of used to define a storage unit that contains a set of any type, often over an extended period of time. files. They are useful for accumulating and transferring data between different types of operating environ- In the evolution of file systems, APIs are gaining ments and devices. This section discusses the con- acceptance relatively recently as a standard for siderations for designing a file system for an adding modular functionality to file systems. Such embedded environment. an API provides a set of C language functions to perform file create, open, read, write, and close File System Overview operations for file manipulation. Widely-known examples of file systems include: The file system described in this Application Note is an embedded file system for the eZ80 family of • Disk Operating System (DOS) featuring the microprocessors that includes standard set of C- FAT12 and FAT16 methods of file allocation language API functions, such as fcreate(), • 32-bit WinNT file system fopen(), fread(), fwrite(), fclose(), and others. For more details of the File System API • Compact Disk File System (CDFS) functions, see Appendix B—File System APIs on • Compact Flash file system. page 13. Each of these file systems is built for a particular hardware environment and is based on a particular Using the Embedded Flash- operating system. Typically, data is stored within a Based File System long-term storage device and loaded into short- term operating storage for processing and manipu- This section contains guidelines to be followed lation. Whenever data is processed, it is stored when using the embedded Flash-based file system within long-term storage. to develop an application. To follow the guidelines, the section first discusses the software implementa- The file system discussed in this Application Note tion for the embedded Flash-based file system. is built for the embedded hardware environment based on Zilog’s eZ80 development modules, Software Implementation which feature external Flash and RAM memory Figure 1 on page 3 displays the functional blocks spaces. Flash Memory is used for long-term stor- of the embedded Flash-based file system. The age purposes, and RAM is used as operating stor- functional blocks comprise a File System Configu- age for data processing. ration Component, File System Manipulation Functions, and the Flash Memory Interface. There are strict standards that govern how data is stored. Though storage media are offered in differ- ent types, such as magnetic media, Flash Memory, and so on, storage organization must suit media requirements and must be optimized for the work- ing environment. Despite these differing media AN017303-0908 Page 2 of 23 Using an eZ80® Flash Memory File System The file system configuration parameters consist of several entities, few are discussed below: File System Configuration File Table—The file table contains the names of Component the files represented in the current file system, along with their sizes and pointers to the data con- tained in each file. The maximum number of files File Access and in the file system is defined by the constant, API Manipulation Functions FTABLESIZE. Sector List—The sector list is the array of 16-bit values containing the sector addresses. The array Flash Memory Interface maintains a size equal to the number of sectors on the disk, NSECTORS, to be able to address each of the physical sectors. Figure 1. Functional Blocks of the Embedded Flash-Based File System Sector Data Area—The sector data area is the space used by the file data. This space is logically File System Configuration Component divided to NSECTORS blocks, called sectors. Each of the sectors maintains a size of SECTORSIZE In Figure 1, the File System Configuration Compo- bytes. nent block represents the configuration file, fileconf.h. It contains a set of configuration The init_file_system() function creates or parameters that you can modify to suit the applica- restores the file system according to the configura- tion. Table 1 lists the maximum allowable size of tion parameters’ values. An example of the the file system and the capacity of its entities as init_file_system() function can be found defined by the configuration parameters. in the fileinit.c file available in the AN0173-SC01.zip file associated with this Table 1. File System Configuration Application Note. Parameters (fileconf.h) Default File Access and Manipulation Functions Parameter Description Value In Figure 1, the File Access and Manipulation NFHANDLES The number of opened 10 Functions block represent the functions that are files used to manage the files, after the file system is created and implemented. These functions are: FTABLESIZE The number of file 32 entries in the file system fcreate(), fopen(), fread(), fwrite(), fclose(), fexists(), and ferase(), and NSECTORS The number of sectors 1000 together they form the file system API. in the disk SECTORSIZE The size of a sector in 128 Flash Memory Interface the disk The Flash Memory Interface stores the volume of VHDRSIZE Volume header size 128 data (created as a result of operations in the file system and files contained in it) into Flash Mem- ory. The Flash Memory Interface allows permanent data storage and enables you to continue working AN017303-0908 Page 3 of 23 Using an eZ80® Flash Memory File System with the file system after cycling power to the stor- age device. Any Flash Library1 can be used as a Flash Memory FILE STRUCTURE Interface. The Flash Loader application available NAME SIZE START with the ZDS II–IDE is an example that uses a Flash Memory Interface. Yet another example is the eZ80® Remote Access Application Note (AN0134) available on the www.zilog.com. SECTOR TABLE SECTOR 1 SECTOR 2 File System Data Structure This section discusses the file_entry data structure used for each structural units that com- pose the embedded Flash-based file system. SECTOR n END OF FILE The file_entry structure used to maintain the file table entries has the following structure: Figure 2. File Sector Chain typedef struct { The size of the file_entry structure, repre- char name[11]; // Name of the file sented by sizeof(file_entry), is 16 bytes. unsigned short start;// Starting The size of a sector number is 2 bytes (of type //sector of the file unsigned short). A volume header, which contains unsigned int size;// Size of file in the volume parameters, must also be included in //bytes the structure. } file_entry; Table 2 lists the embedded Flash-based file system The start variable contains the ordinal number representation with a 16-byte file_entry struc- of the first sector owned by the file.