Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file debug.c \brief Debugging function library. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'debug.c' |
||
5 | // Title : Helpful debugging functions |
||
6 | // Author : Pascal Stang - Copyright (C) 2003 |
||
7 | // Created : 2003-03-13 |
||
8 | // Revised : 2003-03-13 |
||
9 | // Version : 0.1 |
||
10 | // Target MCU : Atmel AVR series |
||
11 | // Editor Tabs : 4 |
||
12 | // |
||
13 | // Description : This file contains a set of functions which may be useful |
||
14 | // for general debugging. |
||
15 | // |
||
16 | // This code is distributed under the GNU Public License |
||
17 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
18 | // |
||
19 | //***************************************************************************** |
||
20 | |||
21 | #include <avr/io.h> |
||
22 | #include <avr/interrupt.h> |
||
23 | |||
24 | #include "global.h" |
||
25 | #include "debug.h" |
||
26 | |||
27 | #include "rprintf.h" // include printf support |
||
28 | |||
29 | // global variables |
||
30 | |||
31 | // functions |
||
32 | |||
33 | // Print a part of memory as a formatted hex table with ascii translation |
||
34 | void debugPrintHexTable(u16 length, u08 *buffer) |
||
35 | { |
||
36 | u08 i; |
||
37 | u16 j; |
||
38 | u08 *buf; |
||
39 | u08 s; |
||
40 | |||
41 | buf = buffer; |
||
42 | |||
43 | // print the low order address indicies and ASCII header |
||
44 | rprintfProgStrM(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\r\n"); |
||
45 | rprintfProgStrM(" ----------------------------------------------- ---- ASCII -----\r\n"); |
||
46 | |||
47 | // print the data |
||
48 | for(j=0; j<((length+15)>>4); j++) |
||
49 | { |
||
50 | // print the high order address index for this line |
||
51 | rprintfu16(j<<4); |
||
52 | rprintfChar(' '); |
||
53 | |||
54 | // print the hex data |
||
55 | for(i=0; i<0x10; i++) |
||
56 | { |
||
57 | // be nice and print only up to the exact end of the data |
||
58 | if( ((j<<4)+i) < length) |
||
59 | { |
||
60 | // print hex byte |
||
61 | rprintfu08(buf[(j<<4)+i]); |
||
62 | rprintfChar(' '); |
||
63 | } |
||
64 | else |
||
65 | { |
||
66 | // we're past the end of the data's length |
||
67 | // print spaces |
||
68 | rprintfProgStrM(" "); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | // leave some space |
||
73 | rprintfChar(' '); |
||
74 | |||
75 | // print the ascii data |
||
76 | for(i=0; i<0x10; i++) |
||
77 | { |
||
78 | // be nice and print only up to the exact end of the data |
||
79 | if( ((j<<4)+i) < length) |
||
80 | { |
||
81 | // get the character |
||
82 | s = buf[(j<<4)+i]; |
||
83 | // make sure character is printable |
||
84 | if(s >= 0x20) |
||
85 | rprintfChar(s); |
||
86 | else |
||
87 | rprintfChar('.'); |
||
88 | } |
||
89 | else |
||
90 | { |
||
91 | // we're past the end of the data's length |
||
92 | // print a space |
||
93 | rprintfChar(' '); |
||
94 | } |
||
95 | } |
||
96 | rprintfCRLF(); |
||
97 | } |
||
98 | } |
Powered by WebSVN v2.8.3