mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-21 17:16:29 +08:00
feat(esp8266): Refactor task watch dog
1. Remove old watch dog function 2. Put WIFI NVS index table from RAM to flash
This commit is contained in:
@ -341,6 +341,13 @@ static int32_t rand_wrapper(void)
|
||||
return (int32_t)esp_random();
|
||||
}
|
||||
|
||||
void *osi_task_top_sp(void)
|
||||
{
|
||||
extern uint32_t **pxCurrentTCB;
|
||||
|
||||
return pxCurrentTCB[0];
|
||||
}
|
||||
|
||||
const wifi_osi_funcs_t s_wifi_osi_funcs = {
|
||||
.version = ESP_WIFI_OS_ADAPTER_VERSION,
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "esp_phy_init.h"
|
||||
#include "esp_wifi_osi.h"
|
||||
#include "esp_heap_caps_init.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include "internal/esp_wifi_internal.h"
|
||||
|
||||
#define FLASH_MAP_ADDR 0x40200000
|
||||
@ -58,11 +59,14 @@ static void user_init_entry(void *param)
|
||||
assert(mac_init() == 0);
|
||||
assert(base_gpio_init() == 0);
|
||||
esp_phy_load_cal_and_init(0);
|
||||
assert(watchdog_init() == 0);
|
||||
assert(wifi_timer_init() == 0);
|
||||
|
||||
esp_wifi_set_rx_pbuf_mem_type(WIFI_RX_PBUF_DRAM);
|
||||
|
||||
#ifdef CONFIG_TASK_WDT
|
||||
esp_task_wdt_init();
|
||||
#endif
|
||||
|
||||
app_main();
|
||||
|
||||
wifi_task_delete(NULL);
|
||||
|
102
components/esp8266/source/task_wdt.c
Normal file
102
components/esp8266/source/task_wdt.c
Normal file
@ -0,0 +1,102 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_libc.h"
|
||||
#include "esp_wifi_osi.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include "portmacro.h"
|
||||
#include "esp8266/eagle_soc.h"
|
||||
|
||||
#define WDT_REG_READ(_reg) REG_READ(PERIPHS_WDT_BASEADDR + _reg)
|
||||
#define WDT_REG_WRITE(_reg, _val) REG_WRITE(PERIPHS_WDT_BASEADDR + _reg, _val)
|
||||
#define CLEAR_WDT_REG_MASK(_reg, _mask) WDT_REG_WRITE(_reg, WDT_REG_READ(_reg) & (~_mask))
|
||||
#define WDT_FEED() WDT_REG_WRITE(WDT_RST_ADDRESS, WDT_FEED_VALUE)
|
||||
|
||||
static const char *TAG = "wdt";
|
||||
|
||||
#ifdef CONFIG_TASK_WDT_PANIC
|
||||
/**
|
||||
* @brief Task watch dog interrupt function and it should do panic
|
||||
*/
|
||||
static void esp_task_wdt_isr(void *param)
|
||||
{
|
||||
extern void panicHandler(void *frame, int wdt);
|
||||
|
||||
panicHandler(osi_task_top_sp(), 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Just for pass compiling and mark wdt calling line
|
||||
*/
|
||||
esp_err_t esp_task_wdt_init(void)
|
||||
{
|
||||
CLEAR_WDT_REG_MASK(WDT_CTL_ADDRESS, BIT0);
|
||||
|
||||
#ifdef CONFIG_TASK_WDT_PANIC
|
||||
const uint32_t panic_time_param = 11;
|
||||
|
||||
_xt_isr_attach(ETS_WDT_INUM, esp_task_wdt_isr, NULL);
|
||||
_xt_isr_unmask(1 << ETS_WDT_INUM);
|
||||
|
||||
WDT_EDGE_INT_ENABLE();
|
||||
|
||||
ESP_LOGD(TAG, "Enable task watch dog panic, panic time parameter is %u", panic_time_param);
|
||||
#else
|
||||
const uint32_t panic_time_param = 1;
|
||||
#endif
|
||||
|
||||
ESP_LOGD(TAG, "task watch dog trigger time parameter is %u", CONFIG_TASK_WDT_TIMEOUT_S);
|
||||
|
||||
WDT_REG_WRITE(WDT_OP_ADDRESS, CONFIG_TASK_WDT_TIMEOUT_S); // 2^n * 0.8ms, mask 0xf, n = 13 -> (2^13 = 8192) * 0.8 * 0.001 = 6.5536
|
||||
WDT_REG_WRITE(WDT_OP_ND_ADDRESS, panic_time_param); // 2^n * 0.8ms, mask 0xf, n = 11 -> (2^11 = 2048) * 0.8 * 0.001 = 1.6384
|
||||
|
||||
SET_PERI_REG_BITS(PERIPHS_WDT_BASEADDR + WDT_CTL_ADDRESS, WDT_CTL_RSTLEN_MASK, 7 << WDT_CTL_RSTLEN_LSB, 0);
|
||||
// interrupt then reset
|
||||
SET_PERI_REG_BITS(PERIPHS_WDT_BASEADDR + WDT_CTL_ADDRESS, WDT_CTL_RSPMOD_MASK, 0 << WDT_CTL_RSPMOD_LSB, 0);
|
||||
// start task watch dog1
|
||||
SET_PERI_REG_BITS(PERIPHS_WDT_BASEADDR + WDT_CTL_ADDRESS, WDT_CTL_EN_MASK, 1 << WDT_CTL_EN_LSB, 0);
|
||||
|
||||
WDT_FEED();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset(Feed) the Task Watchdog Timer (TWDT) on behalf of the currently
|
||||
* running task
|
||||
*/
|
||||
void esp_task_wdt_reset(void)
|
||||
{
|
||||
WDT_FEED();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Just for pass compiling and mark wdt calling line
|
||||
*/
|
||||
void pp_soft_wdt_stop(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Just for pass compiling and mark wdt calling line
|
||||
*/
|
||||
void pp_soft_wdt_restart(void)
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user