34#ifndef _RTEMS_ENDIAN_H
35#define _RTEMS_ENDIAN_H
39#include <machine/endian.h>
41#ifndef _BYTEORDER_FUNC_DEFINED
42#define _BYTEORDER_FUNC_DEFINED
43#define htonl(x) __htonl(x)
44#define htons(x) __htons(x)
45#define ntohl(x) __ntohl(x)
46#define ntohs(x) __ntohs(x)
49#define NTOHS(x) (x) = ntohs(x)
50#define HTONS(x) (x) = htons(x)
51#define NTOHL(x) (x) = ntohl(x)
52#define HTONL(x) (x) = htonl(x)
54static inline uint16_t rtems_uint16_from_little_endian(
const uint8_t *data)
59 for (i = 1; i >= 0; --i) {
60 value = (uint16_t) ((value << 8) + data [i]);
66static inline uint32_t rtems_uint32_from_little_endian(
const uint8_t *data)
71 for (i = 3; i >= 0; --i) {
72 value = (value << 8) + data [i];
78static inline uint64_t rtems_uint64_from_little_endian(
const uint8_t *data)
83 for (i = 7; i >= 0; --i) {
84 value = (value << 8) + (uint64_t) data [i];
90static inline uint16_t rtems_uint16_from_big_endian(
const uint8_t *data)
95 for (i = 0; i < 2; ++i) {
96 value = (uint16_t) ((value << 8) + data [i]);
102static inline uint32_t rtems_uint32_from_big_endian(
const uint8_t *data)
107 for (i = 0; i < 4; ++i) {
108 value = (value << 8) + (uint32_t) data [i];
114static inline uint64_t rtems_uint64_from_big_endian(
const uint8_t *data)
119 for (i = 0; i < 8; ++i) {
120 value = (value << 8) + (uint64_t) data [i];
126static inline void rtems_uint16_to_little_endian( uint16_t value, uint8_t *data)
130 for (i = 0; i < 2; ++i) {
131 data [i] = (uint8_t) value;
136static inline void rtems_uint32_to_little_endian( uint32_t value, uint8_t *data)
140 for (i = 0; i < 4; ++i) {
141 data [i] = (uint8_t) value;
146static inline void rtems_uint64_to_little_endian( uint64_t value, uint8_t *data)
150 for (i = 0; i < 8; ++i) {
151 data [i] = (uint8_t) value;
156static inline void rtems_uint16_to_big_endian( uint16_t value, uint8_t *data)
160 for (i = 1; i >= 0; --i) {
161 data [i] = (uint8_t) value;
166static inline void rtems_uint32_to_big_endian( uint32_t value, uint8_t *data)
170 for (i = 3; i >= 0; --i) {
171 data [i] = (uint8_t) value;
176static inline void rtems_uint64_to_big_endian( uint64_t value, uint8_t *data)
180 for (i = 7; i >= 0; --i) {
181 data [i] = (uint8_t) value;