1 /* 2 * SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA 3 * SPDX-FileCopyrightText: 2015-2016 Intel Corporation 4 * SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 #ifndef _BLE_MESH_TRACE_H_ 10 #define _BLE_MESH_TRACE_H_ 11 12 #include <assert.h> 13 #include "esp_log.h" 14 #include "mesh_util.h" 15 #include "esp_rom_sys.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /* Define common tracing for all */ 22 #ifndef BLE_MESH_LOG_LEVEL_ERROR 23 #define BLE_MESH_LOG_LEVEL_ERROR 1 24 #endif /* BLE_MESH_LOG_LEVEL_ERROR */ 25 26 #ifndef BLE_MESH_LOG_LEVEL_WARN 27 #define BLE_MESH_LOG_LEVEL_WARN 2 28 #endif /* BLE_MESH_LOG_LEVEL_WARN */ 29 30 #ifndef BLE_MESH_LOG_LEVEL_INFO 31 #define BLE_MESH_LOG_LEVEL_INFO 3 32 #endif /* BLE_MESH_LOG_LEVEL_INFO */ 33 34 #ifndef BLE_MESH_LOG_LEVEL_DEBUG 35 #define BLE_MESH_LOG_LEVEL_DEBUG 4 36 #endif /* BLE_MESH_LOG_LEVEL_DEBUG */ 37 38 #ifndef BLE_MESH_LOG_LEVEL_VERBOSE 39 #define BLE_MESH_LOG_LEVEL_VERBOSE 5 40 #endif /*BLE_MESH_LOG_LEVEL_VERBOSE */ 41 42 #ifdef CONFIG_BLE_MESH_STACK_TRACE_LEVEL 43 #define BLE_MESH_LOG_LEVEL CONFIG_BLE_MESH_STACK_TRACE_LEVEL 44 #else 45 #define BLE_MESH_LOG_LEVEL BLE_MESH_LOG_LEVEL_WARN 46 #endif 47 48 #ifdef CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL 49 #define BLE_MESH_NET_BUF_LOG_LEVEL CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL 50 #else 51 #define BLE_MESH_NET_BUF_LOG_LEVEL BLE_MESH_LOG_LEVEL_WARN 52 #endif 53 54 #define BLE_MESH_TRACE_TAG "BLE_MESH" 55 56 #if (LOG_LOCAL_LEVEL >= 4) 57 #define BLE_MESH_LOG_LOCAL_LEVEL_MAPPING (LOG_LOCAL_LEVEL + 1) 58 #else 59 #define BLE_MESH_LOG_LOCAL_LEVEL_MAPPING LOG_LOCAL_LEVEL 60 #endif 61 62 #define BLE_MESH_LOG_LEVEL_CHECK(LAYER, LEVEL) (MAX(LAYER##_LOG_LEVEL, BLE_MESH_LOG_LOCAL_LEVEL_MAPPING) >= BLE_MESH_LOG_LEVEL_##LEVEL) 63 64 #define BLE_MESH_PRINT_E(tag, format, ...) {esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 65 #define BLE_MESH_PRINT_W(tag, format, ...) {esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 66 #define BLE_MESH_PRINT_I(tag, format, ...) {esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 67 #define BLE_MESH_PRINT_D(tag, format, ...) {esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 68 #define BLE_MESH_PRINT_V(tag, format, ...) {esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 69 70 #define printk esp_rom_printf 71 72 #define _STRINGIFY(x) #x 73 #define STRINGIFY(s) _STRINGIFY(s) 74 75 #ifndef __ASSERT 76 #define __ASSERT(test, str) assert(test) 77 #endif 78 79 #ifndef __ASSERT_NO_MSG 80 #define __ASSERT_NO_MSG(x) assert(x) 81 #endif 82 83 #if !CONFIG_BLE_MESH_NO_LOG 84 #define BT_ERR(fmt, args...) do {if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, ERROR)) BLE_MESH_PRINT_E(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 85 #define BT_WARN(fmt, args...) do {if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, WARN)) BLE_MESH_PRINT_W(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 86 #define BT_INFO(fmt, args...) do {if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, INFO)) BLE_MESH_PRINT_I(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 87 #define BT_DBG(fmt, args...) do {if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_DEBUG) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, DEBUG)) BLE_MESH_PRINT_D(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 88 #else 89 #define BT_ERR(fmt, args...) 90 #define BT_WARN(fmt, args...) 91 #define BT_INFO(fmt, args...) 92 #define BT_DBG(fmt, args...) 93 #endif 94 95 #if defined(CONFIG_BLE_MESH_NET_BUF_LOG) && (!CONFIG_BLE_MESH_NO_LOG) 96 #define NET_BUF_ERR(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, ERROR)) BLE_MESH_PRINT_E(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 97 #define NET_BUF_WARN(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, WARN)) BLE_MESH_PRINT_W(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 98 #define NET_BUF_INFO(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, INFO)) BLE_MESH_PRINT_I(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 99 #define NET_BUF_DBG(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_DEBUG) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, DEBUG)) BLE_MESH_PRINT_D(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 100 #define NET_BUF_ASSERT(cond) __ASSERT_NO_MSG(cond) 101 #else 102 #define NET_BUF_ERR(fmt, args...) 103 #define NET_BUF_WARN(fmt, args...) 104 #define NET_BUF_INFO(fmt, args...) 105 #define NET_BUF_DBG(fmt, args...) 106 #define NET_BUF_ASSERT(cond) 107 #endif 108 109 #if defined(CONFIG_BLE_MESH_NET_BUF_SIMPLE_LOG) && (!CONFIG_BLE_MESH_NO_LOG) 110 #define NET_BUF_SIMPLE_ERR(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, ERROR)) BLE_MESH_PRINT_E(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 111 #define NET_BUF_SIMPLE_WARN(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, WARN)) BLE_MESH_PRINT_W(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 112 #define NET_BUF_SIMPLE_INFO(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, INFO)) BLE_MESH_PRINT_I(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 113 #define NET_BUF_SIMPLE_DBG(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_DEBUG) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, DEBUG)) BLE_MESH_PRINT_D(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0) 114 #define NET_BUF_SIMPLE_ASSERT(cond) __ASSERT_NO_MSG(cond) 115 #else 116 #define NET_BUF_SIMPLE_ERR(fmt, args...) 117 #define NET_BUF_SIMPLE_WARN(fmt, args...) 118 #define NET_BUF_SIMPLE_INFO(fmt, args...) 119 #define NET_BUF_SIMPLE_DBG(fmt, args...) 120 #define NET_BUF_SIMPLE_ASSERT(cond) 121 #endif 122 123 #ifdef __cplusplus 124 } 125 #endif 126 127 #endif /* _BLE_MESH_TRACE_H_ */ 128