Debian Codegraph @

xpp/oct612x/include/octmac.h

raw
1 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2
3 File: octmac.h
4
5 Copyright (c) 2001-2007 Octasic Inc.
6
7 Description:
8
9 Common macro definitions.
10
11 This file is part of the Octasic OCT6100 GPL API . The OCT6100 GPL API is
12 free software; you can redistribute it and/or modify it under the terms of
13 the GNU General Public License as published by the Free Software Foundation;
14 either version 2 of the License, or (at your option) any later version.
15
16 The OCT6100 GPL API is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with the OCT6100 GPL API; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 $Octasic_Release: OCT612xAPI-01.00-PR49 $
26
27 $Octasic_Revision: 14 $
28
29 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
30 #ifndef __OCTMAC_H__
31 #define __OCTMAC_H__
32
33 /*--------------------------------------------------------------------------
34 C language
35 ----------------------------------------------------------------------------*/
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /***************************** DEFINES *************************************/
42
43 /* Combine l & h to form a 32 bit quantity. */
44 #define mMAKEULONG(l, h) ((ULONG)(((USHORT)(l)) | (((ULONG)((USHORT)(h))) << 16)))
45
46 #define mLOUCHAR(w) ((UCHAR)(w))
47 #define mHIUCHAR(w) ((UCHAR)(((USHORT)(w) >> 8) & 0xff))
48 #define mLOUSHORT(l) ((USHORT)((ULONG)l))
49 #define mHIUSHORT(l) ((USHORT)(((ULONG)(l) >> 16) & 0xffff))
50 #define mLOSHORT(l) ((SHORT)((ULONG)l))
51 #define mHISHORT(l) ((SHORT)(((ULONG)(l) >> 16) & 0xffff))
52
53 /* Combine l & h to form a 16 bit quantity. */
54 #define mMAKEUSHORT(l, h) (((USHORT)(l)) | ((USHORT)(h)) << 8)
55 #define mMAKESHORT(l, h) ((SHORT)mMAKEUSHORT(l, h))
56
57 /* Extract high and low order parts of 16 and 32 bit quantity */
58 #define mLOBYTE(w) mLOUCHAR(w)
59 #define mHIBYTE(w) mHIUCHAR(w)
60 #define mMAKELONG(l, h) ((LONG)mMAKEULONG(l, h))
61
62 /*--------------------------------------------------------------------------
63 Bite conversion macro
64 ----------------------------------------------------------------------------*/
65 #define mSWAP_INT16(x) mMAKEUSHORT( mHIBYTE(x), mLOBYTE(x) )
66 #define mSWAP_INT32(x) mMAKEULONG( mSWAP_INT16(mHIUSHORT(x)), mSWAP_INT16(mLOUSHORT(x)) )
67
68
69 /* Cast any variable to an instance of the specified type. */
70 #define mMAKETYPE(v, type) (*((type *)&v))
71
72 /* Calculate the byte offset of a field in a structure of type type. */
73 #define mFIELDOFFSET(type, field) ((UINT32)&(((type *)0)->field))
74 #define mCOUNTOF(array) (sizeof(array)/sizeof(array[0]))
75
76 #define mMAX(a,b) (((a) > (b)) ? (a) : (b))
77 #define mMIN(a,b) (((a) < (b)) ? (a) : (b))
78
79 #define mDIM(x) (sizeof(x) / sizeof(x[0]))
80
81 #define mFROMDIGIT(ch) ((ch) - 0x30) /* digit to char */
82 #define mTODIGIT(ch) ((ch) + 0x30) /* int to char */
83
84 #define mISLEAP(a) ( !( a % 400 ) || ( ( a % 100 ) && !( a % 4 ) ) )
85
86 #define mFOREVER for( ;; )
87
88 #define mROUND_TO_NEXT_4( a ) ( ((a) % 4) ? ( (a) + 4 - ((a)%4) ) : (a) )
89
90 /*--------------------------------------------------------------------------
91 C language
92 ----------------------------------------------------------------------------*/
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif /* __OCTMAC_H__ */