Add missing undefined symbols to be sure to use mine
Dependents: DS130x_I2CApp MCP41xxxApp FM24Vxx_I2CApp MCP320xApp ... more
Debug.cpp@4:d03fcf494eb6, 2010-12-08 (annotated)
- Committer:
- Yann
- Date:
- Wed Dec 08 13:16:16 2010 +0000
- Revision:
- 4:d03fcf494eb6
- Parent:
- 0:311a0646b95a
- Child:
- 5:7ddb6bca6d01
V0.0.0.5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yann | 0:311a0646b95a | 1 | #include <cstdarg> |
Yann | 0:311a0646b95a | 2 | #include "Debug.h" |
Yann | 0:311a0646b95a | 3 | |
Yann | 0:311a0646b95a | 4 | #ifdef __DEBUG |
Yann | 0:311a0646b95a | 5 | |
Yann | 0:311a0646b95a | 6 | void DebugHelper::Debug(const char* p_format, ...) { |
Yann | 0:311a0646b95a | 7 | va_list argp; |
Yann | 0:311a0646b95a | 8 | |
Yann | 0:311a0646b95a | 9 | va_start(argp, p_format); |
Yann | 0:311a0646b95a | 10 | vprintf(p_format, argp); |
Yann | 0:311a0646b95a | 11 | va_end(argp); |
Yann | 4:d03fcf494eb6 | 12 | } // End of method DebugHelper::Debug |
Yann | 4:d03fcf494eb6 | 13 | |
Yann | 4:d03fcf494eb6 | 14 | void DebugHelper::HexaDump(unsigned char* p_buffer, int p_count, int p_offset) { |
Yann | 4:d03fcf494eb6 | 15 | |
Yann | 4:d03fcf494eb6 | 16 | int currentIdx = p_offset; |
Yann | 4:d03fcf494eb6 | 17 | unsigned short startAddress = ((unsigned short)(p_offset / 16)) * 16; |
Yann | 4:d03fcf494eb6 | 18 | |
Yann | 4:d03fcf494eb6 | 19 | DEBUG(">>> %d - %d - %d - %d - %d", p_count, p_offset, p_count + p_offset, currentIdx / 16, currentIdx % 16); |
Yann | 4:d03fcf494eb6 | 20 | |
Yann | 4:d03fcf494eb6 | 21 | // Display header |
Yann | 4:d03fcf494eb6 | 22 | 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 | 23 | printf("-----|+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-:--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n"); |
Yann | 4:d03fcf494eb6 | 24 | // 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 |
Yann | 4:d03fcf494eb6 | 25 | // 0 1 2 3 4 5 6 7 8 9 |
Yann | 4:d03fcf494eb6 | 26 | // Address offset padding |
Yann | 4:d03fcf494eb6 | 27 | char line[91]; |
Yann | 4:d03fcf494eb6 | 28 | memset(line, 0x20, 91); |
Yann | 4:d03fcf494eb6 | 29 | sprintf(line, "%04x |", (unsigned short)startAddress); |
Yann | 4:d03fcf494eb6 | 30 | line[6] = 0x20; // Remove NULL character added by sprintf |
Yann | 4:d03fcf494eb6 | 31 | int idx = 0; |
Yann | 4:d03fcf494eb6 | 32 | int hexOffset = 7; |
Yann | 4:d03fcf494eb6 | 33 | int charOffset = 58; |
Yann | 4:d03fcf494eb6 | 34 | for ( ; idx < (int)(currentIdx % 16); idx++) { |
Yann | 4:d03fcf494eb6 | 35 | line[hexOffset] = 0x30; |
Yann | 4:d03fcf494eb6 | 36 | line[hexOffset + 1] = 0x30; |
Yann | 4:d03fcf494eb6 | 37 | hexOffset += 3; |
Yann | 4:d03fcf494eb6 | 38 | charOffset += 2; |
Yann | 4:d03fcf494eb6 | 39 | } |
Yann | 4:d03fcf494eb6 | 40 | // Fill line by line |
Yann | 4:d03fcf494eb6 | 41 | int endOfDump = p_count + p_offset; |
Yann | 4:d03fcf494eb6 | 42 | while(currentIdx < endOfDump) { |
Yann | 4:d03fcf494eb6 | 43 | for ( ; (idx < 16) && (currentIdx < endOfDump); idx++) { |
Yann | 4:d03fcf494eb6 | 44 | line[hexOffset] = DebugHelper::ToHexDigit(*(p_buffer + currentIdx) >> 4); |
Yann | 4:d03fcf494eb6 | 45 | line[hexOffset + 1] = DebugHelper::ToHexDigit(*(p_buffer + currentIdx) & 0x0f); |
Yann | 4:d03fcf494eb6 | 46 | line[charOffset] = DebugHelper::ToCharDigit(*(p_buffer + currentIdx)); |
Yann | 4:d03fcf494eb6 | 47 | // Prepare next byte |
Yann | 4:d03fcf494eb6 | 48 | hexOffset += 3; |
Yann | 4:d03fcf494eb6 | 49 | charOffset += 2; |
Yann | 4:d03fcf494eb6 | 50 | currentIdx += 1; |
Yann | 4:d03fcf494eb6 | 51 | } |
Yann | 4:d03fcf494eb6 | 52 | // Display the line |
Yann | 4:d03fcf494eb6 | 53 | line[56] = ':'; |
Yann | 4:d03fcf494eb6 | 54 | line[89] = 0x0d; |
Yann | 4:d03fcf494eb6 | 55 | line[90] = 0x0a; |
Yann | 4:d03fcf494eb6 | 56 | printf(line); |
Yann | 4:d03fcf494eb6 | 57 | if (currentIdx < endOfDump) { // Prepare next line, one line = 16 digits |
Yann | 4:d03fcf494eb6 | 58 | startAddress += 16; |
Yann | 4:d03fcf494eb6 | 59 | memset(line, 0x20, 91); |
Yann | 4:d03fcf494eb6 | 60 | sprintf(line, "%04x |", (unsigned short)startAddress); |
Yann | 4:d03fcf494eb6 | 61 | line[6] = 0x20; // Remove NULL character added by sprintf |
Yann | 4:d03fcf494eb6 | 62 | idx = 0; |
Yann | 4:d03fcf494eb6 | 63 | hexOffset = 7; |
Yann | 4:d03fcf494eb6 | 64 | charOffset = 58; |
Yann | 4:d03fcf494eb6 | 65 | } else { // End of line padding |
Yann | 4:d03fcf494eb6 | 66 | break; |
Yann | 4:d03fcf494eb6 | 67 | } |
Yann | 4:d03fcf494eb6 | 68 | } // End of 'while' statement |
Yann | 4:d03fcf494eb6 | 69 | } // End of method DebugHelper::HexaDump |
Yann | 0:311a0646b95a | 70 | |
Yann | 0:311a0646b95a | 71 | void DebugHelper::BreakPoint(const char* p_file, int p_line) { |
Yann | 0:311a0646b95a | 72 | printf("Stop in %s at line %d\r\n", p_file, p_line); |
Yann | 0:311a0646b95a | 73 | fflush(stdout); |
Yann | 0:311a0646b95a | 74 | getchar(); |
Yann | 0:311a0646b95a | 75 | fflush(stdin); |
Yann | 4:d03fcf494eb6 | 76 | } // End of method DebugHelper::BreakPoint |
Yann | 0:311a0646b95a | 77 | |
Yann | 0:311a0646b95a | 78 | #endif // __DEBUG |