2018-01-11 08:43:58 -05:00
|
|
|
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
2016-10-21 05:59:57 -04:00
|
|
|
//
|
|
|
|
// 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 "sdkconfig.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-10-25 06:08:55 -04:00
|
|
|
#include <stdbool.h>
|
2016-10-21 05:59:57 -04:00
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include <esp_types.h>
|
|
|
|
#include "esp_err.h"
|
2019-03-26 04:30:43 -04:00
|
|
|
#include "esp_intr_alloc.h"
|
2016-10-28 00:05:42 -04:00
|
|
|
#include "esp_attr.h"
|
2016-11-11 06:20:54 -05:00
|
|
|
#include "esp_freertos_hooks.h"
|
2019-05-13 06:02:45 -04:00
|
|
|
#include "soc/timer_periph.h"
|
2016-11-23 04:23:21 -05:00
|
|
|
#include "driver/timer.h"
|
2017-11-30 23:11:37 -05:00
|
|
|
#include "driver/periph_ctrl.h"
|
2016-10-21 05:59:57 -04:00
|
|
|
#include "esp_int_wdt.h"
|
2020-06-17 03:30:39 -04:00
|
|
|
#include "esp_efuse.h"
|
2016-10-21 05:59:57 -04:00
|
|
|
|
2019-04-30 06:51:55 -04:00
|
|
|
#if CONFIG_ESP_INT_WDT
|
2016-10-21 05:59:57 -04:00
|
|
|
|
|
|
|
|
2020-06-17 03:30:39 -04:00
|
|
|
#define WDT_INT_NUM ETS_T1_WDT_INUM
|
2016-10-21 05:59:57 -04:00
|
|
|
|
2020-06-17 03:30:39 -04:00
|
|
|
#if CONFIG_ESP32_ECO3_CACHE_LOCK_FIX
|
|
|
|
/*
|
|
|
|
* This parameter is indicates the response time of tg1 watchdog to
|
|
|
|
* identify the live lock,
|
|
|
|
*/
|
|
|
|
#define TG1_WDT_LIVELOCK_TIMEOUT_MS (20)
|
|
|
|
|
|
|
|
extern uint32_t _l4_intr_livelock_counter, _l4_intr_livelock_max;
|
|
|
|
#endif
|
2016-10-21 05:59:57 -04:00
|
|
|
|
2016-10-26 00:23:01 -04:00
|
|
|
//Take care: the tick hook can also be called before esp_int_wdt_init() is called.
|
2019-04-30 06:51:55 -04:00
|
|
|
#if CONFIG_ESP_INT_WDT_CHECK_CPU1
|
2016-10-25 06:08:55 -04:00
|
|
|
//Not static; the ISR assembly checks this.
|
|
|
|
bool int_wdt_app_cpu_ticked=false;
|
|
|
|
|
2016-11-11 06:20:54 -05:00
|
|
|
static void IRAM_ATTR tick_hook(void) {
|
2016-10-25 06:18:11 -04:00
|
|
|
if (xPortGetCoreID()!=0) {
|
|
|
|
int_wdt_app_cpu_ticked=true;
|
|
|
|
} else {
|
|
|
|
//Only feed wdt if app cpu also ticked.
|
|
|
|
if (int_wdt_app_cpu_ticked) {
|
2016-10-26 02:54:50 -04:00
|
|
|
TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
|
2020-06-17 03:30:39 -04:00
|
|
|
#if CONFIG_ESP32_ECO3_CACHE_LOCK_FIX
|
|
|
|
_l4_intr_livelock_counter = 0;
|
|
|
|
TIMERG1.wdt_config2=CONFIG_ESP_INT_WDT_TIMEOUT_MS*2/(_l4_intr_livelock_max+1); //Set timeout before interrupt
|
|
|
|
#else
|
2019-04-30 06:51:55 -04:00
|
|
|
TIMERG1.wdt_config2=CONFIG_ESP_INT_WDT_TIMEOUT_MS*2; //Set timeout before interrupt
|
2020-06-17 03:30:39 -04:00
|
|
|
#endif
|
2019-04-30 06:51:55 -04:00
|
|
|
TIMERG1.wdt_config3=CONFIG_ESP_INT_WDT_TIMEOUT_MS*4; //Set timeout before reset
|
2016-10-25 06:18:11 -04:00
|
|
|
TIMERG1.wdt_feed=1;
|
|
|
|
TIMERG1.wdt_wprotect=0;
|
|
|
|
int_wdt_app_cpu_ticked=false;
|
|
|
|
}
|
|
|
|
}
|
2016-10-25 06:08:55 -04:00
|
|
|
}
|
|
|
|
#else
|
2016-11-11 06:20:54 -05:00
|
|
|
static void IRAM_ATTR tick_hook(void) {
|
2016-10-25 06:18:11 -04:00
|
|
|
if (xPortGetCoreID()!=0) return;
|
2016-10-26 02:54:50 -04:00
|
|
|
TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
|
2019-04-30 06:51:55 -04:00
|
|
|
TIMERG1.wdt_config2=CONFIG_ESP_INT_WDT_TIMEOUT_MS*2; //Set timeout before interrupt
|
|
|
|
TIMERG1.wdt_config3=CONFIG_ESP_INT_WDT_TIMEOUT_MS*4; //Set timeout before reset
|
2016-10-25 06:18:11 -04:00
|
|
|
TIMERG1.wdt_feed=1;
|
|
|
|
TIMERG1.wdt_wprotect=0;
|
2016-10-21 05:59:57 -04:00
|
|
|
}
|
2016-10-25 06:08:55 -04:00
|
|
|
#endif
|
2016-10-21 05:59:57 -04:00
|
|
|
|
2016-11-11 06:20:54 -05:00
|
|
|
|
|
|
|
void esp_int_wdt_init() {
|
2017-11-30 23:11:37 -05:00
|
|
|
periph_module_enable(PERIPH_TIMG1_MODULE);
|
2016-11-11 06:20:54 -05:00
|
|
|
TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
|
|
|
|
TIMERG1.wdt_config0.sys_reset_length=7; //3.2uS
|
|
|
|
TIMERG1.wdt_config0.cpu_reset_length=7; //3.2uS
|
|
|
|
TIMERG1.wdt_config0.level_int_en=1;
|
|
|
|
TIMERG1.wdt_config0.stg0=TIMG_WDT_STG_SEL_INT; //1st stage timeout: interrupt
|
|
|
|
TIMERG1.wdt_config0.stg1=TIMG_WDT_STG_SEL_RESET_SYSTEM; //2nd stage timeout: reset system
|
|
|
|
TIMERG1.wdt_config1.clk_prescale=80*500; //Prescaler: wdt counts in ticks of 0.5mS
|
|
|
|
//The timer configs initially are set to 5 seconds, to make sure the CPU can start up. The tick hook sets
|
|
|
|
//it to their actual value.
|
|
|
|
TIMERG1.wdt_config2=10000;
|
|
|
|
TIMERG1.wdt_config3=10000;
|
|
|
|
TIMERG1.wdt_config0.en=1;
|
|
|
|
TIMERG1.wdt_feed=1;
|
|
|
|
TIMERG1.wdt_wprotect=0;
|
|
|
|
TIMERG1.int_clr_timers.wdt=1;
|
2016-11-23 04:23:21 -05:00
|
|
|
timer_group_intr_enable(TIMER_GROUP_1, TIMG_WDT_INT_ENA_M);
|
2018-01-11 08:43:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void esp_int_wdt_cpu_init()
|
|
|
|
{
|
2020-06-17 03:30:39 -04:00
|
|
|
assert((CONFIG_ESP_INT_WDT_TIMEOUT_MS >= (portTICK_PERIOD_MS<<1)) && "Interrupt watchdog timeout needs to meet double SysTick period!");
|
2018-01-11 08:43:58 -05:00
|
|
|
esp_register_freertos_tick_hook_for_cpu(tick_hook, xPortGetCoreID());
|
2016-11-11 06:20:54 -05:00
|
|
|
ESP_INTR_DISABLE(WDT_INT_NUM);
|
|
|
|
intr_matrix_set(xPortGetCoreID(), ETS_TG1_WDT_LEVEL_INTR_SOURCE, WDT_INT_NUM);
|
2020-06-17 03:30:39 -04:00
|
|
|
#if CONFIG_ESP32_ECO3_CACHE_LOCK_FIX
|
|
|
|
/*
|
|
|
|
* This is a workaround for issue 3.15 in "ESP32 ECO and Workarounds for Bugs" document.
|
|
|
|
*/
|
|
|
|
_l4_intr_livelock_max = 0;
|
|
|
|
if (soc_has_cache_lock_bug()) {
|
|
|
|
assert((portTICK_PERIOD_MS<<1) <= TG1_WDT_LIVELOCK_TIMEOUT_MS);
|
|
|
|
assert(CONFIG_ESP_INT_WDT_TIMEOUT_MS >= (TG1_WDT_LIVELOCK_TIMEOUT_MS*3));
|
|
|
|
_l4_intr_livelock_max = CONFIG_ESP_INT_WDT_TIMEOUT_MS/TG1_WDT_LIVELOCK_TIMEOUT_MS - 1;
|
|
|
|
}
|
|
|
|
#endif
|
2016-11-11 06:20:54 -05:00
|
|
|
//We do not register a handler for the interrupt because it is interrupt level 4 which
|
|
|
|
//is not servicable from C. Instead, xtensa_vectors.S has a call to the panic handler for
|
|
|
|
//this interrupt.
|
|
|
|
ESP_INTR_ENABLE(WDT_INT_NUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-23 04:23:21 -05:00
|
|
|
#endif
|