blob: 678b8bad3b0bd2fa876af233b4ebbab3700b6527 (
plain) (
blame)
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
|
/*
* $Id$
*/
#ifndef _RTEMS_ENDIAN_H
#define _RTEMS_ENDIAN_H
#include <rtems.h>
/*
* BSD-style endian declaration
*/
#define BIG_ENDIAN 4321
#define LITTLE_ENDIAN 1234
#ifndef BYTE_ORDER
#if CPU_BIG_ENDIAN
# define BYTE_ORDER BIG_ENDIAN
#elif CPU_LITTLE_ENDIAN
# define BYTE_ORDER LITTLE_ENDIAN
#else
# error "Can't decide which end is which!"
#endif
#endif
#if ( CPU_BIG_ENDIAN == TRUE )
/*
* Very simply on big endian CPUs
*/
static inline uint32_t ntohl( uint32_t _x )
{
return _x;
}
static inline uint16_t ntohs( uint16_t _x )
{
return _x;
}
static inline uint32_t htonl( uint32_t _x )
{
return _x;
}
static inline uint16_t htons( uint16_t _x )
{
return _x;
}
#define NTOHS(x)
#define HTONS(x)
#define NTOHL(x)
#define HTONL(x)
#elif ( CPU_LITTLE_ENDIAN == TRUE )
/*
* A little more complicated on little endian CPUs
*/
static inline uint32_t ntohl( uint32_t _x )
{
return CPU_swap_u32(_x);
}
static inline uint16_t ntohs( uint16_t _x )
{
return CPU_swap_u16(_x);
}
static inline uint32_t htonl( uint32_t _x )
{
return CPU_swap_u32(_x);
}
static inline uint16_t htons( uint16_t _x )
{
return CPU_swap_u16(_x);
}
#define NTOHS(x) (x) = ntohs(x)
#define HTONS(x) (x) = htons(x)
#define NTOHL(x) (x) = ntohl(x)
#define HTONL(x) (x) = htonl(x)
#else
#error "Unknown endian-ness for this cpu"
#endif
#endif /* _RTEMS_ENDIAN_H */
|