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
|
|
|
|
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/linker/sections.h>
|
2016-11-24 09:07:42 +01:00
|
|
|
#include <offsets.h>
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/zephyr.h>
|
|
|
|
#include <zephyr/logging/log.h>
|
|
|
|
#include <zephyr/sys/__assert.h>
|
2016-06-29 13:30:11 +03:00
|
|
|
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/bluetooth/bluetooth.h>
|
|
|
|
#include <zephyr/bluetooth/uuid.h>
|
|
|
|
#include <zephyr/bluetooth/hci.h>
|
2017-05-10 16:27:16 +02:00
|
|
|
|
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)
|
2019-12-09 14:41:43 +01:00
|
|
|
#define BT_ASSERT_PRINT(test) __ASSERT_LOC(test)
|
2020-04-08 10:44:33 +02:00
|
|
|
#define BT_ASSERT_PRINT_MSG(fmt, ...) __ASSERT_MSG_INFO(fmt, ##__VA_ARGS__)
|
2019-08-19 12:38:12 +02:00
|
|
|
#else
|
2019-12-09 14:41:43 +01:00
|
|
|
#define BT_ASSERT_PRINT(test)
|
2020-04-08 10:44:33 +02:00
|
|
|
#define BT_ASSERT_PRINT_MSG(fmt, ...)
|
2019-08-19 12:38:12 +02:00
|
|
|
#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)
|
2019-12-09 14:41:43 +01:00
|
|
|
#define BT_ASSERT(cond) \
|
|
|
|
do { \
|
|
|
|
if (!(cond)) { \
|
|
|
|
BT_ASSERT_PRINT(cond); \
|
|
|
|
BT_ASSERT_DIE(); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2020-04-08 10:44:33 +02:00
|
|
|
|
|
|
|
#define BT_ASSERT_MSG(cond, fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (!(cond)) { \
|
|
|
|
BT_ASSERT_PRINT(cond); \
|
|
|
|
BT_ASSERT_PRINT_MSG(fmt, ##__VA_ARGS__); \
|
|
|
|
BT_ASSERT_DIE(); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2019-08-19 12:38:12 +02:00
|
|
|
#else
|
|
|
|
#define BT_ASSERT(cond) __ASSERT_NO_MSG(cond)
|
2020-04-08 10:44:33 +02:00
|
|
|
#define BT_ASSERT_MSG(cond, msg, ...) __ASSERT(cond, msg, ##__VA_ARGS__)
|
2019-08-19 12:38:12 +02:00
|
|
|
#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) \
|
2020-05-27 11:26:57 -05:00
|
|
|
LOG_HEXDUMP_DBG((const uint8_t *)_data, _length, _str)
|
2018-11-26 14:25:34 +01:00
|
|
|
|
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.
|
2019-11-11 13:21:12 +01:00
|
|
|
*
|
|
|
|
* NOTE: These functions are not thread-safe!
|
2019-09-30 13:21:11 +02:00
|
|
|
*/
|
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);
|
2019-11-11 13:21:12 +01:00
|
|
|
const char *bt_uuid_str_real(const struct bt_uuid *uuid);
|
2017-05-10 16:27:16 +02:00
|
|
|
|
2022-06-20 07:43:37 +02:00
|
|
|
#define bt_hex(buf, len) bt_hex_real(buf, len)
|
|
|
|
#define bt_addr_str(addr) bt_addr_str_real(addr)
|
|
|
|
#define bt_addr_le_str(addr) bt_addr_le_str_real(addr)
|
|
|
|
#define bt_uuid_str(uuid) bt_uuid_str_real(uuid)
|
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 */
|