1 /** 2 * \file 3 * 4 * \brief Asserts related functionality. 5 * 6 * Copyright (C) 2014 Atmel Corporation. All rights reserved. 7 * 8 * \asf_license_start 9 * 10 * \page License 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions are met: 14 * 15 * 1. Redistributions of source code must retain the above copyright notice, 16 * this list of conditions and the following disclaimer. 17 * 18 * 2. Redistributions in binary form must reproduce the above copyright notice, 19 * this list of conditions and the following disclaimer in the documentation 20 * and/or other materials provided with the distribution. 21 * 22 * 3. The name of Atmel may not be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * 4. This software may only be redistributed and used in connection with an 26 * Atmel microcontroller product. 27 * 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 * POSSIBILITY OF SUCH DAMAGE. 39 * 40 * \asf_license_stop 41 * 42 */ 43 44 #ifndef _ASSERT_H_INCLUDED 45 #define _ASSERT_H_INCLUDED 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 #include <compiler.h> 52 53 #ifndef USE_SIMPLE_ASSERT 54 //# define USE_SIMPLE_ASSERT 55 #endif 56 57 /** 58 * \brief Assert macro 59 * 60 * This macro is used to throw asserts. It can be mapped to different function 61 * based on debug level. 62 * 63 * \param[in] condition A condition to be checked; 64 * assert is thrown if the given condition is false 65 */ 66 #define ASSERT(condition) ASSERT_IMPL((condition), __FILE__, __LINE__) 67 68 #ifdef DEBUG 69 70 #ifdef USE_SIMPLE_ASSERT 71 #define ASSERT_IMPL(condition, file, line) \ 72 if (!(condition)) \ 73 __asm("BKPT #0"); 74 #else 75 #define ASSERT_IMPL(condition, file, line) assert((condition), file, line) 76 #endif 77 78 #else /* DEBUG */ 79 80 #ifdef USE_SIMPLE_ASSERT 81 #define ASSERT_IMPL(condition, file, line) ((void)0) 82 #else 83 #define ASSERT_IMPL(condition, file, line) ((void)0) 84 #endif 85 86 #endif /* DEBUG */ 87 88 /** 89 * \brief Assert function 90 * 91 * This function is used to throw asserts. 92 * 93 * \param[in] condition A condition to be checked; assert is thrown if the given 94 * condition is false 95 * \param[in] file File name 96 * \param[in] line Line number 97 */ 98 void assert(const bool condition, const char *const file, const int line); 99 100 #ifdef __cplusplus 101 } 102 #endif 103 #endif /* _ASSERT_H_INCLUDED */ 104