/*! * \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 #ifdef _MSC_VER #define nLITTLE_ENDIAN_HOST #include 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 #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_ */