⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilities.h

📁 由smsc公司改进的lwip2.1.1基于嵌入式系统的TCP/ip协议栈
💻 H
字号:
/* Copyright 2008, SMSC, All rights reserved
File: utilities.h
*/

#ifndef UTILITIES_H
#define UTILITIES_H

#include "core/sps.h"

#ifndef ENDIAN_SETTING
/* ENDIAN_SETTING should be defined in smsc_environment.h */
/* ENDIAN_SETTING should be set to either
	BIG_ENDIAN or LITTLE_ENDIAN 
*/
#error ENDIAN_SETTING is not defined
#endif
/* 
Below are the platform specific byte swap macros.
If you would like customized versions you should defined them
in smsc_environment.h
If they are already defined then they will not be redefined below.
*/

#if (ENDIAN_SETTING==LITTLE_ENDIAN)
/* byte swap is necessary */
#define smsc_htons(num16bit)						\
	((u16_t)(((((u16_t)(num16bit))&0x00FF)<<8)|		\
	((((u16_t)(num16bit))&0xFF00)>>8)))

#define smsc_ntohs(num16bit)	smsc_htons(num16bit)

#define smsc_htonl(num32bit)		\
	(((((u32_t)(num32bit))&0x000000FF)<<24)|				\
	((((u32_t)(num32bit))&0x0000FF00)<<8)|	\
	((((u32_t)(num32bit))&0x00FF0000)>>8)|	\
	((((u32_t)(num32bit))&0xFF000000)>>24))

#define smsc_ntohl(num32bit)	smsc_htonl(num32bit)

#elif (ENDIAN_SETTING==BIG_ENDIAN)
/* byte swap is not necessary */
#define smsc_htons(num16bit) num16bit

#define smsc_ntohs(num16bit) num16bit

#define smsc_htonl(num32bit) num32bit

#define smsc_ntohl(num32bit) num32bit

#else

/* ENDIAN_SETTING must be defined in smsc_environment.h
It should be defined to either BIG_ENDIAN or to LITTLE_ENDIAN
*/
#error invalid ENDIAN_SETTING
#endif


/* Debug Utilities */
/* SMSC_TRACE is used for informational purposes only,
	it may be useful during debugging but is usually too
	noisy to keep it enabled all the time.
	'condition' is usually filled in with an individual module 
	debug enable switch, but it could also be used to specify a runtime
	condition that activates the message. */
#if (SMSC_TRACE_ENABLED)
#define SMSC_TRACE(condition,message) 				\
	do {											\
		if((condition)&(1|DEBUG_TRACE_BIT)) {		\
			SMSC_PLATFORM_MESSAGE(("  TRACE: "));	\
			SMSC_PLATFORM_MESSAGE(message); 		\
			SMSC_PLATFORM_MESSAGE(("\n"));			\
		}											\
	} while(0)
#define SMSC_PRINT(condition,message)			\
	do {										\
		if((condition)&(1|DEBUG_TRACE_BIT)) {	\
			SMSC_PLATFORM_MESSAGE(message);		\
		}										\
	} while(0)
#else
#define SMSC_TRACE(condition,message)
#define SMSC_PRINT(condition,message)
#endif

/* SMSC_NOTICE is intended to be used only when an error is detected
   and fully handled and recoverable. (example is dropping packets) 
	'condition' is usually filled in with an individual module 
	debug enable switch, but it could also be used to specify a runtime
	condition that activates the message. */
#if (SMSC_NOTICE_ENABLED)
#define SMSC_NOTICE(condition,message) 				\
	do {											\
		if((condition)&(1|DEBUG_NOTICE_BIT)) {		\
			SMSC_PLATFORM_MESSAGE((" NOTICE: "));	\
			SMSC_PLATFORM_MESSAGE(message);			\
			SMSC_PLATFORM_MESSAGE(("\n"));			\
		}											\
	} while(0)
#else
#define SMSC_NOTICE(condition,message)
#endif

/* SMSC_WARNING is intended to be used only when an error is detected
   and but may not be handled or recoverable. (example is how to handle unknown codes) 
	'condition' is usually filled in with an individual module 
	debug enable switch, but it could also be used to specify a runtime
	condition that activates the message. */
#if (SMSC_WARNING_ENABLED)
#define SMSC_WARNING(condition,message) 			\
	do {											\
		if((condition)&(1|DEBUG_WARNING_BIT)) {		\
			SMSC_PLATFORM_MESSAGE(("WARNING: "));	\
			SMSC_PLATFORM_MESSAGE(message);			\
			SMSC_PLATFORM_MESSAGE(("\n"));			\
		}											\
	} while(0)
#else
#define SMSC_WARNING(condition,message)
#endif

/* SMSC_ERROR is to be used only when a fatal unrecoverable error has 
   accured. It contains a halt command to prevent further corruption.
   SMSC_ASSERT is similar to SMSC_ERROR in that both can be used to notify
   of a fatal error. SMSC_ASSERT allow the user to provide a condition
   which if false will trigger the error. If the error is triggered an 
   halt command will prevent further execution.
   Neither SMSC_ERROR or SMSC_ASSERT can be enabled on a per module based.
   If they are enabled they are enabled for all modules.
   */
#if (SMSC_ERROR_ENABLED)
#define SMSC_ERROR(message) 								\
	do { 													\
		SMSC_PLATFORM_MESSAGE(("!ERROR!: "));				\
		SMSC_PLATFORM_MESSAGE(message);						\
		SMSC_PLATFORM_HALT_MESSAGE(							\
			("\n!ERROR!: file=%s, line=%d\n",				\
				__FILE__,__LINE__));						\
	} while(0)

#define SMSC_ASSERT(condition) 								\
	do { 													\
		if(!(condition)) {									\
			SMSC_PLATFORM_HALT_MESSAGE(						\
				("ASSERTION FAILURE: file=%s, line=%d\n", 	\
                	__FILE__, __LINE__));					\
        }													\
   	} while(0)
            
/*
* The following macros help by verifying you have a valid structure pointer
*   This is especially useful when void pointers are used to pass structures
*   around. These macros can be used to make sure a structure has been 
*   initialized and make sure it is the correct structure.
*/
#define DECLARE_SIGNATURE	u32_t mSignature;
#define ASSIGN_SIGNATURE(structure_pointer,signature) 				\
	do {															\
		(structure_pointer)->mSignature=((u32_t)signature);			\
	}while(0)
#define CHECK_SIGNATURE(structure_pointer,signature) 				\
	do {															\
		if((structure_pointer)->mSignature!=((u32_t)signature)) {		\
			SMSC_PLATFORM_HALT_MESSAGE(								\
				("SIGNATURE_FAILURE: file=%s, line=%d\n",			\
					__FILE__, __LINE__));							\
		}															\
	} while(0)
#define CLEAR_SIGNATURE(structure_pointer)			\
	do {											\
		(structure_pointer)->mSignature=(u32_t)0);	\
	} while(0)
#else /* SMSC_ERROR_ENABLED */
#define SMSC_ERROR(message)
#define SMSC_ASSERT(condition)  
#define DECLARE_SIGNATURE
#define ASSIGN_SIGNATURE(structure_pointer,signature)
#define CHECK_SIGNATURE(structure_pointer,signature)
#define CLEAR_SIGNATURE(structure_pointer)
#endif /* SMSC_ERROR_ENABLED */

#define MEMORY_ALIGNED_SIZE(size) \
((size+(MEMORY_ALIGNMENT - 1)) & (~(MEMORY_ALIGNMENT-1)))

#define MEMORY_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + (mem_ptr_t)(MEMORY_ALIGNMENT - 1)) & ~((mem_ptr_t)(MEMORY_ALIGNMENT-1))))
/*</BLOCK>*/

#endif /* UTILITIES_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -