Add missing undefined symbols to be sure to use mine

Dependents:   DS130x_I2CApp MCP41xxxApp FM24Vxx_I2CApp MCP320xApp ... more

Committer:
Yann
Date:
Wed Dec 08 13:16:16 2010 +0000
Revision:
4:d03fcf494eb6
Parent:
3:be0c7a9bd686
Child:
5:7ddb6bca6d01
V0.0.0.5

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 0:311a0646b95a 2 * Copyright (c) 2010 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 4:d03fcf494eb6 30 * 3. Remove comment from line 64 (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 0:311a0646b95a 44 * int counter = 0;
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 4:d03fcf494eb6 49 * HEXADUMP_OFFSET((unsigned char *)str.c_str(), str.length(), 19);
Yann 4:d03fcf494eb6 50 * DEBUG("<<<");
Yann 0:311a0646b95a 51 * while(1) {
Yann 0:311a0646b95a 52 * DEBUG("In loop [%d]", counter++) // A sample message
Yann 0:311a0646b95a 53 * myled = 1;
Yann 0:311a0646b95a 54 * wait(0.2);
Yann 0:311a0646b95a 55 * myled = 0;
Yann 0:311a0646b95a 56 * wait(0.2);
Yann 0:311a0646b95a 57 * DEBUG_BREAK() // Wait for any key pressed to continue
Yann 0:311a0646b95a 58 * } // End of 'while' statement
Yann 0:311a0646b95a 59 * DEBUG_LEAVE("main, never reached") // Log the end of the C function 'main'
Yann 0:311a0646b95a 60 * }
Yann 0:311a0646b95a 61 * @endcode
Yann 0:311a0646b95a 62 */
Yann 3:be0c7a9bd686 63 #undef __DEBUG //<! Undefined debug flah, default value
Yann 3:be0c7a9bd686 64 //#define __DEBUG //<! Uncomment this line to activate debug macros
Yann 0:311a0646b95a 65
Yann 3:be0c7a9bd686 66 // Undefined DEBUG symbols to be sure to use mine
Yann 0:311a0646b95a 67 #undef DEBUG_ENTER
Yann 0:311a0646b95a 68 #undef DEBUG_LEAVE
Yann 0:311a0646b95a 69 #undef DEBUG
Yann 0:311a0646b95a 70
Yann 0:311a0646b95a 71 #ifdef __DEBUG
Yann 0:311a0646b95a 72
Yann 4:d03fcf494eb6 73 /** This class implements debug functionalities based on USB console interface. V0.0.0.5
Yann 0:311a0646b95a 74 *
Yann 0:311a0646b95a 75 * Note that this class is based on Helper pattern
Yann 0:311a0646b95a 76 */
Yann 0:311a0646b95a 77 class DebugHelper
Yann 0:311a0646b95a 78 {
Yann 4:d03fcf494eb6 79 static inline unsigned char ToHexDigit(unsigned char p_digit) { return ((p_digit < 10) ? (p_digit + 0x30) : (p_digit + 0x37)); };
Yann 4:d03fcf494eb6 80 static inline char ToCharDigit(unsigned char p_digit) { return (((p_digit < 0x20) || (p_digit > 0x80)) ? '.' : (char)p_digit); };
Yann 0:311a0646b95a 81 public:
Yann 4:d03fcf494eb6 82 /** Standard log method
Yann 4:d03fcf494eb6 83 * @param p_format Format string compliant with C 'printf' format string
Yann 0:311a0646b95a 84 */
Yann 4:d03fcf494eb6 85 static void Debug(const char* p_format, ...);
Yann 4:d03fcf494eb6 86 /** Log an hexadecimal buffer
Yann 4:d03fcf494eb6 87 *
Yann 4:d03fcf494eb6 88 * Note that parameters 'p_offset' and 'p_length' are not supported yet
Yann 4:d03fcf494eb6 89 *
Yann 4:d03fcf494eb6 90 * @param p_buffer The buffer to dump
Yann 4:d03fcf494eb6 91 * @param p_count Number of bytes to dump
Yann 4:d03fcf494eb6 92 * @param p_offset Offset to start the dump. Default: 0
Yann 4:d03fcf494eb6 93 */
Yann 4:d03fcf494eb6 94 static void HexaDump(unsigned char* p_buffer, int p_count, int p_offset = 0);
Yann 0:311a0646b95a 95 /** Break point method based on getchar() C function
Yann 0:311a0646b95a 96 */
Yann 4:d03fcf494eb6 97 static void BreakPoint(const char* p_file, int p_line);
Yann 0:311a0646b95a 98 }; // End of class DebugHelper
Yann 0:311a0646b95a 99
Yann 3:be0c7a9bd686 100 /** Used to log function/method entry (>> )
Yann 0:311a0646b95a 101 *
Yann 0:311a0646b95a 102 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 103 */
Yann 0:311a0646b95a 104 #define DEBUG_ENTER(...) do { DebugHelper::Debug(">> "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 3:be0c7a9bd686 105 /** Used to log function end of function/method (<< )
Yann 0:311a0646b95a 106 *
Yann 0:311a0646b95a 107 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 108 */
Yann 0:311a0646b95a 109 #define DEBUG_LEAVE(...) do { DebugHelper::Debug("<< "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 0:311a0646b95a 110 /** Used to log a standard message
Yann 0:311a0646b95a 111 *
Yann 0:311a0646b95a 112 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 113 */
Yann 0:311a0646b95a 114 #define DEBUG(...) do { DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 4:d03fcf494eb6 115 /** Used to dump an hexadecimal buffer
Yann 4:d03fcf494eb6 116 *
Yann 4:d03fcf494eb6 117 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 118 */
Yann 4:d03fcf494eb6 119 #define HEXADUMP(p_buffer, p_count) DebugHelper::HexaDump(p_buffer, p_count);
Yann 4:d03fcf494eb6 120 /** Used to dump an hexadecimal buffer with an offset
Yann 4:d03fcf494eb6 121 *
Yann 4:d03fcf494eb6 122 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 123 */
Yann 4:d03fcf494eb6 124 #define HEXADUMP_OFFSET(p_buffer, p_count, p_offset) DebugHelper::HexaDump(p_buffer, p_count, p_offset);
Yann 1:fbb7a9674868 125 /** Used to log an error message (?? )
Yann 0:311a0646b95a 126 *
Yann 0:311a0646b95a 127 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 128 */
Yann 2:12cc94a627cf 129 #define DEBUG_ERROR(...) do { DebugHelper::Debug("?? "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 1:fbb7a9674868 130 /** Used to log a warning message (!! )
Yann 0:311a0646b95a 131 *
Yann 0:311a0646b95a 132 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 133 */
Yann 0:311a0646b95a 134 #define DEBUG_WARNING(...) do { DebugHelper::Debug("!! "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 0:311a0646b95a 135
Yann 0:311a0646b95a 136 /** Break point macro
Yann 0:311a0646b95a 137 */
Yann 0:311a0646b95a 138 #define DEBUG_BREAK() DebugHelper::BreakPoint(__FILE__, __LINE__);
Yann 0:311a0646b95a 139
Yann 0:311a0646b95a 140 /** Used to stop program on fatal error
Yann 0:311a0646b95a 141 */
Yann 0:311a0646b95a 142 #define DEBUG_FATAL(cause) error(cause);
Yann 0:311a0646b95a 143
Yann 0:311a0646b95a 144 #else // __DEBUG
Yann 0:311a0646b95a 145
Yann 0:311a0646b95a 146 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 147 */
Yann 0:311a0646b95a 148 #define DEBUG_ENTER(...)
Yann 0:311a0646b95a 149 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 150 */
Yann 0:311a0646b95a 151 #define DEBUG_LEAVE(...)
Yann 0:311a0646b95a 152 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 153 */
Yann 0:311a0646b95a 154 #define DEBUG(...)
Yann 4:d03fcf494eb6 155 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 4:d03fcf494eb6 156 *
Yann 4:d03fcf494eb6 157 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 158 */
Yann 4:d03fcf494eb6 159 #define HEXADUMP(p_buffer, p_count)
Yann 4:d03fcf494eb6 160 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 4:d03fcf494eb6 161 *
Yann 4:d03fcf494eb6 162 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 163 */
Yann 4:d03fcf494eb6 164 #define HEXADUMP_OFFSET(p_buffer, p_count, p_offset)
Yann 2:12cc94a627cf 165 /** Undefine DEBUG_ERROR macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 166 */
Yann 2:12cc94a627cf 167 #define DEBUG_ERROR(...)
Yann 0:311a0646b95a 168 /** Undefine DEBUG_WARNING macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 169 */
Yann 0:311a0646b95a 170 #define DEBUG_WARNING(...)
Yann 0:311a0646b95a 171
Yann 0:311a0646b95a 172 /** Undefine DEBUG_BREAK macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 173 */
Yann 0:311a0646b95a 174 #define DEBUG_BREAK()
Yann 0:311a0646b95a 175
Yann 0:311a0646b95a 176 /** Undefine DEBUG_FATAL macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 177 */
Yann 0:311a0646b95a 178 #define DEBUG_FATAL(cause)
Yann 0:311a0646b95a 179
Yann 0:311a0646b95a 180 #endif // __DEBUG
Yann 0:311a0646b95a 181
Yann 0:311a0646b95a 182 #endif // __DEBUG_H__