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