From 0717729911fb0a5638f3182fab29d543aed634a3 Mon Sep 17 00:00:00 2001 From: morris Date: Sat, 7 Oct 2023 18:23:41 +0800 Subject: [PATCH] fix(hal): replace assert with hal_assert hal is a G0 component but assert may link in the symbols in the newlib component. we'd better not use assert in the hal but use the alternative HAL_ASSERT --- components/hal/emac_hal.c | 7 +++---- components/hal/esp32/include/hal/i2c_ll.h | 10 +++++----- components/hal/esp32/include/hal/mpi_ll.h | 4 ++-- tools/ci/check_api_violation.sh | 3 ++- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/components/hal/emac_hal.c b/components/hal/emac_hal.c index 401d8009d1..a56bc7785b 100644 --- a/components/hal/emac_hal.c +++ b/components/hal/emac_hal.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,12 +9,11 @@ #include "hal/emac_hal.h" #include "hal/emac_ll.h" #include "hal/gpio_ll.h" +#include "hal/assert.h" #define ETH_CRC_LENGTH (4) -#ifndef NDEBUG #define EMAC_HAL_BUF_MAGIC_ID 0x1E1C8416 -#endif // NDEBUG typedef struct { #ifndef NDEBUG @@ -629,7 +628,7 @@ uint32_t emac_hal_receive_frame(emac_hal_context_t *hal, uint8_t *buf, uint32_t emac_hal_auto_buf_info_t *buff_info = (emac_hal_auto_buf_info_t *)buf; #ifndef NDEBUG /* check that buffer was allocated by emac_hal_alloc_recv_buf */ - assert(buff_info->magic_id == EMAC_HAL_BUF_MAGIC_ID); + HAL_ASSERT(buff_info->magic_id == EMAC_HAL_BUF_MAGIC_ID); #endif // NDEBUG copy_len = buff_info->copy_len; ret_len = copy_len; diff --git a/components/hal/esp32/include/hal/i2c_ll.h b/components/hal/esp32/include/hal/i2c_ll.h index ded93f2015..4e327b82ba 100644 --- a/components/hal/esp32/include/hal/i2c_ll.h +++ b/components/hal/esp32/include/hal/i2c_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,7 +15,7 @@ #include "soc/clk_tree_defs.h" #include "hal/i2c_types.h" #include "esp_attr.h" -#include "hal/misc.h" +#include "hal/assert.h" #ifdef __cplusplus extern "C" { @@ -97,7 +97,7 @@ static inline void i2c_ll_master_cal_bus_clk(uint32_t source_clk, uint32_t bus_f static inline void i2c_ll_master_set_bus_timing(i2c_dev_t *hw, i2c_hal_clk_config_t *bus_cfg) { /* SCL period. According to the TRM, we should always subtract 1 to SCL low period */ - assert(bus_cfg->scl_low > 0); + HAL_ASSERT(bus_cfg->scl_low > 0); hw->scl_low_period.period = bus_cfg->scl_low - 1; /* Still according to the TRM, if filter is not enbled, we have to subtract 7, * if SCL filter is enabled, we have to subtract: @@ -106,12 +106,12 @@ static inline void i2c_ll_master_set_bus_timing(i2c_dev_t *hw, i2c_hal_clk_confi * to SCL high period */ uint16_t scl_high = bus_cfg->scl_high; /* In the "worst" case, we will subtract 13, make sure the result will still be correct */ - assert(scl_high > 13); + HAL_ASSERT(scl_high > 13); if (hw->scl_filter_cfg.en) { if (hw->scl_filter_cfg.thres <= 2) { scl_high -= 8; } else { - assert(hw->scl_filter_cfg.thres <= 7); + HAL_ASSERT(hw->scl_filter_cfg.thres <= 7); scl_high -= hw->scl_filter_cfg.thres + 6; } } else { diff --git a/components/hal/esp32/include/hal/mpi_ll.h b/components/hal/esp32/include/hal/mpi_ll.h index 921f38feeb..4ac157c9a0 100644 --- a/components/hal/esp32/include/hal/mpi_ll.h +++ b/components/hal/esp32/include/hal/mpi_ll.h @@ -105,7 +105,7 @@ static inline void mpi_ll_write_to_mem_block(mpi_param_t param, size_t offset, c * */ - //for (uint32_t i = copy_words; i < hw_words; i++) { assert(pbase[i] == 0); } + //for (uint32_t i = copy_words; i < hw_words; i++) { HAL_ASSERT(pbase[i] == 0); } #endif } @@ -131,7 +131,7 @@ static inline void mpi_ll_write_at_offset(mpi_param_t param, int offset, uint32_ */ static inline void mpi_ll_read_from_mem_block(uint32_t* p, size_t n, size_t num_words) { - assert(n >= num_words); + HAL_ASSERT(n >= num_words); uint32_t mem_base = MPI_LL_BLOCK_BASES[MPI_PARAM_Z]; /* Copy data from memory block registers */ esp_dport_access_read_buffer(p, mem_base, num_words); diff --git a/tools/ci/check_api_violation.sh b/tools/ci/check_api_violation.sh index 589b7c839d..7cf673fdbd 100755 --- a/tools/ci/check_api_violation.sh +++ b/tools/ci/check_api_violation.sh @@ -22,10 +22,11 @@ if [ $count -gt 0 ]; then fi # ESP-IDF `hal` component shouldn't call "assert()" directlly -files_to_search=$(git ls-files --full-name 'components/hal/*') +files_to_search=$(git ls-files --full-name 'components/hal/*' | grep -v components/hal/test_apps/) found_libc_assert=$(grep -E '\W+assert\(' $files_to_search) if [ -n "$found_libc_assert" ]; then echo "hal assert violation" echo $found_libc_assert echo "Please use HAL_ASSERT() instead of assert() in hal component" + exit 1 fi