1 /***************************************************************************//**
2  * @file
3  * @brief Implementation of endianness detection & operations.
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
7  *******************************************************************************
8  *
9  * SPDX-License-Identifier: Zlib
10  *
11  * The licensor of this software is Silicon Laboratories Inc.
12  *
13  * This software is provided 'as-is', without any express or implied
14  * warranty. In no event will the authors be held liable for any damages
15  * arising from the use of this software.
16  *
17  * Permission is granted to anyone to use this software for any purpose,
18  * including commercial applications, and to alter it and redistribute it
19  * freely, subject to the following restrictions:
20  *
21  * 1. The origin of this software must not be misrepresented; you must not
22  *    claim that you wrote the original software. If you use this software
23  *    in a product, an acknowledgment in the product documentation would be
24  *    appreciated but is not required.
25  * 2. Altered source versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.
27  * 3. This notice may not be removed or altered from any source distribution.
28  *
29  ******************************************************************************/
30 
31 #ifndef SL_ENDIANNESS_H
32 #define SL_ENDIANNESS_H
33 
34 #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || (__little_endian__ == 1) || WIN32 || (__BYTE_ORDER == __LITTLE_ENDIAN)
35 
36 #define SL_IS_LITTLE_ENDIAN   1
37 #define SL_IS_BIG_ENDIAN      0
38 #define BIGENDIAN_CPU         false     // Should not be used anymore; this is only for backward compatibility(Zigbee)
39 
40 #elif (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || (__big_endian__ == 1) || (__BYTE_ORDER == __BIG_ENDIAN)
41 
42 #define SL_IS_LITTLE_ENDIAN   0
43 #define SL_IS_BIG_ENDIAN      1
44 #define BIGENDIAN_CPU         true     // Should not be used anymore; this is only for backward compatibility(Zigbee)
45 
46 #else
47 // Endianness must be provided by the user
48 #if (defined(CPU_LITTLE_ENDIAN))
49 
50 #define SL_IS_LITTLE_ENDIAN   1
51 #define SL_IS_BIG_ENDIAN      0
52 #define BIGENDIAN_CPU         false     // Should not be used anymore; this is only for backward compatibility(Zigbee)
53 
54 #elif (defined(CPU_BIG_ENDIAN))
55 
56 #define SL_IS_LITTLE_ENDIAN   0
57 #define SL_IS_BIG_ENDIAN      1
58 #define BIGENDIAN_CPU         true     // Should not be used anymore; this is only for backward compatibility(Zigbee)
59 
60 #else
61 #error Endianess not defined
62 #endif
63 #endif
64 
65 #endif
66