From 8d0a8a576312d96cfccc85678fb32e8b67a6eeaa Mon Sep 17 00:00:00 2001 From: devsaurus Date: Wed, 4 Apr 2018 09:25:47 +0200 Subject: [PATCH] refactor task wdt handling to platform layer --- components/platform/flash_api.c | 13 +++------- components/platform/include/platform_wdt.h | 7 +++++ components/platform/wdt.c | 30 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 components/platform/include/platform_wdt.h create mode 100644 components/platform/wdt.c diff --git a/components/platform/flash_api.c b/components/platform/flash_api.c index bbd828ee..9d3ec536 100644 --- a/components/platform/flash_api.c +++ b/components/platform/flash_api.c @@ -9,9 +9,10 @@ #include #include "rom/spi_flash.h" +#include "platform_wdt.h" + #include "esp_image_format.h" #include "esp_flash_data_types.h" -#include "esp_task_wdt.h" #define FLASH_HDR_ADDR 0x1000 @@ -175,14 +176,6 @@ uint32_t flash_rom_get_speed(void) esp_err_t flash_erase(size_t sector) { -#ifdef CONFIG_TASK_WDT - // re-init the task WDT, simulates feeding for the IDLE task -# ifdef CONFIG_TASK_WDT_PANIC - esp_task_wdt_init(CONFIG_TASK_WDT_TIMEOUT_S, true); -# else - esp_task_wdt_init(CONFIG_TASK_WDT_TIMEOUT_S, false); -# endif -#endif - + platform_wdt_feed(); return spi_flash_erase_sector(sector); } diff --git a/components/platform/include/platform_wdt.h b/components/platform/include/platform_wdt.h new file mode 100644 index 00000000..1fdd4fc6 --- /dev/null +++ b/components/platform/include/platform_wdt.h @@ -0,0 +1,7 @@ + +#ifndef __PLATFORM_WDT_H__ +#define __PLATFORM_WDT_H__ + +int platform_wdt_feed( void ); + +#endif diff --git a/components/platform/wdt.c b/components/platform/wdt.c new file mode 100644 index 00000000..c815268e --- /dev/null +++ b/components/platform/wdt.c @@ -0,0 +1,30 @@ +/****************************************************************************** + * WDT api for NodeMCU + * NodeMCU Team + * 2018-04-04 +*******************************************************************************/ + +#include "platform.h" +#include "esp_task_wdt.h" + +#ifdef CONFIG_TASK_WDT +static uint32_t task_wdt_timeout = CONFIG_TASK_WDT_TIMEOUT_S; + +static bool task_wdt_panic = +#ifdef CONFIG_TASK_WDT_PANIC + true; +#else +false; +#endif + +#endif + + +int platform_wdt_feed( void ) +{ +#ifdef CONFIG_TASK_WDT + return esp_task_wdt_init(task_wdt_timeout, task_wdt_panic) == ESP_OK ? PLATFORM_OK : PLATFORM_ERR; +#else + return PLATFORM_OK; +#endif +}