From 6219d5e7d4e586655742f502acb4c85cd628f2a5 Mon Sep 17 00:00:00 2001 From: Armando Date: Tue, 6 Aug 2024 11:02:18 +0800 Subject: [PATCH] fix(lp_i2s): fixed coverity issue --- components/esp_driver_i2s/lp_i2s.c | 12 ++++++------ components/esp_driver_i2s/lp_i2s_pdm.c | 2 +- components/esp_driver_i2s/lp_i2s_std.c | 2 +- components/hal/esp32p4/include/hal/lp_i2s_ll.h | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/esp_driver_i2s/lp_i2s.c b/components/esp_driver_i2s/lp_i2s.c index 0e4e0329cd..7084fc8947 100644 --- a/components/esp_driver_i2s/lp_i2s.c +++ b/components/esp_driver_i2s/lp_i2s.c @@ -44,14 +44,10 @@ esp_err_t lp_i2s_new_channel(const lp_i2s_chan_config_t *chan_cfg, lp_i2s_chan_h ESP_RETURN_ON_FALSE(chan_cfg, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer"); ESP_RETURN_ON_FALSE(chan_cfg->id < SOC_LP_I2S_NUM, ESP_ERR_INVALID_ARG, TAG, "invalid LP I2S port id"); ESP_RETURN_ON_FALSE(chan_cfg->role == I2S_ROLE_SLAVE, ESP_ERR_INVALID_ARG, TAG, "invalid argument: LP I2S not support master"); -#if LP_I2S_LL_TX_SUPPORTED - ESP_RETURN_ON_FALSE(ret_tx_handle, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer"); -#else +#if !LP_I2S_LL_TX_SUPPORTED ESP_RETURN_ON_FALSE(!ret_tx_handle, ESP_ERR_INVALID_ARG, TAG, "tx not supported"); #endif -#if LP_I2S_LL_RX_SUPPORTED - ESP_RETURN_ON_FALSE(ret_rx_handle, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer"); -#else +#if !LP_I2S_LL_RX_SUPPORTED ESP_RETURN_ON_FALSE(!ret_rx_handle, ESP_ERR_INVALID_ARG, TAG, "rx not supported"); #endif ESP_RETURN_ON_FALSE(chan_cfg->threshold % 4 == 0, ESP_ERR_INVALID_ARG, TAG, "threshold must be in multiple of 4"); @@ -67,8 +63,12 @@ esp_err_t lp_i2s_new_channel(const lp_i2s_chan_config_t *chan_cfg, lp_i2s_chan_h ESP_GOTO_ON_ERROR(esp_intr_alloc(lp_i2s_periph_signal[ctlr->id].irq, ESP_INTR_FLAG_IRAM, s_i2s_default_isr, ctlr, &ctlr->intr), err1, TAG, "allocate interrupt failed"); uint8_t chan_search_mask = 0; +#if LP_I2S_LL_TX_SUPPORTED chan_search_mask |= ret_tx_handle ? I2S_DIR_TX : 0; +#endif +#if LP_I2S_LL_RX_SUPPORTED chan_search_mask |= ret_rx_handle ? I2S_DIR_RX : 0; +#endif portENTER_CRITICAL(&g_i2s.spinlock); g_i2s.lp_controller[chan_cfg->id] = ctlr; diff --git a/components/esp_driver_i2s/lp_i2s_pdm.c b/components/esp_driver_i2s/lp_i2s_pdm.c index 31d7c309aa..315035fcce 100644 --- a/components/esp_driver_i2s/lp_i2s_pdm.c +++ b/components/esp_driver_i2s/lp_i2s_pdm.c @@ -53,7 +53,7 @@ esp_err_t lp_i2s_channel_init_pdm_rx_mode(lp_i2s_chan_handle_t handle, const lp_ lp_i2s_ll_select_rx_clk_source(handle->ctlr->id, LP_I2S_CLK_SRC_XTAL_D2); } lp_i2s_ll_clk_source_div_num(handle->ctlr->id, 2); - lp_i2s_ll_rx_set_raw_clk_div(handle->ctlr->id, 0, 0); + lp_i2s_ll_rx_set_raw_clk_div(handle->ctlr->id, 0, 1); lp_i2s_ll_rx_set_bck_div_num(handle->ctlr->hal.dev, 1); } // TODO: make this divisions configurable when support master mode. diff --git a/components/esp_driver_i2s/lp_i2s_std.c b/components/esp_driver_i2s/lp_i2s_std.c index a0a71c486e..f406500431 100644 --- a/components/esp_driver_i2s/lp_i2s_std.c +++ b/components/esp_driver_i2s/lp_i2s_std.c @@ -37,7 +37,7 @@ esp_err_t lp_i2s_channel_init_std_mode(lp_i2s_chan_handle_t handle, const lp_i2s lp_i2s_ll_select_rx_clk_source(handle->ctlr->id, LP_I2S_CLK_SRC_XTAL_D2); } lp_i2s_ll_clk_source_div_num(handle->ctlr->id, 2); - lp_i2s_ll_rx_set_raw_clk_div(handle->ctlr->id, 0, 0); + lp_i2s_ll_rx_set_raw_clk_div(handle->ctlr->id, 0, 1); lp_i2s_ll_rx_set_bck_div_num(handle->ctlr->hal.dev, 1); } // TODO: make this divisions configurable when support master mode. diff --git a/components/hal/esp32p4/include/hal/lp_i2s_ll.h b/components/hal/esp32p4/include/hal/lp_i2s_ll.h index a2e509db45..c9f0d5611b 100644 --- a/components/hal/esp32p4/include/hal/lp_i2s_ll.h +++ b/components/hal/esp32p4/include/hal/lp_i2s_ll.h @@ -218,6 +218,7 @@ static inline void lp_i2s_ll_clk_source_div_num(int id, uint32_t val) */ static inline void lp_i2s_ll_rx_set_raw_clk_div(int id, uint32_t a, uint32_t b) { + HAL_ASSERT(b > 0); if (b <= a / 2) { LPPERI.lp_i2s_rxclk_div_xyz.lp_i2s_rx_clkm_div_yn1 = 0; LPPERI.lp_i2s_rxclk_div_xyz.lp_i2s_rx_clkm_div_x = floor(a / b) - 1;