📄 net_util.h
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2007; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TCP-IP is provided in source form for FREE evaluation, for educational
* use or peaceful research. If you plan on using uC/TCP-IP in a commercial
* product you need to contact Micrium to properly license its use in your
* product. We provide ALL the source code for your convenience and to help
* you experience uC/TCP-IP. The fact that the source code is provided does
* NOT mean that you can use it without paying a licensing fee.
*
* Knowledge of the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK UTILITY LIBRARY
*
* Filename : net_util.h
* Version : V1.89
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s) : (1) NO compiler-supplied standard library functions are used by the network protocol suite.
* 'net_util.*' implements ALL network-specific library functions.
*
* See also 'net.h NETWORK INCLUDE FILES Note #3'.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef NET_UTIL_MODULE
#define NET_UTIL_EXT
#else
#define NET_UTIL_EXT extern
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NETWORK WORD ORDER - TO - CPU WORD ORDER MACRO'S
*
* Description : Convert data values to & from network word order to host CPU word order.
*
* Argument(s) : val Data value to convert (see Note #1).
*
* Return(s) : Converted data value (see Note #1).
*
* Caller(s) : various.
*
* These macro's are network protocol suite application interface (API) macro's & MAY be
* called by application function(s).
*
* Note(s) : (1) 'val' data value to convert & any variable to receive the returned conversion MUST
* start on appropriate CPU word-aligned addresses. This is required because most word-
* aligned processors are more efficient & may even REQUIRE that multi-octet words start
* on CPU word-aligned addresses.
*
* (a) For 16-bit word-aligned processors, this means that
*
* all 16- & 32-bit words MUST start on addresses that are multiples of 2 octets
*
* (b) For 32-bit word-aligned processors, this means that
*
* all 16-bit words MUST start on addresses that are multiples of 2 octets
* all 32-bit words MUST start on addresses that are multiples of 4 octets
*
* See also 'lib_mem.h MEMORY DATA VALUE MACRO'S Note #1a'.
*********************************************************************************************************
*/
#if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
#define NET_UTIL_NET_TO_HOST_32(val) (val)
#define NET_UTIL_NET_TO_HOST_16(val) (val)
#else
#if (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_32)
#define NET_UTIL_NET_TO_HOST_32(val) (((((CPU_INT32U)(val)) & 0xFF000000) >> 24) | \
((((CPU_INT32U)(val)) & 0x00FF0000) >> 8) | \
((((CPU_INT32U)(val)) & 0x0000FF00) << 8) | \
((((CPU_INT32U)(val)) & 0x000000FF) << 24))
#define NET_UTIL_NET_TO_HOST_16(val) (((((CPU_INT16U)(val)) & 0xFF00) >> 8) | \
((((CPU_INT16U)(val)) & 0x00FF) << 8))
#elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_16)
#define NET_UTIL_NET_TO_HOST_32(val) (((((CPU_INT32U)(val)) & 0xFF000000) >> 8) | \
((((CPU_INT32U)(val)) & 0x00FF0000) << 8) | \
((((CPU_INT32U)(val)) & 0x0000FF00) >> 8) | \
((((CPU_INT32U)(val)) & 0x000000FF) << 8))
#define NET_UTIL_NET_TO_HOST_16(val) (((((CPU_INT16U)(val)) & 0xFF00) >> 8) | \
((((CPU_INT16U)(val)) & 0x00FF) << 8))
#else
#define NET_UTIL_NET_TO_HOST_32(val) (val)
#define NET_UTIL_NET_TO_HOST_16(val) (val)
#endif
#endif
#define NET_UTIL_HOST_TO_NET_32(val) NET_UTIL_NET_TO_HOST_32(val)
#define NET_UTIL_HOST_TO_NET_16(val) NET_UTIL_NET_TO_HOST_16(val)
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK DATA VALUE MACRO'S
*
* Description : Encode/decode data values to & from any CPU memory addresses.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -