Add missing undefined symbols to be sure to use mine

Dependents:   DS130x_I2CApp MCP41xxxApp FM24Vxx_I2CApp MCP320xApp ... more

Committer:
Yann
Date:
Thu Dec 09 09:28:06 2010 +0000
Revision:
6:14a596126adf
Parent:
5:7ddb6bca6d01
Child:
7:e10debbe8dad
V0.0.0.7

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 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 3:be0c7a9bd686 65 #undef __DEBUG //<! Undefined debug flah, default value
Yann 3:be0c7a9bd686 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 0:311a0646b95a 72
Yann 0:311a0646b95a 73 #ifdef __DEBUG
Yann 0:311a0646b95a 74
Yann 6:14a596126adf 75 /** This class implements debug functionalities based on USB console interface. V0.0.0.7
Yann 0:311a0646b95a 76 *
Yann 0:311a0646b95a 77 * Note that this class is based on Helper pattern
Yann 0:311a0646b95a 78 */
Yann 0:311a0646b95a 79 class DebugHelper
Yann 0:311a0646b95a 80 {
Yann 5:7ddb6bca6d01 81 /** Convert the specified digit into hexadecimal number (0x30..0x39 (0..9), 0x47..x4c (A..F))
Yann 5:7ddb6bca6d01 82 *
Yann 5:7ddb6bca6d01 83 * @param p_digit The digit to convert
Yann 5:7ddb6bca6d01 84 * @return An hexadecimal digit (0..9-A..F)
Yann 5:7ddb6bca6d01 85 */
Yann 4:d03fcf494eb6 86 static inline unsigned char ToHexDigit(unsigned char p_digit) { return ((p_digit < 10) ? (p_digit + 0x30) : (p_digit + 0x37)); };
Yann 5:7ddb6bca6d01 87 /** Convert the specified hexadecimal digit into a character if it is printable, or replace by a '.' otherwise
Yann 5:7ddb6bca6d01 88 *
Yann 5:7ddb6bca6d01 89 * @param p_digit The hexadecimal digit to convert
Yann 5:7ddb6bca6d01 90 * @return A character is it's printable, '.' otherwise
Yann 5:7ddb6bca6d01 91 */
Yann 4:d03fcf494eb6 92 static inline char ToCharDigit(unsigned char p_digit) { return (((p_digit < 0x20) || (p_digit > 0x80)) ? '.' : (char)p_digit); };
Yann 0:311a0646b95a 93 public:
Yann 4:d03fcf494eb6 94 /** Standard log method
Yann 4:d03fcf494eb6 95 * @param p_format Format string compliant with C 'printf' format string
Yann 0:311a0646b95a 96 */
Yann 4:d03fcf494eb6 97 static void Debug(const char* p_format, ...);
Yann 4:d03fcf494eb6 98 /** Log an hexadecimal buffer
Yann 4:d03fcf494eb6 99 *
Yann 4:d03fcf494eb6 100 * Note that parameters 'p_offset' and 'p_length' are not supported yet
Yann 4:d03fcf494eb6 101 *
Yann 4:d03fcf494eb6 102 * @param p_buffer The buffer to dump
Yann 4:d03fcf494eb6 103 * @param p_count Number of bytes to dump
Yann 4:d03fcf494eb6 104 * @param p_offset Offset to start the dump. Default: 0
Yann 4:d03fcf494eb6 105 */
Yann 4:d03fcf494eb6 106 static void HexaDump(unsigned char* p_buffer, int p_count, int p_offset = 0);
Yann 0:311a0646b95a 107 /** Break point method based on getchar() C function
Yann 0:311a0646b95a 108 */
Yann 4:d03fcf494eb6 109 static void BreakPoint(const char* p_file, int p_line);
Yann 0:311a0646b95a 110 }; // End of class DebugHelper
Yann 0:311a0646b95a 111
Yann 3:be0c7a9bd686 112 /** Used to log function/method entry (>> )
Yann 0:311a0646b95a 113 *
Yann 0:311a0646b95a 114 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 115 */
Yann 0:311a0646b95a 116 #define DEBUG_ENTER(...) do { DebugHelper::Debug(">> "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 3:be0c7a9bd686 117 /** Used to log function end of function/method (<< )
Yann 0:311a0646b95a 118 *
Yann 0:311a0646b95a 119 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 120 */
Yann 0:311a0646b95a 121 #define DEBUG_LEAVE(...) do { DebugHelper::Debug("<< "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 0:311a0646b95a 122 /** Used to log a standard message
Yann 0:311a0646b95a 123 *
Yann 0:311a0646b95a 124 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 125 */
Yann 0:311a0646b95a 126 #define DEBUG(...) do { DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 4:d03fcf494eb6 127 /** Used to dump an hexadecimal buffer
Yann 4:d03fcf494eb6 128 *
Yann 4:d03fcf494eb6 129 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 130 */
Yann 4:d03fcf494eb6 131 #define HEXADUMP(p_buffer, p_count) DebugHelper::HexaDump(p_buffer, p_count);
Yann 4:d03fcf494eb6 132 /** Used to dump an hexadecimal buffer with an offset
Yann 4:d03fcf494eb6 133 *
Yann 4:d03fcf494eb6 134 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 135 */
Yann 4:d03fcf494eb6 136 #define HEXADUMP_OFFSET(p_buffer, p_count, p_offset) DebugHelper::HexaDump(p_buffer, p_count, p_offset);
Yann 1:fbb7a9674868 137 /** Used to log an error message (?? )
Yann 0:311a0646b95a 138 *
Yann 0:311a0646b95a 139 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 140 */
Yann 2:12cc94a627cf 141 #define DEBUG_ERROR(...) do { DebugHelper::Debug("?? "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 1:fbb7a9674868 142 /** Used to log a warning message (!! )
Yann 0:311a0646b95a 143 *
Yann 0:311a0646b95a 144 * Note that \ for multiline macro is not supported yet
Yann 0:311a0646b95a 145 */
Yann 0:311a0646b95a 146 #define DEBUG_WARNING(...) do { DebugHelper::Debug("!! "); DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
Yann 0:311a0646b95a 147
Yann 0:311a0646b95a 148 /** Break point macro
Yann 0:311a0646b95a 149 */
Yann 0:311a0646b95a 150 #define DEBUG_BREAK() DebugHelper::BreakPoint(__FILE__, __LINE__);
Yann 0:311a0646b95a 151
Yann 0:311a0646b95a 152 /** Used to stop program on fatal error
Yann 0:311a0646b95a 153 */
Yann 0:311a0646b95a 154 #define DEBUG_FATAL(cause) error(cause);
Yann 0:311a0646b95a 155
Yann 0:311a0646b95a 156 #else // __DEBUG
Yann 0:311a0646b95a 157
Yann 0:311a0646b95a 158 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 159 */
Yann 0:311a0646b95a 160 #define DEBUG_ENTER(...)
Yann 0:311a0646b95a 161 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 162 */
Yann 0:311a0646b95a 163 #define DEBUG_LEAVE(...)
Yann 0:311a0646b95a 164 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 165 */
Yann 0:311a0646b95a 166 #define DEBUG(...)
Yann 4:d03fcf494eb6 167 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 4:d03fcf494eb6 168 *
Yann 4:d03fcf494eb6 169 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 170 */
Yann 4:d03fcf494eb6 171 #define HEXADUMP(p_buffer, p_count)
Yann 4:d03fcf494eb6 172 /** Undefine DEBUG macro, used when __DEBUG is undefined
Yann 4:d03fcf494eb6 173 *
Yann 4:d03fcf494eb6 174 * Note that \ for multiline macro is not supported yet
Yann 4:d03fcf494eb6 175 */
Yann 4:d03fcf494eb6 176 #define HEXADUMP_OFFSET(p_buffer, p_count, p_offset)
Yann 2:12cc94a627cf 177 /** Undefine DEBUG_ERROR macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 178 */
Yann 2:12cc94a627cf 179 #define DEBUG_ERROR(...)
Yann 0:311a0646b95a 180 /** Undefine DEBUG_WARNING macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 181 */
Yann 0:311a0646b95a 182 #define DEBUG_WARNING(...)
Yann 0:311a0646b95a 183
Yann 0:311a0646b95a 184 /** Undefine DEBUG_BREAK macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 185 */
Yann 0:311a0646b95a 186 #define DEBUG_BREAK()
Yann 0:311a0646b95a 187
Yann 0:311a0646b95a 188 /** Undefine DEBUG_FATAL macro, used when __DEBUG is undefined
Yann 0:311a0646b95a 189 */
Yann 0:311a0646b95a 190 #define DEBUG_FATAL(cause)
Yann 0:311a0646b95a 191
Yann 0:311a0646b95a 192 #endif // __DEBUG
Yann 0:311a0646b95a 193
Yann 0:311a0646b95a 194 #endif // __DEBUG_H__