Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(ARM).Porting TCP-IP programmer's guide.Ver 1.4.pdf
Скачиваний:
31
Добавлен:
23.08.2013
Размер:
2.79 Mб
Скачать

Miscellaneous Library Functions

11.6nvfsio.c

This file implements a set of routines used for reading and writing an area of nonvolatile Flash memory as a simple filesystem. This section describes how to use the functions within nvfsio.c, and contains the following sections:

Overview on page 11-19

nv_fclose() on page 11-20

nv_fgets() on page 11-21

nv_fopen() on page 11-22

nv_fprintf() on page 11-23

nv_fwrite() on page 11-24

nv_initialize() on page 11-25

nv_writeflash() on page 11-26.

11.6.1Overview

To use the functions in nvfsio.c, you will need to define INCLUDE_FLASHFS in your ipport.h file, and set configuration values in misclib\libport.h for the following:

FLASHFIRM the memory address of the start of the Flash memory area.

FLASHBASE the memory address of the start of an area of RAM that is the same size as the Flash memory area.

NUMNVFILES the number of files to support within the Flash file system.

NVFSIZE the maximum size of a file within the Flash file system.

You must provide an area of RAM that is the same size as the Flash memory, and implement nv_initialize() and nv_writeflash() functions as part of your porting. The nv_initialize() function copies the contents of the Flash memory to the RAM area, in preparation for being used by the other Flash file system functions. The nv_writeflash() function should be called to copy the RAM area into the Flash device.

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

11-19

Miscellaneous Library Functions

11.6.2nv_fclose()

This function is called when all operations (either reading or writing) on a Flash file have been completed.

Syntax

void nv_fclose(FILE *nvp)

where:

nvp

is a pointer to a FILE structure as returned by nv_fopen().

Return value

None.

Usage

The nv_fclose() function does not call the nv_writeflash(). It is the responsibility of the porting engineer to ensure that nv_writeflash() is called to copy any data written to the Flash file system into the Flash memory device.

11-20

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B

Miscellaneous Library Functions

11.6.3nv_fgets()

This function is used to read one line at a time from a Flash file.

Syntax

char *nv_fgets(char *buffer, int maxlen, FILE *nvp)

where:

buffer points to an array of characters to hold the returned value.

maxlen indicates the size of buffer.

nvp

is a pointer to a FILE structure as returned by nv_fopen().

Return value

Returns one of the following:

buffer

if successful.

NULL if end-of-file is reached or an error has occurred.

Usage

The nv_fgets() function is used to read lines from the file pointed to by nvp. The value returned by nv_fgets() is a NULL-terminated string that includes any line-feed character (\n) from the end of the line.

Note

It is possible for the last line in a file to not be terminated by a line-feed character.

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

11-21

Miscellaneous Library Functions

11.6.4nv_fopen()

This function provides a subset of the functionality implemented by the standard C function fopen(), preparing a Flash file system file for access by the other Flash file system routines.

Syntax

FILE *nv_fopen(char *name, char *mode) where:

name

is the name of the Flash file system file to be opened.

mode

describes the type of accesses you wish to perform.

Return value

Returns one of the following:

pointer to a FILE structure

if successful.

NULL if not successful.

Usage

The nv_fopen() function is called to obtain access to a file in the Flash file system. The underlying file system code makes no distinction between files opened for reading and files opened for writing. This implementation does not differentiate between different mode strings other than any single letter, where the file is expected to already exist within the Flash file system, or any single letter followed by the character + (ASCII 43), where a new file will be created with zero length.

11-22

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B