initial

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:638edba3adf6 1 /* mbed Microcontroller Library
yihui 0:638edba3adf6 2 * Copyright (c) 2006-2013 ARM Limited
yihui 0:638edba3adf6 3 *
yihui 0:638edba3adf6 4 * Licensed under the Apache License, Version 2.0 (the "License");
yihui 0:638edba3adf6 5 * you may not use this file except in compliance with the License.
yihui 0:638edba3adf6 6 * You may obtain a copy of the License at
yihui 0:638edba3adf6 7 *
yihui 0:638edba3adf6 8 * http://www.apache.org/licenses/LICENSE-2.0
yihui 0:638edba3adf6 9 *
yihui 0:638edba3adf6 10 * Unless required by applicable law or agreed to in writing, software
yihui 0:638edba3adf6 11 * distributed under the License is distributed on an "AS IS" BASIS,
yihui 0:638edba3adf6 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
yihui 0:638edba3adf6 13 * See the License for the specific language governing permissions and
yihui 0:638edba3adf6 14 * limitations under the License.
yihui 0:638edba3adf6 15 */
yihui 0:638edba3adf6 16 #ifndef MBED_DEBUG_H
yihui 0:638edba3adf6 17 #define MBED_DEBUG_H
yihui 0:638edba3adf6 18 #include "device.h"
yihui 0:638edba3adf6 19
yihui 0:638edba3adf6 20 #ifdef __cplusplus
yihui 0:638edba3adf6 21 extern "C" {
yihui 0:638edba3adf6 22 #endif
yihui 0:638edba3adf6 23
yihui 0:638edba3adf6 24 #if DEVICE_STDIO_MESSAGES
yihui 0:638edba3adf6 25 #include <stdio.h>
yihui 0:638edba3adf6 26 #include <stdarg.h>
yihui 0:638edba3adf6 27
yihui 0:638edba3adf6 28 /** Output a debug message
yihui 0:638edba3adf6 29 *
yihui 0:638edba3adf6 30 * @param format printf-style format string, followed by variables
yihui 0:638edba3adf6 31 */
yihui 0:638edba3adf6 32 static inline void debug(const char *format, ...) {
yihui 0:638edba3adf6 33 va_list args;
yihui 0:638edba3adf6 34 va_start(args, format);
yihui 0:638edba3adf6 35 vfprintf(stderr, format, args);
yihui 0:638edba3adf6 36 va_end(args);
yihui 0:638edba3adf6 37 }
yihui 0:638edba3adf6 38
yihui 0:638edba3adf6 39 /** Conditionally output a debug message
yihui 0:638edba3adf6 40 *
yihui 0:638edba3adf6 41 * NOTE: If the condition is constant false (!= 1) and the compiler optimization
yihui 0:638edba3adf6 42 * level is greater than 0, then the whole function will be compiled away.
yihui 0:638edba3adf6 43 *
yihui 0:638edba3adf6 44 * @param condition output only if condition is true (== 1)
yihui 0:638edba3adf6 45 * @param format printf-style format string, followed by variables
yihui 0:638edba3adf6 46 */
yihui 0:638edba3adf6 47 static inline void debug_if(int condition, const char *format, ...) {
yihui 0:638edba3adf6 48 if (condition == 1) {
yihui 0:638edba3adf6 49 va_list args;
yihui 0:638edba3adf6 50 va_start(args, format);
yihui 0:638edba3adf6 51 vfprintf(stderr, format, args);
yihui 0:638edba3adf6 52 va_end(args);
yihui 0:638edba3adf6 53 }
yihui 0:638edba3adf6 54 }
yihui 0:638edba3adf6 55
yihui 0:638edba3adf6 56 #else
yihui 0:638edba3adf6 57 static inline void debug(const char *format, ...) {}
yihui 0:638edba3adf6 58 static inline void debug_if(int condition, const char *format, ...) {}
yihui 0:638edba3adf6 59
yihui 0:638edba3adf6 60 #endif
yihui 0:638edba3adf6 61
yihui 0:638edba3adf6 62 #ifdef __cplusplus
yihui 0:638edba3adf6 63 }
yihui 0:638edba3adf6 64 #endif
yihui 0:638edba3adf6 65
yihui 0:638edba3adf6 66 #endif