1 /** @file 2 * @brief Bluetooth subsystem logging helpers. 3 */ 4 5 /* 6 * Copyright (c) 2017 Nordic Semiconductor ASA 7 * Copyright (c) 2015-2016 Intel Corporation 8 * 9 * SPDX-License-Identifier: Apache-2.0 10 */ 11 #ifndef __BT_LOG_H 12 #define __BT_LOG_H 13 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 //#include "adv.h" 20 #include "hal_trace.h" 21 22 #if !defined(BT_DBG_ENABLED) 23 #define BT_DBG_ENABLED 1 24 #endif 25 26 #if defined(CONFIG_BT_DEBUG_MONITOR) 27 #include <stdio.h> 28 29 /* These defines follow the values used by syslog(2) */ 30 #define BT_LOG_ERR 3 31 #define BT_LOG_WARN 4 32 #define BT_LOG_INFO 6 33 #define BT_LOG_DBG 7 34 35 __printf_like(2, 3) void bt_log(int prio, const char *fmt, ...); 36 37 #define BT_DBG(fmt, ...) \ 38 if (BT_DBG_ENABLED) { \ 39 bt_log(BT_LOG_DBG, "%s (%p): " fmt, \ 40 __func__, k_current_get(), ##__VA_ARGS__); \ 41 } 42 43 #define BT_ERR(fmt, ...) bt_log(BT_LOG_ERR, "%s: " fmt, \ 44 __func__, ##__VA_ARGS__) 45 #define BT_WARN(fmt, ...) bt_log(BT_LOG_WARN, "%s: " fmt, \ 46 __func__, ##__VA_ARGS__) 47 #define BT_INFO(fmt, ...) bt_log(BT_LOG_INFO, fmt, ##__VA_ARGS__) 48 49 /* Enabling debug increases stack size requirement */ 50 #define BT_STACK_DEBUG_EXTRA 300 51 52 #elif defined(CONFIG_BT_DEBUG_LOG) 53 54 #if !defined(SYS_LOG_DOMAIN) 55 #define SYS_LOG_DOMAIN "bt" 56 #endif 57 #define SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG 58 59 #define BT_DBG(fmt, ...) \ 60 if (BT_DBG_ENABLED) { \ 61 printf(fmt"\n",\ 62 ##__VA_ARGS__); \ 63 } 64 65 #define BT_ERR(fmt, ...) printf(fmt"\n", ##__VA_ARGS__) 66 #define BT_WARN(fmt, ...) BT_DBG(fmt"\n", ##__VA_ARGS__) 67 #define BT_INFO(fmt, ...) BT_DBG(fmt"\n", ##__VA_ARGS__) 68 69 /* Enabling debug increases stack size requirement considerably */ 70 #define BT_STACK_DEBUG_EXTRA 300 71 72 #else 73 74 #define BT_DBG TRACE 75 #define BT_ERR BT_DBG 76 #define BT_WARN BT_DBG 77 #define BT_INFO BT_DBG 78 79 #define BT_STACK_DEBUG_EXTRA 0 80 81 #endif 82 83 84 85 #define BT_ASSERT(cond) if (!(cond)) { \ 86 BT_ERR("assert: '" #cond "' failed"); \ 87 k_oops(); \ 88 } 89 90 91 /* This helper is only available when BT_DEBUG is enabled */ 92 const char *bt_hex(const void *buf, size_t len); 93 94 uint8_t stringtohex(char *str, uint8_t *out, uint8_t count); 95 void hextostring(const uint8_t *source, char *dest, int len); 96 97 /* These helpers are only safe to be called from internal threads as they're 98 * not multi-threading safe 99 */ 100 101 102 #ifdef __cplusplus 103 } 104 #endif 105 106 #endif /* __BT_LOG_H */ 107 108