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 HTONLL(value)   SWAPINT64(value)
 
#define htons(value)   swapInt16((uint16_t) (value))
 
#define htonl(value)   swapInt32((uint32_t) (value))
 
#define htonll(value)   swapInt64((uint64_t) (value))
 
#define NTOHS(value)   SWAPINT16(value)
 
#define NTOHL(value)   SWAPINT32(value)
 
#define NTOHLL(value)   SWAPINT64(value)
 
#define ntohs(value)   swapInt16((uint16_t) (value))
 
#define ntohl(value)   swapInt32((uint32_t) (value))
 
#define ntohll(value)   swapInt64((uint64_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

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 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
2.4.4

Definition in file cpu_endian.h.

Macro Definition Documentation

◆ BETOH16

#define BETOH16 (   value)    SWAPINT16(value)

Definition at line 450 of file cpu_endian.h.

◆ betoh16

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

Definition at line 453 of file cpu_endian.h.

◆ BETOH32

#define BETOH32 (   value)    SWAPINT32(value)

Definition at line 451 of file cpu_endian.h.

◆ betoh32

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

Definition at line 454 of file cpu_endian.h.

◆ BETOH64

#define BETOH64 (   value)    SWAPINT64(value)

Definition at line 452 of file cpu_endian.h.

◆ betoh64

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

Definition at line 455 of file cpu_endian.h.

◆ HTOBE16

#define HTOBE16 (   value)    SWAPINT16(value)

Definition at line 442 of file cpu_endian.h.

◆ htobe16

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

Definition at line 445 of file cpu_endian.h.

◆ HTOBE32

#define HTOBE32 (   value)    SWAPINT32(value)

Definition at line 443 of file cpu_endian.h.

◆ htobe32

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

Definition at line 446 of file cpu_endian.h.

◆ HTOBE64

#define HTOBE64 (   value)    SWAPINT64(value)

Definition at line 444 of file cpu_endian.h.

◆ htobe64

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

Definition at line 447 of file cpu_endian.h.

◆ HTOLE16

#define HTOLE16 (   value)    (value)

Definition at line 426 of file cpu_endian.h.

◆ htole16

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

Definition at line 429 of file cpu_endian.h.

◆ HTOLE32

#define HTOLE32 (   value)    (value)

Definition at line 427 of file cpu_endian.h.

◆ htole32

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

Definition at line 430 of file cpu_endian.h.

◆ HTOLE64

#define HTOLE64 (   value)    (value)

Definition at line 428 of file cpu_endian.h.

◆ htole64

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

Definition at line 431 of file cpu_endian.h.

◆ HTONL

#define HTONL (   value)    SWAPINT32(value)

Definition at line 411 of file cpu_endian.h.

◆ htonl

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

Definition at line 414 of file cpu_endian.h.

◆ HTONLL

#define HTONLL (   value)    SWAPINT64(value)

Definition at line 412 of file cpu_endian.h.

◆ htonll

#define htonll (   value)    swapInt64((uint64_t) (value))

Definition at line 415 of file cpu_endian.h.

◆ HTONS

#define HTONS (   value)    SWAPINT16(value)

Definition at line 410 of file cpu_endian.h.

◆ htons

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

Definition at line 413 of file cpu_endian.h.

◆ LETOH16

#define LETOH16 (   value)    (value)

Definition at line 434 of file cpu_endian.h.

◆ letoh16

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

Definition at line 437 of file cpu_endian.h.

◆ LETOH32

#define LETOH32 (   value)    (value)

Definition at line 435 of file cpu_endian.h.

◆ letoh32

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

Definition at line 438 of file cpu_endian.h.

◆ LETOH64

#define LETOH64 (   value)    (value)

Definition at line 436 of file cpu_endian.h.

◆ letoh64

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

Definition at line 439 of file cpu_endian.h.

◆ LOAD16BE

#define LOAD16BE (   p)
Value:
( \
((uint16_t)(((uint8_t *)(p))[0]) << 8) | \
((uint16_t)(((uint8_t *)(p))[1]) << 0))

Definition at line 186 of file cpu_endian.h.

◆ LOAD16LE

#define LOAD16LE (   p)
Value:
( \
((uint16_t)(((uint8_t *)(p))[0]) << 0) | \
((uint16_t)(((uint8_t *)(p))[1]) << 8))

Definition at line 181 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))

Definition at line 197 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))

Definition at line 191 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))

Definition at line 210 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))

Definition at line 203 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))

Definition at line 226 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)

Definition at line 217 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))

Definition at line 246 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))

Definition at line 235 of file cpu_endian.h.

◆ NTOHL

#define NTOHL (   value)    SWAPINT32(value)

Definition at line 419 of file cpu_endian.h.

◆ ntohl

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

Definition at line 422 of file cpu_endian.h.

◆ NTOHLL

#define NTOHLL (   value)    SWAPINT64(value)

Definition at line 420 of file cpu_endian.h.

◆ ntohll

#define ntohll (   value)    swapInt64((uint64_t) (value))

Definition at line 423 of file cpu_endian.h.

◆ NTOHS

#define NTOHS (   value)    SWAPINT16(value)

Definition at line 418 of file cpu_endian.h.

◆ ntohs

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

Definition at line 421 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

Definition at line 262 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

Definition at line 257 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

Definition at line 273 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

Definition at line 267 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

Definition at line 286 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

Definition at line 279 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

Definition at line 302 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,

Definition at line 293 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

Definition at line 322 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

Definition at line 311 of file cpu_endian.h.

◆ SWAPINT16

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

Definition at line 333 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 338 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 345 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 106 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 123 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 75 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 141 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 90 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 39 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 51 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 63 of file cpu_endian.c.

uint8_t a
Definition: ndp.h:411
uint8_t p
Definition: ndp.h:300
uint8_t x
Definition: lldp_ext_med.h:211