1 /****************************************************************************** 2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK") 3 * All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *****************************************************************************/ 18 #pragma once 19 20 #include "config/user_config.h" // for __DEBUG__ 21 22 /////////////////////////////////////////////////////////////////////////////////// 23 #if (__DEBUG__) 24 25 #define assert(expression) \ 26 do { \ 27 if (!(expression)) \ 28 __assert(expression, __FILE__, __LINE__) \ 29 } while (0) 30 31 #define __assert(expression, file, lineno) \ 32 { \ 33 printf("%s:%u: assertion failed!\n", file, lineno); \ 34 } 35 36 #else 37 #define assert(ignore) ((void)0) 38 #endif 39 40 //////////////////// To do compiler warning ////////////////// 41 // http://stackoverflow.com/questions/5966594/how-can-i-use-pragma-message-so-that-the-message-points-to-the-filelineno 42 // http://gcc.gnu.org/ml/gcc-help/2010-10/msg00196.html 43 // http://stackoverflow.com/questions/3030099/c-c-pragma-in-define-macro 44 45 #define _STRINGIFY(x) #x 46 #define STRINGIFY(x) _STRINGIFY(x) 47 48 #ifdef __GNUC__ 49 #define COMPILE_MESSAGE(x) _Pragma(#x) 50 #endif 51 52 #if (__SHOW_TODO__) 53 #ifdef __GNUC__ 54 #define TODO(x) COMPILE_MESSAGE(message("--TODO-- " #x)) 55 #else 56 #define TODO(x) __pragma(message("--TODO-- "_STRINGIFY(x) " ::function: " __FUNCTION__ "@" STRINGIFY(__LINE__))) 57 #endif 58 #else 59 #define TODO(x) 60 #endif 61 62 #if (__SHOW_WARN__) 63 #ifdef __GNUC__ 64 #define WARN(x) COMPILE_MESSAGE(message("--WARN-- " #x)) 65 #else 66 #define WARN(x) __pragma(message("--WARN-- "_STRINGIFY(x) " ::function: " __FUNCTION__ "@" STRINGIFY(__LINE__))) 67 #endif 68 #else 69 #define WARN(x) 70 #endif 71 72 #if (__SHOW_WARN__) 73 #ifdef __GNUC__ 74 #define NOTE(x) COMPILE_MESSAGE(message("--NOTE-- " #x)) 75 #else 76 #define NOTE(x) __pragma(message("--NOTE-- "_STRINGIFY(x) " ::function: " __FUNCTION__ "@" STRINGIFY(__LINE__))) 77 #endif 78 #else 79 #define NOTE(x) 80 #endif 81