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:
Dong Heng
2018-09-10 21:13:15 +08:00
parent 60a0297f32
commit 7e8650dd65
19 changed files with 242 additions and 110 deletions

View File

@ -71,6 +71,45 @@ config MAIN_TASK_STACK_SIZE
which calls app_main(). If app_main() returns then this task is deleted
and its stack memory is freed.
config TASK_WDT
bool "Initialize Task Watchdog Timer on startup"
default y
help
The Task Watchdog Timer can be used to make sure individual tasks are still
running. Enabling this option will cause the Task Watchdog Timer to be
initialized automatically at startup. The Task Watchdog timer can be
initialized after startup as well.
config TASK_WDT_PANIC
bool "Invoke panic handler on Task Watchdog timeout"
depends on TASK_WDT
default n
help
If this option is enabled, the Task Watchdog Timer will be configured to
trigger the panic handler when it times out. And it may cost some time.
choice TASK_WDT_TIMEOUT_S
prompt "Task Watchdog timeout period (seconds)"
depends on TASK_WDT
default TASK_WDT_TIMEOUT_13N
help
Timeout period configuration for the Task Watchdog Timer in seconds.
This is also configurable at run time.
config TASK_WDT_TIMEOUT_13N
bool "6.5536s"
config TASK_WDT_TIMEOUT_14N
bool "13.1072s"
config TASK_WDT_TIMEOUT_15N
bool "26.2144s"
endchoice
config TASK_WDT_TIMEOUT_S
int
default 13 if TASK_WDT_TIMEOUT_13N
default 14 if TASK_WDT_TIMEOUT_14N
default 15 if TASK_WDT_TIMEOUT_15N
endmenu
menu WIFI

View File

@ -117,10 +117,31 @@
//Interrupt remap control registers define{{
#define EDGE_INT_ENABLE_REG (PERIPHS_DPORT_BASEADDR + 0x04)
#define WDT_EDGE_INT_ENABLE() SET_PERI_REG_MASK(EDGE_INT_ENABLE_REG, BIT0)
#define TM1_EDGE_INT_ENABLE() SET_PERI_REG_MASK(EDGE_INT_ENABLE_REG, BIT1)
#define TM1_EDGE_INT_DISABLE() CLEAR_PERI_REG_MASK(EDGE_INT_ENABLE_REG, BIT1)
//}}
//Watch dog reg {{
#define PERIPHS_WDT_BASEADDR 0x60000900
#define WDT_CTL_ADDRESS 0
#define WDT_OP_ADDRESS 0x4
#define WDT_OP_ND_ADDRESS 0x8
#define WDT_RST_ADDRESS 0x14
#define WDT_CTL_RSTLEN_MASK 0x38
#define WDT_CTL_RSPMOD_MASK 0x6
#define WDT_CTL_EN_MASK 0x1
#define WDT_CTL_RSTLEN_LSB 0x3
#define WDT_CTL_RSPMOD_LSB 0x1
#define WDT_CTL_EN_LSB 0
#define WDT_FEED_VALUE 0x73
//}}
//RTC reg {{
#define REG_RTC_BASE PERIPHS_RTC_BASEADDR

View File

@ -0,0 +1,37 @@
// 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.
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
/**
* @brief Initialize the Task Watchdog Timer (TWDT)
*
* @return
* - ESP_OK: Initialization was successful
* - ESP_ERR_NO_MEM: Initialization failed due to lack of memory
*
* @note esp_task_wdt_init() must only be called after the scheduler
* started
*/
esp_err_t esp_task_wdt_init(void);
/**
* @brief Reset(Feed) the Task Watchdog Timer (TWDT) on behalf of the currently
* running task
*/
void esp_task_wdt_reset(void);

View File

@ -149,6 +149,8 @@ extern wifi_osi_funcs_t s_wifi_osi_funcs;
#define wifi_rand() \
s_wifi_osi_funcs.rand()
void *osi_task_top_sp(void);
#ifdef __cplusplus
}
#endif

View File

@ -1,9 +1,9 @@
gwen:
core: b9f2d3e
net80211: 48cd36b
pp: 82269d9
smartconfig:eca7811
wpa: b9f2d3e
espnow: 95a55d0
wps: 48cd36b
core: 103fbb8
net80211: 103fbb8
pp: 103fbb8
smartconfig:103fbb8
wpa: 103fbb8
espnow: 103fbb8
wps: 103fbb8
phy: 1055_8

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

View File

@ -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);

View 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)
{
}