cpu_endian.h File Reference

Byte order conversion. More...

#include "os_port.h"

Go to the source code of this file.

Macros

#define LOAD16LE(p)
 
#define LOAD16BE(p)
 
#define LOAD24LE(p)
 
#define LOAD24BE(p)
 
#define LOAD32LE(p)
 
#define LOAD32BE(p)
 
#define LOAD48LE(p)
 
#define LOAD48BE(p)
 
#define LOAD64LE(p)
 
#define LOAD64BE(p)
 
#define STORE16LE(a, p)
 
#define STORE16BE(a, p)
 
#define STORE24LE(a, p)
 
#define STORE24BE(a, p)
 
#define STORE32LE(a, p)
 
#define STORE32BE(a, p)
 
#define STORE48LE(a, p)
 
#define STORE48BE(a, p)
 
#define STORE64LE(a, p)
 
#define STORE64BE(a, p)
 
#define SWAPINT16(x)
 
#define SWAPINT32(x)
 
#define SWAPINT64(x)
 
#define HTONS(value)   SWAPINT16(value)
 
#define HTONL(value)   SWAPINT32(value)
 
#define htons(value)   swapInt16((uint16_t) (value))
 
#define htonl(value)   swapInt32((uint32_t) (value))
 
#define NTOHS(value)   SWAPINT16(value)
 
#define NTOHL(value)   SWAPINT32(value)
 
#define ntohs(value)   swapInt16((uint16_t) (value))
 
#define ntohl(value)   swapInt32((uint32_t) (value))
 
#define HTOLE16(value)   (value)
 
#define HTOLE32(value)   (value)
 
#define HTOLE64(value)   (value)
 
#define htole16(value)   ((uint16_t) (value))
 
#define htole32(value)   ((uint32_t) (value))
 
#define htole64(value)   ((uint64_t) (value))
 
#define LETOH16(value)   (value)
 
#define LETOH32(value)   (value)
 
#define LETOH64(value)   (value)
 
#define letoh16(value)   ((uint16_t) (value))
 
#define letoh32(value)   ((uint32_t) (value))
 
#define letoh64(value)   ((uint64_t) (value))
 
#define HTOBE16(value)   SWAPINT16(value)
 
#define HTOBE32(value)   SWAPINT32(value)
 
#define HTOBE64(value)   SWAPINT64(value)
 
#define htobe16(value)   swapInt16((uint16_t) (value))
 
#define htobe32(value)   swapInt32((uint32_t) (value))
 
#define htobe64(value)   swapInt64((uint64_t) (value))
 
#define BETOH16(value)   SWAPINT16(value)
 
#define BETOH32(value)   SWAPINT32(value)
 
#define BETOH64(value)   SWAPINT64(value)
 
#define betoh16(value)   swapInt16((uint16_t) (value))
 
#define betoh32(value)   swapInt32((uint32_t) (value))
 
#define betoh64(value)   swapInt64((uint64_t) (value))
 

Functions

uint16_t swapInt16 (uint16_t value)
 Reverse the byte order of a 16-bit word. More...
 
uint32_t swapInt32 (uint32_t value)
 Reverse the byte order of a 32-bit word. More...
 
uint64_t swapInt64 (uint64_t value)
 Reverse the byte order of a 64-bit word. More...
 
uint8_t reverseInt4 (uint8_t value)
 Reverse bit order in a 4-bit word. More...
 
uint8_t reverseInt8 (uint8_t value)
 Reverse bit order in a byte. More...
 
uint16_t reverseInt16 (uint16_t value)
 Reverse bit order in a 16-bit word. More...
 
uint32_t reverseInt32 (uint32_t value)
 Reverse bit order in a 32-bit word. More...
 
uint64_t reverseInt64 (uint64_t value)
 Reverse bit order in a 64-bit word. More...
 

Detailed Description

Byte order conversion.

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file cpu_endian.h.

Macro Definition Documentation

◆ BETOH16

#define BETOH16 (   value)    SWAPINT16(value)

Definition at line 424 of file cpu_endian.h.

◆ betoh16

#define betoh16 (   value)    swapInt16((uint16_t) (value))

Definition at line 427 of file cpu_endian.h.

◆ BETOH32

#define BETOH32 (   value)    SWAPINT32(value)

Definition at line 425 of file cpu_endian.h.

◆ betoh32

#define betoh32 (   value)    swapInt32((uint32_t) (value))

Definition at line 428 of file cpu_endian.h.

◆ BETOH64

#define BETOH64 (   value)    SWAPINT64(value)

Definition at line 426 of file cpu_endian.h.

◆ betoh64

#define betoh64 (   value)    swapInt64((uint64_t) (value))

Definition at line 429 of file cpu_endian.h.

◆ HTOBE16

#define HTOBE16 (   value)    SWAPINT16(value)

Definition at line 416 of file cpu_endian.h.

◆ htobe16

#define htobe16 (   value)    swapInt16((uint16_t) (value))

Definition at line 419 of file cpu_endian.h.

◆ HTOBE32

#define HTOBE32 (   value)    SWAPINT32(value)

Definition at line 417 of file cpu_endian.h.

◆ htobe32

#define htobe32 (   value)    swapInt32((uint32_t) (value))

Definition at line 420 of file cpu_endian.h.

◆ HTOBE64

#define HTOBE64 (   value)    SWAPINT64(value)

Definition at line 418 of file cpu_endian.h.

◆ htobe64

#define htobe64 (   value)    swapInt64((uint64_t) (value))

Definition at line 421 of file cpu_endian.h.

◆ HTOLE16

#define HTOLE16 (   value)    (value)

Definition at line 400 of file cpu_endian.h.

◆ htole16

#define htole16 (   value)    ((uint16_t) (value))

Definition at line 403 of file cpu_endian.h.

◆ HTOLE32

#define HTOLE32 (   value)    (value)

Definition at line 401 of file cpu_endian.h.

◆ htole32

#define htole32 (   value)    ((uint32_t) (value))

Definition at line 404 of file cpu_endian.h.

◆ HTOLE64

#define HTOLE64 (   value)    (value)

Definition at line 402 of file cpu_endian.h.

◆ htole64

#define htole64 (   value)    ((uint64_t) (value))

Definition at line 405 of file cpu_endian.h.

◆ HTONL

#define HTONL (   value)    SWAPINT32(value)

Definition at line 389 of file cpu_endian.h.

◆ htonl

#define htonl (   value)    swapInt32((uint32_t) (value))

Definition at line 391 of file cpu_endian.h.

◆ HTONS

#define HTONS (   value)    SWAPINT16(value)

Definition at line 388 of file cpu_endian.h.

◆ htons

#define htons (   value)    swapInt16((uint16_t) (value))

Definition at line 390 of file cpu_endian.h.

◆ LETOH16

#define LETOH16 (   value)    (value)

Definition at line 408 of file cpu_endian.h.

◆ letoh16

#define letoh16 (   value)    ((uint16_t) (value))

Definition at line 411 of file cpu_endian.h.

◆ LETOH32

#define LETOH32 (   value)    (value)

Definition at line 409 of file cpu_endian.h.

◆ letoh32

#define letoh32 (   value)    ((uint32_t) (value))

Definition at line 412 of file cpu_endian.h.

◆ LETOH64

#define LETOH64 (   value)    (value)

Definition at line 410 of file cpu_endian.h.

◆ letoh64

#define letoh64 (   value)    ((uint64_t) (value))

Definition at line 413 of file cpu_endian.h.

◆ LOAD16BE

#define LOAD16BE (   p)
Value:
( \
((uint16_t)(((uint8_t *)(p))[0]) << 8) | \
((uint16_t)(((uint8_t *)(p))[1]) << 0))
uint8_t p
Definition: ndp.h:295

Definition at line 168 of file cpu_endian.h.

◆ LOAD16LE

#define LOAD16LE (   p)
Value:
( \
((uint16_t)(((uint8_t *)(p))[0]) << 0) | \
((uint16_t)(((uint8_t *)(p))[1]) << 8))
uint8_t p
Definition: ndp.h:295

Definition at line 163 of file cpu_endian.h.

◆ LOAD24BE

#define LOAD24BE (   p)
Value:
( \
((uint32_t)(((uint8_t *)(p))[0]) << 16) | \
((uint32_t)(((uint8_t *)(p))[1]) << 8) | \
((uint32_t)(((uint8_t *)(p))[2]) << 0))
uint8_t p
Definition: ndp.h:295

Definition at line 179 of file cpu_endian.h.

◆ LOAD24LE

#define LOAD24LE (   p)
Value:
( \
((uint32_t)(((uint8_t *)(p))[0]) << 0)| \
((uint32_t)(((uint8_t *)(p))[1]) << 8) | \
((uint32_t)(((uint8_t *)(p))[2]) << 16))
uint8_t p
Definition: ndp.h:295

Definition at line 173 of file cpu_endian.h.

◆ LOAD32BE

#define LOAD32BE (   p)
Value:
( \
((uint32_t)(((uint8_t *)(p))[0]) << 24) | \
((uint32_t)(((uint8_t *)(p))[1]) << 16) | \
((uint32_t)(((uint8_t *)(p))[2]) << 8) | \
((uint32_t)(((uint8_t *)(p))[3]) << 0))
uint8_t p
Definition: ndp.h:295

Definition at line 192 of file cpu_endian.h.

◆ LOAD32LE

#define LOAD32LE (   p)
Value:
( \
((uint32_t)(((uint8_t *)(p))[0]) << 0) | \
((uint32_t)(((uint8_t *)(p))[1]) << 8) | \
((uint32_t)(((uint8_t *)(p))[2]) << 16) | \
((uint32_t)(((uint8_t *)(p))[3]) << 24))
uint8_t p
Definition: ndp.h:295

Definition at line 185 of file cpu_endian.h.

◆ LOAD48BE

#define LOAD48BE (   p)
Value:
( \
((uint64_t)(((uint8_t *)(p))[0]) << 40) | \
((uint64_t)(((uint8_t *)(p))[1]) << 32) | \
((uint64_t)(((uint8_t *)(p))[2]) << 24) | \
((uint64_t)(((uint8_t *)(p))[3]) << 16) | \
((uint64_t)(((uint8_t *)(p))[4]) << 8) | \
((uint64_t)(((uint8_t *)(p))[5]) << 0))
uint8_t p
Definition: ndp.h:295

Definition at line 208 of file cpu_endian.h.

◆ LOAD48LE

#define LOAD48LE (   p)
Value:
( \
((uint64_t)(((uint8_t *)(p))[0]) << 0) | \
((uint64_t)(((uint8_t *)(p))[1]) << 8) | \
((uint64_t)(((uint8_t *)(p))[2]) << 16) | \
((uint64_t)(((uint8_t *)(p))[3]) << 24) | \
((uint64_t)(((uint8_t *)(p))[4]) << 32) | \
((uint64_t)(((uint8_t *)(p))[5]) << 40)
uint8_t p
Definition: ndp.h:295

Definition at line 199 of file cpu_endian.h.

◆ LOAD64BE

#define LOAD64BE (   p)
Value:
( \
((uint64_t)(((uint8_t *)(p))[0]) << 56) | \
((uint64_t)(((uint8_t *)(p))[1]) << 48) | \
((uint64_t)(((uint8_t *)(p))[2]) << 40) | \
((uint64_t)(((uint8_t *)(p))[3]) << 32) | \
((uint64_t)(((uint8_t *)(p))[4]) << 24) | \
((uint64_t)(((uint8_t *)(p))[5]) << 16) | \
((uint64_t)(((uint8_t *)(p))[6]) << 8) | \
((uint64_t)(((uint8_t *)(p))[7]) << 0))
uint8_t p
Definition: ndp.h:295

Definition at line 228 of file cpu_endian.h.

◆ LOAD64LE

#define LOAD64LE (   p)
Value:
( \
((uint64_t)(((uint8_t *)(p))[0]) << 0) | \
((uint64_t)(((uint8_t *)(p))[1]) << 8) | \
((uint64_t)(((uint8_t *)(p))[2]) << 16) | \
((uint64_t)(((uint8_t *)(p))[3]) << 24) | \
((uint64_t)(((uint8_t *)(p))[4]) << 32) | \
((uint64_t)(((uint8_t *)(p))[5]) << 40) | \
((uint64_t)(((uint8_t *)(p))[6]) << 48) | \
((uint64_t)(((uint8_t *)(p))[7]) << 56))
uint8_t p
Definition: ndp.h:295

Definition at line 217 of file cpu_endian.h.

◆ NTOHL

#define NTOHL (   value)    SWAPINT32(value)

Definition at line 395 of file cpu_endian.h.

◆ ntohl

#define ntohl (   value)    swapInt32((uint32_t) (value))

Definition at line 397 of file cpu_endian.h.

◆ NTOHS

#define NTOHS (   value)    SWAPINT16(value)

Definition at line 394 of file cpu_endian.h.

◆ ntohs

#define ntohs (   value)    swapInt16((uint16_t) (value))

Definition at line 396 of file cpu_endian.h.

◆ STORE16BE

#define STORE16BE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint16_t)(a) >> 8) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint16_t)(a) >> 0) & 0xFFU
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 244 of file cpu_endian.h.

◆ STORE16LE

#define STORE16LE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint16_t)(a) >> 0) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint16_t)(a) >> 8) & 0xFFU
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 239 of file cpu_endian.h.

◆ STORE24BE

#define STORE24BE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint32_t)(a) >> 16) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint32_t)(a) >> 8) & 0xFFU, \
((uint8_t *)(p))[2] = ((uint32_t)(a) >> 0) & 0xFFU
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 255 of file cpu_endian.h.

◆ STORE24LE

#define STORE24LE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint32_t)(a) >> 0) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint32_t)(a) >> 8) & 0xFFU, \
((uint8_t *)(p))[2] = ((uint32_t)(a) >> 16) & 0xFFU
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 249 of file cpu_endian.h.

◆ STORE32BE

#define STORE32BE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint32_t)(a) >> 24) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint32_t)(a) >> 16) & 0xFFU, \
((uint8_t *)(p))[2] = ((uint32_t)(a) >> 8) & 0xFFU, \
((uint8_t *)(p))[3] = ((uint32_t)(a) >> 0) & 0xFFU
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 268 of file cpu_endian.h.

◆ STORE32LE

#define STORE32LE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint32_t)(a) >> 0) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint32_t)(a) >> 8) & 0xFFU, \
((uint8_t *)(p))[2] = ((uint32_t)(a) >> 16) & 0xFFU, \
((uint8_t *)(p))[3] = ((uint32_t)(a) >> 24) & 0xFFU
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 261 of file cpu_endian.h.

◆ STORE48BE

#define STORE48BE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint64_t)(a) >> 40) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint64_t)(a) >> 32) & 0xFFU, \
((uint8_t *)(p))[2] = ((uint64_t)(a) >> 24) & 0xFFU, \
((uint8_t *)(p))[3] = ((uint64_t)(a) >> 16) & 0xFFU, \
((uint8_t *)(p))[4] = ((uint64_t)(a) >> 8) & 0xFFU, \
((uint8_t *)(p))[5] = ((uint64_t)(a) >> 0) & 0xFFU
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 284 of file cpu_endian.h.

◆ STORE48LE

#define STORE48LE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint64_t)(a) >> 0) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint64_t)(a) >> 8) & 0xFFU, \
((uint8_t *)(p))[2] = ((uint64_t)(a) >> 16) & 0xFFU, \
((uint8_t *)(p))[3] = ((uint64_t)(a) >> 24) & 0xFFU, \
((uint8_t *)(p))[4] = ((uint64_t)(a) >> 32) & 0xFFU, \
((uint8_t *)(p))[5] = ((uint64_t)(a) >> 40) & 0xFFU,
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 275 of file cpu_endian.h.

◆ STORE64BE

#define STORE64BE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint64_t)(a) >> 56) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint64_t)(a) >> 48) & 0xFFU, \
((uint8_t *)(p))[2] = ((uint64_t)(a) >> 40) & 0xFFU, \
((uint8_t *)(p))[3] = ((uint64_t)(a) >> 32) & 0xFFU, \
((uint8_t *)(p))[4] = ((uint64_t)(a) >> 24) & 0xFFU, \
((uint8_t *)(p))[5] = ((uint64_t)(a) >> 16) & 0xFFU, \
((uint8_t *)(p))[6] = ((uint64_t)(a) >> 8) & 0xFFU, \
((uint8_t *)(p))[7] = ((uint64_t)(a) >> 0) & 0xFFU
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 304 of file cpu_endian.h.

◆ STORE64LE

#define STORE64LE (   a,
  p 
)
Value:
((uint8_t *)(p))[0] = ((uint64_t)(a) >> 0) & 0xFFU, \
((uint8_t *)(p))[1] = ((uint64_t)(a) >> 8) & 0xFFU, \
((uint8_t *)(p))[2] = ((uint64_t)(a) >> 16) & 0xFFU, \
((uint8_t *)(p))[3] = ((uint64_t)(a) >> 24) & 0xFFU, \
((uint8_t *)(p))[4] = ((uint64_t)(a) >> 32) & 0xFFU, \
((uint8_t *)(p))[5] = ((uint64_t)(a) >> 40) & 0xFFU, \
((uint8_t *)(p))[6] = ((uint64_t)(a) >> 48) & 0xFFU, \
((uint8_t *)(p))[7] = ((uint64_t)(a) >> 56) & 0xFFU
uint8_t p
Definition: ndp.h:295
uint8_t a
Definition: ndp.h:407

Definition at line 293 of file cpu_endian.h.

◆ SWAPINT16

#define SWAPINT16 (   x)
Value:
( \
(((uint16_t)(x) & 0x00FFU) << 8) | \
(((uint16_t)(x) & 0xFF00U) >> 8))

Definition at line 315 of file cpu_endian.h.

◆ SWAPINT32

#define SWAPINT32 (   x)
Value:
( \
(((uint32_t)(x) & 0x000000FFUL) << 24) | \
(((uint32_t)(x) & 0x0000FF00UL) << 8) | \
(((uint32_t)(x) & 0x00FF0000UL) >> 8) | \
(((uint32_t)(x) & 0xFF000000UL) >> 24))

Definition at line 320 of file cpu_endian.h.

◆ SWAPINT64

#define SWAPINT64 (   x)
Value:
( \
(((uint64_t)(x) & 0x00000000000000FFULL) << 56) | \
(((uint64_t)(x) & 0x000000000000FF00ULL) << 40) | \
(((uint64_t)(x) & 0x0000000000FF0000ULL) << 24) | \
(((uint64_t)(x) & 0x00000000FF000000ULL) << 8) | \
(((uint64_t)(x) & 0x000000FF00000000ULL) >> 8) | \
(((uint64_t)(x) & 0x0000FF0000000000ULL) >> 24) | \
(((uint64_t)(x) & 0x00FF000000000000ULL) >> 40) | \
(((uint64_t)(x) & 0xFF00000000000000ULL) >> 56))

Definition at line 327 of file cpu_endian.h.

Function Documentation

◆ reverseInt16()

uint16_t reverseInt16 ( uint16_t  value)

Reverse bit order in a 16-bit word.

Parameters
[in]value16-bit value
Returns
16-bit value with bit order reversed

Definition at line 104 of file cpu_endian.c.

◆ reverseInt32()

uint32_t reverseInt32 ( uint32_t  value)

Reverse bit order in a 32-bit word.

Parameters
[in]value32-bit value
Returns
32-bit value with bit order reversed

Definition at line 121 of file cpu_endian.c.

◆ reverseInt4()

uint8_t reverseInt4 ( uint8_t  value)

Reverse bit order in a 4-bit word.

Parameters
[in]value4-bit value
Returns
4-bit value with bit order reversed

Definition at line 73 of file cpu_endian.c.

◆ reverseInt64()

uint64_t reverseInt64 ( uint64_t  value)

Reverse bit order in a 64-bit word.

Parameters
[in]value64-bit value
Returns
64-bit value with bit order reversed

Definition at line 139 of file cpu_endian.c.

◆ reverseInt8()

uint8_t reverseInt8 ( uint8_t  value)

Reverse bit order in a byte.

Parameters
[in]value8-bit value
Returns
8-bit value with bit order reversed

Definition at line 88 of file cpu_endian.c.

◆ swapInt16()

uint16_t swapInt16 ( uint16_t  value)

Reverse the byte order of a 16-bit word.

Parameters
[in]value16-bit value
Returns
16-bit value with byte order swapped

Definition at line 37 of file cpu_endian.c.

◆ swapInt32()

uint32_t swapInt32 ( uint32_t  value)

Reverse the byte order of a 32-bit word.

Parameters
[in]value32-bit value
Returns
32-bit value with byte order swapped

Definition at line 49 of file cpu_endian.c.

◆ swapInt64()

uint64_t swapInt64 ( uint64_t  value)

Reverse the byte order of a 64-bit word.

Parameters
[in]value64-bit value
Returns
64-bit value with byte order swapped

Definition at line 61 of file cpu_endian.c.