mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 21:24:32 +02:00
fix(lp_i2s): fixed coverity issue
This commit is contained in:
committed by
Armando (Dou Yiwen)
parent
e62133ad8e
commit
6219d5e7d4
@@ -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;
|
||||||
|
@@ -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.
|
||||||
|
@@ -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.
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user