2 * local version of endian.h - byte order defines
4 * Copyright 2004, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
20 /* Byte swap a 16 bit value */
21 #define BCMSWAP16(val) \
23 (((uint16)(val) & (uint16)0x00ffU) << 8) | \
24 (((uint16)(val) & (uint16)0xff00U) >> 8) ))
26 /* Byte swap a 32 bit value */
27 #define BCMSWAP32(val) \
29 (((uint32)(val) & (uint32)0x000000ffUL) << 24) | \
30 (((uint32)(val) & (uint32)0x0000ff00UL) << 8) | \
31 (((uint32)(val) & (uint32)0x00ff0000UL) >> 8) | \
32 (((uint32)(val) & (uint32)0xff000000UL) >> 24) ))
37 return BCMSWAP16(val
);
43 return BCMSWAP32(val
);
46 /* buf - start of buffer of shorts to swap */
47 /* len - byte length of buffer */
49 bcmswap16_buf(uint16
*buf
, uint len
)
54 *buf
= bcmswap16(*buf
);
61 #define HTON16(i) BCMSWAP16(i)
62 #define hton16(i) bcmswap16(i)
63 #define hton32(i) bcmswap32(i)
64 #define ntoh16(i) bcmswap16(i)
65 #define ntoh32(i) bcmswap32(i)
76 #define ltoh16(i) bcmswap16(i)
77 #define ltoh32(i) bcmswap32(i)
78 #define htol16(i) bcmswap16(i)
79 #define htol32(i) bcmswap32(i)
84 #define ltoh16_buf(buf, i)
85 #define htol16_buf(buf, i)
87 #define ltoh16_buf(buf, i) bcmswap16_buf((uint16*)buf, i)
88 #define htol16_buf(buf, i) bcmswap16_buf((uint16*)buf, i)
92 * load 16-bit value from unaligned little endian byte array.
95 ltoh16_ua(uint8
*bytes
)
97 return (bytes
[1]<<8)+bytes
[0];
101 * load 32-bit value from unaligned little endian byte array.
104 ltoh32_ua(uint8
*bytes
)
106 return (bytes
[3]<<24)+(bytes
[2]<<16)+(bytes
[1]<<8)+bytes
[0];
110 * load 16-bit value from unaligned big(network) endian byte array.
113 ntoh16_ua(uint8
*bytes
)
115 return (bytes
[0]<<8)+bytes
[1];
119 * load 32-bit value from unaligned big(network) endian byte array.
122 ntoh32_ua(uint8
*bytes
)
124 return (bytes
[0]<<24)+(bytes
[1]<<16)+(bytes
[2]<<8)+bytes
[3];
127 #endif /* _BCMENDIAN_H_ */
This page took 0.053186 seconds and 5 git commands to generate.