summaryrefslogtreecommitdiff
path: root/c/mbglib/include/words.h
diff options
context:
space:
mode:
Diffstat (limited to 'c/mbglib/include/words.h')
-rw-r--r--c/mbglib/include/words.h192
1 files changed, 167 insertions, 25 deletions
diff --git a/c/mbglib/include/words.h b/c/mbglib/include/words.h
index 9597b8a..ab77508 100644
--- a/c/mbglib/include/words.h
+++ b/c/mbglib/include/words.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: words.h 1.9 2003/02/07 11:36:54Z MARTIN TRASH $
+ * $Id: words.h 1.16 2008/12/05 12:05:41Z martin REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,7 +10,27 @@
*
* -----------------------------------------------------------------------
* $Log: words.h $
- * Revision 1.9 2003/02/07 11:36:54Z MARTIN
+ * Revision 1.16 2008/12/05 12:05:41Z martin
+ * Define dummy int64_t/uint64_t types for targets
+ * which don't support 64 bit data types.
+ * Revision 1.15 2008/07/14 14:44:00Z martin
+ * Use fixed size C99 types which come with GCC and newer Borland compilers.
+ * Revision 1.14 2008/01/30 10:27:50Z martin
+ * Moved some macro definitions here.
+ * Revision 1.13 2007/03/08 15:00:30Z martin
+ * Fixed incompatibility of macro _IS_MBG_FIRMWARE.
+ * Added a workaround for _IS_MBG_FIRMWARE under CVI.
+ * Support for BSD.
+ * Revision 1.12 2006/12/15 10:45:46 martin
+ * Added macro _IS_MBG_FIRMWARE.
+ * Cleanup for Linux, QNX, and Watcom C.
+ * Include mbg_tgt.h for non-firmware targets.
+ * Revision 1.11 2004/11/10 10:45:34 martin
+ * Added C99 fixed-type handling for QNX.
+ * Revision 1.10 2004/11/09 13:12:56 martin
+ * Redefined C99 integer types with fixed sizes as standard types
+ * if required, depending on the environment.
+ * Revision 1.9 2003/02/07 11:36:54 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().
@@ -36,6 +56,30 @@
/* Other headers to be included */
+
+#if defined( _CVI )
+ // This is a hack for CVI which seems to be unable
+ // to handle recursive preprocessor symbols.
+ #define _IS_MBG_FIRMWARE 0
+#endif
+
+#if !defined( _IS_MBG_FIRMWARE )
+
+ #define _IS_MBG_FIRMWARE \
+ ( \
+ defined( _C166 ) || \
+ defined( _CC51 ) || \
+ defined( __ARM ) \
+ )
+
+
+#endif
+
+#if !_IS_MBG_FIRMWARE
+ #include <mbg_tgt.h>
+#endif
+
+
#ifdef _WORDS
#define _ext
#else
@@ -45,15 +89,125 @@
/* Start of header body */
-typedef unsigned char uchar;
-#if defined( __linux )
- #ifdef __KERNEL__
+// Check whether the target system supports C99 fixed-size types.
+
+#if defined( MBG_TGT_LINUX ) // any Linux target
+
+ #if defined( __KERNEL__ )
#include <linux/types.h>
#else
+ #include <stdint.h>
#include <sys/types.h>
#endif
+
+ #define _C99_BIT_TYPES_DEFINED 1
+
+#elif defined( MBG_TGT_BSD )
+
+ #include <sys/types.h>
+
+ #define _C99_BIT_TYPES_DEFINED 1
+
+#elif defined( MBG_TGT_QNX ) // QNX 4.x or QNX 6.x
+
+ #if defined( MBG_TGT_QNX_NTO ) // QNX 6.x (Neutrino) with gcc
+ #include <stdint.h>
+ #else // QNX 4.x with Watcom C 10.6
+ #include <sys/types.h> // 64 bit types not supported
+ #endif
+
+ #define _C99_BIT_TYPES_DEFINED 1
+
+#endif
+
+
+// If it's not yet clear whether fixed-size types are supported,
+// check the build environment which may be multi-platform.
+
+#if !defined( _C99_BIT_TYPES_DEFINED )
+
+ #if defined( __WATCOMC__ )
+ #if __WATCOMC__ > 1230 // Open Watcom C 1.3 and above
+ #include <stdint.h>
+ #define _C99_BIT_TYPES_DEFINED 1
+ #elif defined( __WATCOM_INT64__ ) // Watcom C 11, non-QNX
+ typedef __int64 int64_t;
+ typedef unsigned __int64 uint64_t;
+
+ #define _C99_BIT_TYPES_DEFINED 1
+ #endif
+ #endif
+
+ #if defined( __BORLANDC__ )
+ #if ( __BORLANDC__ >= 0x570 ) // at least Borland Developer Studio 2006
+ #define _C99_BIT_TYPES_DEFINED 1
+ #endif
+ #endif
+
+ #if defined( __GNUC__ )
+ #include <stdint.h>
+ #define _C99_BIT_TYPES_DEFINED 1
+ #endif
+
+#endif
+
+
+// If neither the target system nor the build environment define C99 fixed-size
+// types define those types based on standard types with the proper sizes
+// commonly used in 16/32 bit environments.
+
+#if defined( _C99_BIT_TYPES_DEFINED )
+
+ #define MBG_TGT_HAS_64BIT_TYPES 1
+
#else
+
+ typedef char int8_t;
+ typedef unsigned char uint8_t;
+
+ typedef short int16_t;
+ typedef unsigned short uint16_t;
+
+ typedef long int32_t;
+ typedef unsigned long uint32_t;
+
+
+ #if defined( MBG_TGT_WIN32 )
+
+ typedef __int64 int64_t;
+ typedef unsigned __int64 uint64_t;
+
+ #define MBG_TGT_HAS_64BIT_TYPES 1
+
+ #else
+ // The types below are required to avoid build errors
+ // if these types are formally used in function prototypes.
+ // We explicitely use abnormal data types to hopefully
+ // cause compiler errors in case these types are
+ // unexpectedly used to generate real code for a target
+ // platform which does not support 64 bit types.
+ typedef void *int64_t;
+ typedef void *uint64_t;
+ #endif
+
+#endif
+
+
+
+#if !defined( MBG_TGT_HAS_64BIT_TYPES )
+
+ #define MBG_TGT_HAS_64BIT_TYPES 0
+
+#endif
+
+
+
+// Some commonly used types
+
+typedef unsigned char uchar;
+
+#if !defined( MBG_TGT_LINUX )
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
@@ -67,25 +221,15 @@ typedef unsigned long longword;
typedef unsigned long dword;
-#if !defined( __OS2__ ) && !defined( _Windows ) && \
- !defined( _WIN32 ) && !defined( __WIN32__ )
+#define HI_BYTE( _x ) ( (_x) >> 8 )
+#define LO_BYTE( _x ) ( (_x) & 0xFF )
- #ifndef BYTE
- #define BYTE unsigned char
- #endif
+#define HI_WORD( _x ) ( (_x) >> 16 )
+#define LO_WORD( _x ) ( (_x) & 0xFFFF )
- #ifndef WORD
- #define WORD unsigned short
- #endif
-
- #ifndef LONG
- #define LONG unsigned long
- #endif
-
- #ifndef LONGWORD
- #define LONGWORD longword
- #endif
-#endif
+// the macros below assume little endianess
+#define BYTE_OF( _x, _n ) *( ( (uint8_t *) &(_x) ) + (_n) )
+#define WORD_OF( _x, _n ) *( ( (uint16_t *) &(_x) ) + (_n) )
// a macro to swap the byte order of a 16 bit value
@@ -114,7 +258,7 @@ typedef unsigned long dword;
// little-endian, so we must use macros to adjust the
// byte order if the C51 is used.
-#if defined _CC51
+#if defined( _CC51 )
#define _hilo_16( _x ) _bswap16( _x )
#define _hilo_32( _x ) _bswap32( _x )
#else
@@ -122,8 +266,6 @@ typedef unsigned long dword;
#define _hilo_32( _x ) (_x)
#endif
-
-
/* End of header body */
#undef _ext