1*16ece135SMatthias Ringwald /* 2*16ece135SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3*16ece135SMatthias Ringwald * 4*16ece135SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5*16ece135SMatthias Ringwald * modification, are permitted provided that the following conditions 6*16ece135SMatthias Ringwald * are met: 7*16ece135SMatthias Ringwald * 8*16ece135SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9*16ece135SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10*16ece135SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11*16ece135SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12*16ece135SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13*16ece135SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14*16ece135SMatthias Ringwald * contributors may be used to endorse or promote products derived 15*16ece135SMatthias Ringwald * from this software without specific prior written permission. 16*16ece135SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17*16ece135SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18*16ece135SMatthias Ringwald * monetary gain. 19*16ece135SMatthias Ringwald * 20*16ece135SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21*16ece135SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*16ece135SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*16ece135SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24*16ece135SMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25*16ece135SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26*16ece135SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27*16ece135SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28*16ece135SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29*16ece135SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30*16ece135SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*16ece135SMatthias Ringwald * SUCH DAMAGE. 32*16ece135SMatthias Ringwald * 33*16ece135SMatthias Ringwald * Please inquire about commercial licensing options at 34*16ece135SMatthias Ringwald * [email protected] 35*16ece135SMatthias Ringwald * 36*16ece135SMatthias Ringwald */ 37*16ece135SMatthias Ringwald 38*16ece135SMatthias Ringwald /* 39*16ece135SMatthias Ringwald * btstack_debug.h 40*16ece135SMatthias Ringwald * 41*16ece135SMatthias Ringwald * allow to funnel debug & error messages 42*16ece135SMatthias Ringwald */ 43*16ece135SMatthias Ringwald 44*16ece135SMatthias Ringwald #ifndef __DEBUG_H 45*16ece135SMatthias Ringwald #define __DEBUG_H 46*16ece135SMatthias Ringwald 47*16ece135SMatthias Ringwald #include "btstack-config.h" 48*16ece135SMatthias Ringwald #include "hci_dump.h" 49*16ece135SMatthias Ringwald 50*16ece135SMatthias Ringwald #include <stdio.h> 51*16ece135SMatthias Ringwald 52*16ece135SMatthias Ringwald #ifdef __AVR__ 53*16ece135SMatthias Ringwald #include <avr/pgmspace.h> 54*16ece135SMatthias Ringwald #endif 55*16ece135SMatthias Ringwald 56*16ece135SMatthias Ringwald #ifndef EMBEDDED 57*16ece135SMatthias Ringwald // Avoid complaints of unused arguments when log levels are disabled. 58*16ece135SMatthias Ringwald static inline void __log_unused(const char *format, ...) { 59*16ece135SMatthias Ringwald } 60*16ece135SMatthias Ringwald #else 61*16ece135SMatthias Ringwald #define __log_unused(...) 62*16ece135SMatthias Ringwald #endif 63*16ece135SMatthias Ringwald 64*16ece135SMatthias Ringwald #ifdef __AVR__ 65*16ece135SMatthias Ringwald #define HCI_DUMP_LOG(log_level, format, ...) hci_dump_log_P(log_level, PSTR(format), ## __VA_ARGS__) 66*16ece135SMatthias Ringwald #define BTSTACK_PRINTF(format, ...) printf_P(PSTR(format), ## __VA_ARGS__) 67*16ece135SMatthias Ringwald #else 68*16ece135SMatthias Ringwald #define HCI_DUMP_LOG(log_level, format, ...) hci_dump_log(log_level, format, ## __VA_ARGS__) 69*16ece135SMatthias Ringwald #define BTSTACK_PRINTF(format, ...) printf(format, ## __VA_ARGS__) 70*16ece135SMatthias Ringwald #endif 71*16ece135SMatthias Ringwald 72*16ece135SMatthias Ringwald #ifdef ENABLE_LOG_DEBUG 73*16ece135SMatthias Ringwald #ifdef HAVE_HCI_DUMP 74*16ece135SMatthias Ringwald #define log_debug(format, ...) HCI_DUMP_LOG(LOG_LEVEL_DEBUG, format, ## __VA_ARGS__) 75*16ece135SMatthias Ringwald #else 76*16ece135SMatthias Ringwald #define log_debug(format, ...) BTSTACK_PRINTF(format "\n", ## __VA_ARGS__) 77*16ece135SMatthias Ringwald #endif 78*16ece135SMatthias Ringwald #else 79*16ece135SMatthias Ringwald #define log_debug(...) __log_unused(__VA_ARGS__) 80*16ece135SMatthias Ringwald #endif 81*16ece135SMatthias Ringwald 82*16ece135SMatthias Ringwald #ifdef ENABLE_LOG_INFO 83*16ece135SMatthias Ringwald #ifdef HAVE_HCI_DUMP 84*16ece135SMatthias Ringwald #define log_info(format, ...) HCI_DUMP_LOG(LOG_LEVEL_INFO, format, ## __VA_ARGS__) 85*16ece135SMatthias Ringwald #else 86*16ece135SMatthias Ringwald #define log_info(format, ...) BTSTACK_PRINTF(format "\n", ## __VA_ARGS__) 87*16ece135SMatthias Ringwald #endif 88*16ece135SMatthias Ringwald #else 89*16ece135SMatthias Ringwald #define log_info(...) __log_unused(__VA_ARGS__) 90*16ece135SMatthias Ringwald #endif 91*16ece135SMatthias Ringwald 92*16ece135SMatthias Ringwald #ifdef ENABLE_LOG_ERROR 93*16ece135SMatthias Ringwald #ifdef HAVE_HCI_DUMP 94*16ece135SMatthias Ringwald #define log_error(format, ...) HCI_DUMP_LOG(LOG_LEVEL_ERROR, format, ## __VA_ARGS__) 95*16ece135SMatthias Ringwald #else 96*16ece135SMatthias Ringwald #define log_error(format, ...) BTSTACK_PRINTF(format "\n", ## __VA_ARGS__) 97*16ece135SMatthias Ringwald #endif 98*16ece135SMatthias Ringwald #else 99*16ece135SMatthias Ringwald #define log_error(...) __log_unused(__VA_ARGS__) 100*16ece135SMatthias Ringwald #endif 101*16ece135SMatthias Ringwald 102*16ece135SMatthias Ringwald #endif // __DEBUG_H 103