Add missing undefined symbols to be sure to use mine

Dependents:   DS130x_I2CApp MCP41xxxApp FM24Vxx_I2CApp MCP320xApp ... more

Committer:
Yann
Date:
Fri Jan 14 16:08:28 2011 +0000
Revision:
8:ce74b6c101b9
Parent:
7:e10debbe8dad
Child:
9:a11adabe9ded
V0.0.0.9

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yann 0:311a0646b95a 1 /* mbed Debug library used by all my developed program
Yann 8:ce74b6c101b9 2 * Copyright (c) 2010-2011 ygarcia
Yann 0:311a0646b95a 3 *
Yann 0:311a0646b95a 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Yann 0:311a0646b95a 5 * of this software and associated documentation files (the "Software"), to deal
Yann 0:311a0646b95a 6 * in the Software without restriction, including without limitation the rights
Yann 0:311a0646b95a 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Yann 0:311a0646b95a 8 * copies of the Software, and to permit persons to whom the Software is
Yann 0:311a0646b95a 9 * furnished to do so, subject to the following conditions:
Yann 0:311a0646b95a 10 *
Yann 0:311a0646b95a 11 * The above copyright notice and this permission notice shall be included in
Yann 0:311a0646b95a 12 * all copies or substantial portions of the Software.
Yann 0:311a0646b95a 13 *
Yann 0:311a0646b95a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Yann 0:311a0646b95a 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Yann 0:311a0646b95a 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Yann 0:311a0646b95a 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Yann 0:311a0646b95a 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Yann 0:311a0646b95a 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Yann 0:311a0646b95a 20 * THE SOFTWARE.
Yann 0:311a0646b95a 21 */
Yann 0:311a0646b95a 22 #if !defined(__DEBUG_H__)
Yann 0:311a0646b95a 23 #define __DEBUG_H__
Yann 0:311a0646b95a 24
Yann 0:311a0646b95a 25 #include "mbed.h"
Yann 0:311a0646b95a 26
Yann 0:311a0646b95a 27 /** The steps below describe how to use this library:
Yann 0:311a0646b95a 28 * 1. Import this library to your project 'As file', because you will need to modify this file as described in step 2
Yann 0:311a0646b95a 29 * 2. Edit this library
Yann 5:7ddb6bca6d01 30 * 3. Remove comment from line 66 (search for '//#define __DEBUG' in this file) to get the DEBUG macro defimed properly. By default, __DEBUG flahg is undef
Yann 0:311a0646b95a 31 * 4. Rebuild this library and use the debug macro as decribe in sample code
Yann 0:311a0646b95a 32 *
Yann 0:311a0646b95a 33 * IMPORTANT: If you modify this libray, please keep this comment up to date for future users
Yann 0:311a0646b95a 34 *
Yann 0:311a0646b95a 35 * Please refer to handbook (http://mbed.org/handbook/Debugging) for mbed Debugging support
Yann 0:311a0646b95a 36 *
Yann 0:311a0646b95a 37 * @code
Yann 0:311a0646b95a 38 * #include "Debug.h" // This header alway includes mbed.h file
Yann 0:311a0646b95a 39 *
Yann 0:311a0646b95a 40 * DigitalOut myled(LED1);
Yann 0:311a0646b95a 41 *
Yann 0:311a0646b95a 42 * int main() {
Yann 0:311a0646b95a 43 * DEBUG_ENTER("main") // Log the entry of the C function 'main'
Yann 5:7ddb6bca6d01 44 *
Yann 4:d03fcf494eb6 45 * std::string str("This is a sample for heaxdecimal dump using DebugLibrary");
Yann 4:d03fcf494eb6 46 * DEBUG(">>> Example:");
Yann 4:d03fcf494eb6 47 * HEXADUMP((unsigned char *)str.c_str(), str.length());
Yann 4:d03fcf494eb6 48 * DEBUG("===");
Yann 5:7ddb6bca6d01 49 * HEXADUMP_OFFSET((unsigned char *)str.c_str(), str.length() - 19, 19);
Yann 4:d03fcf494eb6 50 * DEBUG("<<<");
Yann 5:7ddb6bca6d01 51 *
Yann 5:7ddb6bca6d01 52 * int counter = 0;
Yann 0:311a0646b95a 53 * while(1) {
Yann 0:311a0646b95a 54 * DEBUG("In loop [%d]", counter++) // A sample message
Yann 0:311a0646b95a 55 * myled = 1;
Yann 0:311a0646b95a 56 * wait(0.2);
Yann 0:311a0646b95a 57 * myled = 0;
Yann 0:311a0646b95a 58 * wait(0.2);
Yann 0:311a0646b95a 59 * DEBUG_BREAK() // Wait for any key pressed to continue
Yann 0:311a0646b95a 60 * } // End of 'while' statement
Yann 0:311a0646b95a 61 * DEBUG_LEAVE("main, never reached") // Log the end of the C function 'main'
Yann 0:311a0646b95a 62 * }
Yann 0:311a0646b95a 63 * @endcode
Yann 0:311a0646b95a 64 */
Yann 8:ce74b6c101b9 65 //#undef __DEBUG //<! Undefined debug flah, default value
Yann 8:ce74b6c101b9 66 #define __DEBUG //<! Uncomment this line to activate debug macros
Yann 0:311a0646b95a 67
Yann 3:be0c7a9bd686 68 // Undefined DEBUG symbols to be sure to use mine
Yann 0:311a0646b95a 69 #undef DEBUG_ENTER
Yann 0:311a0646b95a 70 #undef DEBUG_LEAVE
Yann 0:311a0646b95a 71 #undef DEBUG
Yann 8:ce74b6c101b9 72 #undef HEXADUMP
Yann 8:ce74b6c101b9 73 #undef HEXADUMP_OFFSET
Yann 8:ce74b6c101b9 74 #undef DEBUG_ERROR
Yann 8:ce74b6c101b9 75 #undef DEBUG_WARNING
Yann 8:ce74b6c101b9 76 #undef DEBUG_BREAK
Yann 8:ce74b6c101b9 77 #undef DEBUG_FATAL
Yann 0:311a0646b95a 78
Yann 0:311a0646b95a 79 #ifdef __DEBUG
Yann 0:311a0646b95a 80
Yann 7:e10debbe8dad 81 /** This class implements debug functionalities based on USB console interface. V0.0.0.8
Yann 0:311a0646b95a 82 *
Yann 0:311a0646b95a 83 * Note that this class is based on Helper pattern
Yann 0:311a0646b95a 84 */
Yann 0:311a0646b95a 85 class DebugHelper
Yann 0:311a0646b95a 86 {
Yann 5:7ddb6bca6d01 87 /** Convert the specified digit into hexadecimal number (0x30..0x39 (0..9), 0x47..x4c (A..F))
Yann 5:7ddb6bca6d01 88 *
Yann 5:7ddb6bca6d01 89 * @param p_digit The digit to convert
Yann 5:7ddb6bca6d01 90 * @return An hexadecimal digit (0..9-A..F)
Yann 5:7ddb6bca6d01 91 */
Yann 4:d03fcf494eb6 92 static inline unsigned char ToHexDigit(unsigned char p_digit) { return ((p_digit < 10) ? (p_digit + 0x30) : (p_digit + 0x37)); };
Yann 5:7ddb6bca6d01 93 /** Convert the specified hexadecimal digit into a character if it is printable, or replace by a '.' otherwise
Yann 5:7ddb6bca6d01 94 *
Yann 5:7ddb6bca6d01 95 * @param p_digit The hexadecimal digit to convert
Yann 5:7ddb6bca6d01 96 * @return A character is it's printable, '.' otherwise
Yann 5:7ddb6bca6d01 97 */
Yann 4:d03fcf494eb6 98 static inline char ToCharDigit(unsigned char p_digit) { return (((p_digit < 0x20) || (p_digit > 0x80)) ? '.' : (char)p_digit); };
Yann 0:311a0646b95a 99 public:
Yann 4:d03fcf494eb6 100 /** Standard log method
Yann 4:d03fcf494eb6 101 * @param p_format Format string compliant with C 'printf' format string
Yann 0:311a0646b95a 102 */
Yann 4:d03fcf494eb6 103 static void Debug(const char* p_format, ...);
Yann 4:d03fcf494eb6 104 /** Log an hexadecimal buffer
Yann 4:d03fcf494eb6 105 *
Yann 4:d03fcf494eb6 106 * Note that parameters 'p_offset' and 'p_length' are not supported yet
Yann 4:d03fcf494eb6 107 *
Yann 4:d03fcf494eb6 108 * @param p_buffer The buffer to dump
Yann 4:d03fcf494eb6 109 * @param p_count Number of bytes to dump
Yann 4:d03fcf494eb6 110 * @param p_offset Offset to start the dump. Default: 0
Yann 4:d03fcf494eb6 111 */
Yann 4:d03fcf494eb6 112 static void HexaDump(unsigned char* p_buffer, int p_count, int p_offset = 0);
Yann 0:311a0646b95a 113 /** Break point method based on getchar() C function
Yann 0:311a0646b95a 114 */
Yann 4:d03fcf494eb6 115 static void BreakPoint(const char* p_file, int p_line);
Yann 0:311a0646b95a 116 }; // End of class DebugHelper
Yann 0:311a0646b95a 117
Yann 3:be0c7a9bd686 118 /** Used to log function/method entry (>> )
Yann 0:311a0646b95a 119 *
Yann 0:311a0646b95a 120 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 121 */
Yann 0:311a0646b95a 122 #define DEBUG_ENTER(...) do { DebugHelper::Debug(">> "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 3:be0c7a9bd686 123 /** Used to log function end of function/method (<< )
Yann 0:311a0646b95a 124 *
Yann 0:311a0646b95a 125 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 126 */
Yann 0:311a0646b95a 127 #define DEBUG_LEAVE(...) do { DebugHelper::Debug("<< "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 0:311a0646b95a 128 /** Used to log a standard message
Yann 0:311a0646b95a 129 *
Yann 0:311a0646b95a 130 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 131 */
Yann 0:311a0646b95a 132 #define DEBUG(...) do { DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 4:d03fcf494eb6 133 /** Used to dump an hexadecimal buffer
Yann 4:d03fcf494eb6 134 *
Yann 4:d03fcf494eb6 135 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 136 */
Yann 4:d03fcf494eb6 137 #define HEXADUMP(p_buffer, p_count) DebugHelper::HexaDump(p_buffer, p_count);
Yann 4:d03fcf494eb6 138 /** Used to dump an hexadecimal buffer with an offset
Yann 4:d03fcf494eb6 139 *
Yann 4:d03fcf494eb6 140 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 141 */
Yann 4:d03fcf494eb6 142 #define HEXADUMP_OFFSET(p_buffer, p_count, p_offset) DebugHelper::HexaDump(p_buffer, p_count, p_offset);
Yann 1:fbb7a9674868 143 /** Used to log an error message (?? )
Yann 0:311a0646b95a 144 *
Yann 0:311a0646b95a 145 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 146 */
Yann 2:12cc94a627cf 147 #define DEBUG_ERROR(...) do { DebugHelper::Debug("?? "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 1:fbb7a9674868 148 /** Used to log a warning message (!! )
Yann 0:311a0646b95a 149 *
Yann 0:311a0646b95a 150 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 151 */
Yann 0:311a0646b95a 152 #define DEBUG_WARNING(...) do { DebugHelper::Debug("!! "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 0:311a0646b95a 153
Yann 0:311a0646b95a 154 /** Break point macro
Yann 0:311a0646b95a 155 */
Yann 0:311a0646b95a 156 #define DEBUG_BREAK() DebugHelper::BreakPoint(__FILE__, __LINE__);
Yann 0:311a0646b95a 157
Yann 0:311a0646b95a 158 /** Used to stop program on fatal error
Yann 0:311a0646b95a 159 */
Yann 0:311a0646b95a 160 #define DEBUG_FATAL(cause) error(cause);
Yann 0:311a0646b95a 161
Yann 0:311a0646b95a 162 #else // __DEBUG
Yann 0:311a0646b95a 163
Yann 0:311a0646b95a 164 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 165 */
Yann 0:311a0646b95a 166 #define DEBUG_ENTER(...)
Yann 0:311a0646b95a 167 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 168 */
Yann 0:311a0646b95a 169 #define DEBUG_LEAVE(...)
Yann 0:311a0646b95a 170 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 171 */
Yann 0:311a0646b95a 172 #define DEBUG(...)
Yann 4:d03fcf494eb6 173 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 4:d03fcf494eb6 174 *
Yann 4:d03fcf494eb6 175 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 176 */
Yann 4:d03fcf494eb6 177 #define HEXADUMP(p_buffer, p_count)
Yann 4:d03fcf494eb6 178 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 4:d03fcf494eb6 179 *
Yann 4:d03fcf494eb6 180 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 181 */
Yann 4:d03fcf494eb6 182 #define HEXADUMP_OFFSET(p_buffer, p_count, p_offset)
Yann 2:12cc94a627cf 183 /** Undefine DEBUG_ERROR macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 184 */
Yann 2:12cc94a627cf 185 #define DEBUG_ERROR(...)
Yann 0:311a0646b95a 186 /** Undefine DEBUG_WARNING macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 187 */
Yann 0:311a0646b95a 188 #define DEBUG_WARNING(...)
Yann 0:311a0646b95a 189
Yann 0:311a0646b95a 190 /** Undefine DEBUG_BREAK macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 191 */
Yann 0:311a0646b95a 192 #define DEBUG_BREAK()
Yann 0:311a0646b95a 193
Yann 0:311a0646b95a 194 /** Undefine DEBUG_FATAL macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 195 */
Yann 0:311a0646b95a 196 #define DEBUG_FATAL(cause)
Yann 0:311a0646b95a 197
Yann 0:311a0646b95a 198 #endif // __DEBUG
Yann 0:311a0646b95a 199
Yann 0:311a0646b95a 200 #endif // __DEBUG_H__