Notes on lwIP TCP/IP stack III: Detailed description of configuration file per.h & cc.h

Keywords: network

Catalog

1. per.h (performance testing)

2. cc.h (cpu and compiler configuration)

Macro Definition

Nonstandard function

1. per.h (performance testing)

In opt.h configuration, the LWIP_PERF option controls performance testing, and when it is necessary to enable this function to do some related configuration work.

All definitions related to this part cannot be placed in lwipopts.h, but in arch/perf.h! Measure calls are made throughout the lwip, and these calls can be defined as null.

  • PERF_START: Start measuring something.
  • PERF_STOP(x): Stop measuring something and record the results.

per.h can be created or retrieved from official routines, and then modified to suit its own content.

In many cases, this function is not used, just add the file, directly defined as empty, regardless of the final use of the function, in fact, it has not changed; of course, if the actual need to measure performance, it needs to achieve the corresponding start/stop, recording and other functions.

#ifndef LWIP_ARCH_PERF_H
#define LWIP_ARCH_PERF_H

/* Defined as empty */
#define PERF_START    
#define PERF_STOP(x) 

#endif /* LWIP_ARCH_PERF_H */

2. cc.h (cpu and compiler configuration)

Because configuration is not an option of lwIP itself, and is related to CPU and compiler, so they are placed in cc.h file, the old version also has a cpu.h, the new version is no longer needed. Relevant configuration and function reference arch.h and def.h.

cc.h can be created or retrieved from official routines, and then modified to suit its own content. Place it in the same directory as perf.h, / arch/cc.h. Because the protocol stack contains directories, it can not be written as other, otherwise, it will add to the picture.

  • Macro Definition

/* 
    Define the byte order of the system. Network data needs to be converted into host byte order. 
    Permissible values: LITTLE_ENDIAN and BIG_ENDIAN */
#define 	BYTE_ORDER   LITTLE_ENDIAN

/* Define the Random Number Generator Function of the System */ 
#define 	LWIP_RAND()   ((u32_t)rand())

/* Platform-specific diagnostic output. */ 
#define 	LWIP_PLATFORM_DIAG(x)   do {printf x;} while(0)

/* Platform-specific assertion processing. */  
#define 	LWIP_PLATFORM_ASSERT(x)

/* Whether the standard C library contains stddef.h or not, the standard library is used by default. */ 
#define 	LWIP_NO_STDDEF_H   0

/* Whether the standard C library contains stdint.h or not, the standard library is used by default */  
#define 	LWIP_NO_STDINT_H   0

/* Whether the standard C library contains inttypes.h or not, the standard library is used by default. */  
#define 	LWIP_NO_INTTYPES_H   0

/* Does the standard C library contain limits.h, and the standard library is used by default? */  
#define 	LWIP_NO_LIMITS_H   0

/* Whether the standard C library contains ctype.h or not, the standard library is used by default. */  
#define 	LWIP_NO_CTYPE_H   0
 
#define 	LWIP_CONST_CAST(target_type, val)   ((target_type)((ptrdiff_t)val))
 
#define 	LWIP_ALIGNMENT_CAST(target_type, val)   LWIP_CONST_CAST(target_type, val)
 
#define 	LWIP_PTR_NUMERIC_CAST(target_type, val)   LWIP_CONST_CAST(target_type, val)
 
#define 	LWIP_PACKED_CAST(target_type, val)   LWIP_CONST_CAST(target_type, val)

/* Allocate a memory buffer of a specified size that is large enough to align its starting address with LWIP_MEM_ALIGN. */ 
#define 	LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size)   u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]

/*     
    Calculate the memory size of the aligned buffer - Return the next maximum multiple of MEM_ALIGNMENT
   (For example, LWIP_MEM_ALIGN_SIZE (3) and LWIP_MEM_ALIGN_SIZE (4) will generate 4 for MEM_ALIGNMENT== 4.
 */ 
#define 	LWIP_MEM_ALIGN_SIZE(size)   (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))

/* When using an unaligned type as storage, calculate the safe memory size of the aligned buffer. This includes the initial (MEM_ALIGNMENT-1) margin of security */ 
#define 	LWIP_MEM_ALIGN_BUFFER(size)   (((size) + MEM_ALIGNMENT - 1U))

/* Align memory pointers to the alignment defined by MEM_ALIGNMENT so that ADDR%MEM_ALIGNMENT== 0 */ 
#define 	LWIP_MEM_ALIGN(addr)   ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))


/* Packaging structure support. Place BEFORE before declaring the packaging structure. */ 
#define 	PACK_STRUCT_BEGIN

/* Packaging structure support. Place AFTER before declaring the packaging structure. */ 
#define 	PACK_STRUCT_END

/* Packaging structure support. Place between the end of the declaration and the semicolon of the packaging structure. */ 
#define 	PACK_STRUCT_STRUCT

/* Packaging structure support. Encapsulate u32_t and u16_t members. */ 
#define 	PACK_STRUCT_FIELD(x)   x

/* Packaging structure support. Contains u8_t members, some of which warn against packaging. */ 
#define 	PACK_STRUCT_FLD_8(x)   PACK_STRUCT_FIELD(x)

/* Packaging structure support. Some compilers warn against wrapping for members of the wrapping structure itself. */ 
#define 	PACK_STRUCT_FLD_S(x)   PACK_STRUCT_FIELD(x)

/*
    PACK_STRUCT_USE_INCLUDES == 1: Use the # include file to support the packaging structure before and after packaging struct.
    This file is included before the structure "arch / bpstruct.h".
    This structure is the file contained after "arch / epstruct.h".
*/ 
#define 	PACK_STRUCT_USE_INCLUDES

/* Eliminate compiler warnings about unused parameters */ 
#define 	LWIP_UNUSED_ARG(x)   (void)x

/* 
    LWIP_PROVIDE_ERRNO == 1: Let lwIP provide ERRNO values and'errno'variables. 
    If this option is disabled, cc.h must define'errno', include <errno.h>, define LWIP_ERRNO_STDINCLUDE to include <errno.h> or define LWIP_ERRNO_INCLUDE as <errno.h> or equivalent.
*/ 
#define 	LWIP_PROVIDE_ERRNO
  • Nonstandard function

lwIP provides default implementations for non-standard functions. If necessary, these can be mapped to OS functionality to reduce code footprint.

char *  lwip_strnstr (const char *buffer, const char *token, size_t n)
 
int  lwip_stricmp (const char *str1, const char *str2)
 
int  lwip_strnicmp (const char *str1, const char *str2, size_t len)
 
void  lwip_itoa (char *result, size_t bufsize, int number)

 

 

Posted by thosecars82 on Wed, 07 Aug 2019 05:07:49 -0700