1142
|
1 |
/*****************************************************************************
|
|
2 |
*
|
|
3 |
* $Id$
|
|
4 |
*
|
|
5 |
****************************************************************************/
|
|
6 |
|
|
7 |
#include <sys/types.h>
|
|
8 |
|
|
9 |
/*****************************************************************************/
|
|
10 |
|
|
11 |
#define swap16(x) \
|
|
12 |
((uint16_t)( \
|
|
13 |
(((uint16_t)(x) & 0x00ffU) << 8) | \
|
|
14 |
(((uint16_t)(x) & 0xff00U) >> 8) ))
|
|
15 |
#define swap32(x) \
|
|
16 |
((uint32_t)( \
|
|
17 |
(((uint32_t)(x) & 0x000000ffUL) << 24) | \
|
|
18 |
(((uint32_t)(x) & 0x0000ff00UL) << 8) | \
|
|
19 |
(((uint32_t)(x) & 0x00ff0000UL) >> 8) | \
|
|
20 |
(((uint32_t)(x) & 0xff000000UL) >> 24) ))
|
|
21 |
|
|
22 |
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
23 |
|
|
24 |
#define le16tocpu(x) x
|
|
25 |
#define le32tocpu(x) x
|
|
26 |
|
|
27 |
#define cputole16(x) x
|
|
28 |
#define cputole32(x) x
|
|
29 |
|
|
30 |
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
31 |
|
|
32 |
#define le16tocpu(x) swap16(x)
|
|
33 |
#define le32tocpu(x) swap32(x)
|
|
34 |
|
|
35 |
#define cputole16(x) swap16(x)
|
|
36 |
#define cputole32(x) swap32(x)
|
|
37 |
|
|
38 |
#endif
|
|
39 |
|
|
40 |
/****************************************************************************/
|