mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_debug.h Source File

mbed_debug.h

00001 
00002 /** \addtogroup platform */
00003 /** @{*/
00004 /**
00005  * \defgroup platform_debug Debug functions
00006  * @{
00007  */
00008 
00009 /* mbed Microcontroller Library
00010  * Copyright (c) 2006-2013 ARM Limited
00011  * SPDX-License-Identifier: Apache-2.0
00012  *
00013  * Licensed under the Apache License, Version 2.0 (the "License");
00014  * you may not use this file except in compliance with the License.
00015  * You may obtain a copy of the License at
00016  *
00017  *     http://www.apache.org/licenses/LICENSE-2.0
00018  *
00019  * Unless required by applicable law or agreed to in writing, software
00020  * distributed under the License is distributed on an "AS IS" BASIS,
00021  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022  * See the License for the specific language governing permissions and
00023  * limitations under the License.
00024  */
00025 #ifndef MBED_DEBUG_H
00026 #define MBED_DEBUG_H
00027 #if DEVICE_STDIO_MESSAGES
00028 #include <stdio.h>
00029 #include <stdarg.h>
00030 #endif
00031 #include "mbed_toolchain.h"
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 static inline void debug(const char *format, ...) MBED_PRINTF(1, 2);
00038 static inline void debug_if(int condition, const char *format, ...) MBED_PRINTF(2, 3);
00039 
00040 /** Output a debug message
00041  *
00042  * @param format printf-style format string, followed by variables
00043  */
00044 static inline void debug(const char *format, ...)
00045 {
00046 #if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
00047     va_list args;
00048     va_start(args, format);
00049     vfprintf(stderr, format, args);
00050     va_end(args);
00051 #endif
00052 }
00053 
00054 
00055 /** Conditionally output a debug message
00056  *
00057  * NOTE: If the condition is constant false (== 0) and the compiler optimization
00058  * level is greater than 0, then the whole function will be compiled away.
00059  *
00060  * @param condition output only if condition is true (!= 0)
00061  * @param format printf-style format string, followed by variables
00062  */
00063 static inline void debug_if(int condition, const char *format, ...)
00064 {
00065 #if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
00066     if (condition) {
00067         va_list args;
00068         va_start(args, format);
00069         vfprintf(stderr, format, args);
00070         va_end(args);
00071     }
00072 #endif
00073 }
00074 
00075 
00076 #ifdef __cplusplus
00077 }
00078 #endif
00079 
00080 #endif
00081 
00082 /**@}*/
00083 
00084 /**@}*/
00085