MCUX CLNS
MCUX Crypto Library Normal Secure
 
Loading...
Searching...
No Matches
mcuxClMemory_Endianness.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/* Copyright 2020-2021 NXP */
3/* */
4/* NXP Confidential. This software is owned or controlled by NXP and may */
5/* only be used strictly in accordance with the applicable license terms. */
6/* By expressly accepting such terms or by downloading, installing, */
7/* activating and/or otherwise using the software, you are agreeing that */
8/* you have read, and that you agree to comply with and are bound by, such */
9/* license terms. If you do not agree to be bound by the applicable license */
10/* terms, then you may not retain, install, activate or otherwise use the */
11/* software. */
12/*--------------------------------------------------------------------------*/
13
26#ifndef MCUXCLMEMORY_ENDIANNESS_H_
27#define MCUXCLMEMORY_ENDIANNESS_H_
28
29#include <mcuxClMemory_Types.h>
30#include <mcuxClConfig.h> // Exported features flags header
31
32
33/**********************************************
34 * MACROS
35 **********************************************/
36
46#define mcuxClMemory_StoreLittleEndian32( destination, value ) \
47do \
48{ \
49 uint32_t local_value = (uint32_t)(value); \
50 ((uint8_t*)(destination))[0] = (uint8_t) (((local_value) & 0x000000FFU) >> 0u);\
51 ((uint8_t*)(destination))[1] = (uint8_t) (((local_value) & 0x0000FF00U) >> 8u);\
52 ((uint8_t*)(destination))[2] = (uint8_t) (((local_value) & 0x00FF0000U) >> 16u);\
53 ((uint8_t*)(destination))[3] = (uint8_t) (((local_value) & 0xFF000000U) >> 24u);\
54} while (false)
55
64#define mcuxClMemory_StoreBigEndian32( destination, value ) \
65do \
66{ \
67 uint32_t local_value = (uint32_t)(value); \
68 ((uint8_t*)(destination))[0] = (uint8_t) (((local_value) & 0xFF000000U) >> 24u);\
69 ((uint8_t*)(destination))[1] = (uint8_t) (((local_value) & 0x00FF0000U) >> 16u);\
70 ((uint8_t*)(destination))[2] = (uint8_t) (((local_value) & 0x0000FF00U) >> 8u);\
71 ((uint8_t*)(destination))[3] = (uint8_t) (((local_value) & 0x000000FFU) >> 0u);\
72} while (false)
73
82#define mcuxClMemory_LoadLittleEndian32( source ) \
83 ( (((uint32_t) ((const uint8_t*)(source))[0]) << 0u) | \
84 (((uint32_t) ((const uint8_t*)(source))[1]) << 8u) | \
85 (((uint32_t) ((const uint8_t*)(source))[2]) << 16u) | \
86 (((uint32_t) ((const uint8_t*)(source))[3]) << 24u) )
87
88
96#define mcuxClMemory_LoadBigEndian32( source ) \
97 ( (((uint32_t) ((const uint8_t*)(source))[0]) << 24u) | \
98 (((uint32_t) ((const uint8_t*)(source))[1]) << 16u) | \
99 (((uint32_t) ((const uint8_t*)(source))[2]) << 8u) | \
100 (((uint32_t) ((const uint8_t*)(source))[3]) << 0u) )
101
109#ifdef __REV
110#define MCUXCLMEMORY_SWITCH_4BYTE_ENDIANNESS(input) __REV(input)
111#else
112#define MCUXCLMEMORY_SWITCH_4BYTE_ENDIANNESS(input) ((((input) & 0xffu) << 24u) | (((input) & 0xff00u) << 8u) | (((input) & 0xff0000u) >> 8u) | (((input) & 0xff000000u) >> 24u))
113#endif
114
115#endif /* MCUXCLMEMORY_ENDIANNESS_H_ */
Memory type header.