1 /*        $NetBSD: debug.h,v 1.11 2010/08/09 23:07:20 uwe Exp $       */
2 
3 /*-
4  * Copyright (c) 1999-2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * debug version exports all symbols.
34  */
35 #ifdef DEBUG
36 #define STATIC
37 #else
38 #define STATIC static
39 #endif
40 
41 /*
42  * printf control
43  *        sample:
44  * #ifdef FOO_DEBUG
45  * #define DPRINTF_ENABLE
46  * #define DPRINTF_DEBUG      foo_debug
47  * #define DPRINTF_LEVEL      2
48  * #endif
49  */
50 #ifdef USE_HPC_DPRINTF
51 
52 #ifdef DPRINTF_ENABLE
53 
54 #ifndef DPRINTF_DEBUG
55 #error "specify unique debug variable"
56 #endif
57 
58 #ifndef DPRINTF_LEVEL
59 #define DPRINTF_LEVEL         1
60 #endif
61 
62 int DPRINTF_DEBUG = DPRINTF_LEVEL;
63 #endif /* DPRINTF_ENABLE */
64 
65 
66 #ifdef __DPRINTF_EXT
67 /*
68  * printf with function name prepended
69  */
70 
71 #define   PRINTF(fmt, args...)          do {                          \
72                     printf("%s: " fmt, __func__ , ##args);  \
73           } while (/* CONSTCOND */0)
74 
75 #ifdef DPRINTF_ENABLE
76 
77 #define   DPRINTF(fmt, args...)         do {                \
78                     if (DPRINTF_DEBUG)            \
79                               PRINTF(fmt, ##args);          \
80           } while (/* CONSTCOND */0)
81 
82 #define   _DPRINTF(fmt, args...)        do {                \
83                     if (DPRINTF_DEBUG)            \
84                               printf(fmt, ##args);          \
85           } while (/* CONSTCOND */0)
86 
87 #define DPRINTFN(n, fmt, args...)       do {      \
88                     if (DPRINTF_DEBUG > (n))      \
89                               PRINTF(fmt, ##args);          \
90           } while (/* CONSTCOND */0)
91 
92 #define _DPRINTFN(n, fmt, args...) do {           \
93                     if (DPRINTF_DEBUG > (n))      \
94                               printf(fmt, ##args);          \
95           } while (/* CONSTCOND */0)
96 
97 #else  /* !DPRINTF_ENABLE */
98 #define   DPRINTF(args...)    do {} while (/* CONSTCOND */ 0)
99 #define   _DPRINTF(args...)   do {} while (/* CONSTCOND */ 0)
100 #define DPRINTFN(n, args...)  do {} while (/* CONSTCOND */ 0)
101 #define _DPRINTFN(n, args...) do {} while (/* CONSTCOND */ 0)
102 #endif /* !DPRINTF_ENABLE */
103 
104 #else  /* !__DPRINTF_EXT */
105 /*
106  * normal debug printf
107  */
108 
109 #ifdef DPRINTF_ENABLE
110 
111 #define   DPRINTF(arg)        do {                          \
112                     if (DPRINTF_DEBUG)            \
113                               printf arg;                   \
114           } while (/* CONSTCOND */0)
115 
116 #define DPRINTFN(n, arg)      do {                \
117                     if (DPRINTF_DEBUG > (n))      \
118                               printf arg;                   \
119           } while (/* CONSTCOND */0)
120 
121 #else  /* !DPRINTF_ENABLE */
122 #define   DPRINTF(arg)                  do {} while (/* CONSTCOND */ 0)
123 #define DPRINTFN(n, arg)      do {} while (/* CONSTCOND */ 0)
124 #endif /* !DPRINTF_ENABLE */
125 
126 #endif /* !__DPRINT_EXT */
127 #endif /* USE_HPC_DPRINTF */
128 
129 
130 /*
131  * debug print utility
132  */
133 #define DBG_BIT_PRINT_COUNT   (1 << 0)
134 #define DBG_BIT_PRINT_QUIET   (1 << 1)
135 
136 void __dbg_bit_print(uint32_t, int, int, int, const char *, int);
137 
138 #define dbg_bit_print(a) do {                                                   \
139                     __dbg_bit_print((a), sizeof(typeof(a)), 0, 0, NULL,         \
140                               DBG_BIT_PRINT_COUNT);                                       \
141           } while (/* CONSTCOND */0)
142 
143 #define dbg_bit_print_msg(a, m) do {                                            \
144                     __dbg_bit_print((a), sizeof(typeof(a)), 0, 0, (m),          \
145                               DBG_BIT_PRINT_COUNT);                                       \
146           } while (/* CONSTCOND */0)
147 
148 #define dbg_bit_display(a) do {                                                           \
149                     __dbg_bit_print((a), sizeof(typeof(a)), 0, 0, NULL,         \
150                               DBG_BIT_PRINT_QUIET);                                       \
151           } while (/* CONSTCOND */0)
152 
153 void dbg_bitmask_print(uint32_t, uint32_t, const char *);
154 void dbg_draw_line(int);
155 void dbg_banner_title(const char *, size_t);
156 void dbg_banner_line(void);
157 
158 #define dbg_banner_function() do {                                              \
159                     dbg_banner_title(__func__, sizeof(__func__) - 1); \
160           } while (/* CONSTCOND */ 0)
161 
162 /* HPC_DEBUG_LCD */
163 #define RGB565_BLACK                    0x0000
164 #define RGB565_RED            0xf800
165 #define RGB565_GREEN                    0x07e0
166 #define RGB565_YELLOW                   0xffe0
167 #define RGB565_BLUE           0x001f
168 #define RGB565_MAGENTA                  0xf81f
169 #define RGB565_CYAN           0x07ff
170 #define RGB565_WHITE                    0xffff
171 
172 void dbg_lcd_test(void);
173