Add missing undefined symbols to be sure to use mine

Dependents:   DS130x_I2CApp MCP41xxxApp FM24Vxx_I2CApp MCP320xApp ... more

Committer:
Yann
Date:
Thu Oct 11 07:17:24 2012 +0000
Revision:
9:a11adabe9ded
Parent:
8:ce74b6c101b9
Add MIT licensing support

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