Imported more library files

Not compiling currently
This commit is contained in:
2025-04-12 23:37:19 +01:00
parent 264a3462e0
commit 9d06f983af
2518 changed files with 1021900 additions and 52 deletions

View File

@@ -0,0 +1,247 @@
/**
* Copyright (c) 2020 nlio Authors. All Rights Reserved.
* Copyright 2012-2016 Nest Labs Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines defines functions for performing by value
* byte reordering for 16-, 32-, and 64-bit quantities both
* to-and-from the target system (i.e. host) byte ordering
* to-and-from both little and big endian byte ordering,
* specifically for big endian target systems.
*/
#ifndef NLBYTEORDER_BIG_H
#define NLBYTEORDER_BIG_H
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in little endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint16_t nlByteOrderSwap16LittleToHost(uint16_t inValue)
{
return nlByteOrderValueSwap16(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in little endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint32_t nlByteOrderSwap32LittleToHost(uint32_t inValue)
{
return nlByteOrderValueSwap32(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in little endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint64_t nlByteOrderSwap64LittleToHost(uint64_t inValue)
{
return nlByteOrderValueSwap64(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in target system (i.e. host) byte ordering to little endian byte
* ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint16_t nlByteOrderSwap16HostToLittle(uint16_t inValue)
{
return nlByteOrderValueSwap16(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in target system (i.e. host) byte ordering to little endian byte
* ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint32_t nlByteOrderSwap32HostToLittle(uint32_t inValue)
{
return nlByteOrderValueSwap32(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in target system (i.e. host) byte ordering to little endian byte
* ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint64_t nlByteOrderSwap64HostToLittle(uint64_t inValue)
{
return nlByteOrderValueSwap64(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in big endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint16_t nlByteOrderSwap16BigToHost(uint16_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in big endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint32_t nlByteOrderSwap32BigToHost(uint32_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in big endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint64_t nlByteOrderSwap64BigToHost(uint64_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in target system (i.e. host) byte ordering to big endian byte
* ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint16_t nlByteOrderSwap16HostToBig(uint16_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in target system (i.e. host) byte ordering to big endian byte
* ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint32_t nlByteOrderSwap32HostToBig(uint32_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in target system (i.e. host) byte ordering to big endian byte
* ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint64_t nlByteOrderSwap64HostToBig(uint64_t inValue)
{
return inValue;
}
#endif /* NLBYTEORDER_BIG_H */

View File

@@ -0,0 +1,246 @@
/**
* Copyright 2012-2016 Nest Labs Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines defines functions for performing by value
* byte reordering for 16-, 32-, and 64-bit quantities both
* to-and-from the target system (i.e. host) byte ordering
* to-and-from both little and big endian byte ordering,
* specifically for little endian target systems.
*/
#ifndef NLBYTEORDER_LITTLE_H
#define NLBYTEORDER_LITTLE_H
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in little endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint16_t nlByteOrderSwap16LittleToHost(uint16_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in little endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint32_t nlByteOrderSwap32LittleToHost(uint32_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in little endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint64_t nlByteOrderSwap64LittleToHost(uint64_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in target system (i.e. host) byte ordering to little endian byte
* ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint16_t nlByteOrderSwap16HostToLittle(uint16_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in target system (i.e. host) byte ordering to little endian byte
* ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint32_t nlByteOrderSwap32HostToLittle(uint32_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in target system (i.e. host) byte ordering to little endian byte
* ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint64_t nlByteOrderSwap64HostToLittle(uint64_t inValue)
{
return inValue;
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in big endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint16_t nlByteOrderSwap16BigToHost(uint16_t inValue)
{
return nlByteOrderValueSwap16(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in big endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint32_t nlByteOrderSwap32BigToHost(uint32_t inValue)
{
return nlByteOrderValueSwap32(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in big endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint64_t nlByteOrderSwap64BigToHost(uint64_t inValue)
{
return nlByteOrderValueSwap64(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in target system (i.e. host) byte ordering to big endian byte
* ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint16_t nlByteOrderSwap16HostToBig(uint16_t inValue)
{
return nlByteOrderValueSwap16(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in target system (i.e. host) byte ordering to big endian byte
* ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint32_t nlByteOrderSwap32HostToBig(uint32_t inValue)
{
return nlByteOrderValueSwap32(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in target system (i.e. host) byte ordering to big endian byte
* ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint64_t nlByteOrderSwap64HostToBig(uint64_t inValue)
{
return nlByteOrderValueSwap64(inValue);
}
#endif /* NLBYTEORDER_LITTLE_H */

View File

@@ -0,0 +1,329 @@
/**
* Copyright (c) 2020 nlio Authors. All Rights Reserved.
* Copyright 2012-2017 Nest Labs Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines macros for performing in place byte-
* swapping of compile-time constants via the C preprocessor as
* well as functions for performing byte-swapping by value and in
* place by pointer for 16-, 32-, and 64-bit types.
*/
#ifndef NLBYTEORDER_H
#define NLBYTEORDER_H
#include <nlio-private.h>
#include <stdint.h>
/*
* If we are compiling under clang, GCC, or any such compatible
* compiler, in which -fno-builtins or -ffreestanding might be
* asserted, thereby eliminating built-in function optimization, we
* STILL want to leverage built-in bswap{16,32,64}, if available. We
* want this because it allows the compiler to use
* architecture-specific machine instructions or inline code
* generation to optimize an otherwise-generic and non-optimized code
* for byte reordering, which is exactly the kind of efficiency that
* would be expected of nlByteOrder.
*/
#if __nlIOHasBuiltin(__builtin_bswap16)
#define __nlBYTEORDER_BSWAP16 __builtin_bswap16
#else
#define __nlBYTEORDER_BSWAP16 nlByteOrderConstantSwap16
#endif
#if __nlIOHasBuiltin(__builtin_bswap32)
#define __nlBYTEORDER_BSWAP32 __builtin_bswap32
#else
#define __nlBYTEORDER_BSWAP32 nlByteOrderConstantSwap32
#endif
#if __nlIOHasBuiltin(__builtin_bswap64)
#define __nlBYTEORDER_BSWAP64 __builtin_bswap64
#else
#define __nlBYTEORDER_BSWAP64 nlByteOrderConstantSwap64
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @def nlByteOrderConstantSwap16
*
* @brief
* Performs a preprocessor-compatible in place byte swap of the
* provided 16-bit value.
*
*/
#define nlByteOrderConstantSwap16(c) \
((uint16_t) \
((((uint16_t)(c) & (uint16_t)0x00ffU) << 8) | \
(((uint16_t)(c) & (uint16_t)0xff00U) >> 8)))
/**
* @def nlByteOrderConstantSwap32
*
* @brief
* Performs a preprocessor-compatible in place byte swap of the
* provided 32-bit value.
*
*/
#define nlByteOrderConstantSwap32(c) \
((uint32_t) \
((((uint32_t)(c) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(c) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(c) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(c) & (uint32_t)0xff000000UL) >> 24)))
/**
* @def nlByteOrderConstantSwap64
*
* @brief
* Performs a preprocessor-compatible in place byte swap of the
* provided 64-bit value.
*
*/
#define nlByteOrderConstantSwap64(c) \
((uint64_t) \
((((uint64_t)(c) & (uint64_t)0x00000000000000ffULL) << 56) | \
(((uint64_t)(c) & (uint64_t)0x000000000000ff00ULL) << 40) | \
(((uint64_t)(c) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(c) & (uint64_t)0x00000000ff000000ULL) << 8) | \
(((uint64_t)(c) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(c) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(c) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(c) & (uint64_t)0xff00000000000000ULL) >> 56)))
/**
* @def NLBYTEORDER_LITTLE_ENDIAN
*
* @brief
* Constant preprocessor definition used to test #NLBYTEORDER
* against to determine whether the target system uses little
* endian byte ordering.
*
* @code
* #if NLBYTEORDER == NLBYTEORDER_LITTLE_ENDIAN
*
* Do something that is little endian byte ordering-specific.
*
* #endif
* @endcode
*
*/
#define NLBYTEORDER_LITTLE_ENDIAN 0x1234
/**
* @def NLBYTEORDER_BIG_ENDIAN
*
* @brief
* Constant preprocessor definition used to test #NLBYTEORDER
* against to determine whether the target system uses big
* endian byte ordering.
*
* @code
* #if NLBYTEORDER == NLBYTEORDER_BIG_ENDIAN
*
* Do something that is little endian byte ordering-specific.
*
* #endif
* @endcode
*
*/
#define NLBYTEORDER_BIG_ENDIAN 0x4321
/**
* @def NLBYTEORDER_UNKNOWN_ENDIAN
*
* @brief
* Constant preprocessor definition used to test #NLBYTEORDER
* against to determine whether the target system uses unknown
* byte ordering.
*
* @code
* #elif NLBYTEORDER == NLBYTEORDER_UNKNOWN_ENDIAN
* #error "Unknown byte ordering!"
* #endif
* @endcode
*
*/
#define NLBYTEORDER_UNKNOWN_ENDIAN 0xFFFF
/**
* @def NLBYTEORDER
*
* @brief
* Constant preprocessor definition containing the target system
* byte ordering. May be one of:
*
* - NLBYTEORDER_BIG_ENDIAN
* - NLBYTEORDER_LITTLE_ENDIAN
* - NLBYTEORDER_UNKNOWN_ENDIAN
*
*/
#if defined(__BYTE_ORDER__)
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define NLBYTEORDER NLBYTEORDER_LITTLE_ENDIAN
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define NLBYTEORDER NLBYTEORDER_BIG_ENDIAN
# endif /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */
#elif defined(__LITTLE_ENDIAN__) && (__LITTLE_ENDIAN__ == 1)
#define NLBYTEORDER NLBYTEORDER_LITTLE_ENDIAN
#elif defined(__BIG_ENDIAN__) && (__BIG_ENDIAN__ == 1)
#define NLBYTEORDER NLBYTEORDER_BIG_ENDIAN
#else
#error "Endianness undefined!"
#define NLBYTEORDER NLBYTEORDER_UNKNOWN_ENDIAN
#endif /* defined(__BYTE_ORDER__) */
enum {
nlByteOrderUnknown = NLBYTEORDER_UNKNOWN_ENDIAN,
nlByteOrderLittleEndian = NLBYTEORDER_LITTLE_ENDIAN,
nlByteOrderBigEndian = NLBYTEORDER_BIG_ENDIAN
};
/**
* This represents a type for a byte ordering.
*/
typedef uint16_t nlByteOrder;
/**
* This returns the byte order of the current system.
*
* @return The byte order of the current system.
*/
static inline nlByteOrder nlByteOrderGetCurrent(void)
{
#if (NLBYTEORDER == NLBYTEORDER_LITTLE_ENDIAN)
return nlByteOrderLittleEndian;
#elif (NLBYTEORDER == NLBYTEORDER_BIG_ENDIAN)
return nlByteOrderBigEndian;
#else
return nlByteOrderUnknown;
#endif
}
/**
* This unconditionally performs a byte order swap by value of the
* specified 16-bit value.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint16_t nlByteOrderValueSwap16(uint16_t inValue)
{
return __nlBYTEORDER_BSWAP16(inValue);
}
/**
* This unconditionally performs a byte order swap by value of the
* specified 32-bit value.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint32_t nlByteOrderValueSwap32(uint32_t inValue)
{
return __nlBYTEORDER_BSWAP32(inValue);
}
/**
* This unconditionally performs a byte order swap by value of the
* specified 64-bit value.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
static inline uint64_t nlByteOrderValueSwap64(uint64_t inValue)
{
return __nlBYTEORDER_BSWAP64(inValue);
}
/**
* This unconditionally performs a byte order swap by pointer in place
* of the specified 16-bit value.
*
* @warning The input value is assumed to be on a natural alignment
* boundary for the target system. It is the responsibility of the
* caller to perform any necessary alignment to avoid system faults
* for systems that do not support unaligned accesses.
*
* @param[inout] inValue A pointer to the 16-bit value to be byte
* order swapped.
*/
static inline void nlByteOrderPointerSwap16(uint16_t *inValue)
{
*inValue = nlByteOrderValueSwap16(*inValue);
}
/**
* This unconditionally performs a byte order swap by pointer in place
* of the specified 32-bit value.
*
* @warning The input value is assumed to be on a natural alignment
* boundary for the target system. It is the responsibility of the
* caller to perform any necessary alignment to avoid system faults
* for systems that do not support unaligned accesses.
*
* @param[inout] inValue A pointer to the 32-bit value to be byte
* order swapped.
*/
static inline void nlByteOrderPointerSwap32(uint32_t *inValue)
{
*inValue = nlByteOrderValueSwap32(*inValue);
}
/**
* This unconditionally performs a byte order swap by pointer in place
* of the specified 64-bit value.
*
* @warning The input value is assumed to be on a natural alignment
* boundary for the target system. It is the responsibility of the
* caller to perform any necessary alignment to avoid system faults
* for systems that do not support unaligned accesses.
*
* @param[inout] inValue A pointer to the 64-bit value to be byte
* order swapped.
*/
static inline void nlByteOrderPointerSwap64(uint64_t *inValue)
{
*inValue = nlByteOrderValueSwap64(*inValue);
}
#if (NLBYTEORDER == NLBYTEORDER_LITTLE_ENDIAN)
#include <nlbyteorder-little.h>
#elif (NLBYTEORDER == NLBYTEORDER_BIG_ENDIAN)
#include <nlbyteorder-big.h>
#endif /* (NLBYTEORDER == NLBYTEORDER_LITTLE_ENDIAN) */
#ifdef __cplusplus
}
#endif
#undef __nlBYTEORDER_BSWAP16
#undef __nlBYTEORDER_BSWAP32
#undef __nlBYTEORDER_BSWAP64
#endif /* NLBYTEORDER_H */

View File

@@ -0,0 +1,378 @@
/**
* Copyright 2012-2016 Nest Labs Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines C++ functions for performing byte-swapping
* by value and in place by pointer for 16-, 32-, and 64-bit
* types.
*
*/
#ifndef NLBYTEORDER_HPP
#define NLBYTEORDER_HPP
#include <nlbyteorder.h>
namespace nl
{
namespace ByteOrder
{
enum {
Unknown = nlByteOrderUnknown,
LittleEndian = nlByteOrderLittleEndian,
BigEndian = nlByteOrderBigEndian
};
/**
* This represents a type for a byte ordering.
*/
typedef nlByteOrder ByteOrder;
/**
* This returns the byte order of the current system.
*
* @return The byte order of the current system.
*/
inline ByteOrder GetCurrent(void)
{
return nlByteOrderGetCurrent();
}
/**
* This unconditionally performs a byte order swap by value of the
* specified 16-bit value.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint16_t Swap16(uint16_t inValue)
{
return nlByteOrderValueSwap16(inValue);
}
/**
* This unconditionally performs a byte order swap by value of the
* specified 32-bit value.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint32_t Swap32(uint32_t inValue)
{
return nlByteOrderValueSwap32(inValue);
}
/**
* This unconditionally performs a byte order swap by value of the
* specified 64-bit value.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint64_t Swap64(uint64_t inValue)
{
return nlByteOrderValueSwap64(inValue);
}
/**
* This unconditionally performs a byte order swap by pointer in place
* of the specified 16-bit value.
*
* @warning The input value is assumed to be on a natural alignment
* boundary for the target system. It is the responsibility of the
* caller to perform any necessary alignment to avoid system faults
* for systems that do not support unaligned accesses.
*
* @param[inout] inValue A pointer to the 16-bit value to be byte
* order swapped.
*/
inline void Swap16(uint16_t *inValue)
{
nlByteOrderPointerSwap16(inValue);
}
/**
* This unconditionally performs a byte order swap by pointer in place
* of the specified 32-bit value.
*
* @warning The input value is assumed to be on a natural alignment
* boundary for the target system. It is the responsibility of the
* caller to perform any necessary alignment to avoid system faults
* for systems that do not support unaligned accesses.
*
* @param[inout] inValue A pointer to the 32-bit value to be byte
* order swapped.
*/
inline void Swap32(uint32_t *inValue)
{
nlByteOrderPointerSwap32(inValue);
}
/**
* This unconditionally performs a byte order swap by pointer in place
* of the specified 64-bit value.
*
* @warning The input value is assumed to be on a natural alignment
* boundary for the target system. It is the responsibility of the
* caller to perform any necessary alignment to avoid system faults
* for systems that do not support unaligned accesses.
*
* @param[inout] inValue A pointer to the 64-bit value to be byte
* order swapped.
*/
inline void Swap64(uint64_t *inValue)
{
nlByteOrderPointerSwap64(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in little endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint16_t Swap16LittleToHost(uint16_t inValue)
{
return nlByteOrderSwap16LittleToHost(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in little endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint32_t Swap32LittleToHost(uint32_t inValue)
{
return nlByteOrderSwap32LittleToHost(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in little endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint64_t Swap64LittleToHost(uint64_t inValue)
{
return nlByteOrderSwap64LittleToHost(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in target system (i.e. host) byte ordering to little endian byte
* ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint16_t Swap16HostToLittle(uint16_t inValue)
{
return nlByteOrderSwap16HostToLittle(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in target system (i.e. host) byte ordering to little endian byte
* ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint32_t Swap32HostToLittle(uint32_t inValue)
{
return nlByteOrderSwap32HostToLittle(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in target system (i.e. host) byte ordering to little endian byte
* ordering.
*
* Consequently, on little endian target systems, this is a no-op and
* on big endian target systems, this performs a reordering.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint64_t Swap64HostToLittle(uint64_t inValue)
{
return nlByteOrderSwap64HostToLittle(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in big endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint16_t Swap16BigToHost(uint16_t inValue)
{
return nlByteOrderSwap16BigToHost(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in big endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint32_t Swap32BigToHost(uint32_t inValue)
{
return nlByteOrderSwap32BigToHost(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in big endian byte ordering to the target system (i.e. host)
* byte ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint64_t Swap64BigToHost(uint64_t inValue)
{
return nlByteOrderSwap64BigToHost(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 16-bit value, presumed to
* be in target system (i.e. host) byte ordering to big endian byte
* ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 16-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint16_t Swap16HostToBig(uint16_t inValue)
{
return nlByteOrderSwap16HostToBig(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 32-bit value, presumed to
* be in target system (i.e. host) byte ordering to big endian byte
* ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 32-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint32_t Swap32HostToBig(uint32_t inValue)
{
return nlByteOrderSwap32HostToBig(inValue);
}
/**
* This conditionally performs, as necessary for the target system, a
* byte order swap by value of the specified 64-bit value, presumed to
* be in target system (i.e. host) byte ordering to big endian byte
* ordering.
*
* Consequently, on little endian target systems, this performs a
* reordering and on big endian target systems, this is a no-op.
*
* @param[in] inValue The 64-bit value to be byte order swapped.
*
* @return The input value, byte order swapped.
*/
inline uint64_t Swap64HostToBig(uint64_t inValue)
{
return nlByteOrderSwap64HostToBig(inValue);
}
} // namespace ByteOrder
} // namespace nl
#endif // NLBYTEORDER_HPP

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,922 @@
/**
* Copyright 2013-2016 Nest Labs Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines C++ functions for safely performing simple,
* memory-mapped accesses, potentially to unaligned, aligned, and
* unaligned memory locations with byte reordering, specifically
* for big endian target systems.
*/
#ifndef NLIO_BYTEORDER_BIG_HPP
#define NLIO_BYTEORDER_BIG_HPP
#include <nlio-base.hpp>
#include <nlbyteorder.hpp>
namespace nl
{
namespace IO
{
namespace BigEndian
{
/**
* Perform a, potentially unaligned, memory read of the big endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to read
* the 8-bit big endian byte ordered value from.
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t Get8(const void *p)
{
return IO::Get8(p);
}
/**
* Perform a, potentially unaligned, memory read of the big endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to read
* the 16-bit big endian byte ordered value from.
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t Get16(const void *p)
{
return ByteOrder::Swap16BigToHost(IO::Get16(p));
}
/**
* Perform a, potentially unaligned, memory read of the big endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to read
* the 32-bit big endian byte ordered value from.
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t Get32(const void *p)
{
return ByteOrder::Swap32BigToHost(IO::Get32(p));
}
/**
* Perform a, potentially unaligned, memory read of the big endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to read
* the 64-bit big endian byte ordered value from.
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t Get64(const void *p)
{
return ByteOrder::Swap64BigToHost(IO::Get64(p));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to write
* the target system byte ordered 8-bit value to in big
* endian byte ordering.
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void Put8(void *p, uint8_t v)
{
IO::Put8(p, v);
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to write
* the target system byte ordered 16-bit value to in big
* endian byte ordering.
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void Put16(void *p, uint16_t v)
{
IO::Put16(p, ByteOrder::Swap16HostToBig(v));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to write
* the target system byte ordered 32-bit value to in big
* endian byte ordering.
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void Put32(void *p, uint32_t v)
{
IO::Put32(p, ByteOrder::Swap32HostToBig(v));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to write
* the target system byte ordered 64-bit value to in big
* endian byte ordering.
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void Put64(void *p, uint64_t v)
{
IO::Put64(p, ByteOrder::Swap64HostToBig(v));
}
/**
* Perform a, potentially unaligned, memory read of the big endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 8-bits (1 byte).
*
* @param[inout] p A reference to a pointer address, potentially
* unaligned, to read the 8-bit big endian byte
* ordered value from and to then increment by 8-
* bits (1 byte).
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t Read8(const void *&p)
{
return IO::Read8(p);
}
/**
* Perform a, potentially unaligned, memory read of the big endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 16-bits (2 bytes).
*
* @param[inout] p A reference to a pointer address, potentially
* unaligned, to read the 16-bit big endian byte
* ordered value from and to then increment by 16-
* bits (2 bytes).
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t Read16(const void *&p)
{
return ByteOrder::Swap16BigToHost(IO::Read16(p));
}
/**
* Perform a, potentially unaligned, memory read of the big endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 32-bits (4 bytes).
*
* @param[inout] p A reference to a pointer address, potentially
* unaligned, to read the 32-bit big endian byte
* ordered value from and to then increment by 32-
* bits (4 bytes).
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t Read32(const void *&p)
{
return ByteOrder::Swap32BigToHost(IO::Read32(p));
}
/**
* Perform a, potentially unaligned, memory read of the big endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 64-bits (8 bytes).
*
* @param[inout] p A reference to a pointer address, potentially
* unaligned, to read the 64-bit big endian byte
* ordered value from and to then increment by 64-
* bits (8 bytes).
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t Read64(const void *&p)
{
return ByteOrder::Swap64BigToHost(IO::Read64(p));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p A reference to a pointer address, potentially
* unaligned, to write the target system byte
* ordered 8-bit value to in big endian byte
* ordering and to then increment by 8-bits (1
* byte).
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void Write8(void *&p, uint8_t v)
{
IO::Write8(p, v);
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p A reference to a pointer address, potentially
* unaligned, to write the target system byte
* ordered 16-bit value to in big endian byte
* ordering and to then increment by 16-bits (2
* bytes).
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void Write16(void *&p, uint16_t v)
{
IO::Write16(p, ByteOrder::Swap16HostToBig(v));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p A reference to a pointer address, potentially
* unaligned, to write the target system byte
* ordered 32-bit value to in big endian byte
* ordering and to then increment by 16-bits (4
* bytes).
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void Write32(void *&p, uint32_t v)
{
IO::Write32(p, ByteOrder::Swap32HostToBig(v));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p A reference to a pointer address, potentially
* unaligned, to write the target system byte
* ordered 64-bit value to in big endian byte
* ordering and to then increment by 64-bits (8
* bytes).
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void Write64(void *&p, uint64_t v)
{
IO::Write64(p, ByteOrder::Swap64HostToBig(v));
}
/**
* Perform an aligned memory read of the big endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An aligned pointer address to read
* the 8-bit big endian byte ordered value from.
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t GetAligned8(const void *p)
{
return IO::GetAligned8(p);
}
/**
* Perform an aligned memory read of the big endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An aligned pointer address to read
* the 16-bit big endian byte ordered value from.
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t GetAligned16(const void *p)
{
return ByteOrder::Swap16BigToHost(IO::GetAligned16(p));
}
/**
* Perform an aligned memory read of the big endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An aligned pointer address to read
* the 32-bit big endian byte ordered value from.
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t GetAligned32(const void *p)
{
return ByteOrder::Swap32BigToHost(IO::GetAligned32(p));
}
/**
* Perform an aligned memory read of the big endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An aligned pointer address to read
* the 64-bit big endian byte ordered value from.
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t GetAligned64(const void *p)
{
return ByteOrder::Swap64BigToHost(IO::GetAligned64(p));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p An aligned pointer address to write
* the target system byte ordered 8-bit value to in big
* endian byte ordering.
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void PutAligned8(void *p, uint8_t v)
{
IO::PutAligned8(p, v);
}
/**
* Perform an aligned memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p An aligned pointer address to write
* the target system byte ordered 16-bit value to in big
* endian byte ordering.
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void PutAligned16(void *p, uint16_t v)
{
IO::PutAligned16(p, ByteOrder::Swap16HostToBig(v));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p An aligned pointer address to write
* the target system byte ordered 32-bit value to in big
* endian byte ordering.
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void PutAligned32(void *p, uint32_t v)
{
IO::PutAligned32(p, ByteOrder::Swap32HostToBig(v));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p An aligned pointer address to write
* the target system byte ordered 64-bit value to in big
* endian byte ordering.
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void PutAligned64(void *p, uint64_t v)
{
IO::PutAligned64(p, ByteOrder::Swap64HostToBig(v));
}
/**
* Perform an aligned memory read of the big endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 8-bits (1 byte).
*
* @param[inout] p A reference to an aligned pointer address
* to read the 8-bit big endian byte
* ordered value from and to then increment by 8-
* bits (1 byte).
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t ReadAligned8(const void *&p)
{
return IO::ReadAligned8(p);
}
/**
* Perform an aligned memory read of the big endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 16-bits (2 bytes).
*
* @param[inout] p A reference to an aligned pointer address
* to read the 16-bit big endian byte
* ordered value from and to then increment by 16-
* bits (2 bytes).
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t ReadAligned16(const void *&p)
{
return ByteOrder::Swap16BigToHost(IO::ReadAligned16(p));
}
/**
* Perform an aligned memory read of the big endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 32-bits (4 bytes).
*
* @param[inout] p A reference to an aligned pointer address
* to read the 32-bit big endian byte
* ordered value from and to then increment by 32-
* bits (4 bytes).
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t ReadAligned32(const void *&p)
{
return ByteOrder::Swap32BigToHost(IO::ReadAligned32(p));
}
/**
* Perform an aligned memory read of the big endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 64-bits (8 bytes).
*
* @param[inout] p A reference to an aligned pointer address
* to read the 64-bit big endian byte
* ordered value from and to then increment by 64-
* bits (8 bytes).
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t ReadAligned64(const void *&p)
{
return ByteOrder::Swap64BigToHost(IO::ReadAligned64(p));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[inout] p A reference to an aligned pointer address
* to write the target system byte
* ordered 8-bit value to in big endian byte
* ordering and to then increment by 8-bits (1
* byte).
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void WriteAligned8(void *&p, uint8_t v)
{
IO::WriteAligned8(p, v);
}
/**
* Perform an aligned memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[inout] p A reference to an aligned pointer address
* to write the target system byte
* ordered 16-bit value to in big endian byte
* ordering and to then increment by 16-bits (2
* bytes).
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void WriteAligned16(void *&p, uint16_t v)
{
IO::WriteAligned16(p, ByteOrder::Swap16HostToBig(v));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[inout] p A reference to an aligned pointer address
* to write the target system byte
* ordered 32-bit value to in big endian byte
* ordering and to then increment by 16-bits (4
* bytes).
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void WriteAligned32(void *&p, uint32_t v)
{
IO::WriteAligned32(p, ByteOrder::Swap32HostToBig(v));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[inout] p A reference to an aligned pointer address
* to write the target system byte
* ordered 64-bit value to in big endian byte
* ordering and to then increment by 64-bits (8
* bytes).
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void WriteAligned64(void *&p, uint64_t v)
{
IO::WriteAligned64(p, ByteOrder::Swap64HostToBig(v));
}
/**
* Perform an unaligned memory read of the big endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An unaligned pointer address to read
* the 8-bit big endian byte ordered value from.
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t GetUnaligned8(const void *p)
{
return IO::GetUnaligned8(p);
}
/**
* Perform an unaligned memory read of the big endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An unaligned pointer address to read
* the 16-bit big endian byte ordered value from.
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t GetUnaligned16(const void *p)
{
return ByteOrder::Swap16BigToHost(IO::GetUnaligned16(p));
}
/**
* Perform an unaligned memory read of the big endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An unaligned pointer address to read
* the 32-bit big endian byte ordered value from.
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t GetUnaligned32(const void *p)
{
return ByteOrder::Swap32BigToHost(IO::GetUnaligned32(p));
}
/**
* Perform an unaligned memory read of the big endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An unaligned pointer address to read
* the 64-bit big endian byte ordered value from.
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t GetUnaligned64(const void *p)
{
return ByteOrder::Swap64BigToHost(IO::GetUnaligned64(p));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p An unaligned pointer address to write
* the target system byte ordered 8-bit value to in big
* endian byte ordering.
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void PutUnaligned8(void *p, uint8_t v)
{
IO::PutUnaligned8(p, v);
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p An unaligned pointer address to write
* the target system byte ordered 16-bit value to in big
* endian byte ordering.
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void PutUnaligned16(void *p, uint16_t v)
{
IO::PutUnaligned16(p, ByteOrder::Swap16HostToBig(v));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p An unaligned pointer address to write
* the target system byte ordered 32-bit value to in big
* endian byte ordering.
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void PutUnaligned32(void *p, uint32_t v)
{
IO::PutUnaligned32(p, ByteOrder::Swap32HostToBig(v));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[in] p An unaligned pointer address to write
* the target system byte ordered 64-bit value to in big
* endian byte ordering.
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void PutUnaligned64(void *p, uint64_t v)
{
IO::PutUnaligned64(p, ByteOrder::Swap64HostToBig(v));
}
/**
* Perform an unaligned memory read of the big endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 8-bits (1 byte).
*
* @param[inout] p A reference to an unaligned pointer address
* to read the 8-bit big endian byte
* ordered value from and to then increment by 8-
* bits (1 byte).
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t ReadUnaligned8(const void *&p)
{
return IO::ReadUnaligned8(p);
}
/**
* Perform an unaligned memory read of the big endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 16-bits (2 bytes).
*
* @param[inout] p A reference to an unaligned pointer address
* to read the 16-bit big endian byte
* ordered value from and to then increment by 16-
* bits (2 bytes).
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t ReadUnaligned16(const void *&p)
{
return ByteOrder::Swap16BigToHost(IO::ReadUnaligned16(p));
}
/**
* Perform an unaligned memory read of the big endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 32-bits (4 bytes).
*
* @param[inout] p A reference to an unaligned pointer address
* to read the 32-bit big endian byte
* ordered value from and to then increment by 32-
* bits (4 bytes).
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t ReadUnaligned32(const void *&p)
{
return ByteOrder::Swap32BigToHost(IO::ReadUnaligned32(p));
}
/**
* Perform an unaligned memory read of the big endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 64-bits (8 bytes).
*
* @param[inout] p A reference to an unaligned pointer address
* to read the 64-bit big endian byte
* ordered value from and to then increment by 64-
* bits (8 bytes).
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t ReadUnaligned64(const void *&p)
{
return ByteOrder::Swap64BigToHost(IO::ReadUnaligned64(p));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[inout] p A reference to an unaligned pointer address
* to write the target system byte
* ordered 8-bit value to in big endian byte
* ordering and to then increment by 8-bits (1
* byte).
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void WriteUnaligned8(void *&p, uint8_t v)
{
IO::WriteUnaligned8(p, v);
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[inout] p A reference to an unaligned pointer address
* to write the target system byte
* ordered 16-bit value to in big endian byte
* ordering and to then increment by 16-bits (2
* bytes).
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void WriteUnaligned16(void *&p, uint16_t v)
{
IO::WriteUnaligned16(p, ByteOrder::Swap16HostToBig(v));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[inout] p A reference to an unaligned pointer address
* to write the target system byte
* ordered 32-bit value to in big endian byte
* ordering and to then increment by 16-bits (4
* bytes).
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void WriteUnaligned32(void *&p, uint32_t v)
{
IO::WriteUnaligned32(p, ByteOrder::Swap32HostToBig(v));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in big endian byte ordering.
*
* @param[inout] p A reference to an unaligned pointer address
* to write the target system byte
* ordered 64-bit value to in big endian byte
* ordering and to then increment by 64-bits (8
* bytes).
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void WriteUnaligned64(void *&p, uint64_t v)
{
IO::WriteUnaligned64(p, ByteOrder::Swap64HostToBig(v));
}
} // namespace BigEndian
} // namespace IO
} // namespace nl
#endif // NLIO_BYTEORDER_BIG_HPP

View File

@@ -0,0 +1,922 @@
/**
* Copyright 2013-2016 Nest Labs Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines C++ functions for safely performing simple,
* memory-mapped accesses, potentially to unaligned, aligned, and
* unaligned memory locations with byte reordering, specifically
* for little endian target systems.
*/
#ifndef NLIO_BYTEORDER_LITTLE_HPP
#define NLIO_BYTEORDER_LITTLE_HPP
#include <nlio-base.hpp>
#include <nlbyteorder.hpp>
namespace nl
{
namespace IO
{
namespace LittleEndian
{
/**
* Perform a, potentially unaligned, memory read of the little endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to read
* the 8-bit little endian byte ordered value from.
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t Get8(const void *p)
{
return IO::Get8(p);
}
/**
* Perform a, potentially unaligned, memory read of the little endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to read
* the 16-bit little endian byte ordered value from.
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t Get16(const void *p)
{
return ByteOrder::Swap16LittleToHost(IO::Get16(p));
}
/**
* Perform a, potentially unaligned, memory read of the little endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to read
* the 32-bit little endian byte ordered value from.
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t Get32(const void *p)
{
return ByteOrder::Swap32LittleToHost(IO::Get32(p));
}
/**
* Perform a, potentially unaligned, memory read of the little endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to read
* the 64-bit little endian byte ordered value from.
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t Get64(const void *p)
{
return ByteOrder::Swap64LittleToHost(IO::Get64(p));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to write
* the target system byte ordered 8-bit value to in little
* endian byte ordering.
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void Put8(void *p, uint8_t v)
{
IO::Put8(p, v);
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to write
* the target system byte ordered 16-bit value to in little
* endian byte ordering.
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void Put16(void *p, uint16_t v)
{
IO::Put16(p, ByteOrder::Swap16HostToLittle(v));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to write
* the target system byte ordered 32-bit value to in little
* endian byte ordering.
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void Put32(void *p, uint32_t v)
{
IO::Put32(p, ByteOrder::Swap32HostToLittle(v));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p A pointer address, potentially unaligned, to write
* the target system byte ordered 64-bit value to in little
* endian byte ordering.
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void Put64(void *p, uint64_t v)
{
IO::Put64(p, ByteOrder::Swap64HostToLittle(v));
}
/**
* Perform a, potentially unaligned, memory read of the little endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 8-bits (1 byte).
*
* @param[inout] p A reference to a pointer address, potentially
* unaligned, to read the 8-bit little endian byte
* ordered value from and to then increment by 8-
* bits (1 byte).
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t Read8(const void *&p)
{
return IO::Read8(p);
}
/**
* Perform a, potentially unaligned, memory read of the little endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 16-bits (2 bytes).
*
* @param[inout] p A reference to a pointer address, potentially
* unaligned, to read the 16-bit little endian byte
* ordered value from and to then increment by 16-
* bits (2 bytes).
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t Read16(const void *&p)
{
return ByteOrder::Swap16LittleToHost(IO::Read16(p));
}
/**
* Perform a, potentially unaligned, memory read of the little endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 32-bits (4 bytes).
*
* @param[inout] p A reference to a pointer address, potentially
* unaligned, to read the 32-bit little endian byte
* ordered value from and to then increment by 32-
* bits (4 bytes).
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t Read32(const void *&p)
{
return ByteOrder::Swap32LittleToHost(IO::Read32(p));
}
/**
* Perform a, potentially unaligned, memory read of the little endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 64-bits (8 bytes).
*
* @param[inout] p A reference to a pointer address, potentially
* unaligned, to read the 64-bit little endian byte
* ordered value from and to then increment by 64-
* bits (8 bytes).
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t Read64(const void *&p)
{
return ByteOrder::Swap64LittleToHost(IO::Read64(p));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p A reference to a pointer address, potentially
* unaligned, to write the target system byte
* ordered 8-bit value to in little endian byte
* ordering and to then increment by 8-bits (1
* byte).
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void Write8(void *&p, uint8_t v)
{
IO::Write8(p, v);
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p A reference to a pointer address, potentially
* unaligned, to write the target system byte
* ordered 16-bit value to in little endian byte
* ordering and to then increment by 16-bits (2
* bytes).
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void Write16(void *&p, uint16_t v)
{
IO::Write16(p, ByteOrder::Swap16HostToLittle(v));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p A reference to a pointer address, potentially
* unaligned, to write the target system byte
* ordered 32-bit value to in little endian byte
* ordering and to then increment by 16-bits (4
* bytes).
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void Write32(void *&p, uint32_t v)
{
IO::Write32(p, ByteOrder::Swap32HostToLittle(v));
}
/**
* Perform a, potentially unaligned, memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p A reference to a pointer address, potentially
* unaligned, to write the target system byte
* ordered 64-bit value to in little endian byte
* ordering and to then increment by 64-bits (8
* bytes).
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void Write64(void *&p, uint64_t v)
{
IO::Write64(p, ByteOrder::Swap64HostToLittle(v));
}
/**
* Perform an aligned memory read of the little endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An aligned pointer address to read
* the 8-bit little endian byte ordered value from.
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t GetAligned8(const void *p)
{
return IO::GetAligned8(p);
}
/**
* Perform an aligned memory read of the little endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An aligned pointer address to read
* the 16-bit little endian byte ordered value from.
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t GetAligned16(const void *p)
{
return ByteOrder::Swap16LittleToHost(IO::GetAligned16(p));
}
/**
* Perform an aligned memory read of the little endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An aligned pointer address to read
* the 32-bit little endian byte ordered value from.
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t GetAligned32(const void *p)
{
return ByteOrder::Swap32LittleToHost(IO::GetAligned32(p));
}
/**
* Perform an aligned memory read of the little endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An aligned pointer address to read
* the 64-bit little endian byte ordered value from.
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t GetAligned64(const void *p)
{
return ByteOrder::Swap64LittleToHost(IO::GetAligned64(p));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p An aligned pointer address to write
* the target system byte ordered 8-bit value to in little
* endian byte ordering.
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void PutAligned8(void *p, uint8_t v)
{
IO::PutAligned8(p, v);
}
/**
* Perform an aligned memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p An aligned pointer address to write
* the target system byte ordered 16-bit value to in little
* endian byte ordering.
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void PutAligned16(void *p, uint16_t v)
{
IO::PutAligned16(p, ByteOrder::Swap16HostToLittle(v));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p An aligned pointer address to write
* the target system byte ordered 32-bit value to in little
* endian byte ordering.
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void PutAligned32(void *p, uint32_t v)
{
IO::PutAligned32(p, ByteOrder::Swap32HostToLittle(v));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p An aligned pointer address to write
* the target system byte ordered 64-bit value to in little
* endian byte ordering.
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void PutAligned64(void *p, uint64_t v)
{
IO::PutAligned64(p, ByteOrder::Swap64HostToLittle(v));
}
/**
* Perform an aligned memory read of the little endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 8-bits (1 byte).
*
* @param[inout] p A reference to an aligned pointer address
* to read the 8-bit little endian byte
* ordered value from and to then increment by 8-
* bits (1 byte).
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t ReadAligned8(const void *&p)
{
return IO::ReadAligned8(p);
}
/**
* Perform an aligned memory read of the little endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 16-bits (2 bytes).
*
* @param[inout] p A reference to an aligned pointer address
* to read the 16-bit little endian byte
* ordered value from and to then increment by 16-
* bits (2 bytes).
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t ReadAligned16(const void *&p)
{
return ByteOrder::Swap16LittleToHost(IO::ReadAligned16(p));
}
/**
* Perform an aligned memory read of the little endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 32-bits (4 bytes).
*
* @param[inout] p A reference to an aligned pointer address
* to read the 32-bit little endian byte
* ordered value from and to then increment by 32-
* bits (4 bytes).
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t ReadAligned32(const void *&p)
{
return ByteOrder::Swap32LittleToHost(IO::ReadAligned32(p));
}
/**
* Perform an aligned memory read of the little endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 64-bits (8 bytes).
*
* @param[inout] p A reference to an aligned pointer address
* to read the 64-bit little endian byte
* ordered value from and to then increment by 64-
* bits (8 bytes).
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t ReadAligned64(const void *&p)
{
return ByteOrder::Swap64LittleToHost(IO::ReadAligned64(p));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[inout] p A reference to an aligned pointer address
* to write the target system byte
* ordered 8-bit value to in little endian byte
* ordering and to then increment by 8-bits (1
* byte).
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void WriteAligned8(void *&p, uint8_t v)
{
IO::WriteAligned8(p, v);
}
/**
* Perform an aligned memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[inout] p A reference to an aligned pointer address
* to write the target system byte
* ordered 16-bit value to in little endian byte
* ordering and to then increment by 16-bits (2
* bytes).
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void WriteAligned16(void *&p, uint16_t v)
{
IO::WriteAligned16(p, ByteOrder::Swap16HostToLittle(v));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[inout] p A reference to an aligned pointer address
* to write the target system byte
* ordered 32-bit value to in little endian byte
* ordering and to then increment by 16-bits (4
* bytes).
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void WriteAligned32(void *&p, uint32_t v)
{
IO::WriteAligned32(p, ByteOrder::Swap32HostToLittle(v));
}
/**
* Perform an aligned memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[inout] p A reference to an aligned pointer address
* to write the target system byte
* ordered 64-bit value to in little endian byte
* ordering and to then increment by 64-bits (8
* bytes).
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void WriteAligned64(void *&p, uint64_t v)
{
IO::WriteAligned64(p, ByteOrder::Swap64HostToLittle(v));
}
/**
* Perform an unaligned memory read of the little endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An unaligned pointer address to read
* the 8-bit little endian byte ordered value from.
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t GetUnaligned8(const void *p)
{
return IO::GetUnaligned8(p);
}
/**
* Perform an unaligned memory read of the little endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An unaligned pointer address to read
* the 16-bit little endian byte ordered value from.
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t GetUnaligned16(const void *p)
{
return ByteOrder::Swap16LittleToHost(IO::GetUnaligned16(p));
}
/**
* Perform an unaligned memory read of the little endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An unaligned pointer address to read
* the 32-bit little endian byte ordered value from.
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t GetUnaligned32(const void *p)
{
return ByteOrder::Swap32LittleToHost(IO::GetUnaligned32(p));
}
/**
* Perform an unaligned memory read of the little endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in target system byte ordering.
*
* @param[in] p An unaligned pointer address to read
* the 64-bit little endian byte ordered value from.
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t GetUnaligned64(const void *p)
{
return ByteOrder::Swap64LittleToHost(IO::GetUnaligned64(p));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p An unaligned pointer address to write
* the target system byte ordered 8-bit value to in little
* endian byte ordering.
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void PutUnaligned8(void *p, uint8_t v)
{
IO::PutUnaligned8(p, v);
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p An unaligned pointer address to write
* the target system byte ordered 16-bit value to in little
* endian byte ordering.
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void PutUnaligned16(void *p, uint16_t v)
{
IO::PutUnaligned16(p, ByteOrder::Swap16HostToLittle(v));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p An unaligned pointer address to write
* the target system byte ordered 32-bit value to in little
* endian byte ordering.
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void PutUnaligned32(void *p, uint32_t v)
{
IO::PutUnaligned32(p, ByteOrder::Swap32HostToLittle(v));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[in] p An unaligned pointer address to write
* the target system byte ordered 64-bit value to in little
* endian byte ordering.
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void PutUnaligned64(void *p, uint64_t v)
{
IO::PutUnaligned64(p, ByteOrder::Swap64HostToLittle(v));
}
/**
* Perform an unaligned memory read of the little endian
* byte ordered 8-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 8-bits (1 byte).
*
* @param[inout] p A reference to an unaligned pointer address
* to read the 8-bit little endian byte
* ordered value from and to then increment by 8-
* bits (1 byte).
*
* @return The 8-bit value at the specified pointer address.
*/
static inline uint8_t ReadUnaligned8(const void *&p)
{
return IO::ReadUnaligned8(p);
}
/**
* Perform an unaligned memory read of the little endian
* byte ordered 16-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 16-bits (2 bytes).
*
* @param[inout] p A reference to an unaligned pointer address
* to read the 16-bit little endian byte
* ordered value from and to then increment by 16-
* bits (2 bytes).
*
* @return The 16-bit value at the specified pointer address.
*/
static inline uint16_t ReadUnaligned16(const void *&p)
{
return ByteOrder::Swap16LittleToHost(IO::ReadUnaligned16(p));
}
/**
* Perform an unaligned memory read of the little endian
* byte ordered 32-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 32-bits (4 bytes).
*
* @param[inout] p A reference to an unaligned pointer address
* to read the 32-bit little endian byte
* ordered value from and to then increment by 32-
* bits (4 bytes).
*
* @return The 32-bit value at the specified pointer address.
*/
static inline uint32_t ReadUnaligned32(const void *&p)
{
return ByteOrder::Swap32LittleToHost(IO::ReadUnaligned32(p));
}
/**
* Perform an unaligned memory read of the little endian
* byte ordered 64-bit value from the specified pointer address,
* perform byte reordering, as necessary, for the target system to put
* the value in target system byte ordering, and increment the pointer
* by 64-bits (8 bytes).
*
* @param[inout] p A reference to an unaligned pointer address
* to read the 64-bit little endian byte
* ordered value from and to then increment by 64-
* bits (8 bytes).
*
* @return The 64-bit value at the specified pointer address.
*/
static inline uint64_t ReadUnaligned64(const void *&p)
{
return ByteOrder::Swap64LittleToHost(IO::ReadUnaligned64(p));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 8-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[inout] p A reference to an unaligned pointer address
* to write the target system byte
* ordered 8-bit value to in little endian byte
* ordering and to then increment by 8-bits (1
* byte).
*
* @param[in] v The 8-bit value to write.
*
*/
static inline void WriteUnaligned8(void *&p, uint8_t v)
{
IO::WriteUnaligned8(p, v);
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 16-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[inout] p A reference to an unaligned pointer address
* to write the target system byte
* ordered 16-bit value to in little endian byte
* ordering and to then increment by 16-bits (2
* bytes).
*
* @param[in] v The 16-bit value to write.
*
*/
static inline void WriteUnaligned16(void *&p, uint16_t v)
{
IO::WriteUnaligned16(p, ByteOrder::Swap16HostToLittle(v));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 32-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[inout] p A reference to an unaligned pointer address
* to write the target system byte
* ordered 32-bit value to in little endian byte
* ordering and to then increment by 16-bits (4
* bytes).
*
* @param[in] v The 32-bit value to write.
*
*/
static inline void WriteUnaligned32(void *&p, uint32_t v)
{
IO::WriteUnaligned32(p, ByteOrder::Swap32HostToLittle(v));
}
/**
* Perform an unaligned memory write of the target system
* byte ordered 64-bit value to the specified pointer address,
* perform byte reordering, as necessary, for the target system to
* put the value in little endian byte ordering.
*
* @param[inout] p A reference to an unaligned pointer address
* to write the target system byte
* ordered 64-bit value to in little endian byte
* ordering and to then increment by 64-bits (8
* bytes).
*
* @param[in] v The 64-bit value to write.
*
*/
static inline void WriteUnaligned64(void *&p, uint64_t v)
{
IO::WriteUnaligned64(p, ByteOrder::Swap64HostToLittle(v));
}
} // namespace LittleEndian
} // namespace IO
} // namespace nl
#endif // NLIO_BYTEORDER_LITTLE_HPP

View File

@@ -0,0 +1,33 @@
/**
* Copyright 2013-2016 Nest Labs Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines C++ functions for safely performing simple,
* memory-mapped accesses, potentially to unaligned memory
* locations with byte reordering.
*/
#ifndef NLIO_BYTEORDER_HPP
#define NLIO_BYTEORDER_HPP
#include <nlio-base.hpp>
#include <nlbyteorder.hpp>
#include <nlio-byteorder-big.hpp>
#include <nlio-byteorder-little.hpp>
#endif // NLIO_BYTEORDER_HPP

View File

@@ -0,0 +1,50 @@
/**
* Copyright 2017 Nest Labs Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines private macros and interfaces.
*/
#ifndef NLIO_PRIVATE_H
#define NLIO_PRIVATE_H
/*
* If we are compiling under clang, GCC, or any such compatible
* compiler, in which -fno-builtins or -ffreestanding might be
* asserted, thereby eliminating built-in function optimization, we
* may STILL want to leverage built-ins.
*
* Provide an internal convenience macro to do so.
*/
/**
* @def __nlIOHasBuiltin
*
* @brief
* Determines whether or not the compiler in effect has support
* for the specified built-in function.
*
*/
#ifdef __clang__
#define __nlIOHasBuiltin(...) __has_builtin(__VA_ARGS__)
#elif defined __GNUC__
#define __nlIOHasBuiltin(...) 1
#else
#define __nlIOHasBuiltin(...) 0
#endif /* __clang__ */
#endif /* NLIO_PRIVATE_H */

View File

@@ -0,0 +1,38 @@
/**
* Copyright 2013-2016 Nest Labs Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file is an umbrella header for the C++ language
* definitions of functions for safely performing simple,
* memory-mapped accesses, potentially to unaligned memory
* locations, with or without byte reordering.
*/
#ifndef NLIO_HPP
#define NLIO_HPP
#include <nlio-base.hpp>
#include <nlio-byteorder.hpp>
#endif // NLIO_HPP