Kévin Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * |
| 4 | * \brief Asserts related functionality. |
| 5 | * |
| 6 | * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries. |
| 7 | * |
| 8 | * \asf_license_start |
| 9 | * |
| 10 | * \page License |
| 11 | * |
| 12 | * Subject to your compliance with these terms, you may use Microchip |
| 13 | * software and any derivatives exclusively with Microchip products. |
| 14 | * It is your responsibility to comply with third party license terms applicable |
| 15 | * to your use of third party software (including open source software) that |
| 16 | * may accompany Microchip software. |
| 17 | * |
| 18 | * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, |
| 19 | * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, |
| 20 | * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, |
| 21 | * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE |
| 22 | * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL |
| 23 | * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE |
| 24 | * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE |
| 25 | * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT |
| 26 | * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY |
| 27 | * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, |
| 28 | * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. |
| 29 | * |
| 30 | * \asf_license_stop |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #ifndef _ASSERT_H_INCLUDED |
| 35 | #define _ASSERT_H_INCLUDED |
| 36 | |
| 37 | #ifdef __cplusplus |
| 38 | extern "C" { |
| 39 | #endif |
| 40 | |
| 41 | #include <compiler.h> |
| 42 | |
| 43 | #ifndef USE_SIMPLE_ASSERT |
| 44 | //# define USE_SIMPLE_ASSERT |
| 45 | #endif |
| 46 | |
| 47 | /** |
| 48 | * \brief Assert macro |
| 49 | * |
| 50 | * This macro is used to throw asserts. It can be mapped to different function |
| 51 | * based on debug level. |
| 52 | * |
| 53 | * \param[in] condition A condition to be checked; |
| 54 | * assert is thrown if the given condition is false |
| 55 | */ |
| 56 | #define ASSERT(condition) ASSERT_IMPL((condition), __FILE__, __LINE__) |
| 57 | |
| 58 | #ifdef DEBUG |
| 59 | |
| 60 | #ifdef USE_SIMPLE_ASSERT |
| 61 | #define ASSERT_IMPL(condition, file, line) \ |
| 62 | if (!(condition)) \ |
| 63 | __asm("BKPT #0"); |
| 64 | #else |
| 65 | #define ASSERT_IMPL(condition, file, line) assert((condition), file, line) |
| 66 | #endif |
| 67 | |
| 68 | #else /* DEBUG */ |
| 69 | |
| 70 | #ifdef USE_SIMPLE_ASSERT |
| 71 | #define ASSERT_IMPL(condition, file, line) ((void)0) |
| 72 | #else |
| 73 | #define ASSERT_IMPL(condition, file, line) ((void)0) |
| 74 | #endif |
| 75 | |
| 76 | #endif /* DEBUG */ |
| 77 | |
| 78 | /** |
| 79 | * \brief Assert function |
| 80 | * |
| 81 | * This function is used to throw asserts. |
| 82 | * |
| 83 | * \param[in] condition A condition to be checked; assert is thrown if the given |
| 84 | * condition is false |
| 85 | * \param[in] file File name |
| 86 | * \param[in] line Line number |
| 87 | */ |
| 88 | void assert(const bool condition, const char *const file, const int line); |
| 89 | |
| 90 | #ifdef __cplusplus |
| 91 | } |
| 92 | #endif |
| 93 | #endif /* _ASSERT_H_INCLUDED */ |