Rev 254 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 254 | Rev 396 | ||
---|---|---|---|
1 | #include <stdio.h> |
1 | #include <stdio.h> |
2 | #include <stdarg.h> |
2 | #include <stdarg.h> |
3 | #include <string.h> |
3 | #include <string.h> |
4 | 4 | ||
5 | #include "91x_lib.h" |
5 | #include "91x_lib.h" |
6 | #include "main.h" |
6 | #include "main.h" |
7 | #include "debug.h" |
7 | #include "debug.h" |
- | 8 | #include "uart1.h" |
|
- | 9 | ||
- | 10 | // get the address of calling function |
|
- | 11 | // |
|
- | 12 | // usage: Backtrace(__builtin_frame_address (0)); |
|
- | 13 | // |
|
- | 14 | void Backtrace(void* fp) |
|
- | 15 | { |
|
- | 16 | UART1_PutString("\n\r### Backtrace: "); |
|
- | 17 | sprintf(text, "%p ", *((int*)fp - 1)); |
|
- | 18 | UART1_PutString(text); |
|
- | 19 | } |
|
- | 20 | ||
- | 21 | ||
8 | 22 | ||
9 | #ifdef DEBUG // only include functions if DEBUG is defined in main.h |
23 | #ifdef DEBUG // only include functions if DEBUG is defined in main.h |
10 | 24 | ||
11 | #warning : "### DEBUG-Funktion aktiv ###" |
25 | #warning : "### DEBUG-Funktion aktiv ###" |
- | 26 | ||
12 | 27 | ||
13 | 28 | ||
14 | 29 | ||
15 | u8 Debug_BufPtr = 0; |
30 | u8 Debug_BufPtr = 0; |
16 | Debug_t tDebug; |
31 | Debug_t tDebug; |
17 | u8 SendDebugOutput = 0; |
32 | u8 SendDebugOutput = 0; |
18 | 33 | ||
19 | // function called from _printf_P to output character |
34 | // function called from _printf_P to output character |
20 | void Debug_Putchar(char c) |
35 | void Debug_Putchar(char c) |
21 | { |
36 | { |
22 | if (!SendDebugOutput) |
37 | if (!SendDebugOutput) |
23 | { |
38 | { |
24 | tDebug.Text[Debug_BufPtr++] = c; // copy character to buffer |
39 | tDebug.Text[Debug_BufPtr++] = c; // copy character to buffer |
25 | if (Debug_BufPtr > 30) Debug_BufPtr = 30; // avoid buffer overflow |
40 | if (Debug_BufPtr > 30) Debug_BufPtr = 30; // avoid buffer overflow |
26 | } |
41 | } |
27 | } |
42 | } |
28 | 43 | ||
29 | void DebugSend(u8 cmd) |
44 | void DebugSend(u8 cmd) |
30 | { |
45 | { |
31 | if (!SendDebugOutput) |
46 | if (!SendDebugOutput) |
32 | { |
47 | { |
33 | tDebug.Cmd = cmd; |
48 | tDebug.Cmd = cmd; |
34 | tDebug.Text[Debug_BufPtr] = '\0'; // end of text marker |
49 | tDebug.Text[Debug_BufPtr] = '\0'; // end of text marker |
35 | Debug_BufPtr = 0; // set bufferindex to 0 |
50 | Debug_BufPtr = 0; // set bufferindex to 0 |
36 | SendDebugOutput = 1; // set flag to trasmit data the next time in serial transmit function |
51 | SendDebugOutput = 1; // set flag to trasmit data the next time in serial transmit function |
37 | } |
52 | } |
38 | } |
53 | } |
39 | #endif |
54 | #endif |
40 | 55 | ||
41 | 56 |