Просмотр исходного кода

Merge branch 'refactor/remove_hal_dependency_on_log' into 'master'

hal: Remove dependency on log component

Closes IDF-4859

See merge request espressif/esp-idf!17709
Omar Chebib 3 лет назад
Родитель
Сommit
bd50aa4dfc

+ 35 - 0
components/hal/Kconfig

@@ -30,4 +30,39 @@ menu "Hardware Abstraction Layer (HAL) and Low Level (LL)"
         default 0 if HAL_ASSERTION_DISABLE
         default 1 if HAL_ASSERTION_SILIENT
         default 2 if HAL_ASSERTION_ENABLE
+
+    choice HAL_LOG_LEVEL
+        bool "HAL layer log verbosity"
+        default HAL_LOG_LEVEL_INFO
+        # If LOG component is linked, one of the following configuration symbol will be defined.
+        # Else, none will be defined, in that case, we need this HAL_LOG_LEVEL symbol.
+        depends on !LOG_DEFAULT_LEVEL_NONE && !LOG_DEFAULT_LEVEL_ERROR && !LOG_DEFAULT_LEVEL_WARN && \
+            !LOG_DEFAULT_LEVEL_INFO && !LOG_DEFAULT_LEVEL_DEBUG && !LOG_DEFAULT_LEVEL_VERBOSE
+
+        help
+            Specify how much output to see in HAL logs.
+
+        config HAL_LOG_LEVEL_NONE
+            bool "No output"
+        config HAL_LOG_LEVEL_ERROR
+            bool "Error"
+        config HAL_LOG_LEVEL_WARN
+            bool "Warning"
+        config HAL_LOG_LEVEL_INFO
+            bool "Info"
+        config HAL_LOG_LEVEL_DEBUG
+            bool "Debug"
+        config HAL_LOG_LEVEL_VERBOSE
+            bool "Verbose"
+    endchoice
+
+    config HAL_LOG_LEVEL
+        int
+        default 0 if HAL_LOG_LEVEL_NONE
+        default 1 if HAL_LOG_LEVEL_ERROR
+        default 2 if HAL_LOG_LEVEL_WARN
+        default 3 if HAL_LOG_LEVEL_INFO
+        default 4 if HAL_LOG_LEVEL_DEBUG
+        default 5 if HAL_LOG_LEVEL_VERBOSE
+
 endmenu

+ 62 - 13
components/hal/platform_port/include/hal/log.h

@@ -1,19 +1,18 @@
-// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/*
+ * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 #pragma once
 
+/**
+ * When compiling a G0 application, `log` component is not available, thus its headers (`esp_log.h`) and Kconfig macros
+ * are not available either.
+ * In that case, we have to define the LOG macros to use ROM functions, which are part of G0 layer.
+ */
+#if __has_include("esp_log.h")
+
 #include "esp_log.h"
 
 #define HAL_LOGE(...)    ESP_LOGE(__VA_ARGS__)
@@ -27,3 +26,53 @@
 #define HAL_EARLY_LOGI(...)    ESP_EARLY_LOGI(__VA_ARGS__)
 #define HAL_EARLY_LOGD(...)    ESP_EARLY_LOGD(__VA_ARGS__)
 #define HAL_EARLY_LOGV(...)    ESP_EARLY_LOGV(__VA_ARGS__)
+
+#else // __has_include("esp_log.h")
+
+#include "esp_rom_sys.h"
+
+#define HAL_LOG_NONE    0
+#define HAL_LOG_ERROR   1
+#define HAL_LOG_WARN    2
+#define HAL_LOG_INFO    3
+#define HAL_LOG_DEBUG   4
+#define HAL_LOG_VERBOSE 5
+
+
+#if CONFIG_HAL_LOG_LEVEL >= HAL_LOG_ERROR
+    #define HAL_LOGE(tag, fmt, ...) esp_rom_printf("%s(err): " fmt, tag, ##__VA_ARGS__)
+#else
+    #define HAL_LOGE(tag, fmt, ...)
+#endif
+
+#if CONFIG_HAL_LOG_LEVEL >= HAL_LOG_WARN
+    #define HAL_LOGW(tag, fmt, ...) esp_rom_printf("%s(warn): " fmt, tag, ##__VA_ARGS__)
+#else
+    #define HAL_LOGW(tag, fmt, ...)
+#endif
+
+#if CONFIG_HAL_LOG_LEVEL >= HAL_LOG_INFO
+    #define HAL_LOGI(tag, fmt, ...) esp_rom_printf("%s(info): " fmt, tag, ##__VA_ARGS__)
+#else
+    #define HAL_LOGI(tag, fmt, ...)
+#endif
+
+#if CONFIG_HAL_LOG_LEVEL >= HAL_LOG_DEBUG
+    #define HAL_LOGD(tag, fmt, ...) esp_rom_printf("%s(dbg): " fmt, tag, ##__VA_ARGS__)
+#else
+    #define HAL_LOGD(tag, fmt, ...)
+#endif
+
+#if CONFIG_HAL_LOG_LEVEL >= HAL_LOG_VERBOSE
+    #define HAL_LOGV(tag, fmt, ...) esp_rom_printf("%s: " fmt, tag, ##__VA_ARGS__)
+#else
+    #define HAL_LOGV(tag, fmt, ...)
+#endif
+
+#define HAL_EARLY_LOGE(...)    HAL_LOGE(__VA_ARGS__)
+#define HAL_EARLY_LOGW(...)    HAL_LOGW(__VA_ARGS__)
+#define HAL_EARLY_LOGI(...)    HAL_LOGI(__VA_ARGS__)
+#define HAL_EARLY_LOGD(...)    HAL_LOGD(__VA_ARGS__)
+#define HAL_EARLY_LOGV(...)    HAL_LOGV(__VA_ARGS__)
+
+#endif // __has_include("esp_log.h")

+ 7 - 14
components/hal/sdio_slave_hal.c

@@ -1,16 +1,8 @@
-// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/*
+ * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 // The HAL layer for SDIO slave (common part)
 
@@ -30,7 +22,8 @@
     return ret_val;\
 } }while (0)
 
-static const char TAG[] = "SDIO_HAL";
+/* The tag may be unused if log level is set to NONE  */
+static const __attribute__((unused)) char TAG[] = "SDIO_HAL";
 
 static esp_err_t init_send_queue(sdio_slave_context_t *hal);
 

+ 0 - 3
components/hal/spi_flash_hal.c

@@ -11,11 +11,9 @@
 #include <string.h>
 #include "soc/soc_caps.h"
 #include "hal/spi_flash_hal.h"
-#include "hal/log.h"
 
 #define APB_CYCLE_NS   (1000*1000*1000LL/APB_CLK_FREQ)
 
-static const char TAG[] = "FLASH_HAL";
 
 typedef struct {
     int div;
@@ -127,7 +125,6 @@ esp_err_t spi_flash_hal_init(spi_flash_hal_context_t *data_out, const spi_flash_
     }
 #endif
 
-    HAL_LOGD(TAG, "extra_dummy: %d", data_out->extra_dummy);
     return ESP_OK;
 }
 

+ 3 - 1
components/hal/spi_hal.c

@@ -24,7 +24,9 @@
 #define spi_dma_ll_set_out_eof_generation(dev, chan, enable)          gdma_ll_tx_set_eof_mode(&GDMA, chan, enable);
 #endif
 
-static const char SPI_HAL_TAG[] = "spi_hal";
+/* The tag may be unused if log level is set to NONE  */
+static const __attribute__((unused)) char SPI_HAL_TAG[] = "spi_hal";
+
 #define SPI_HAL_CHECK(a, str, ret_val, ...) \
     if (!(a)) { \
         HAL_LOGE(SPI_HAL_TAG,"%s(%d): "str, __FUNCTION__, __LINE__, ##__VA_ARGS__); \

+ 0 - 2
tools/ci/check_copyright_ignore.txt

@@ -939,10 +939,8 @@ components/hal/mcpwm_hal.c
 components/hal/mpu_hal.c
 components/hal/platform_port/include/hal/assert.h
 components/hal/platform_port/include/hal/check.h
-components/hal/platform_port/include/hal/log.h
 components/hal/platform_port/include/hal/misc.h
 components/hal/rtc_io_hal.c
-components/hal/sdio_slave_hal.c
 components/hal/sha_hal.c
 components/hal/sigmadelta_hal.c
 components/hal/soc_hal.c