xref: /btstack/src/btstack_debug.h (revision 7907f06931c075b55e3402fa469abbe35eebee25)
116ece135SMatthias Ringwald /*
216ece135SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
316ece135SMatthias Ringwald  *
416ece135SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
516ece135SMatthias Ringwald  * modification, are permitted provided that the following conditions
616ece135SMatthias Ringwald  * are met:
716ece135SMatthias Ringwald  *
816ece135SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
916ece135SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
1016ece135SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
1116ece135SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
1216ece135SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
1316ece135SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
1416ece135SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
1516ece135SMatthias Ringwald  *    from this software without specific prior written permission.
1616ece135SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
1716ece135SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
1816ece135SMatthias Ringwald  *    monetary gain.
1916ece135SMatthias Ringwald  *
2016ece135SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
2116ece135SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2216ece135SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2316ece135SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
2416ece135SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2516ece135SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2616ece135SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
2716ece135SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2816ece135SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2916ece135SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
3016ece135SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3116ece135SMatthias Ringwald  * SUCH DAMAGE.
3216ece135SMatthias Ringwald  *
3316ece135SMatthias Ringwald  * Please inquire about commercial licensing options at
3416ece135SMatthias Ringwald  * [email protected]
3516ece135SMatthias Ringwald  *
3616ece135SMatthias Ringwald  */
3716ece135SMatthias Ringwald 
3816ece135SMatthias Ringwald /*
3916ece135SMatthias Ringwald  *  btstack_debug.h
4016ece135SMatthias Ringwald  *
4116ece135SMatthias Ringwald  *  allow to funnel debug & error messages
4216ece135SMatthias Ringwald  */
4316ece135SMatthias Ringwald 
4416ece135SMatthias Ringwald #ifndef __DEBUG_H
4516ece135SMatthias Ringwald #define __DEBUG_H
4616ece135SMatthias Ringwald 
47*7907f069SMatthias Ringwald #include "btstack_config.h"
4816ece135SMatthias Ringwald #include "hci_dump.h"
4916ece135SMatthias Ringwald 
5016ece135SMatthias Ringwald #include <stdio.h>
5116ece135SMatthias Ringwald 
5216ece135SMatthias Ringwald #ifdef __AVR__
5316ece135SMatthias Ringwald #include <avr/pgmspace.h>
5416ece135SMatthias Ringwald #endif
5516ece135SMatthias Ringwald 
5616ece135SMatthias Ringwald #ifndef EMBEDDED
5716ece135SMatthias Ringwald // Avoid complaints of unused arguments when log levels are disabled.
5816ece135SMatthias Ringwald static inline void __log_unused(const char *format, ...) {
5916ece135SMatthias Ringwald }
6016ece135SMatthias Ringwald #else
6116ece135SMatthias Ringwald #define __log_unused(...)
6216ece135SMatthias Ringwald #endif
6316ece135SMatthias Ringwald 
6416ece135SMatthias Ringwald #ifdef __AVR__
6516ece135SMatthias Ringwald #define HCI_DUMP_LOG(log_level, format, ...) hci_dump_log_P(log_level, PSTR(format), ## __VA_ARGS__)
6616ece135SMatthias Ringwald #define BTSTACK_PRINTF(format, ...)          printf_P(PSTR(format), ## __VA_ARGS__)
6716ece135SMatthias Ringwald #else
6816ece135SMatthias Ringwald #define HCI_DUMP_LOG(log_level, format, ...) hci_dump_log(log_level, format, ## __VA_ARGS__)
6916ece135SMatthias Ringwald #define BTSTACK_PRINTF(format, ...)          printf(format, ## __VA_ARGS__)
7016ece135SMatthias Ringwald #endif
7116ece135SMatthias Ringwald 
7216ece135SMatthias Ringwald #ifdef ENABLE_LOG_DEBUG
7316ece135SMatthias Ringwald #ifdef HAVE_HCI_DUMP
7416ece135SMatthias Ringwald #define log_debug(format, ...)  HCI_DUMP_LOG(LOG_LEVEL_DEBUG, format,  ## __VA_ARGS__)
7516ece135SMatthias Ringwald #else
7616ece135SMatthias Ringwald #define log_debug(format, ...)  BTSTACK_PRINTF(format "\n",  ## __VA_ARGS__)
7716ece135SMatthias Ringwald #endif
7816ece135SMatthias Ringwald #else
7916ece135SMatthias Ringwald #define log_debug(...) __log_unused(__VA_ARGS__)
8016ece135SMatthias Ringwald #endif
8116ece135SMatthias Ringwald 
8216ece135SMatthias Ringwald #ifdef ENABLE_LOG_INFO
8316ece135SMatthias Ringwald #ifdef HAVE_HCI_DUMP
8416ece135SMatthias Ringwald #define log_info(format, ...)  HCI_DUMP_LOG(LOG_LEVEL_INFO, format,  ## __VA_ARGS__)
8516ece135SMatthias Ringwald #else
8616ece135SMatthias Ringwald #define log_info(format, ...)  BTSTACK_PRINTF(format "\n",  ## __VA_ARGS__)
8716ece135SMatthias Ringwald #endif
8816ece135SMatthias Ringwald #else
8916ece135SMatthias Ringwald #define log_info(...) __log_unused(__VA_ARGS__)
9016ece135SMatthias Ringwald #endif
9116ece135SMatthias Ringwald 
9216ece135SMatthias Ringwald #ifdef ENABLE_LOG_ERROR
9316ece135SMatthias Ringwald #ifdef HAVE_HCI_DUMP
9416ece135SMatthias Ringwald #define log_error(format, ...)  HCI_DUMP_LOG(LOG_LEVEL_ERROR, format,  ## __VA_ARGS__)
9516ece135SMatthias Ringwald #else
9616ece135SMatthias Ringwald #define log_error(format, ...)  BTSTACK_PRINTF(format "\n",  ## __VA_ARGS__)
9716ece135SMatthias Ringwald #endif
9816ece135SMatthias Ringwald #else
9916ece135SMatthias Ringwald #define log_error(...) __log_unused(__VA_ARGS__)
10016ece135SMatthias Ringwald #endif
10116ece135SMatthias Ringwald 
10216ece135SMatthias Ringwald #endif // __DEBUG_H
103