2017-10-25 20:28:13 +02:00
|
|
|
/*
|
|
|
|
* Licensed under the GNU General Public License version 2 with exceptions. See
|
|
|
|
* LICENSE file in the project root for full license information
|
|
|
|
*/
|
|
|
|
|
2015-05-07 16:25:17 +02:00
|
|
|
#ifndef CC_H
|
|
|
|
#define CC_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
2017-10-25 20:28:13 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <sys/param.h>
|
2017-10-15 15:50:50 +02:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <endian.h>
|
|
|
|
#else
|
|
|
|
#include <machine/endian.h>
|
|
|
|
#endif
|
2015-05-07 16:25:17 +02:00
|
|
|
|
|
|
|
#define CC_PACKED_BEGIN
|
|
|
|
#define CC_PACKED_END
|
|
|
|
#define CC_PACKED __attribute__((packed))
|
|
|
|
|
|
|
|
#define CC_ASSERT(exp) assert (exp)
|
|
|
|
#define CC_STATIC_ASSERT(exp) _Static_assert (exp, "")
|
|
|
|
|
2017-11-07 08:43:56 +01:00
|
|
|
#define CC_DEPRECATED __attribute__((deprecated))
|
|
|
|
|
2015-05-07 16:25:17 +02:00
|
|
|
#define CC_SWAP32(x) __builtin_bswap32 (x)
|
|
|
|
#define CC_SWAP16(x) ((uint16_t)(x) >> 8 | ((uint16_t)(x) & 0xFF) << 8)
|
|
|
|
|
2017-10-27 17:36:24 +02:00
|
|
|
#define CC_ATOMIC_SET(var,val) __atomic_store_n(&var,val,__ATOMIC_SEQ_CST)
|
|
|
|
#define CC_ATOMIC_GET(var) __atomic_load_n(&var,__ATOMIC_SEQ_CST)
|
|
|
|
#define CC_ATOMIC_ADD(var,val) __atomic_add_fetch(&var,val,__ATOMIC_SEQ_CST)
|
|
|
|
#define CC_ATOMIC_SUB(var,val) __atomic_sub_fetch(&var,val,__ATOMIC_SEQ_CST)
|
|
|
|
#define CC_ATOMIC_AND(var,val) __atomic_and_fetch(&var,val,__ATOMIC_SEQ_CST)
|
|
|
|
#define CC_ATOMIC_OR(var,val) __atomic_or_fetch(&var,val,__ATOMIC_SEQ_CST)
|
|
|
|
|
2015-05-25 16:53:19 +02:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2015-05-07 16:25:17 +02:00
|
|
|
#define htoes(x) CC_SWAP16 (x)
|
|
|
|
#define htoel(x) CC_SWAP32 (x)
|
|
|
|
#else
|
|
|
|
#define htoes(x) (x)
|
|
|
|
#define htoel(x) (x)
|
|
|
|
#endif
|
|
|
|
|
2015-05-25 16:53:19 +02:00
|
|
|
#define etohs(x) htoes (x)
|
|
|
|
#define etohl(x) htoel (x)
|
|
|
|
|
2015-05-18 16:54:09 +02:00
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
|
|
#define EC_LITTLE_ENDIAN
|
|
|
|
#else
|
|
|
|
#define EC_BIG_ENDIAN
|
|
|
|
#endif
|
|
|
|
|
2015-05-07 17:43:02 +02:00
|
|
|
#ifdef ESC_DEBUG
|
|
|
|
#define DPRINT(...) rprintp ("esc_foe: "__VA_ARGS__) /* TODO */
|
|
|
|
#else
|
|
|
|
#define DPRINT(...)
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2015-05-07 16:25:17 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CC_H */
|