1 /*******************************************************************************
2  * @file
3  * @brief SL_ENUM Implementation
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 #ifndef SL_ENUM_H
31 #define SL_ENUM_H
32 
33 /*******************************************************************************
34  * @addtogroup enum Enumerations
35  * @brief Enumerations with stable binary representation
36  * @details
37  * Silicon Labs libraries do not use enumerations because the ARM EABI leaves
38  * their size ambiguous, which causes problems if the application is built
39  * with different flags than the library. Instead, uint8_t typedefs
40  * are used in compiled code for all enumerations. For documentation purposes,
41  * this is converted to an actual enumeration in documentation.
42  * @{
43  ******************************************************************************/
44 
45 #ifdef DOXYGEN
46 /// Enumeration mapped to uint8_t
47 #define SL_ENUM(name) enum name
48 /// Enumeration mapped to arbitrary type
49 #define SL_ENUM_GENERIC(name, type) enum name
50 #else
51 // NOTE: The following macros might cause MISRA warnings because
52 //       Macro parameters need to be enclosed in parentheses.
53 //       However, it is not possible in C to enclose declaration
54 //       identifiers in parentheses. For example:
55 //         typedef uint8_t (some_identifier);
56 //       is not syntactically correct in the C language (C99).
57 #define SL_ENUM(name) typedef uint8_t name; enum name##_enum
58 #define SL_ENUM_GENERIC(name, type) typedef type name; enum name##_enum
59 
60 // For debugging, use the following define to turn this back into a proper enumeration
61 // #define SL_ENUM(name) typedef enum name##_enum name; enum name##_enum
62 #endif
63 
64 /** @} end enum */
65 
66 #endif // SL_ENUM_H
67