Watchdog-Checkbox

This commit is contained in:
2024-05-14 11:45:35 +02:00
parent b842d6eb05
commit 8f35f4f914
6 changed files with 78 additions and 210 deletions

View File

@ -3,18 +3,20 @@ package fabrik.simulator.pic16f84;
public class WatchdogTimer {
private static long watchdogTime;
private static long lastReset = 0;
private static boolean enabled = false;
private static long getTimeFromRegister() {
return (PreScaler.isPrescalerOnTimer()) ? 18L : PreScaler.getFactor() * 18L;
}
public static void testAndTrigger () {
public static void testAndTrigger() {
watchdogTime = getTimeFromRegister() * 1000;
if (!PreScaler.isPrescalerOnTimer() && (Commands.getTotalExecutionTime() >= (watchdogTime + lastReset))){
if (enabled && (Commands.getTotalExecutionTime() >= (watchdogTime + lastReset - 1))){
DataRegister.resetPC();
System.err.println("Watchdog Timer triggered");
DataRegister.clearBit(3, 4);
lastReset = Commands.getTotalExecutionTime();
Controller_Frontend.stopRunFromBackend();
}
}
@ -24,4 +26,12 @@ public class WatchdogTimer {
DataRegister.setBit(3, 3);
DataRegister.setBit(3, 4);
}
public static void enable() {
enabled = true;
}
public static void disable() {
enabled = false;
}
}