Dependency inversions
This commit is contained in:
@ -1,49 +1,69 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class WatchdogTimer {
|
||||
private static long watchdogTime;
|
||||
private static long lastReset = 0;
|
||||
private static boolean enabled = false;
|
||||
private static long rawtimer = 0;
|
||||
private static long realtimer = 0;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
private static long getTimeFromRegister() {
|
||||
return (PreScaler.isPrescalerOnTimer()) ? 18L : PreScaler.getFactor() * 18L;
|
||||
public class WatchdogTimer implements WatchdogTimerInterface {
|
||||
private long watchdogTime;
|
||||
private double lastReset = 0;
|
||||
private boolean enabled = false;
|
||||
private long rawtimer = 0;
|
||||
private long realtimer = 0;
|
||||
|
||||
|
||||
private final DataRegisterInterface dataRegister;
|
||||
private final ProgramStackInterface programStack;
|
||||
private final FrontendControllerInterface frontendController;
|
||||
private final PreScaler preScaler;
|
||||
private final CommandInterface command;
|
||||
|
||||
|
||||
public WatchdogTimer( DataRegisterInterface dataRegister, ProgramStackInterface programStack, FrontendControllerInterface frontendController,PreScaler preScaler, CommandInterface command){
|
||||
|
||||
this.dataRegister = dataRegister;
|
||||
this.programStack = programStack;
|
||||
this.preScaler = preScaler;
|
||||
this.command = command;
|
||||
this.frontendController = frontendController;
|
||||
|
||||
}
|
||||
|
||||
private long getTimeFromRegister() {
|
||||
return (preScaler.isPrescalerOnTimer()) ? 18L : preScaler.getFactor() * 18L;
|
||||
}
|
||||
|
||||
public static void testAndTrigger() {
|
||||
public void testAndTrigger() {
|
||||
watchdogTime = getTimeFromRegister() * 1000;
|
||||
if (enabled) {
|
||||
if (realtimer >= (watchdogTime + lastReset - 1)) {
|
||||
DataRegister.clearBit(3, 4);
|
||||
lastReset = Commands.getTotalExecutionTime();
|
||||
Controller_Frontend.stopRunFromBackend("Watchdog Timer");
|
||||
dataRegister.clearBit(3, 4);
|
||||
lastReset = command.getTotalExecutionTime();
|
||||
frontendController.stopRunFromBackend("Watchdog Timer");
|
||||
}
|
||||
else {
|
||||
rawtimer++;
|
||||
realtimer = (long) (rawtimer * Controller_Frontend.getExecutionTimeMultiplier());
|
||||
realtimer = (long) (rawtimer * frontendController.getExecutionTimeMultiplier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset (){
|
||||
lastReset = Commands.getTotalExecutionTime();
|
||||
public void reset (){
|
||||
lastReset = command.getTotalExecutionTime();
|
||||
rawtimer = 0;
|
||||
realtimer = 0;
|
||||
PreScaler.reset();
|
||||
DataRegister.setBit(3, 3);
|
||||
DataRegister.setBit(3, 4);
|
||||
preScaler.reset();
|
||||
dataRegister.setBit(3, 3);
|
||||
dataRegister.setBit(3, 4);
|
||||
}
|
||||
|
||||
public static void enable() {
|
||||
public void enable() {
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
public static void disable() {
|
||||
public void disable() {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public static long get (){
|
||||
public long get (){
|
||||
return realtimer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user