Add missing undefined symbols to be sure to use mine
Dependents: DS130x_I2CApp MCP41xxxApp FM24Vxx_I2CApp MCP320xApp ... more
Debug.cpp
00001 /* mbed Debug library used by all my developed program 00002 * Copyright (c) 2010-2012 ygarcia, MIT License 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00005 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00006 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00007 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00008 * furnished to do so, subject to the following conditions: 00009 * 00010 * The above copyright notice and this permission notice shall be included in all copies or 00011 * substantial portions of the Software. 00012 * 00013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00014 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00015 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00016 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00018 */ 00019 #include <cstdarg> 00020 #include "Debug.h" 00021 00022 #ifdef __DEBUG 00023 00024 #define __LINE_LENGTH__ 93 00025 00026 void DebugHelper::Debug(const char* p_format, ...) { 00027 va_list argp; 00028 00029 va_start(argp, p_format); 00030 vprintf(p_format, argp); 00031 va_end(argp); 00032 } // End of method DebugHelper::Debug 00033 00034 void DebugHelper::HexaDump(unsigned char* p_buffer, int p_count, int p_offset) { 00035 00036 int currentIdx = p_offset; 00037 unsigned short startAddress = ((unsigned short)(p_offset / 16)) * 16; 00038 00039 // Display header 00040 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"); 00041 printf("-----|+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-:--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n"); 00042 // 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901 2 00043 // 0 1 2 3 4 5 6 7 8 9 00044 // Address offset padding 00045 char line[__LINE_LENGTH__ + 1]; 00046 memset(line, 0x20, __LINE_LENGTH__); 00047 line[__LINE_LENGTH__] = 0x00; // NULL character 00048 sprintf(line, "%04x |", (unsigned short)startAddress); 00049 line[6] = 0x20; // Remove NULL character added by sprintf 00050 int idx = 0; 00051 int hexOffset = 7; 00052 int charOffset = 58; 00053 for ( ; idx < (int)(currentIdx % 16); idx++) { 00054 line[hexOffset] = 0x30; 00055 line[hexOffset + 1] = 0x30; 00056 hexOffset += 3; 00057 charOffset += 2; 00058 } 00059 // Fill line by line 00060 int endOfDump = p_count + p_offset; 00061 while(currentIdx < endOfDump) { 00062 for ( ; (idx < 16) && (currentIdx < endOfDump); idx++) { 00063 line[hexOffset] = DebugHelper::ToHexDigit(*(p_buffer + currentIdx) >> 4); 00064 line[hexOffset + 1] = DebugHelper::ToHexDigit(*(p_buffer + currentIdx) & 0x0f); 00065 line[charOffset] = DebugHelper::ToCharDigit(*(p_buffer + currentIdx)); 00066 // Prepare next byte 00067 hexOffset += 3; 00068 charOffset += 2; 00069 currentIdx += 1; 00070 } 00071 // Display the line 00072 line[56] = ':'; 00073 line[__LINE_LENGTH__ - 1] = 0x0d; 00074 line[__LINE_LENGTH__] = 0x0a; 00075 printf(line); 00076 if (currentIdx < endOfDump) { // Prepare next line, one line = 16 digits 00077 startAddress += 16; 00078 memset(line, 0x20, __LINE_LENGTH__); 00079 sprintf(line, "%04x |", (unsigned short)startAddress); 00080 line[6] = 0x20; // Remove NULL character added by sprintf 00081 idx = 0; 00082 hexOffset = 7; 00083 charOffset = 58; 00084 } else { // End of line padding 00085 break; 00086 } 00087 } // End of 'while' statement 00088 } // End of method DebugHelper::HexaDump 00089 00090 void DebugHelper::BreakPoint(const char* p_file, int p_line) { 00091 printf("Stop in %s at line %d\r\n", p_file, p_line); 00092 fflush(stdout); 00093 getchar(); 00094 fflush(stdin); 00095 } // End of method DebugHelper::BreakPoint 00096 00097 #endif // __DEBUG
Generated on Tue Jul 12 2022 21:17:35 by
1.7.2
Yann Garcia