1*d9aafa85Suwe /* $NetBSD: debug.h,v 1.11 2010/08/09 23:07:20 uwe Exp $ */ 27d170993Such 37d170993Such /*- 47d170993Such * Copyright (c) 1999-2002 The NetBSD Foundation, Inc. 57d170993Such * All rights reserved. 67d170993Such * 77d170993Such * This code is derived from software contributed to The NetBSD Foundation 87d170993Such * by UCHIYAMA Yasushi. 97d170993Such * 107d170993Such * Redistribution and use in source and binary forms, with or without 117d170993Such * modification, are permitted provided that the following conditions 127d170993Such * are met: 137d170993Such * 1. Redistributions of source code must retain the above copyright 147d170993Such * notice, this list of conditions and the following disclaimer. 157d170993Such * 2. Redistributions in binary form must reproduce the above copyright 167d170993Such * notice, this list of conditions and the following disclaimer in the 177d170993Such * documentation and/or other materials provided with the distribution. 187d170993Such * 197d170993Such * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 207d170993Such * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 217d170993Such * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 227d170993Such * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 237d170993Such * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 247d170993Such * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 257d170993Such * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 267d170993Such * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 277d170993Such * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 287d170993Such * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 297d170993Such * POSSIBILITY OF SUCH DAMAGE. 307d170993Such */ 317d170993Such 327d170993Such /* 337d170993Such * debug version exports all symbols. 347d170993Such */ 357d170993Such #ifdef DEBUG 367d170993Such #define STATIC 377d170993Such #else 387d170993Such #define STATIC static 397d170993Such #endif 407d170993Such 417d170993Such /* 427d170993Such * printf control 437d170993Such * sample: 447d170993Such * #ifdef FOO_DEBUG 457d170993Such * #define DPRINTF_ENABLE 467d170993Such * #define DPRINTF_DEBUG foo_debug 477d170993Such * #define DPRINTF_LEVEL 2 487d170993Such * #endif 497d170993Such */ 507d170993Such #ifdef USE_HPC_DPRINTF 51*d9aafa85Suwe 527d170993Such #ifdef DPRINTF_ENABLE 53*d9aafa85Suwe 547d170993Such #ifndef DPRINTF_DEBUG 55*d9aafa85Suwe #error "specify unique debug variable" 567d170993Such #endif 57*d9aafa85Suwe 587d170993Such #ifndef DPRINTF_LEVEL 597d170993Such #define DPRINTF_LEVEL 1 607d170993Such #endif 61*d9aafa85Suwe 627d170993Such int DPRINTF_DEBUG = DPRINTF_LEVEL; 637d170993Such #endif /* DPRINTF_ENABLE */ 647d170993Such 65*d9aafa85Suwe 66*d9aafa85Suwe #ifdef __DPRINTF_EXT 67*d9aafa85Suwe /* 68*d9aafa85Suwe * printf with function name prepended 69*d9aafa85Suwe */ 70*d9aafa85Suwe 71*d9aafa85Suwe #define PRINTF(fmt, args...) do { \ 72*d9aafa85Suwe printf("%s: " fmt, __func__ , ##args); \ 73*d9aafa85Suwe } while (/* CONSTCOND */0) 74*d9aafa85Suwe 75*d9aafa85Suwe #ifdef DPRINTF_ENABLE 76*d9aafa85Suwe 77*d9aafa85Suwe #define DPRINTF(fmt, args...) do { \ 78*d9aafa85Suwe if (DPRINTF_DEBUG) \ 79*d9aafa85Suwe PRINTF(fmt, ##args); \ 80*d9aafa85Suwe } while (/* CONSTCOND */0) 81*d9aafa85Suwe 82*d9aafa85Suwe #define _DPRINTF(fmt, args...) do { \ 83*d9aafa85Suwe if (DPRINTF_DEBUG) \ 84*d9aafa85Suwe printf(fmt, ##args); \ 85*d9aafa85Suwe } while (/* CONSTCOND */0) 86*d9aafa85Suwe 87*d9aafa85Suwe #define DPRINTFN(n, fmt, args...) do { \ 88*d9aafa85Suwe if (DPRINTF_DEBUG > (n)) \ 89*d9aafa85Suwe PRINTF(fmt, ##args); \ 90*d9aafa85Suwe } while (/* CONSTCOND */0) 91*d9aafa85Suwe 92*d9aafa85Suwe #define _DPRINTFN(n, fmt, args...) do { \ 93*d9aafa85Suwe if (DPRINTF_DEBUG > (n)) \ 94*d9aafa85Suwe printf(fmt, ##args); \ 95*d9aafa85Suwe } while (/* CONSTCOND */0) 96*d9aafa85Suwe 97*d9aafa85Suwe #else /* !DPRINTF_ENABLE */ 98*d9aafa85Suwe #define DPRINTF(args...) do {} while (/* CONSTCOND */ 0) 99*d9aafa85Suwe #define _DPRINTF(args...) do {} while (/* CONSTCOND */ 0) 100*d9aafa85Suwe #define DPRINTFN(n, args...) do {} while (/* CONSTCOND */ 0) 101*d9aafa85Suwe #define _DPRINTFN(n, args...) do {} while (/* CONSTCOND */ 0) 102*d9aafa85Suwe #endif /* !DPRINTF_ENABLE */ 103*d9aafa85Suwe 104*d9aafa85Suwe #else /* !__DPRINTF_EXT */ 1057d170993Such /* 1067d170993Such * normal debug printf 1077d170993Such */ 1087d170993Such 109*d9aafa85Suwe #ifdef DPRINTF_ENABLE 110*d9aafa85Suwe 111*d9aafa85Suwe #define DPRINTF(arg) do { \ 112*d9aafa85Suwe if (DPRINTF_DEBUG) \ 113*d9aafa85Suwe printf arg; \ 114*d9aafa85Suwe } while (/* CONSTCOND */0) 115*d9aafa85Suwe 116*d9aafa85Suwe #define DPRINTFN(n, arg) do { \ 117*d9aafa85Suwe if (DPRINTF_DEBUG > (n)) \ 118*d9aafa85Suwe printf arg; \ 119*d9aafa85Suwe } while (/* CONSTCOND */0) 120*d9aafa85Suwe 121*d9aafa85Suwe #else /* !DPRINTF_ENABLE */ 122*d9aafa85Suwe #define DPRINTF(arg) do {} while (/* CONSTCOND */ 0) 123*d9aafa85Suwe #define DPRINTFN(n, arg) do {} while (/* CONSTCOND */ 0) 124*d9aafa85Suwe #endif /* !DPRINTF_ENABLE */ 125*d9aafa85Suwe 126*d9aafa85Suwe #endif /* !__DPRINT_EXT */ 1277d170993Such #endif /* USE_HPC_DPRINTF */ 1287d170993Such 129*d9aafa85Suwe 1307d170993Such /* 1317d170993Such * debug print utility 1327d170993Such */ 133f8cb4c37Stakemura #define DBG_BIT_PRINT_COUNT (1 << 0) 134f8cb4c37Stakemura #define DBG_BIT_PRINT_QUIET (1 << 1) 135*d9aafa85Suwe 136*d9aafa85Suwe void __dbg_bit_print(uint32_t, int, int, int, const char *, int); 137*d9aafa85Suwe 138*d9aafa85Suwe #define dbg_bit_print(a) do { \ 139*d9aafa85Suwe __dbg_bit_print((a), sizeof(typeof(a)), 0, 0, NULL, \ 140*d9aafa85Suwe DBG_BIT_PRINT_COUNT); \ 141*d9aafa85Suwe } while (/* CONSTCOND */0) 142*d9aafa85Suwe 143*d9aafa85Suwe #define dbg_bit_print_msg(a, m) do { \ 144*d9aafa85Suwe __dbg_bit_print((a), sizeof(typeof(a)), 0, 0, (m), \ 145*d9aafa85Suwe DBG_BIT_PRINT_COUNT); \ 146*d9aafa85Suwe } while (/* CONSTCOND */0) 147*d9aafa85Suwe 148*d9aafa85Suwe #define dbg_bit_display(a) do { \ 149*d9aafa85Suwe __dbg_bit_print((a), sizeof(typeof(a)), 0, 0, NULL, \ 150*d9aafa85Suwe DBG_BIT_PRINT_QUIET); \ 151*d9aafa85Suwe } while (/* CONSTCOND */0) 152*d9aafa85Suwe 153*d9aafa85Suwe void dbg_bitmask_print(uint32_t, uint32_t, const char *); 1547d170993Such void dbg_draw_line(int); 1557d170993Such void dbg_banner_title(const char *, size_t); 1567d170993Such void dbg_banner_line(void); 157*d9aafa85Suwe 158*d9aafa85Suwe #define dbg_banner_function() do { \ 159*d9aafa85Suwe dbg_banner_title(__func__, sizeof(__func__) - 1); \ 160*d9aafa85Suwe } while (/* CONSTCOND */ 0) 161c0a13ed2Such 162c0a13ed2Such /* HPC_DEBUG_LCD */ 163c0a13ed2Such #define RGB565_BLACK 0x0000 164c0a13ed2Such #define RGB565_RED 0xf800 165c0a13ed2Such #define RGB565_GREEN 0x07e0 166c0a13ed2Such #define RGB565_YELLOW 0xffe0 167c0a13ed2Such #define RGB565_BLUE 0x001f 168c0a13ed2Such #define RGB565_MAGENTA 0xf81f 169c0a13ed2Such #define RGB565_CYAN 0x07ff 170c0a13ed2Such #define RGB565_WHITE 0xffff 171c0a13ed2Such 172c0a13ed2Such void dbg_lcd_test(void); 173