1 /** 2 * @file 3 * @brief Assertion checks for debugging. 4 */ 5 6 /* **************************************************************************** 7 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the "Software"), 11 * to deal in the Software without restriction, including without limitation 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 * and/or sell copies of the Software, and to permit persons to whom the 14 * Software is furnished to do so, subject to the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be included 17 * in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 23 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 * OTHER DEALINGS IN THE SOFTWARE. 26 * 27 * Except as contained in this notice, the name of Maxim Integrated 28 * Products, Inc. shall not be used except as stated in the Maxim Integrated 29 * Products, Inc. Branding Policy. 30 * 31 * The mere transfer of this software does not imply any licenses 32 * of trade secrets, proprietary technology, copyrights, patents, 33 * trademarks, maskwork rights, or any other form of intellectual 34 * property whatsoever. Maxim Integrated Products, Inc. retains all 35 * ownership rights. 36 * 37 * 38 * $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $ 39 * $Revision: 36818 $ 40 * 41 *************************************************************************** */ 42 43 /* Define to prevent redundant inclusion */ 44 #ifndef _MXC_ASSERT_H_ 45 #define _MXC_ASSERT_H_ 46 47 /* **** Includes **** */ 48 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 /** 55 * @ingroup syscfg 56 * @defgroup mxc_assertions Assertion Checks for Debugging 57 * @brief Assertion checks for debugging. 58 * @{ 59 */ 60 /* **** Definitions **** */ 61 /** 62 * @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be 63 * defined. 64 */ 65 ///@cond 66 #ifdef MXC_ASSERT_ENABLE 67 /** 68 * Macro that checks the expression for true and generates an assertion. 69 * @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be 70 * defined. 71 */ 72 #define MXC_ASSERT(expr) \ 73 if (!(expr)) \ 74 { \ 75 mxc_assert(#expr, __FILE__, __LINE__); \ 76 } 77 /** 78 * Macro that generates an assertion with the message "FAIL". 79 * @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be 80 * defined. 81 */ 82 #define MXC_ASSERT_FAIL() mxc_assert("FAIL", __FILE__, __LINE__); 83 #else 84 #define MXC_ASSERT(expr) 85 #define MXC_ASSERT_FAIL() 86 #endif 87 ///@endcond 88 /* **** Globals **** */ 89 90 /* **** Function Prototypes **** */ 91 92 /** 93 * @brief Assert an error when the given expression fails during debugging. 94 * @param expr String with the expression that failed the assertion. 95 * @param file File containing the failed assertion. 96 * @param line Line number for the failed assertion. 97 * @note This is defined as a weak function and can be overridden at the 98 * application layer to print the debugging information. 99 * @code 100 * printf("%s, file: %s, line %d\n", expr, file, line); 101 * @endcode 102 * @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be 103 * defined. 104 */ 105 void mxc_assert(const char *expr, const char *file, int line); 106 107 /**@} end of group MXC_Assertions*/ 108 109 #ifdef __cplusplus 110 } 111 #endif 112 113 #endif /* _MXC_ASSERT_H_ */ 114