4.104.114.84.95
Last change
on this file since 7a4e32f4 was
7a4e32f4,
checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/09/07 at 16:27:09
|
2007-05-09 Ralf Corsépius <ralf.corsepius@…>
- include/rtems/endian.h: New (Copied from
libnetworking/machine/endian.h).
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | /* |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #ifndef _RTEMS_ENDIAN_H |
---|
6 | #define _RTEMS_ENDIAN_H |
---|
7 | |
---|
8 | #include <rtems.h> |
---|
9 | |
---|
10 | /* |
---|
11 | * BSD-style endian declaration |
---|
12 | */ |
---|
13 | #define BIG_ENDIAN 4321 |
---|
14 | #define LITTLE_ENDIAN 1234 |
---|
15 | |
---|
16 | #ifndef BYTE_ORDER |
---|
17 | #if CPU_BIG_ENDIAN |
---|
18 | # define BYTE_ORDER BIG_ENDIAN |
---|
19 | #elif CPU_LITTLE_ENDIAN |
---|
20 | # define BYTE_ORDER LITTLE_ENDIAN |
---|
21 | #else |
---|
22 | # error "Can't decide which end is which!" |
---|
23 | #endif |
---|
24 | #endif |
---|
25 | |
---|
26 | #if ( CPU_BIG_ENDIAN == TRUE ) |
---|
27 | |
---|
28 | /* |
---|
29 | * Very simply on big endian CPUs |
---|
30 | */ |
---|
31 | |
---|
32 | static inline uint32_t ntohl( uint32_t _x ) |
---|
33 | { |
---|
34 | return _x; |
---|
35 | } |
---|
36 | |
---|
37 | static inline uint16_t ntohs( uint16_t _x ) |
---|
38 | { |
---|
39 | return _x; |
---|
40 | } |
---|
41 | |
---|
42 | static inline uint32_t htonl( uint32_t _x ) |
---|
43 | { |
---|
44 | return _x; |
---|
45 | } |
---|
46 | |
---|
47 | static inline uint16_t htons( uint16_t _x ) |
---|
48 | { |
---|
49 | return _x; |
---|
50 | } |
---|
51 | |
---|
52 | #define NTOHS(x) |
---|
53 | #define HTONS(x) |
---|
54 | #define NTOHL(x) |
---|
55 | #define HTONL(x) |
---|
56 | |
---|
57 | #elif ( CPU_LITTLE_ENDIAN == TRUE ) |
---|
58 | |
---|
59 | /* |
---|
60 | * A little more complicated on little endian CPUs |
---|
61 | */ |
---|
62 | |
---|
63 | static inline uint32_t ntohl( uint32_t _x ) |
---|
64 | { |
---|
65 | return CPU_swap_u32(_x); |
---|
66 | } |
---|
67 | |
---|
68 | static inline uint16_t ntohs( uint16_t _x ) |
---|
69 | { |
---|
70 | return CPU_swap_u16(_x); |
---|
71 | } |
---|
72 | |
---|
73 | static inline uint32_t htonl( uint32_t _x ) |
---|
74 | { |
---|
75 | return CPU_swap_u32(_x); |
---|
76 | } |
---|
77 | |
---|
78 | static inline uint16_t htons( uint16_t _x ) |
---|
79 | { |
---|
80 | return CPU_swap_u16(_x); |
---|
81 | } |
---|
82 | |
---|
83 | #define NTOHS(x) (x) = ntohs(x) |
---|
84 | #define HTONS(x) (x) = htons(x) |
---|
85 | #define NTOHL(x) (x) = ntohl(x) |
---|
86 | #define HTONL(x) (x) = htonl(x) |
---|
87 | |
---|
88 | #else |
---|
89 | #error "Unknown endian-ness for this cpu" |
---|
90 | #endif |
---|
91 | |
---|
92 | #endif /* _RTEMS_ENDIAN_H */ |
---|
Note: See
TracBrowser
for help on using the repository browser.