summaryrefslogtreecommitdiff
path: root/sys/arch/hpc/include/debug.h
blob: 978f1d037f763f7c7128bd4d49bc88a53627dae7 (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*	$NetBSD: debug.h,v 1.11 2010/08/09 23:07:20 uwe Exp $	*/

/*-
 * Copyright (c) 1999-2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * debug version exports all symbols.
 */
#ifdef DEBUG
#define STATIC
#else
#define STATIC static
#endif

/*
 * printf control
 *	sample:
 * #ifdef FOO_DEBUG
 * #define DPRINTF_ENABLE
 * #define DPRINTF_DEBUG	foo_debug
 * #define DPRINTF_LEVEL	2
 * #endif
 */
#ifdef USE_HPC_DPRINTF

#ifdef DPRINTF_ENABLE

#ifndef DPRINTF_DEBUG
#error "specify unique debug variable"
#endif

#ifndef DPRINTF_LEVEL
#define DPRINTF_LEVEL	1
#endif

int DPRINTF_DEBUG = DPRINTF_LEVEL;
#endif /* DPRINTF_ENABLE */


#ifdef __DPRINTF_EXT
/*
 * printf with function name prepended
 */

#define	PRINTF(fmt, args...)	do {			\
		printf("%s: " fmt, __func__ , ##args);	\
	} while (/* CONSTCOND */0)

#ifdef DPRINTF_ENABLE

#define	DPRINTF(fmt, args...)	do {		\
		if (DPRINTF_DEBUG)		\
			PRINTF(fmt, ##args);	\
	} while (/* CONSTCOND */0)

#define	_DPRINTF(fmt, args...)	do {		\
		if (DPRINTF_DEBUG)		\
			printf(fmt, ##args);	\
	} while (/* CONSTCOND */0)

#define DPRINTFN(n, fmt, args...)	do {	\
		if (DPRINTF_DEBUG > (n))	\
			PRINTF(fmt, ##args);	\
	} while (/* CONSTCOND */0)

#define _DPRINTFN(n, fmt, args...) do {		\
		if (DPRINTF_DEBUG > (n))	\
			printf(fmt, ##args);	\
	} while (/* CONSTCOND */0)

#else  /* !DPRINTF_ENABLE */
#define	DPRINTF(args...)	do {} while (/* CONSTCOND */ 0)
#define	_DPRINTF(args...)	do {} while (/* CONSTCOND */ 0)
#define DPRINTFN(n, args...)	do {} while (/* CONSTCOND */ 0)
#define _DPRINTFN(n, args...)	do {} while (/* CONSTCOND */ 0)
#endif /* !DPRINTF_ENABLE */

#else  /* !__DPRINTF_EXT */
/*
 * normal debug printf
 */

#ifdef DPRINTF_ENABLE

#define	DPRINTF(arg)	do {			\
		if (DPRINTF_DEBUG)		\
			printf arg;		\
	} while (/* CONSTCOND */0)

#define DPRINTFN(n, arg)	do {		\
		if (DPRINTF_DEBUG > (n))	\
			printf arg;		\
	} while (/* CONSTCOND */0)

#else  /* !DPRINTF_ENABLE */
#define	DPRINTF(arg)		do {} while (/* CONSTCOND */ 0)
#define DPRINTFN(n, arg)	do {} while (/* CONSTCOND */ 0)
#endif /* !DPRINTF_ENABLE */

#endif /* !__DPRINT_EXT */
#endif /* USE_HPC_DPRINTF */


/*
 * debug print utility
 */
#define DBG_BIT_PRINT_COUNT	(1 << 0)
#define DBG_BIT_PRINT_QUIET	(1 << 1)

void __dbg_bit_print(uint32_t, int, int, int, const char *, int);

#define dbg_bit_print(a) do {						\
		__dbg_bit_print((a), sizeof(typeof(a)), 0, 0, NULL,	\
			DBG_BIT_PRINT_COUNT);				\
	} while (/* CONSTCOND */0)

#define dbg_bit_print_msg(a, m) do {					\
		__dbg_bit_print((a), sizeof(typeof(a)), 0, 0, (m),	\
			DBG_BIT_PRINT_COUNT);				\
	} while (/* CONSTCOND */0)

#define dbg_bit_display(a) do {						\
		__dbg_bit_print((a), sizeof(typeof(a)), 0, 0, NULL,	\
			DBG_BIT_PRINT_QUIET);				\
	} while (/* CONSTCOND */0)

void dbg_bitmask_print(uint32_t, uint32_t, const char *);
void dbg_draw_line(int);
void dbg_banner_title(const char *, size_t);
void dbg_banner_line(void);

#define dbg_banner_function() do {					\
		dbg_banner_title(__func__, sizeof(__func__) - 1);	\
	} while (/* CONSTCOND */ 0)

/* HPC_DEBUG_LCD */
#define RGB565_BLACK		0x0000
#define RGB565_RED		0xf800
#define RGB565_GREEN		0x07e0
#define RGB565_YELLOW		0xffe0
#define RGB565_BLUE		0x001f
#define RGB565_MAGENTA		0xf81f
#define RGB565_CYAN		0x07ff
#define RGB565_WHITE		0xffff

void dbg_lcd_test(void);