2015-07-01 16:47:13 -04:00
|
|
|
/** @file
|
2015-06-16 17:25:37 +03:00
|
|
|
* @brief Bluetooth subsystem logging helpers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-05-10 16:27:16 +02:00
|
|
|
* Copyright (c) 2017 Nordic Semiconductor ASA
|
2016-06-10 12:10:18 +03:00
|
|
|
* Copyright (c) 2015-2016 Intel Corporation
|
2015-06-16 17:25:37 +03:00
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-06-16 17:25:37 +03:00
|
|
|
*/
|
|
|
|
#ifndef __BT_LOG_H
|
|
|
|
#define __BT_LOG_H
|
|
|
|
|
2017-06-17 11:30:47 -04:00
|
|
|
#include <linker/sections.h>
|
2016-11-24 09:07:42 +01:00
|
|
|
#include <offsets.h>
|
2016-11-12 11:37:02 +02:00
|
|
|
#include <zephyr.h>
|
2019-08-12 12:54:12 -05:00
|
|
|
#include <logging/log.h>
|
2016-06-29 13:30:11 +03:00
|
|
|
|
2017-05-10 16:27:16 +02:00
|
|
|
#include <bluetooth/bluetooth.h>
|
|
|
|
#include <bluetooth/hci.h>
|
|
|
|
|
2016-01-22 12:38:49 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-01-17 11:01:47 +02:00
|
|
|
#if !defined(BT_DBG_ENABLED)
|
|
|
|
#define BT_DBG_ENABLED 1
|
|
|
|
#endif
|
|
|
|
|
2018-07-17 10:35:52 +03:00
|
|
|
#if BT_DBG_ENABLED
|
|
|
|
#define LOG_LEVEL LOG_LEVEL_DBG
|
|
|
|
#else
|
2018-11-22 14:27:32 +01:00
|
|
|
#define LOG_LEVEL CONFIG_BT_LOG_LEVEL
|
2017-05-31 13:47:56 +03:00
|
|
|
#endif
|
2016-04-27 17:57:03 +03:00
|
|
|
|
2019-11-25 11:07:28 +08:00
|
|
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);
|
2018-07-17 10:35:52 +03:00
|
|
|
|
|
|
|
#define BT_DBG(fmt, ...) LOG_DBG(fmt, ##__VA_ARGS__)
|
|
|
|
#define BT_ERR(fmt, ...) LOG_ERR(fmt, ##__VA_ARGS__)
|
|
|
|
#define BT_WARN(fmt, ...) LOG_WRN(fmt, ##__VA_ARGS__)
|
|
|
|
#define BT_INFO(fmt, ...) LOG_INF(fmt, ##__VA_ARGS__)
|
2016-09-08 19:16:35 +02:00
|
|
|
|
2019-08-19 12:38:12 +02:00
|
|
|
#if defined(CONFIG_BT_ASSERT_VERBOSE)
|
|
|
|
#define BT_ASSERT_PRINT(fmt, ...) printk(fmt, ##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define BT_ASSERT_PRINT(fmt, ...)
|
|
|
|
#endif /* CONFIG_BT_ASSERT_VERBOSE */
|
|
|
|
|
|
|
|
#if defined(CONFIG_BT_ASSERT_PANIC)
|
|
|
|
#define BT_ASSERT_DIE k_panic
|
|
|
|
#else
|
|
|
|
#define BT_ASSERT_DIE k_oops
|
|
|
|
#endif /* CONFIG_BT_ASSERT_PANIC */
|
|
|
|
|
|
|
|
#if defined(CONFIG_BT_ASSERT)
|
2016-09-08 19:16:35 +02:00
|
|
|
#define BT_ASSERT(cond) if (!(cond)) { \
|
2019-08-19 12:38:12 +02:00
|
|
|
BT_ASSERT_PRINT("assert: '" #cond \
|
|
|
|
"' failed\n"); \
|
|
|
|
BT_ASSERT_DIE(); \
|
2016-09-08 19:16:35 +02:00
|
|
|
}
|
2019-08-19 12:38:12 +02:00
|
|
|
#else
|
|
|
|
#define BT_ASSERT(cond) __ASSERT_NO_MSG(cond)
|
|
|
|
#endif/* CONFIG_BT_ASSERT*/
|
2016-09-08 19:16:35 +02:00
|
|
|
|
2018-11-26 14:25:34 +01:00
|
|
|
#define BT_HEXDUMP_DBG(_data, _length, _str) \
|
|
|
|
LOG_HEXDUMP_DBG((const u8_t *)_data, _length, _str)
|
|
|
|
|
2019-09-30 13:21:11 +02:00
|
|
|
/* NOTE: These helper functions always encodes into the same buffer storage.
|
|
|
|
* It is the responsibility of the user of this function to copy the information
|
|
|
|
* in this string if needed.
|
|
|
|
*/
|
2018-10-17 14:09:40 +03:00
|
|
|
const char *bt_hex_real(const void *buf, size_t len);
|
|
|
|
const char *bt_addr_str_real(const bt_addr_t *addr);
|
|
|
|
const char *bt_addr_le_str_real(const bt_addr_le_t *addr);
|
2017-05-10 16:27:16 +02:00
|
|
|
|
2019-09-30 13:21:11 +02:00
|
|
|
/* NOTE: log_strdup does not guarantee a duplication of the string.
|
|
|
|
* It is therefore still the responsibility of the user to handle the
|
|
|
|
* restrictions in the underlying function call.
|
|
|
|
*/
|
2018-10-17 14:09:40 +03:00
|
|
|
#define bt_hex(buf, len) log_strdup(bt_hex_real(buf, len))
|
|
|
|
#define bt_addr_str(addr) log_strdup(bt_addr_str_real(addr))
|
|
|
|
#define bt_addr_le_str(addr) log_strdup(bt_addr_le_str_real(addr))
|
2017-05-10 16:27:16 +02:00
|
|
|
|
2016-01-22 12:38:49 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-16 17:25:37 +03:00
|
|
|
#endif /* __BT_LOG_H */
|