-
Notifications
You must be signed in to change notification settings - Fork 7
/
debug.h
94 lines (81 loc) · 2.67 KB
/
debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef debug_h
#define debug_h
/*
* Copyright © 2010-2015, Matthias Urlichs <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License (included; see the file LICENSE)
* for more details.
*/
#include "dev_config.h"
#ifndef NO_DEBUG //
#ifdef UART_DEBUG
#ifndef HAVE_UART
#error "Cannot debug using UART without having one"
#endif
#include "uart.h"
/* These macros always send something. They should only be used in
* sync-safe places, i.e. not in interrupt code or whatever.
*/
#define DBG_C(x) uart_putc(x)
#define DBG_S(x) uart_puts(x)
#define DBG_P(x) uart_puts_P(x)
#define DBG_P_(x) uart_puts_p(x)
#define DBG_N(x) uart_puthex_nibble(x)
#define DBG_W(x) uart_puthex_word(x)
#define DBG_X(x) uart_puthex_byte_(x)
#define DBG_NL() uart_putc('\n')
#endif /* UART_DEBUG */
#ifdef CONSOLE_DEBUG
#ifdef DBG_C
#error "Cannot use two debug methods concurrently"
#endif
#ifndef N_CONSOLE
#error "Cannot debug using console without having one"
#endif
#include "console.h"
#define DBG_C(x) console_putc(x)
#define DBG_S(x) console_puts(x)
#define DBG_P(x) console_puts_P(x)
#define DBG_P_(x) console_puts_p(x)
#define DBG_N(x) console_puthex_nibble(x)
#define DBG_W(x) console_puthex_word(x)
#define DBG_X(x) console_puthex_byte_(x)
#define DBG_NL() console_putc('\n')
#endif // console
#endif // !NO_DEBUG
#ifndef DBG_C
#define DBG_C(x) do { } while(0)
#define DBG_S(x) do { } while(0)
#define DBG_P(x) do { } while(0)
#define DBG_P_(x) do { } while(0)
#define DBG_N(x) do { } while(0)
#define DBG_W(x) do { } while(0)
#define DBG_X(x) do { } while(0)
#define DBG_NL() do { } while(0)
#endif
//************* second part: debugging via emitting a bit/byte to a port
#if defined(HAVE_DBG_PORT) && !defined(NO_DEBUG)
#define DBGA(x,v) do { v=(x); asm volatile("out %0,%1" :: "i"(((int)&DBGPORT)-__SFR_OFFSET),"r"(v)); } while(0)
#define DBG(x) do { uint8_t _x; DBGA(x,_x); } while(0)
#else
#define DBG(x) do { } while(0)
#define DBGA(x,v) do { } while(0)
#undef DBGPORT
#endif
#if defined(HAVE_DBG_PIN) && !defined(NO_DEBUG)
#define DBG_ON() do { DBGPINPORT |= (1<<DBGPIN); } while(0)
#define DBG_OFF() do { DBGPINPORT &= ~(1<<DBGPIN); } while(0)
#else
#define DBG_ON() do { } while(0)
#define DBG_OFF() do { } while(0)
#undef DBGPINPORT
#endif
#endif // debug_h