2015-07-02 04:47:13 +08:00
|
|
|
/** @file
|
2015-06-16 22:25:37 +08:00
|
|
|
* @brief Bluetooth subsystem logging helpers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-06-10 17:10:18 +08:00
|
|
|
* Copyright (c) 2015-2016 Intel Corporation
|
2015-06-16 22:25:37 +08:00
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-06-16 22:25:37 +08:00
|
|
|
*/
|
|
|
|
#ifndef __BT_LOG_H
|
|
|
|
#define __BT_LOG_H
|
|
|
|
|
2016-06-29 18:30:11 +08:00
|
|
|
#include <sections.h>
|
2016-11-24 16:07:42 +08:00
|
|
|
#include <offsets.h>
|
2016-11-12 17:37:02 +08:00
|
|
|
#include <zephyr.h>
|
2016-06-29 18:30:11 +08:00
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-01-17 17:01:47 +08:00
|
|
|
#if !defined(BT_DBG_ENABLED)
|
|
|
|
#define BT_DBG_ENABLED 1
|
|
|
|
#endif
|
|
|
|
|
2016-04-20 22:54:07 +08:00
|
|
|
#if defined(CONFIG_BLUETOOTH_DEBUG_MONITOR)
|
2016-04-27 22:57:03 +08:00
|
|
|
#include <stdio.h>
|
2016-04-20 22:54:07 +08:00
|
|
|
|
|
|
|
/* These defines follow the values used by syslog(2) */
|
|
|
|
#define BT_LOG_ERR 3
|
|
|
|
#define BT_LOG_WARN 4
|
|
|
|
#define BT_LOG_INFO 6
|
|
|
|
#define BT_LOG_DBG 7
|
|
|
|
|
2017-01-17 18:42:22 +08:00
|
|
|
__printf_like(2, 3) void bt_log(int prio, const char *fmt, ...);
|
2016-04-20 22:54:07 +08:00
|
|
|
|
2017-01-17 17:01:47 +08:00
|
|
|
#define BT_DBG(fmt, ...) \
|
|
|
|
if (BT_DBG_ENABLED) { \
|
|
|
|
bt_log(BT_LOG_DBG, "%s (%p): " fmt, \
|
|
|
|
__func__, k_current_get(), ##__VA_ARGS__); \
|
|
|
|
}
|
|
|
|
|
2016-04-20 22:54:07 +08:00
|
|
|
#define BT_ERR(fmt, ...) bt_log(BT_LOG_ERR, "%s: " fmt, \
|
|
|
|
__func__, ##__VA_ARGS__)
|
|
|
|
#define BT_WARN(fmt, ...) bt_log(BT_LOG_WARN, "%s: " fmt, \
|
|
|
|
__func__, ##__VA_ARGS__)
|
|
|
|
#define BT_INFO(fmt, ...) bt_log(BT_LOG_INFO, fmt, ##__VA_ARGS__)
|
2016-09-09 01:16:35 +08:00
|
|
|
|
2016-12-08 02:54:49 +08:00
|
|
|
/* Enabling debug increases stack size requirement */
|
2016-12-09 20:02:28 +08:00
|
|
|
#define BT_STACK_DEBUG_EXTRA 300
|
2016-04-20 22:54:07 +08:00
|
|
|
|
2016-04-27 22:57:03 +08:00
|
|
|
#elif defined(CONFIG_BLUETOOTH_DEBUG_LOG)
|
2016-04-20 22:54:07 +08:00
|
|
|
|
2016-04-27 22:57:03 +08:00
|
|
|
#define SYS_LOG_DOMAIN "bt"
|
|
|
|
#define SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
|
2016-12-18 01:56:56 +08:00
|
|
|
#include <logging/sys_log.h>
|
2016-04-27 22:57:03 +08:00
|
|
|
|
2017-01-17 17:01:47 +08:00
|
|
|
#define BT_DBG(fmt, ...) \
|
|
|
|
if (BT_DBG_ENABLED) { \
|
|
|
|
SYS_LOG_DBG("(%p) " fmt, k_current_get(), \
|
|
|
|
##__VA_ARGS__); \
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:57:03 +08:00
|
|
|
#define BT_ERR(fmt, ...) SYS_LOG_ERR(fmt, ##__VA_ARGS__)
|
|
|
|
#define BT_WARN(fmt, ...) SYS_LOG_WRN(fmt, ##__VA_ARGS__)
|
|
|
|
#define BT_INFO(fmt, ...) SYS_LOG_INF(fmt, ##__VA_ARGS__)
|
2016-09-09 01:16:35 +08:00
|
|
|
|
2015-12-15 16:23:59 +08:00
|
|
|
/* Enabling debug increases stack size requirement considerably */
|
2016-12-09 20:02:28 +08:00
|
|
|
#define BT_STACK_DEBUG_EXTRA 300
|
2016-04-20 22:54:07 +08:00
|
|
|
|
2015-06-16 22:25:37 +08:00
|
|
|
#else
|
2016-04-20 22:54:07 +08:00
|
|
|
|
2017-01-17 17:01:47 +08:00
|
|
|
static inline __printf_like(1, 2) void _bt_log_dummy(const char *fmt, ...) {};
|
|
|
|
|
|
|
|
#define BT_DBG(fmt, ...) \
|
|
|
|
if (0) { \
|
|
|
|
_bt_log_dummy(fmt, ##__VA_ARGS__); \
|
|
|
|
}
|
|
|
|
#define BT_ERR BT_DBG
|
|
|
|
#define BT_WARN BT_DBG
|
|
|
|
#define BT_INFO BT_DBG
|
2016-09-09 01:16:35 +08:00
|
|
|
|
2015-12-15 16:23:59 +08:00
|
|
|
#define BT_STACK_DEBUG_EXTRA 0
|
2016-04-20 22:54:07 +08:00
|
|
|
|
|
|
|
#endif
|
2015-06-16 22:25:37 +08:00
|
|
|
|
2016-09-09 01:16:35 +08:00
|
|
|
#define BT_ASSERT(cond) if (!(cond)) { \
|
|
|
|
BT_ERR("assert: '" #cond "' failed"); \
|
|
|
|
_SysFatalErrorHandler(0, NULL); \
|
|
|
|
}
|
|
|
|
|
2015-12-15 16:23:59 +08:00
|
|
|
#define BT_STACK(name, size) \
|
2016-11-24 16:07:42 +08:00
|
|
|
char __stack name[(size) + K_THREAD_SIZEOF + \
|
|
|
|
BT_STACK_DEBUG_EXTRA]
|
2015-12-15 16:23:59 +08:00
|
|
|
#define BT_STACK_NOINIT(name, size) \
|
2016-11-24 16:07:42 +08:00
|
|
|
char __noinit __stack name[(size) + K_THREAD_SIZEOF + \
|
|
|
|
BT_STACK_DEBUG_EXTRA]
|
2015-12-15 16:23:59 +08:00
|
|
|
|
2017-01-17 17:01:47 +08:00
|
|
|
/* This helper is only available when BLUETOOTH_DEBUG is enabled */
|
2016-07-04 00:37:38 +08:00
|
|
|
const char *bt_hex(const void *buf, size_t len);
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-16 22:25:37 +08:00
|
|
|
#endif /* __BT_LOG_H */
|