1 /**
2  * @file
3  * @brief      Assertion checks for debugging.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_MXC_ASSERT_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_MXC_ASSERT_H_
29 
30 /* **** Includes **** */
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /**
37  * @ingroup    syscfg
38  * @defgroup   mxc_assertions Assertion Checks for Debugging
39  * @brief      Assertion checks for debugging.
40  * @{
41  */
42 /* **** Definitions **** */
43 /**
44  * @note       To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be
45  *             defined.
46  */
47 ///@cond
48 #ifdef MXC_ASSERT_ENABLE
49 /**
50  * Macro that checks the expression for true and generates an assertion.
51  * @note       To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be
52  *             defined.
53  */
54 #define MXC_ASSERT(expr)                       \
55     if (!(expr)) {                             \
56         mxc_assert(#expr, __FILE__, __LINE__); \
57     }
58 /**
59  * Macro that generates an assertion with the message "FAIL".
60  * @note       To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be
61  *             defined.
62  */
63 #define MXC_ASSERT_FAIL() mxc_assert("FAIL", __FILE__, __LINE__);
64 #else
65 #define MXC_ASSERT(expr)
66 #define MXC_ASSERT_FAIL()
67 #endif
68 ///@endcond
69 /* **** Globals **** */
70 
71 /* **** Function Prototypes **** */
72 
73 /**
74  * @brief      Assert an error when the given expression fails during debugging.
75  * @param      expr  String with the expression that failed the assertion.
76  * @param      file  File containing the failed assertion.
77  * @param      line  Line number for the failed assertion.
78  * @note       This is defined as a weak function and can be overridden at the
79  *             application layer to print the debugging information.
80  *             @code
81  *             printf("%s, file: %s, line %d\n", expr, file, line);
82  *             @endcode
83  * @note       To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be
84  *             defined.
85  */
86 void mxc_assert(const char *expr, const char *file, int line);
87 
88 /**@} end of group MXC_Assertions*/
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_MXC_ASSERT_H_
95