Add missing undefined symbols to be sure to use mine
Dependents: DS130x_I2CApp MCP41xxxApp FM24Vxx_I2CApp MCP320xApp ... more
Debug.cpp@9:a11adabe9ded, 2012-10-11 (annotated)
- Committer:
- Yann
- Date:
- Thu Oct 11 07:17:24 2012 +0000
- Revision:
- 9:a11adabe9ded
- Parent:
- 7:e10debbe8dad
Add MIT licensing support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yann | 9:a11adabe9ded | 1 | /* mbed Debug library used by all my developed program |
Yann | 9:a11adabe9ded | 2 | * Copyright (c) 2010-2012 ygarcia, MIT License |
Yann | 9:a11adabe9ded | 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 | 9:a11adabe9ded | 8 | * furnished to do so, subject to the following conditions: |
Yann | 9:a11adabe9ded | 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 | 9:a11adabe9ded | 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 | 9:a11adabe9ded | 18 | */ |
Yann | 0:311a0646b95a | 19 | #include <cstdarg> |
Yann | 0:311a0646b95a | 20 | #include "Debug.h" |
Yann | 0:311a0646b95a | 21 | |
Yann | 0:311a0646b95a | 22 | #ifdef __DEBUG |
Yann | 0:311a0646b95a | 23 | |
Yann | 7:e10debbe8dad | 24 | #define __LINE_LENGTH__ 93 |
Yann | 5:7ddb6bca6d01 | 25 | |
Yann | 0:311a0646b95a | 26 | void DebugHelper::Debug(const char* p_format, ...) { |
Yann | 0:311a0646b95a | 27 | va_list argp; |
Yann | 0:311a0646b95a | 28 | |
Yann | 0:311a0646b95a | 29 | va_start(argp, p_format); |
Yann | 0:311a0646b95a | 30 | vprintf(p_format, argp); |
Yann | 0:311a0646b95a | 31 | va_end(argp); |
Yann | 4:d03fcf494eb6 | 32 | } // End of method DebugHelper::Debug |
Yann | 4:d03fcf494eb6 | 33 | |
Yann | 4:d03fcf494eb6 | 34 | void DebugHelper::HexaDump(unsigned char* p_buffer, int p_count, int p_offset) { |
Yann | 4:d03fcf494eb6 | 35 | |
Yann | 4:d03fcf494eb6 | 36 | int currentIdx = p_offset; |
Yann | 4:d03fcf494eb6 | 37 | unsigned short startAddress = ((unsigned short)(p_offset / 16)) * 16; |
Yann | 4:d03fcf494eb6 | 38 | |
Yann | 4:d03fcf494eb6 | 39 | // Display header |
Yann | 4:d03fcf494eb6 | 40 | printf(" HEX | 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F : 0 1 2 3 4 5 6 7 8 9 A B C D E F \r\n"); |
Yann | 4:d03fcf494eb6 | 41 | printf("-----|+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-:--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n"); |
Yann | 7:e10debbe8dad | 42 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901 2 |
Yann | 4:d03fcf494eb6 | 43 | // 0 1 2 3 4 5 6 7 8 9 |
Yann | 4:d03fcf494eb6 | 44 | // Address offset padding |
Yann | 7:e10debbe8dad | 45 | char line[__LINE_LENGTH__ + 1]; |
Yann | 5:7ddb6bca6d01 | 46 | memset(line, 0x20, __LINE_LENGTH__); |
Yann | 7:e10debbe8dad | 47 | line[__LINE_LENGTH__] = 0x00; // NULL character |
Yann | 4:d03fcf494eb6 | 48 | sprintf(line, "%04x |", (unsigned short)startAddress); |
Yann | 4:d03fcf494eb6 | 49 | line[6] = 0x20; // Remove NULL character added by sprintf |
Yann | 4:d03fcf494eb6 | 50 | int idx = 0; |
Yann | 4:d03fcf494eb6 | 51 | int hexOffset = 7; |
Yann | 4:d03fcf494eb6 | 52 | int charOffset = 58; |
Yann | 4:d03fcf494eb6 | 53 | for ( ; idx < (int)(currentIdx % 16); idx++) { |
Yann | 4:d03fcf494eb6 | 54 | line[hexOffset] = 0x30; |
Yann | 4:d03fcf494eb6 | 55 | line[hexOffset + 1] = 0x30; |
Yann | 4:d03fcf494eb6 | 56 | hexOffset += 3; |
Yann | 4:d03fcf494eb6 | 57 | charOffset += 2; |
Yann | 4:d03fcf494eb6 | 58 | } |
Yann | 4:d03fcf494eb6 | 59 | // Fill line by line |
Yann | 4:d03fcf494eb6 | 60 | int endOfDump = p_count + p_offset; |
Yann | 4:d03fcf494eb6 | 61 | while(currentIdx < endOfDump) { |
Yann | 4:d03fcf494eb6 | 62 | for ( ; (idx < 16) && (currentIdx < endOfDump); idx++) { |
Yann | 4:d03fcf494eb6 | 63 | line[hexOffset] = DebugHelper::ToHexDigit(*(p_buffer + currentIdx) >> 4); |
Yann | 4:d03fcf494eb6 | 64 | line[hexOffset + 1] = DebugHelper::ToHexDigit(*(p_buffer + currentIdx) & 0x0f); |
Yann | 4:d03fcf494eb6 | 65 | line[charOffset] = DebugHelper::ToCharDigit(*(p_buffer + currentIdx)); |
Yann | 4:d03fcf494eb6 | 66 | // Prepare next byte |
Yann | 4:d03fcf494eb6 | 67 | hexOffset += 3; |
Yann | 4:d03fcf494eb6 | 68 | charOffset += 2; |
Yann | 4:d03fcf494eb6 | 69 | currentIdx += 1; |
Yann | 4:d03fcf494eb6 | 70 | } |
Yann | 4:d03fcf494eb6 | 71 | // Display the line |
Yann | 4:d03fcf494eb6 | 72 | line[56] = ':'; |
Yann | 7:e10debbe8dad | 73 | line[__LINE_LENGTH__ - 1] = 0x0d; |
Yann | 7:e10debbe8dad | 74 | line[__LINE_LENGTH__] = 0x0a; |
Yann | 4:d03fcf494eb6 | 75 | printf(line); |
Yann | 4:d03fcf494eb6 | 76 | if (currentIdx < endOfDump) { // Prepare next line, one line = 16 digits |
Yann | 4:d03fcf494eb6 | 77 | startAddress += 16; |
Yann | 5:7ddb6bca6d01 | 78 | memset(line, 0x20, __LINE_LENGTH__); |
Yann | 4:d03fcf494eb6 | 79 | sprintf(line, "%04x |", (unsigned short)startAddress); |
Yann | 4:d03fcf494eb6 | 80 | line[6] = 0x20; // Remove NULL character added by sprintf |
Yann | 4:d03fcf494eb6 | 81 | idx = 0; |
Yann | 4:d03fcf494eb6 | 82 | hexOffset = 7; |
Yann | 4:d03fcf494eb6 | 83 | charOffset = 58; |
Yann | 4:d03fcf494eb6 | 84 | } else { // End of line padding |
Yann | 4:d03fcf494eb6 | 85 | break; |
Yann | 4:d03fcf494eb6 | 86 | } |
Yann | 4:d03fcf494eb6 | 87 | } // End of 'while' statement |
Yann | 4:d03fcf494eb6 | 88 | } // End of method DebugHelper::HexaDump |
Yann | 0:311a0646b95a | 89 | |
Yann | 0:311a0646b95a | 90 | void DebugHelper::BreakPoint(const char* p_file, int p_line) { |
Yann | 0:311a0646b95a | 91 | printf("Stop in %s at line %d\r\n", p_file, p_line); |
Yann | 0:311a0646b95a | 92 | fflush(stdout); |
Yann | 0:311a0646b95a | 93 | getchar(); |
Yann | 0:311a0646b95a | 94 | fflush(stdin); |
Yann | 4:d03fcf494eb6 | 95 | } // End of method DebugHelper::BreakPoint |
Yann | 0:311a0646b95a | 96 | |
Yann | 0:311a0646b95a | 97 | #endif // __DEBUG |