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{if(!(expression)) __assert (expression, __FILE__, __LINE__)}while(0) 27 28 #define __assert(expression, file, lineno) {printf ("%s:%u: assertion failed!\n", file, lineno);} 29 30 #else 31 #define assert(ignore) ((void) 0) 32 #endif 33 34 //////////////////// To do compiler warning ////////////////// 35 // http://stackoverflow.com/questions/5966594/how-can-i-use-pragma-message-so-that-the-message-points-to-the-filelineno 36 // http://gcc.gnu.org/ml/gcc-help/2010-10/msg00196.html 37 // http://stackoverflow.com/questions/3030099/c-c-pragma-in-define-macro 38 39 #define _STRINGIFY(x) #x 40 #define STRINGIFY(x) _STRINGIFY(x) 41 42 #ifdef __GNUC__ 43 #define COMPILE_MESSAGE(x) _Pragma (#x) 44 #endif 45 46 #if (__SHOW_TODO__) 47 #ifdef __GNUC__ 48 #define TODO(x) COMPILE_MESSAGE(message ("--TODO-- " #x)) 49 #else 50 #define TODO(x) __pragma(message("--TODO-- "_STRINGIFY(x) " ::function: " __FUNCTION__ "@"STRINGIFY(__LINE__))) 51 #endif 52 #else 53 #define TODO(x) 54 #endif 55 56 #if (__SHOW_WARN__) 57 #ifdef __GNUC__ 58 #define WARN(x) COMPILE_MESSAGE(message ("--WARN-- " #x)) 59 #else 60 #define WARN(x) __pragma(message("--WARN-- "_STRINGIFY(x) " ::function: " __FUNCTION__ "@"STRINGIFY(__LINE__))) 61 #endif 62 #else 63 #define WARN(x) 64 #endif 65 66 #if (__SHOW_WARN__) 67 #ifdef __GNUC__ 68 #define NOTE(x) COMPILE_MESSAGE(message ("--NOTE-- " #x)) 69 #else 70 #define NOTE(x) __pragma(message("--NOTE-- "_STRINGIFY(x) " ::function: " __FUNCTION__ "@"STRINGIFY(__LINE__))) 71 #endif 72 #else 73 #define NOTE(x) 74 #endif 75 76 77