From 3bad4e3ca41fa11ab27dfcf05698803efd7346ad Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 17 Jan 2022 10:06:38 +0800 Subject: [PATCH] Task WDT: Fix overflow issue during timeout calculation Closes https://github.com/espressif/esp-idf/issues/8239 --- components/esp_common/src/task_wdt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/esp_common/src/task_wdt.c b/components/esp_common/src/task_wdt.c index 5c73e20774..6cbf8ab72f 100644 --- a/components/esp_common/src/task_wdt.c +++ b/components/esp_common/src/task_wdt.c @@ -224,9 +224,9 @@ esp_err_t esp_task_wdt_init(uint32_t timeout, bool panic) wdt_hal_init(&twdt_context, TWDT_INSTANCE, TWDT_PRESCALER, true); wdt_hal_write_protect_disable(&twdt_context); //Configure 1st stage timeout and behavior - wdt_hal_config_stage(&twdt_context, WDT_STAGE0, twdt_config->timeout * 1000000 / TWDT_TICKS_PER_US, WDT_STAGE_ACTION_INT); + wdt_hal_config_stage(&twdt_context, WDT_STAGE0, twdt_config->timeout * (1000000 / TWDT_TICKS_PER_US), WDT_STAGE_ACTION_INT); //Configure 2nd stage timeout and behavior - wdt_hal_config_stage(&twdt_context, WDT_STAGE1, 2*twdt_config->timeout * 1000000 / TWDT_TICKS_PER_US, WDT_STAGE_ACTION_RESET_SYSTEM); + wdt_hal_config_stage(&twdt_context, WDT_STAGE1, twdt_config->timeout * (2 * 1000000 / TWDT_TICKS_PER_US), WDT_STAGE_ACTION_RESET_SYSTEM); //Enable the WDT wdt_hal_enable(&twdt_context); wdt_hal_write_protect_enable(&twdt_context); @@ -238,8 +238,8 @@ esp_err_t esp_task_wdt_init(uint32_t timeout, bool panic) //Reconfigure hardware timer wdt_hal_write_protect_disable(&twdt_context); wdt_hal_disable(&twdt_context); - wdt_hal_config_stage(&twdt_context, WDT_STAGE0, twdt_config->timeout*1000*1000/TWDT_TICKS_PER_US, WDT_STAGE_ACTION_INT); - wdt_hal_config_stage(&twdt_context, WDT_STAGE1, 2*twdt_config->timeout*1000*1000/TWDT_TICKS_PER_US, WDT_STAGE_ACTION_RESET_SYSTEM); + wdt_hal_config_stage(&twdt_context, WDT_STAGE0, twdt_config->timeout * (1000 * 1000 / TWDT_TICKS_PER_US), WDT_STAGE_ACTION_INT); + wdt_hal_config_stage(&twdt_context, WDT_STAGE1, twdt_config->timeout * (2 * 1000 * 1000 / TWDT_TICKS_PER_US), WDT_STAGE_ACTION_RESET_SYSTEM); wdt_hal_enable(&twdt_context); wdt_hal_write_protect_enable(&twdt_context); }