MCUX CLNS
MCUX Crypto Library Normal Secure
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 ) \
47 do \
48 { \
49  (destination)[0] = (uint8_t) (((value) & 0x000000FFU) >> 0u); \
50  (destination)[1] = (uint8_t) (((value) & 0x0000FF00U) >> 8u); \
51  (destination)[2] = (uint8_t) (((value) & 0x00FF0000U) >> 16u); \
52  (destination)[3] = (uint8_t) (((value) & 0xFF000000U) >> 24u); \
53 } while (false)
54 
63 #define mcuxClMemory_StoreBigEndian32( destination, value ) \
64 do \
65 { \
66  (destination)[0] = (uint8_t) (((value) & 0xFF000000U) >> 24u); \
67  (destination)[1] = (uint8_t) (((value) & 0x00FF0000U) >> 16u); \
68  (destination)[2] = (uint8_t) (((value) & 0x0000FF00U) >> 8u); \
69  (destination)[3] = (uint8_t) (((value) & 0x000000FFU) >> 0u); \
70 } while (false)
71 
80 #define mcuxClMemory_LoadLittleEndian32( source ) \
81  ( (((uint32_t) (source)[0]) << 0u) | \
82  (((uint32_t) (source)[1]) << 8u) | \
83  (((uint32_t) (source)[2]) << 16u) | \
84  (((uint32_t) (source)[3]) << 24u) )
85 
86 
94 #define mcuxClMemory_LoadBigEndian32( source ) \
95  ( (((uint32_t) (source)[0]) << 24u) | \
96  (((uint32_t) (source)[1]) << 16u) | \
97  (((uint32_t) (source)[2]) << 8u) | \
98  (((uint32_t) (source)[3]) << 0u) )
99 
107 #ifdef __REV
108 #define MCUXCLMEMORY_SWITCH_4BYTE_ENDIANNESS(input) __REV(input)
109 #else
110 #define MCUXCLMEMORY_SWITCH_4BYTE_ENDIANNESS(input) ((((input) & 0xffu) << 24u) | (((input) & 0xff00u) << 8u) | (((input) & 0xff0000u) >> 8u) | (((input) & 0xff000000u) >> 24u))
111 #endif
112 
113 #endif /* MCUXCLMEMORY_ENDIANNESS_H_ */
114 
Memory type header.