1 /***************************************************************************//**
2  * @file
3  * @brief API "assert" implementation.
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2021 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_ASSERT_H
32 #define SL_ASSERT_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #if defined(DOXY_DOC_ONLY)
39 /** Included for documentation purposes only. This define is not present by default.
40  *  DEBUG_EFM should be defined from the compiler to enable the default internal
41  *  assert handler. */
42 #define DEBUG_EFM
43 #endif
44 
45 #if defined(DEBUG_EFM) || defined(DEBUG_EFM_USER)
46 /***************************************************************************//**
47  * @addtogroup assert ASSERT - Assert
48  * @brief Assert/error checking module
49  * @details
50  * By default, library assert usage is not included to reduce
51  * footprint and processing overhead. Further, assert usage is decoupled
52  * from ISO C assert handling (NDEBUG usage) to allow using ISO C
53  * assert without including assert statements.
54  *
55  * Below are available defines for controlling assert inclusion. The defines
56  * are typically for a project to be used by the preprocessor.
57  *
58  * @li If DEBUG_EFM is defined, the internal library assert handling will
59  * be used. This is implemented as a simple while(true) loop. DEBUG_EFM is not
60  * defined by default.
61  *
62  * @li If DEBUG_EFM_USER is defined, the user must provide custom
63  * implementation of the assertEFM() function.
64  *
65  * @li If both DEBUG_EFM and DEBUG_EFM_USER are undefined, all EFM_ASSERT()
66  * statements are not operational.
67  *
68  * @note
69  * The internal assert is documented because DEBUG_EFM is defined in
70  * the doxygen configuration.
71  * @{
72  ******************************************************************************/
73 /* Due to footprint considerations, we only pass file name and line number, */
74 /* not the assert expression (nor function name (C99)) */
75 /***************************************************************************//**
76  * @brief
77  *    Assert function for EFM.
78  * @param[in] file -  path and file name of the assert.
79  *
80  * @param[in] line - line number, in the file.
81  ******************************************************************************/
82 void assertEFM(const char *file, int line);
83 /** Default assertion is not operational */
84 #define EFM_ASSERT(expr)    ((expr) ? ((void)0) : assertEFM(__FILE__, __LINE__))
85 
86 #else
87 
88 /** Default assertion is not operational */
89 #define EFM_ASSERT(expr)    ((void)(expr))
90 
91 #endif /* defined(DEBUG_EFM) || defined(DEBUG_EFM_USER) */
92 
93 /** @} (end addtogroup assert) */
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif /* SL_ASSERT_H */
100