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 4480e33422SMatthias Ringwald #ifndef DEBUG_H 4580e33422SMatthias Ringwald #define DEBUG_H 4616ece135SMatthias Ringwald 477907f069SMatthias Ringwald #include "btstack_config.h" 488314c363SMatthias Ringwald #include "btstack_defines.h" 4916ece135SMatthias Ringwald #include "hci_dump.h" 5016ece135SMatthias Ringwald 5116ece135SMatthias Ringwald #include <stdio.h> 5216ece135SMatthias Ringwald 5316ece135SMatthias Ringwald #ifdef __AVR__ 5416ece135SMatthias Ringwald #include <avr/pgmspace.h> 5516ece135SMatthias Ringwald #endif 5616ece135SMatthias Ringwald 5750ca9754SMatthias Ringwald #ifdef HAVE_ASSERT 5850ca9754SMatthias Ringwald #include <assert.h> 5950ca9754SMatthias Ringwald #endif 6050ca9754SMatthias Ringwald 61dd807209SMatthias Ringwald // fallback to __FILE__ for untagged files 62a981810dSMatthias Ringwald #ifndef BTSTACK_FILE__ 63a981810dSMatthias Ringwald #define BTSTACK_FILE__ __FILE__ 64dd807209SMatthias Ringwald #endif 65dd807209SMatthias Ringwald 6650ca9754SMatthias Ringwald #ifdef HAVE_ASSERT 6750ca9754SMatthias Ringwald // map to libc assert 6850ca9754SMatthias Ringwald #define btstack_assert(condition) assert(condition) 6950ca9754SMatthias Ringwald #else /* HAVE_ASSERT */ 7050ca9754SMatthias Ringwald #ifdef ENABLE_BTSTACK_ASSERT 7150ca9754SMatthias Ringwald void btstack_assert_failed(const char * file, uint16_t line_nr); 7250ca9754SMatthias Ringwald #ifndef btstack_assert 7350ca9754SMatthias Ringwald // use btstack macro that calls btstack_assert_failed() - provided by port 7450ca9754SMatthias Ringwald #define btstack_assert(condition) if (condition) {} else { btstack_assert_failed(BTSTACK_FILE__, __LINE__); } 7550ca9754SMatthias Ringwald #endif 7650ca9754SMatthias Ringwald #else /* btstack_assert */ 7750ca9754SMatthias Ringwald // asserts off 7850ca9754SMatthias Ringwald #define btstack_assert(condition) {} 7950ca9754SMatthias Ringwald #endif 8050ca9754SMatthias Ringwald #endif 8150ca9754SMatthias Ringwald 82cd4b3424SMatthias Ringwald // allow to provide port specific printf 83cd4b3424SMatthias Ringwald #ifndef BTSTACK_PRINTF 8416ece135SMatthias Ringwald #ifdef __AVR__ 8516ece135SMatthias Ringwald #define BTSTACK_PRINTF(format, ...) printf_P(PSTR(format), ## __VA_ARGS__) 8616ece135SMatthias Ringwald #else 8716ece135SMatthias Ringwald #define BTSTACK_PRINTF(format, ...) printf(format, ## __VA_ARGS__) 8816ece135SMatthias Ringwald #endif 89cd4b3424SMatthias Ringwald #endif 90cd4b3424SMatthias Ringwald 91cd4b3424SMatthias Ringwald #ifdef __AVR__ 92a981810dSMatthias Ringwald #define HCI_DUMP_LOG(log_level, format, ...) hci_dump_log_P(log_level, PSTR("%s.%u: " format), BTSTACK_FILE__, __LINE__, ## __VA_ARGS__) 93cd4b3424SMatthias Ringwald #else 94a981810dSMatthias Ringwald #define HCI_DUMP_LOG(log_level, format, ...) hci_dump_log(log_level, "%s.%u: " format, BTSTACK_FILE__, __LINE__, ## __VA_ARGS__) 95cd4b3424SMatthias Ringwald #endif 9616ece135SMatthias Ringwald 9716ece135SMatthias Ringwald #ifdef ENABLE_LOG_DEBUG 98fa087deaSMatthias Ringwald #define log_debug(format, ...) HCI_DUMP_LOG(HCI_DUMP_LOG_LEVEL_DEBUG, format, ## __VA_ARGS__) 9916ece135SMatthias Ringwald #else 100*45e83228SMatthias Ringwald #define log_debug(...) (void)(0) 10116ece135SMatthias Ringwald #endif 10216ece135SMatthias Ringwald 10316ece135SMatthias Ringwald #ifdef ENABLE_LOG_INFO 104fa087deaSMatthias Ringwald #define log_info(format, ...) HCI_DUMP_LOG(HCI_DUMP_LOG_LEVEL_INFO, format, ## __VA_ARGS__) 10516ece135SMatthias Ringwald #else 106*45e83228SMatthias Ringwald #define log_info(...) (void)(0) 10716ece135SMatthias Ringwald #endif 10816ece135SMatthias Ringwald 10916ece135SMatthias Ringwald #ifdef ENABLE_LOG_ERROR 110fa087deaSMatthias Ringwald #define log_error(format, ...) HCI_DUMP_LOG(HCI_DUMP_LOG_LEVEL_ERROR, format, ## __VA_ARGS__) 11116ece135SMatthias Ringwald #else 112*45e83228SMatthias Ringwald #define log_error(...) (void)(0) 11316ece135SMatthias Ringwald #endif 11416ece135SMatthias Ringwald 1158314c363SMatthias Ringwald /** 1168314c363SMatthias Ringwald * @brief Log Security Manager key via log_info 1178314c363SMatthias Ringwald * @param key to log 1188314c363SMatthias Ringwald */ 1198314c363SMatthias Ringwald void log_info_key(const char * name, sm_key_t key); 1208314c363SMatthias Ringwald 1218314c363SMatthias Ringwald /** 1228314c363SMatthias Ringwald * @brief Hexdump via log_info 1238314c363SMatthias Ringwald * @param data 1248314c363SMatthias Ringwald * @param size 1258314c363SMatthias Ringwald */ 1268314c363SMatthias Ringwald void log_info_hexdump(const void *data, int size); 1278314c363SMatthias Ringwald 128cb42147aSMatthias Ringwald /** 129cb42147aSMatthias Ringwald * @brief Hexdump via log_debug * @param data 130cb42147aSMatthias Ringwald * @param size 131cb42147aSMatthias Ringwald */ 132cb42147aSMatthias Ringwald void log_debug_hexdump(const void *data, int size); 133cb42147aSMatthias Ringwald 13480e33422SMatthias Ringwald #endif // DEBUG_H 135