1 /* 2 * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #pragma once 7 8 #include "sdkconfig.h" 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 extern void __assert_func(const char *file, int line, const char *func, const char *expr); 15 extern void abort(void); 16 17 #ifndef __ASSERT_FUNC 18 #ifdef __ASSERT_FUNCTION 19 #define __ASSERT_FUNC __ASSERT_FUNCTION 20 #else 21 #define __ASSERT_FUNC "??" 22 #endif 23 #endif 24 25 #if BOOTLOADER_BUILD 26 // Bootloader has very limited size, while full assertion takes up quite a lot bytes as it prints file, line, and 27 // function info. Therefore, we set the HAL assertion level in bootloader to be no larger than 1 (silent). 28 #if CONFIG_HAL_DEFAULT_ASSERTION_LEVEL == 2 29 #undef CONFIG_HAL_DEFAULT_ASSERTION_LEVEL 30 #define CONFIG_HAL_DEFAULT_ASSERTION_LEVEL 1 31 #endif 32 #endif 33 34 #if IS_ULP_COCPU 35 #define HAL_ASSERT(__e) ((void)(__e)) 36 #elif CONFIG_HAL_DEFAULT_ASSERTION_LEVEL == 1 // silent 37 #define HAL_ASSERT(__e) (__builtin_expect(!!(__e), 1) ? (void)0 : abort()) 38 #elif CONFIG_HAL_DEFAULT_ASSERTION_LEVEL == 2 // full assertion 39 #define HAL_ASSERT(__e) (__builtin_expect(!!(__e), 1) ? (void)0 : __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, #__e)) 40 #else // no assert 41 #define HAL_ASSERT(__e) ((void)(__e)) 42 #endif 43 44 #ifdef __cplusplus 45 } 46 #endif 47