endian.h

来自「ssd192Xv1 液晶驱动程序 驱动程序 彩屏液晶」· C头文件 代码 · 共 37 行

H
37
字号
#ifndef __ENDIAN_H__
#define __ENDIAN_H__

#include "cpu.h"

#ifdef LITTLE_ENDIAN
#undef LITTLE_ENDIAN
#endif

#ifdef BIG_ENDIAN
#undef BIG_ENDIAN
#endif


#define LITTLE_ENDIAN		1
#define BIG_ENDIAN		2

#if (CPU == MC68VZ328)
#define ENDIAN		BIG_ENDIAN
#elif ((CPU == MC9328MXL) || (CPU==LPC22xx))
#define ENDIAN		LITTLE_ENDIAN
#else
#error ENDIAN Setting cannot be defined because CPU is invalid
#endif

#if (ENDIAN==BIG_ENDIAN)

#define SWAP16(x)	((((x) >> 8) & 0x00ff) | (((x) << 8) & 0xff00))
#define SWAP32(x)	((((x) >> 24) & 0x000000ff) | \
			 (((x) >> 8) &  0x0000ff00) | \
			 (((x) << 8) &  0x00ff0000) | \
			 (((x) << 24) & 0xff000000))

#else

#define SWAP16(x)	x
#define SWAP32(x)	x

#endif

	// these macros are for swapping regardless of endian
#define SWAPSHORT(x)	((((x) >> 8) & 0x00ff) | (((x) << 8) & 0xff00))
#define SWAPLONG(x)	((((x) >> 24) & 0x000000ff) | \
			 (((x) >> 8) &  0x0000ff00) | \
			 (((x) << 8) &  0x00ff0000) | \
			 (((x) << 24) & 0xff000000))
#endif	/* _ENDIAN_H_ */

⌨️ 快捷键说明

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