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_MAX32650_MXC_ASSERT_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_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 Macro that checks the expression for true and generates an assertion if false. The symbol @c MXC_ASSERT_ENABLE must be 45 * defined to use this macro. 46 */ 47 48 #ifdef MXC_ASSERT_ENABLE 49 50 #define MXC_ASSERT(expr) \ 51 if (!(expr)) { \ 52 mxc_assert(#expr, __FILE__, __LINE__); \ 53 } 54 55 /** 56 * Macro that generates an assertion with the message "FAIL". 57 * @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be 58 * defined. 59 */ 60 #define MXC_ASSERT_FAIL() mxc_assert("FAIL", __FILE__, __LINE__); 61 #else 62 #define MXC_ASSERT(expr) 63 #define MXC_ASSERT_FAIL() 64 #endif 65 /* **** Globals **** */ 66 67 /* **** Function Prototypes **** */ 68 69 /** 70 * @brief Assert an error when the given expression fails during debugging. 71 * @param expr String with the expression that failed the assertion. 72 * @param file File containing the failed assertion. 73 * @param line Line number for the failed assertion. 74 * @note This is defined as a weak function and can be overridden at the 75 * application layer to print the debugging information. 76 * @code 77 * printf("%s, file: %s, line %d\n", expr, file, line); 78 * @endcode 79 * @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be 80 * defined. 81 */ 82 void mxc_assert(const char *expr, const char *file, int line); 83 84 /**@} end of group MXC_Assertions*/ 85 86 #ifdef __cplusplus 87 } 88 #endif 89 90 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_MXC_ASSERT_H_ 91