diff options
Diffstat (limited to 'common/words.h')
-rw-r--r-- | common/words.h | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/common/words.h b/common/words.h new file mode 100644 index 0000000..9597b8a --- /dev/null +++ b/common/words.h @@ -0,0 +1,131 @@ + +/************************************************************************** + * + * $Id: words.h 1.9 2003/02/07 11:36:54Z MARTIN TRASH $ + * + * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany + * + * Description: + * Definitions of commonly used data types. + * + * ----------------------------------------------------------------------- + * $Log: words.h $ + * Revision 1.9 2003/02/07 11:36:54Z MARTIN + * New macros _hilo_16() and _hilo_32() for endian conversion. + * Revision 1.8 2002/05/28 10:09:54 MARTIN + * Added new macros _var_bswap16() and _var_bswap32(). + * Revision 1.7 2001/03/14 11:30:48 MARTIN + * Removed definitions for UINT8, UINT16, UINT32. + * Redefined preprocessor control for Win32. + * Revision 1.6 2001/02/28 15:43:20 MARTIN + * Modified preprocessor syntax. + * Revision 1.5 2001/02/05 10:20:53 MARTIN + * Include different Linux types for user space and kernel space programs. + * Source code cleanup. + * Revision 1.4 2000/09/15 08:34:11 MARTIN + * Exclude some definitions if compiling under Win NT. + * Revision 1.3 2000/08/22 15:04:28 MARTIN + * Added new file header. + * Added macros to revert endianess of 16 and 32 bit values. + * + **************************************************************************/ + +#ifndef _WORDS_H +#define _WORDS_H + + +/* Other headers to be included */ + +#ifdef _WORDS + #define _ext +#else + #define _ext extern +#endif + + +/* Start of header body */ + +typedef unsigned char uchar; + +#if defined( __linux ) + #ifdef __KERNEL__ + #include <linux/types.h> + #else + #include <sys/types.h> + #endif +#else + typedef unsigned short ushort; + typedef unsigned int uint; + typedef unsigned long ulong; +#endif + +typedef double udouble; + +typedef unsigned char byte; +typedef unsigned short word; +typedef unsigned long longword; +typedef unsigned long dword; + + +#if !defined( __OS2__ ) && !defined( _Windows ) && \ + !defined( _WIN32 ) && !defined( __WIN32__ ) + + #ifndef BYTE + #define BYTE unsigned char + #endif + + #ifndef WORD + #define WORD unsigned short + #endif + + #ifndef LONG + #define LONG unsigned long + #endif + + #ifndef LONGWORD + #define LONGWORD longword + #endif +#endif + + +// a macro to swap the byte order of a 16 bit value +#define _bswap16( _x ) \ +( \ + ( ( ( (ushort) (_x) ) & 0x00FF ) << 8 ) | \ + ( ( ( (ushort) (_x) ) & 0xFF00 ) >> 8 ) \ +) + +// a macro to swap the byte order of a 32 bit value +#define _bswap32( _x ) \ +( \ + ( ( ( (ulong) (_x) ) & 0x000000FFUL ) << 24 ) | \ + ( ( ( (ulong) (_x) ) & 0x0000FF00UL ) << 8 ) | \ + ( ( ( (ulong) (_x) ) & 0x00FF0000UL ) >> 8 ) | \ + ( ( ( (ulong) (_x) ) & 0xFF000000UL ) >> 24 ) \ +) + +#define _var_bswap16( _v ) (_v) = _bswap16( _v ) +#define _var_bswap32( _v ) (_v) = _bswap32( _v ) + + +// The C51 compiler is big-endian, that means the most +// significant byte of a 16 or 32 bit value is stored in +// the lowest memory location. Most other systems are +// little-endian, so we must use macros to adjust the +// byte order if the C51 is used. + +#if defined _CC51 + #define _hilo_16( _x ) _bswap16( _x ) + #define _hilo_32( _x ) _bswap32( _x ) +#else + #define _hilo_16( _x ) (_x) + #define _hilo_32( _x ) (_x) +#endif + + + +/* End of header body */ + +#undef _ext + +#endif /* _WORDS_H */ |