refactor task wdt handling to platform layer

This commit is contained in:
devsaurus 2018-04-04 09:25:47 +02:00
parent a63da92e82
commit 8d0a8a5763
3 changed files with 40 additions and 10 deletions

View File

@ -9,9 +9,10 @@
#include <stdlib.h> #include <stdlib.h>
#include "rom/spi_flash.h" #include "rom/spi_flash.h"
#include "platform_wdt.h"
#include "esp_image_format.h" #include "esp_image_format.h"
#include "esp_flash_data_types.h" #include "esp_flash_data_types.h"
#include "esp_task_wdt.h"
#define FLASH_HDR_ADDR 0x1000 #define FLASH_HDR_ADDR 0x1000
@ -175,14 +176,6 @@ uint32_t flash_rom_get_speed(void)
esp_err_t flash_erase(size_t sector) esp_err_t flash_erase(size_t sector)
{ {
#ifdef CONFIG_TASK_WDT platform_wdt_feed();
// 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
return spi_flash_erase_sector(sector); return spi_flash_erase_sector(sector);
} }

View File

@ -0,0 +1,7 @@
#ifndef __PLATFORM_WDT_H__
#define __PLATFORM_WDT_H__
int platform_wdt_feed( void );
#endif

30
components/platform/wdt.c Normal file
View File

@ -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
}