Merge branch 'fix/fix_lp_i2s_coverity_issue' into 'master'

lp_i2s: fixed coverity issue

Closes IDF-10715, IDF-10713, IDF-10716, IDF-10714, and IDF-10717

See merge request espressif/esp-idf!32617
This commit is contained in:
Armando (Dou Yiwen) 2024-08-07 17:29:06 +08:00
commit 3a0c25124e
8 changed files with 13 additions and 12 deletions

View File

@ -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, 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->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"); 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 #if !LP_I2S_LL_TX_SUPPORTED
ESP_RETURN_ON_FALSE(ret_tx_handle, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
#else
ESP_RETURN_ON_FALSE(!ret_tx_handle, ESP_ERR_INVALID_ARG, TAG, "tx not supported"); ESP_RETURN_ON_FALSE(!ret_tx_handle, ESP_ERR_INVALID_ARG, TAG, "tx not supported");
#endif #endif
#if LP_I2S_LL_RX_SUPPORTED #if !LP_I2S_LL_RX_SUPPORTED
ESP_RETURN_ON_FALSE(ret_rx_handle, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
#else
ESP_RETURN_ON_FALSE(!ret_rx_handle, ESP_ERR_INVALID_ARG, TAG, "rx not supported"); ESP_RETURN_ON_FALSE(!ret_rx_handle, ESP_ERR_INVALID_ARG, TAG, "rx not supported");
#endif #endif
ESP_RETURN_ON_FALSE(chan_cfg->threshold % 4 == 0, ESP_ERR_INVALID_ARG, TAG, "threshold must be in multiple of 4"); 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"); 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; uint8_t chan_search_mask = 0;
#if LP_I2S_LL_TX_SUPPORTED
chan_search_mask |= ret_tx_handle ? I2S_DIR_TX : 0; 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; chan_search_mask |= ret_rx_handle ? I2S_DIR_RX : 0;
#endif
portENTER_CRITICAL(&g_i2s.spinlock); portENTER_CRITICAL(&g_i2s.spinlock);
g_i2s.lp_controller[chan_cfg->id] = ctlr; g_i2s.lp_controller[chan_cfg->id] = ctlr;

View File

@ -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_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_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); lp_i2s_ll_rx_set_bck_div_num(handle->ctlr->hal.dev, 1);
} }
// TODO: make this divisions configurable when support master mode. // TODO: make this divisions configurable when support master mode.

View File

@ -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_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_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); lp_i2s_ll_rx_set_bck_div_num(handle->ctlr->hal.dev, 1);
} }
// TODO: make this divisions configurable when support master mode. // TODO: make this divisions configurable when support master mode.

View File

@ -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) 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) { 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_yn1 = 0;
LPPERI.lp_i2s_rxclk_div_xyz.lp_i2s_rx_clkm_div_x = floor(a / b) - 1; LPPERI.lp_i2s_rxclk_div_xyz.lp_i2s_rx_clkm_div_x = floor(a / b) - 1;

View File

@ -277,7 +277,7 @@ where:
* - Dout * - Dout
- ADC raw digital reading result. - ADC raw digital reading result.
* - Vmax * - Vmax
- Maximum measurable input analog voltage, this is related to the ADC attenuation, please refer to the On-Chip Sensor and Analog Signal Processing chapter in `TRM <{IDF_TARGET_TRM_EN_URL}>`__. - Maximum measurable input analog voltage, this is related to the ADC attenuation, please refer to the On-Chip Sensor and Analog Signal Processing chapter in `Datasheet <{IDF_TARGET_DATASHEET_EN_URL}>`__.
* - Dmax * - Dmax
- Maximum of the output ADC raw digital reading result, which is 2^bitwidth, where the bitwidth is the :cpp:member:`adc_digi_pattern_config_t::bit_width` configured before. - Maximum of the output ADC raw digital reading result, which is 2^bitwidth, where the bitwidth is the :cpp:member:`adc_digi_pattern_config_t::bit_width` configured before.

View File

@ -86,7 +86,7 @@ Unit Configuration
After an ADC instance is created, set up the :cpp:type:`adc_oneshot_chan_cfg_t` to configure ADC IOs to measure analog signal: After an ADC instance is created, set up the :cpp:type:`adc_oneshot_chan_cfg_t` to configure ADC IOs to measure analog signal:
- :cpp:member:`adc_oneshot_chan_cfg_t::atten`, ADC attenuation. Refer to `TRM <{IDF_TARGET_TRM_EN_URL}>`__ > ``On-Chip Sensor and Analog Signal Processing``. - :cpp:member:`adc_oneshot_chan_cfg_t::atten`, ADC attenuation. Refer to `Datasheet <{IDF_TARGET_DATASHEET_EN_URL}>`__ > ``ADC Characteristics``.
- :cpp:member:`adc_oneshot_chan_cfg_t::bitwidth`, the bitwidth of the raw conversion result. - :cpp:member:`adc_oneshot_chan_cfg_t::bitwidth`, the bitwidth of the raw conversion result.
.. note:: .. note::

View File

@ -165,7 +165,7 @@ ADC 连续转换模式驱动基于 {IDF_TARGET_NAME} SAR ADC 模块实现,不
按照以下步骤设置 :cpp:type:`adc_digi_pattern_config_t` 按照以下步骤设置 :cpp:type:`adc_digi_pattern_config_t`
- :cpp:member:`adc_digi_pattern_config_t::atten`ADC 衰减。请参阅 `技术参考手册 <{IDF_TARGET_TRM_CN_URL}#sensor>`__ 中的片上传感器与模拟信号处理章节。 - :cpp:member:`adc_digi_pattern_config_t::atten`ADC 衰减。请参阅 `技术规格书 <{IDF_TARGET_DATASHEET_CN_URL}#sensor>`__ 中的 ``ADC 特性`` 章节。
- :cpp:member:`adc_digi_pattern_config_t::channel`IO 对应的 ADC 通道号,请参阅下文注意事项。 - :cpp:member:`adc_digi_pattern_config_t::channel`IO 对应的 ADC 通道号,请参阅下文注意事项。
- :cpp:member:`adc_digi_pattern_config_t::unit`IO 所属的 ADC 单元。 - :cpp:member:`adc_digi_pattern_config_t::unit`IO 所属的 ADC 单元。
- :cpp:member:`adc_digi_pattern_config_t::bit_width`:原始转换结果的位宽。 - :cpp:member:`adc_digi_pattern_config_t::bit_width`:原始转换结果的位宽。

View File

@ -86,7 +86,7 @@ ADC 单次转换模式驱动基于 {IDF_TARGET_NAME} SAR ADC 模块实现,不
创建 ADC 单元实例后,请设置 :cpp:type:`adc_oneshot_chan_cfg_t` 配置 ADC IO 以测量模拟信号,具体如下: 创建 ADC 单元实例后,请设置 :cpp:type:`adc_oneshot_chan_cfg_t` 配置 ADC IO 以测量模拟信号,具体如下:
- :cpp:member:`adc_oneshot_chan_cfg_t::atten`ADC 衰减。请参阅 `技术参考手册 <{IDF_TARGET_TRM_CN_URL}>`__ > ``片上传感器与模拟信号处理`` - :cpp:member:`adc_oneshot_chan_cfg_t::atten`ADC 衰减。请参阅 `技术规格书 <{IDF_TARGET_DATASHEET_CN_URL}>`__ > ``ADC 特性``
- :cpp:member:`adc_oneshot_chan_cfg_t::bitwidth`,原始转换结果的位宽。 - :cpp:member:`adc_oneshot_chan_cfg_t::bitwidth`,原始转换结果的位宽。
.. note:: .. note::