mbed library sources
Fork of mbed-src by
capi/mbed_debug.h@1:62685faffa05, 2012-11-29 (annotated)
- Committer:
- emilmont
- Date:
- Thu Nov 29 15:41:14 2012 +0000
- Revision:
- 1:62685faffa05
- Child:
- 2:143cac498751
Update sources to [Rev 49]
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:62685faffa05 | 1 | /* mbed Microcontroller Library |
emilmont | 1:62685faffa05 | 2 | * Copyright (c) 2006-2012 ARM Limited |
emilmont | 1:62685faffa05 | 3 | * |
emilmont | 1:62685faffa05 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
emilmont | 1:62685faffa05 | 5 | * of this software and associated documentation files (the "Software"), to deal |
emilmont | 1:62685faffa05 | 6 | * in the Software without restriction, including without limitation the rights |
emilmont | 1:62685faffa05 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
emilmont | 1:62685faffa05 | 8 | * copies of the Software, and to permit persons to whom the Software is |
emilmont | 1:62685faffa05 | 9 | * furnished to do so, subject to the following conditions: |
emilmont | 1:62685faffa05 | 10 | * |
emilmont | 1:62685faffa05 | 11 | * The above copyright notice and this permission notice shall be included in |
emilmont | 1:62685faffa05 | 12 | * all copies or substantial portions of the Software. |
emilmont | 1:62685faffa05 | 13 | * |
emilmont | 1:62685faffa05 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
emilmont | 1:62685faffa05 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
emilmont | 1:62685faffa05 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
emilmont | 1:62685faffa05 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
emilmont | 1:62685faffa05 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
emilmont | 1:62685faffa05 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
emilmont | 1:62685faffa05 | 20 | * SOFTWARE. |
emilmont | 1:62685faffa05 | 21 | */ |
emilmont | 1:62685faffa05 | 22 | #ifndef MBED_DEBUG_H |
emilmont | 1:62685faffa05 | 23 | #define MBED_DEBUG_H |
emilmont | 1:62685faffa05 | 24 | #include "device.h" |
emilmont | 1:62685faffa05 | 25 | |
emilmont | 1:62685faffa05 | 26 | #ifdef __cplusplus |
emilmont | 1:62685faffa05 | 27 | extern "C" { |
emilmont | 1:62685faffa05 | 28 | #endif |
emilmont | 1:62685faffa05 | 29 | |
emilmont | 1:62685faffa05 | 30 | #ifdef DEVICE_STDIO_MESSAGES |
emilmont | 1:62685faffa05 | 31 | #include <stdio.h> |
emilmont | 1:62685faffa05 | 32 | #include <stdarg.h> |
emilmont | 1:62685faffa05 | 33 | |
emilmont | 1:62685faffa05 | 34 | /** Output a debug message |
emilmont | 1:62685faffa05 | 35 | * |
emilmont | 1:62685faffa05 | 36 | * @param format printf-style format string, followed by variables |
emilmont | 1:62685faffa05 | 37 | */ |
emilmont | 1:62685faffa05 | 38 | static inline void debug(const char *format, ...) { |
emilmont | 1:62685faffa05 | 39 | va_list args; |
emilmont | 1:62685faffa05 | 40 | va_start(args, format); |
emilmont | 1:62685faffa05 | 41 | vfprintf(stderr, format, args); |
emilmont | 1:62685faffa05 | 42 | va_end(args); |
emilmont | 1:62685faffa05 | 43 | } |
emilmont | 1:62685faffa05 | 44 | |
emilmont | 1:62685faffa05 | 45 | /** Conditionally output a debug message |
emilmont | 1:62685faffa05 | 46 | * |
emilmont | 1:62685faffa05 | 47 | * NOTE: If the condition is constant false (!= 1) and the compiler optimization |
emilmont | 1:62685faffa05 | 48 | * level is greater than 0, then the whole function will be compiled away. |
emilmont | 1:62685faffa05 | 49 | * |
emilmont | 1:62685faffa05 | 50 | * @param condition output only if condition is true (== 1) |
emilmont | 1:62685faffa05 | 51 | * @param format printf-style format string, followed by variables |
emilmont | 1:62685faffa05 | 52 | */ |
emilmont | 1:62685faffa05 | 53 | static inline void debug_if(int condition, const char *format, ...) { |
emilmont | 1:62685faffa05 | 54 | if (condition == 1) { |
emilmont | 1:62685faffa05 | 55 | va_list args; |
emilmont | 1:62685faffa05 | 56 | va_start(args, format); |
emilmont | 1:62685faffa05 | 57 | vfprintf(stderr, format, args); |
emilmont | 1:62685faffa05 | 58 | va_end(args); |
emilmont | 1:62685faffa05 | 59 | } |
emilmont | 1:62685faffa05 | 60 | } |
emilmont | 1:62685faffa05 | 61 | |
emilmont | 1:62685faffa05 | 62 | #else |
emilmont | 1:62685faffa05 | 63 | static inline void debug(const char *format, ...) {} |
emilmont | 1:62685faffa05 | 64 | static inline void debug_if(int condition, const char *format, ...) {} |
emilmont | 1:62685faffa05 | 65 | |
emilmont | 1:62685faffa05 | 66 | #endif |
emilmont | 1:62685faffa05 | 67 | |
emilmont | 1:62685faffa05 | 68 | #ifdef __cplusplus |
emilmont | 1:62685faffa05 | 69 | } |
emilmont | 1:62685faffa05 | 70 | #endif |
emilmont | 1:62685faffa05 | 71 | |
emilmont | 1:62685faffa05 | 72 | #endif |