mirror of https://github.com/rusefi/rusefi.git
Initial support for watchdog
This commit is contained in:
parent
731f24c57b
commit
585ca0c829
|
@ -224,6 +224,7 @@ static void doPeriodicSlowCallback() {
|
|||
}
|
||||
#endif // EFI_TCU
|
||||
|
||||
tryResetWatchdog();
|
||||
}
|
||||
|
||||
void initPeriodicEvents() {
|
||||
|
|
|
@ -147,6 +147,10 @@ void writeToFlashNow() {
|
|||
persistentState.version = FLASH_DATA_VERSION;
|
||||
persistentState.crc = flashStateCrc(persistentState);
|
||||
|
||||
// there's no wdgStop() for STM32, so we cannot disable it.
|
||||
// we just set a long timeout of 5 secs to wait until flash is done.
|
||||
startWatchdog(5000);
|
||||
|
||||
#if EFI_STORAGE_MFS == TRUE
|
||||
mfs_error_t err;
|
||||
/* In case of MFS:
|
||||
|
@ -173,6 +177,9 @@ void writeToFlashNow() {
|
|||
isSuccess = (result1 == FLASH_RETURN_SUCCESS) && (result2 == FLASH_RETURN_SUCCESS);
|
||||
#endif
|
||||
|
||||
// restart the watchdog with the default timeout
|
||||
startWatchdog();
|
||||
|
||||
if (isSuccess) {
|
||||
efiPrintf("FLASH_SUCCESS");
|
||||
} else {
|
||||
|
|
|
@ -131,6 +131,9 @@ BOR_Result_t BOR_Set(BOR_Level_t BORValue) {
|
|||
return BOR_Result_Ok;
|
||||
}
|
||||
|
||||
void resetWatchdog() {
|
||||
}
|
||||
|
||||
void baseMCUInit(void) {
|
||||
// looks like this holds a random value on start? Let's set a nice clean zero
|
||||
DWT->CYCCNT = 0;
|
||||
|
|
|
@ -21,6 +21,9 @@ extern "C" {
|
|||
void HardFaultVector(void);
|
||||
}
|
||||
|
||||
void resetWatchdog() {
|
||||
}
|
||||
|
||||
void baseMCUInit(void) {
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
#include "mpu_util.h"
|
||||
#include "flash_int.h"
|
||||
|
||||
void resetWatchdog() {
|
||||
}
|
||||
|
||||
void baseMCUInit(void) {
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@ void jump_to_openblt();
|
|||
void causeHardFault();
|
||||
bool allowFlashWhileRunning();
|
||||
|
||||
// 300 ms is our default timeout (we use 'int' for compatibility with addConsoleActionI())
|
||||
void startWatchdog(int timeoutMs = 300);
|
||||
void setWatchdogResetPeriod(int resetMs);
|
||||
void tryResetWatchdog();
|
||||
|
||||
bool ramReadProbe(volatile const char *read_address);
|
||||
#if defined(STM32F4)
|
||||
bool isStm32F42x();
|
||||
|
|
|
@ -103,11 +103,44 @@ BOR_Result_t BOR_Set(BOR_Level_t BORValue) {
|
|||
return BOR_Result_Ok;
|
||||
}
|
||||
|
||||
void startWatchdog(int timeoutMs) {
|
||||
#if HAL_USE_WDG
|
||||
// RL is a 12-bit value so we use a "2 ms" prescaler to support long timeouts (> 4.095 sec)
|
||||
static WDGConfig wdgcfg;
|
||||
wdgcfg.pr = STM32_IWDG_PR_64; // t = (1/32768) * 64 = ~2 ms
|
||||
wdgcfg.rlr = STM32_IWDG_RL((uint32_t)((32.768f / 64.0f) * timeoutMs));
|
||||
wdgStart(&WDGD1, &wdgcfg);
|
||||
#endif // HAL_USE_WDG
|
||||
}
|
||||
|
||||
static efitimems_t watchdogResetPeriodMs = 0;
|
||||
|
||||
void setWatchdogResetPeriod(int resetMs) {
|
||||
watchdogResetPeriodMs = (efitimems_t)resetMs;
|
||||
}
|
||||
|
||||
void tryResetWatchdog() {
|
||||
#if HAL_USE_WDG
|
||||
static efitimems_t lastTimeWasResetMs = 0;
|
||||
// check if it's time to reset the watchdog
|
||||
efitimems_t curTimeResetMs = getTimeNowMs();
|
||||
if (curTimeResetMs >= lastTimeWasResetMs + watchdogResetPeriodMs) {
|
||||
// we assume tryResetWatchdog() is called from a timer callback
|
||||
wdgResetI(&WDGD1);
|
||||
lastTimeWasResetMs = curTimeResetMs;
|
||||
}
|
||||
#endif // HAL_USE_WDG
|
||||
}
|
||||
|
||||
void baseMCUInit(void) {
|
||||
// looks like this holds a random value on start? Let's set a nice clean zero
|
||||
DWT->CYCCNT = 0;
|
||||
|
||||
BOR_Set(BOR_Level_1); // one step above default value
|
||||
|
||||
// 200 ms is our default period for runMainLoop
|
||||
setWatchdogResetPeriod(200);
|
||||
startWatchdog();
|
||||
}
|
||||
|
||||
extern uint32_t __main_stack_base__;
|
||||
|
|
Loading…
Reference in New Issue