summaryrefslogtreecommitdiffstats
path: root/Master/Masterarbeit/src/common/inc/global.h
blob: df3d812d461f72a233b038955e616f9190df6413 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*!
 * \file global.h
 * \author S. Eisenhauer
 * \date 31.08.2011
 * \brief Global include file
 *
 * This file is used in all other components
 * It defines
 * \li common datatypes
 * \li a macro for printing error messages to STDERR
 * \li a macro for printing debug messages to STDOUT when compiled with -DDEBUG_MODE
 *
 */

#ifndef GLOBAL_H_
#define GLOBAL_H_

#include <stdio.h>

#ifdef _MSC_VER

#define nLITTLE_ENDIAN_HOST

#include <boost/cstdint.hpp>
using boost::uint32_t;
using boost::int32_t;
using boost::uint8_t;
using boost::int8_t;

#ifdef DEBUG_MODE

#define DEBUG_PRINT(format, ...) \
		{ \
			static char message[512]; \
			sprintf_s(message,512,format, __VA_ARGS__); \
			fprintf(stdout, "[%s] line %d : %s\n", __FUNCTION__,__LINE__, message); \
			fflush(stdout); \
		}

#else /* !DEBUG_MODE */

#define DEBUG_PRINT(format, ...)

#endif /* !DEBUG_MODE */

#define ERROR_PRINT(format, ...) \
		{ \
			static char message[512]; \
			sprintf_s(message,512,format, __VA_ARGS__); \
			fprintf(stderr, "[%s] line %d : %s\n", __FUNCTION__,__LINE__, message); \
			fflush(stderr); \
		}

#else /* x2e embedded SDK*/

#include <stdint.h>
#ifdef DEBUG_MODE

#define DEBUG_PRINT(format, args...) \
		{ \
			static char message[512]; \
			snprintf(message,512,format, ##args); \
			fprintf(stdout, "[%s] line %d : %s\n", __PRETTY_FUNCTION__,__LINE__, message); \
			fflush(stdout); \
		}

#else /* !DEBUG_MODE */

#define DEBUG_PRINT(format, args...)

#endif /* !DEBUG_MODE */

#define ERROR_PRINT(format, args...) \
		{ \
			static char message[512]; \
			snprintf(message,512,format, ##args); \
			fprintf(stderr, "[%s] line %d : %s\n", __PRETTY_FUNCTION__,__LINE__, message); \
			fflush(stderr); \
		}
#endif /* _MSC_VER */

#ifdef nLITTLE_ENDIAN_HOST /* little endian macros, convert to big endian byte order */
#define BYTE_SWAP16(type,value) \
	( (type) ((0xff00 & val) >> 8) | ((0xff & val) << 8) )

#define BYTE_SWAP32(type,value) \
	( (type) ((0xff000000 & value) >> 24) | \
			((0x00ff0000 & value) >> 8) | \
			((0x0000ff00 & value) << 8) | \
			((0x000000ff & value) << 24) )

#define MAKE_INT32(a,b,c,d)		int32_t( ( ( (uint32_t) d ) << 24 ) | ( ( (uint32_t) c ) << 16 ) | ( ( (uint32_t) b ) << 8 ) | uint8_t(a)  )
#define MAKE_UINT32(a,b,c,d)	uint32_t( ( ( (uint32_t) d ) << 24 ) | ( ( (uint32_t) c ) << 16 ) | ( ( (uint32_t) b ) << 8 ) | uint8_t(a)  )
#define HIGH_BYTE(w) uint8_t( w >> 8  )
#define LOW_BYTE(w) uint8_t( w & 0xff )
#define HIGH_WORD(dw) uint16_t( dw >> 16 )
#define LOW_WORD(dw) uint16_t( dw & 0xffff )

#else /* big endian macros, keep byte order*/
#define BYTE_SWAP16(type,value) \
	( (type) value )

#define BYTE_SWAP32(type,value) \
	( (type) value )
	
#define MAKE_INT32(a,b,c,d)		int32_t( ( ( (uint32_t) a ) << 24 ) | ( ( (uint32_t) b ) << 16 ) | ( ( (uint32_t) c ) << 8 ) | uint8_t(d)  )
#define MAKE_UINT32(a,b,c,d)	uint32_t( ( ( (uint32_t) a ) << 24 ) | ( ( (uint32_t) b ) << 16 ) | ( ( (uint32_t) c ) << 8 ) | uint8_t(d)  )
#define HIGH_BYTE(w) uint8_t( w & 0xff )
#define LOW_BYTE(w) uint8_t( w >> 8  )
#define HIGH_WORD(dw) uint16_t( dw & 0xffff )
#define LOW_WORD(dw) uint16_t( dw >> 16 )

#endif /* nLITTLE_ENDIAN_HOST endianess macros */

#define nTIMER_INTERVAL_US (1000) //timer interval in mircoseconds
#define nMAX_SAFE_STACK (4*1024)

/*!
 * \brief Enumeration of used priotities
 */
enum tenPrio
{
	nenRT=80,	//!< real-time priority, above interrupts
	nenNORMAL=20, //!< normal priority
	nenLOW=10 //!< low priority
};

/*!
 * \brief Enumeration for error codes
 */
enum tenRetCodes
{
	nenOK, //!< no error
    nenERR_SOFILE, //!< shared object file could not be opened
    nenERR_SYMBOL, //!< symbol could not be found in shared object
    nenERR_MAKE, //!< Executing the generated Makefile resulted in error state
    nenERR_FTP, //!< An error occured in FTP operation
    nenERR_NOTIMPLEMENTED, //!< invoking an unimplemented method
    nenERR_MOVELOG, //!< error in log rotation
    nenERR_MAX_PLUGINS_REACHED //!< Maximum number of active plugins reached
};
/*!
 * \brief Enumeration for message direction
 */
enum tenMsgDirection
{
	nenRx = 0, //!< received message
	nenTx = 1  //!< sent message
};
/*!
* \brief Definition of a received message
*/
struct tstLogMessage
{
	uint32_t u32TsHigh; //!< Upper 32 Bit of the 64 Bit 100 ns Timestamp
	uint32_t u32TsLow; //!< Lower 32 Bit of the 64 Bit 100 ns Timestamp
	int32_t	 i32Interface; //!< Interface-Handle on which the message was received
	uint32_t u32MsgId; //!< ID of the received message
	uint8_t  au8Data[8]; //!< Data of the received message
	uint8_t	 u8Dir; //!< direction of message
};
#endif /* GLOBAL_H_ */