diff --git a/components/log/include/esp_log_level.h b/components/log/include/esp_log_level.h index bfd390ab9e..cc982f9cc4 100644 --- a/components/log/include/esp_log_level.h +++ b/components/log/include/esp_log_level.h @@ -7,6 +7,7 @@ #pragma once #include +#include "esp_assert.h" #include "sdkconfig.h" #ifdef __cplusplus @@ -26,7 +27,11 @@ typedef enum { ESP_LOG_MAX = 6, /*!< Number of levels supported */ } esp_log_level_t; +#define ESP_LOG_LEVEL_LEN (3) /*!< Number of bits used to represent the log level */ +#define ESP_LOG_LEVEL_MASK ((1 << ESP_LOG_LEVEL_LEN) - 1) /*!< Mask for log level */ + /** @cond */ +ESP_STATIC_ASSERT(ESP_LOG_MAX <= ESP_LOG_LEVEL_MASK, "Log level items of esp_log_level_t must fit ESP_LOG_LEVEL_MASK"); // LOG_LOCAL_LEVEL controls what log levels are included in the binary. #ifndef LOG_LOCAL_LEVEL diff --git a/components/log/src/log_level/tag_log_level/cache/log_binary_heap.c b/components/log/src/log_level/tag_log_level/cache/log_binary_heap.c index c4ea9615ef..86bb87cafd 100644 --- a/components/log/src/log_level/tag_log_level/cache/log_binary_heap.c +++ b/components/log/src/log_level/tag_log_level/cache/log_binary_heap.c @@ -56,12 +56,12 @@ ESP_STATIC_ASSERT(((CONFIG_LOG_TAG_LEVEL_IMPL_CACHE_SIZE & (CONFIG_LOG_TAG_LEVEL_IMPL_CACHE_SIZE + 1)) == 0), "Number of tags to be cached must be 2**n - 1, n >= 2. [1, 3, 7, 15, 31, 63, 127, 255, ...]"); #define TAG_CACHE_SIZE (CONFIG_LOG_TAG_LEVEL_IMPL_CACHE_SIZE) -#define MAX_GENERATION ((1 << 29) - 1) +#define MAX_GENERATION ((1 << (32 - ESP_LOG_LEVEL_LEN)) - 1) typedef struct { const char *tag; - uint32_t level : 3; - uint32_t generation : 29; // this size should be the same in MAX_GENERATION + uint32_t level : ESP_LOG_LEVEL_LEN; + uint32_t generation : (32 - ESP_LOG_LEVEL_LEN); // this size should be the same in MAX_GENERATION } cached_tag_entry_t; static cached_tag_entry_t s_log_cache[TAG_CACHE_SIZE];