📄 tmacro.h
字号:
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This software is copyrighted by and is the sole property of
* VIA Networking Technologies, Inc. This software may only be used
* in accordance with the corresponding license agreement. Any unauthorized
* use, duplication, transmission, distribution, or disclosure of this
* software is expressly forbidden.
*
* This software is provided by VIA Networking Technologies, Inc. "as is"
* and any express or implied warranties, including, but not limited to, the
* implied warranties of merchantability and fitness for a particular purpose
* are disclaimed. In no event shall VIA Networking Technologies, Inc.
* be liable for any direct, indirect, incidental, special, exemplary, or
* consequential damages.
*
*
* File: tmacro.h
*
* Purpose: Define basic common types and macros
*
* Author: Tevin Chen
*
* Date: Jan 08, 2002
*
*/
#ifndef __TMACRO_H__
#define __TMACRO_H__
#if !defined(__TTYPE_H__)
#include "ttype.h"
#endif
/****** Common helper macros ***********************************************/
// null statement
#define NULL_FUNC()
#if !defined(LONIBBLE)
#define LONIBBLE(b) ((UINT8)(b) & 0x0F)
#endif
#if !defined(HINIBBLE)
#define HINIBBLE(b) ((UINT8)(((UINT16)(b) >> 4) & 0x0F))
#endif
#if !defined(LOBYTE)
#define LOBYTE(w) ((UINT8)(w))
#endif
#if !defined(HIBYTE)
#define HIBYTE(w) ((UINT8)(((UINT16)(w) >> 8) & 0xFF))
#endif
#if !defined(LOWORD)
#define LOWORD(d) ((UINT16)(d))
#endif
#if !defined(HIWORD)
#define HIWORD(d) ((UINT16)((((UINT32)(d)) >> 16) & 0xFFFF))
#endif
#if !defined(MAKEBYTE)
#define MAKEBYTE(ln, hn) ((UINT8)(((UINT8)(ln) & 0x0F) | ((UINT8)(hn) << 4)))
#endif
#if !defined(MAKEWORD)
#define MAKEWORD(lb, hb) ((UINT16)(((UINT8)(lb)) | (((UINT16)((UINT8)(hb))) << 8)))
#endif
#if !defined(MAKEDWORD)
#define MAKEDWORD(lw, hw) ((UINT32)(((UINT16)(lw)) | (((UINT32)((UINT16)(hw))) << 16)))
#endif
// Bytes Reverse: big endian to little endian convert
#if !defined(REVWORD)
#define REVWORD(n) ((((UINT16)(n)) << 8) | ((UINT16)(n) >> 8))
#endif
#if !defined(REVDWORD)
#define REVDWORD(n) ((((UINT32)(n)) << 24) | \
((((UINT32)(n) & 0x0000ff00UL)) << 8) | \
((((UINT32)(n) & 0x00ff0000UL)) >> 8) | \
(((UINT32)(n)) >> 24))
#endif
// big endian to little endian convert
#if !defined(HTONS)
#if defined(__BIG_ENDIAN)
#define HTONS(n) (n)
#else
#define HTONS(n) REVWORD(n)
#endif
#endif /* HTONS */
#if !defined(HTONL)
#if defined(__BIG_ENDIAN)
#define HTONL(n) (n)
#else
#define HTONL(n) REVDWORD(n)
#endif
#endif /* HTONL */
#ifndef NTOHS
#define NTOHS HTONS
#endif
#ifndef NTOHL
#define NTOHL HTONL
#endif
/* map to known network names */
#define ntohs(x) NTOHS(x)
#define ntohl(x) NTOHL(x)
#define htons(x) HTONS(x)
#define htonl(x) HTONL(x)
#ifndef NOMINMAX
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#endif // NOMINMAX
/****** Misc macros ********************************************************/
// calculate element # of array
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#endif /* __TMACRO_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -