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

Miscellaneous Library Functions

11.6.5nv_fprintf()

This function is used in a similar manner to the standard C function fprintf() to write data to a Flash file.

Syntax

int nv_fprintf(FILE *nvp, char *format, …) where:

nvp

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

format

is a format string like printf().

is a list of arguments, as described by format.

Return value

Returns one of the following:

number of bytes written

if successful.

-1

on error.

Usage

The nv_fprintf() function provides a way to print information to a Flash file. It is used in the same way as the standard C fprintf() function is used, but with the restriction that the total length of the formatted output must not exceed the value of

FBUFLEN defined in nvfsio.c.

ARM DUI 0079B

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

11-23

Miscellaneous Library Functions

11.6.6nv_fwrite()

This function is used to write a block of data to a Flash file.

Syntax

int nv_fwrite(char *buffer, int length, FILE *nvp)

where:

buffer points to the data to be written to the file.

length indicates the number of bytes to write to the file.

nvp

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

Return value

Returns one of the following:

number of bytes written

if successful.

-1

on error.

Usage

The nv_fwrite() function writes data at the current offset in the file, and the current offset and length of the file are adjusted to be equal to the current offset + length bytes. The nv_fwrite() function will not allow you to create a file that is larger than NVFSIZE bytes, and this is regulated by truncating length bytes if necessary.

Note

The arguments to nv_fwrite() do not correspond to those used by the standard C function fwrite().

11-24

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

ARM DUI 0079B

Miscellaneous Library Functions

11.6.7nv_initialize()

This function needs to be provided by you, the porting engineer. It should copy the contents of the Flash memory into an area of memory starting at FLASHBASE.

Syntax

void nv_initialize(void)

Return value

None.

Usage

You should call nv_initialize() in your system startup code before calling nv_get_parms() or other routines that will attempt to use the Flash filesystem functions.

Your implementation of nv_initialize() should test that the first 16-bit word of the Flash memory contains the value NVTAG_PATTERN (defined in misclib\nvfsio.h), and if so, nv_initialize() should copy the first NVRAMSIZE bytes of the Flash memory to an area of NVRAMSIZE bytes of memory at address FLASHBASE. Both

NVRAMSIZE and FLASHBASE are defined in misclib\libport.h

If the first word of the Flash memory does not contain the value NVTAG_PATTERN, this indicates that the Flash memory has not been initialized, and in this case, nv_initialize() should create an empty structure in the FLASHBASE memory by first zeroing the memory, and then be setting the tag value of each file entry to be NVTAG_PATTERN, and the pointer value to be -1 using code similar to:

{

extern struct nvpfile *nvpfiles; int i;

for (i = 0; i < NUMNVFILES; i++)

{

nvpfiles[i].tag = NVTAG_PATTERN; nvpfiles[i].pointer = -1;

}

}

ARM DUI 0079B

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

11-25

Miscellaneous Library Functions

11.6.8nv_writeflash()

This function needs to be provided by you, the porting engineer. It should copy the contents of the memory area at FLASHBASE into the Flash memory device.

Syntax

void nv_writeflash(void)

Return value

None.

Usage

You should call nv_writeflash() in your code whenever you want to synchronize the contents of the Flash memory with the current state of the Flash file system. This could be whenever you close a file having written to it, or on a user-initiated event, or a timeout. This is a design decision you must make.

The nv_writeflash() function must copy the NVRAMSIZE bytes of memory from FLASHBASE into the Flash memory device, using whatever programming requirements are specified by the device manufacturer.

11-26

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

ARM DUI 0079B