mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/propogate_isr_allocation_failure_v4.4' into 'release/v4.4'
Fix MCPWM multiplication overflow (v4.4) See merge request espressif/esp-idf!19891
This commit is contained in:
commit
d0ba3fd63e
@ -285,9 +285,11 @@ esp_err_t mcpwm_set_duty_in_us(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num,
|
|||||||
|
|
||||||
mcpwm_critical_enter(mcpwm_num);
|
mcpwm_critical_enter(mcpwm_num);
|
||||||
int real_group_prescale = mcpwm_ll_group_get_clock_prescale(hal->dev);
|
int real_group_prescale = mcpwm_ll_group_get_clock_prescale(hal->dev);
|
||||||
unsigned long int real_timer_clk_hz =
|
// to avid multiplication overflow, use uint64_t here
|
||||||
|
uint64_t real_timer_clk_hz =
|
||||||
SOC_MCPWM_BASE_CLK_HZ / real_group_prescale / mcpwm_ll_timer_get_clock_prescale(hal->dev, timer_num);
|
SOC_MCPWM_BASE_CLK_HZ / real_group_prescale / mcpwm_ll_timer_get_clock_prescale(hal->dev, timer_num);
|
||||||
mcpwm_ll_operator_set_compare_value(hal->dev, op, cmp, duty_in_us * real_timer_clk_hz / 1000000);
|
uint64_t compare_val = real_timer_clk_hz * duty_in_us / 1000000;
|
||||||
|
mcpwm_ll_operator_set_compare_value(hal->dev, op, cmp, (uint32_t)compare_val);
|
||||||
mcpwm_ll_operator_enable_update_compare_on_tez(hal->dev, op, cmp, true);
|
mcpwm_ll_operator_enable_update_compare_on_tez(hal->dev, op, cmp, true);
|
||||||
mcpwm_critical_exit(mcpwm_num);
|
mcpwm_critical_exit(mcpwm_num);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
@ -225,16 +225,18 @@ esp_err_t timer_isr_callback_add(timer_group_t group_num, timer_idx_t timer_num,
|
|||||||
ESP_RETURN_ON_FALSE(group_num < TIMER_GROUP_MAX, ESP_ERR_INVALID_ARG, TIMER_TAG, TIMER_GROUP_NUM_ERROR);
|
ESP_RETURN_ON_FALSE(group_num < TIMER_GROUP_MAX, ESP_ERR_INVALID_ARG, TIMER_TAG, TIMER_GROUP_NUM_ERROR);
|
||||||
ESP_RETURN_ON_FALSE(timer_num < TIMER_MAX, ESP_ERR_INVALID_ARG, TIMER_TAG, TIMER_NUM_ERROR);
|
ESP_RETURN_ON_FALSE(timer_num < TIMER_MAX, ESP_ERR_INVALID_ARG, TIMER_TAG, TIMER_NUM_ERROR);
|
||||||
ESP_RETURN_ON_FALSE(p_timer_obj[group_num][timer_num] != NULL, ESP_ERR_INVALID_ARG, TIMER_TAG, TIMER_NEVER_INIT_ERROR);
|
ESP_RETURN_ON_FALSE(p_timer_obj[group_num][timer_num] != NULL, ESP_ERR_INVALID_ARG, TIMER_TAG, TIMER_NEVER_INIT_ERROR);
|
||||||
|
esp_err_t ret = ESP_OK;
|
||||||
|
|
||||||
timer_disable_intr(group_num, timer_num);
|
timer_disable_intr(group_num, timer_num);
|
||||||
p_timer_obj[group_num][timer_num]->timer_isr_fun.fn = isr_handler;
|
p_timer_obj[group_num][timer_num]->timer_isr_fun.fn = isr_handler;
|
||||||
p_timer_obj[group_num][timer_num]->timer_isr_fun.args = args;
|
p_timer_obj[group_num][timer_num]->timer_isr_fun.args = args;
|
||||||
p_timer_obj[group_num][timer_num]->timer_isr_fun.isr_timer_group = group_num;
|
p_timer_obj[group_num][timer_num]->timer_isr_fun.isr_timer_group = group_num;
|
||||||
timer_isr_register(group_num, timer_num, timer_isr_default, (void *)p_timer_obj[group_num][timer_num],
|
ret = timer_isr_register(group_num, timer_num, timer_isr_default, (void *)p_timer_obj[group_num][timer_num],
|
||||||
intr_alloc_flags, &(p_timer_obj[group_num][timer_num]->timer_isr_fun.timer_isr_handle));
|
intr_alloc_flags, &(p_timer_obj[group_num][timer_num]->timer_isr_fun.timer_isr_handle));
|
||||||
|
ESP_RETURN_ON_ERROR(ret, TIMER_TAG, "register interrupt service failed");
|
||||||
timer_enable_intr(group_num, timer_num);
|
timer_enable_intr(group_num, timer_num);
|
||||||
|
|
||||||
return ESP_OK;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t timer_isr_callback_remove(timer_group_t group_num, timer_idx_t timer_num)
|
esp_err_t timer_isr_callback_remove(timer_group_t group_num, timer_idx_t timer_num)
|
||||||
|
Loading…
Reference in New Issue
Block a user