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

TCP/IP API Functions

4.2.6npalloc()

This function, like npfree() (see npfree() on page 4-10), allocates the dynamic memory for the IP stack. The syntax for this function is exactly the same as the standard C library call, malloc(), except that memory returned by npalloc() is assumed to be pre-initialized to all zeros. In this respect npalloc() is like calloc().

Syntax

void *npalloc(int size)

where:

size

is the size in bytes of the memory to be allocated.

Return value

Returns a pointer to the block allocated, or NULL if no memory is available.

Usage

If your embedded system already supports standard calloc() calls, add the following line to ipport.h:

#define npalloc(size)

calloc(1,size)

If your system does not support calloc(), you must implement it. A description of how this function works and sample code is available in The C Programming Language.

The great majority of the calls to npalloc() are made at initialization time. Only the UDP and TCP layers require these calls during runtime. Some ports with severe memory shortages have modified these layers to use pre-allocated blocks of static memory rather than implementing fully functional npalloc() and npfree() functions, but this invariably involves more work and puts limits on the number of simultaneous connections that can be supported.

You may also want to add debugging facilities in order to help detect any memory leaks within the system. An example implementation of a simple debugging npalloc() can be found in \armthumb\memman.c.

ARM DUI 0079B

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

4-9

TCP/IP API Functions

4.2.7npfree()

This function frees dynamic memory for the IP stack. The syntax for this function is exactly the same as the standard C library call, free().

Syntax

void npfree(void *)

Return value

None.

Usage

If your embedded system already supports standard free() calls, add the following line to ipport.h:

#define npfree(ptr)

free(ptr)

If your system does not support free(), you must implement it. See The C

Programming Language for a description.

You may want to add some debugging facilities in order to help detect memory leaks within the system. An example implementation of a simple debugging npfree() can be found in \armthumb\memman.c.

4-10

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

ARM DUI 0079B

TCP/IP API Functions

4.2.8panic()

This function is called if the stack detects a fatal system error.

Syntax

void panic(char *msg)

where:

msg

is a short message describing the fault.

Return value

Generally there is no return from this function. However, it is sometimes useful to allow a return under the control of a debugger.

Usage

The task performed by this function varies with the implementation. In a testing or development environment, it could print messages, start debuggers, or perform other debugging tasks. The system designer should decide what action will be taken in an embedded implementation. One possibility is to restart (warm boot) the system. It is recommended that you do not continue execution after panic() has been called.

ARM DUI 0079B

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

4-11

TCP/IP API Functions

4.2.9prep_ifaces()

This call prepares the nets[ ] structures for the network interfaces used by this port.

Syntax

int prep_ifaces(int ifIndex)

where:

ifIndex is the index to be used for the first nets[ ] structure.

Return value

Returns an index to the nets[ ] structure for the next interface to be set up. If no interfaces were set up, the returned value is the same as the passed value.

Usage

The integer passed is the nets[ ] index of the first interface to set up. This is always 0 in standard ports, but nets[0] has a dedicated use in some customized versions. If you are setting up multiple interfaces, you must set nets[X] for each interface. If the interfaces are similar, using a for loop to set them may be appropriate.

The appropriate nets[ ] members must be filled in. See Network interfaces on page 4-15 for full details.

4-12

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

ARM DUI 0079B