Working WatchdogTimer
This commit is contained in:
@@ -5,6 +5,7 @@ import de.darkress.pic16f84sim.decoder.CommandDecoder;
|
|||||||
import de.darkress.pic16f84sim.microcontroller.Cycles;
|
import de.darkress.pic16f84sim.microcontroller.Cycles;
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Watchdog;
|
||||||
import de.darkress.pic16f84sim.parser.Parser;
|
import de.darkress.pic16f84sim.parser.Parser;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -13,18 +14,30 @@ class Main
|
|||||||
{
|
{
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
|
||||||
Command[] program = Parser.parser("de/darkress/pic16f84sim/TestPrograms/TPicSim7.LST");
|
Command[] program = Parser.parser("de/darkress/pic16f84sim/TestPrograms/TPicSim11.LST");
|
||||||
|
|
||||||
Memory.initMemory();
|
Memory.initMemory();
|
||||||
|
|
||||||
while(ProgramCounter.getPc() < 1024)
|
while(ProgramCounter.getPc() < 1024)
|
||||||
{
|
{
|
||||||
|
if((Memory.getRegister(0x03) & 0x10) == 0x00) { // Checking WDT in Status Register
|
||||||
|
System.out.println("Resetting device");
|
||||||
|
Watchdog.resetProgram();
|
||||||
|
}
|
||||||
System.out.println("Command: " + program[ProgramCounter.getPc()].toString());
|
System.out.println("Command: " + program[ProgramCounter.getPc()].toString());
|
||||||
program[ProgramCounter.getPc()].execute();
|
program[ProgramCounter.getPc()].execute();
|
||||||
|
|
||||||
System.out.println(Integer.toHexString(Memory.workingRegister) + " " + Cycles.getCycles());
|
System.out.println(Integer.toHexString(Memory.workingRegister) + " " + Cycles.getCycles());
|
||||||
System.out.println(Integer.toHexString(Memory.getOption()) + " " + Integer.toHexString(Memory.getTimer()));
|
System.out.println(Integer.toHexString(Memory.getOption()) + " " + Integer.toHexString(Memory.getTimer()));
|
||||||
|
|
||||||
|
System.out.println(Integer.toHexString(Memory.getRegister(0x20)) + " " + Integer.toHexString(Memory.getRegister(0x21)));
|
||||||
|
System.out.println(Integer.toHexString(Memory.getRegister(0x22)) + " " + Integer.toHexString(Memory.getRegister(0x23)));
|
||||||
|
|
||||||
System.out.println(Integer.toHexString(Memory.getPCLATH()) + " " + Integer.toHexString(Memory.getPCL()) + "\n");
|
System.out.println(Integer.toHexString(Memory.getPCLATH()) + " " + Integer.toHexString(Memory.getPCL()) + "\n");
|
||||||
|
|
||||||
|
if(ProgramCounter.getPc() == 0x10) {
|
||||||
|
System.out.println(Memory.getRegister(0x20));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,10 +56,10 @@ public class Timer
|
|||||||
cyclesToTimerIncrease--;
|
cyclesToTimerIncrease--;
|
||||||
if(cyclesToTimerIncrease == 0) {
|
if(cyclesToTimerIncrease == 0) {
|
||||||
resetTimeToTimerIncrease();
|
resetTimeToTimerIncrease();
|
||||||
Watchdog.increaseWatchdogTimer();
|
Watchdog.decreaseWatchdogTimer();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Watchdog.increaseWatchdogTimer();
|
Watchdog.decreaseWatchdogTimer();
|
||||||
}
|
}
|
||||||
if(timerEnabled()) {
|
if(timerEnabled()) {
|
||||||
if(!getPrescalerAssignment()) { // Assigned to timer0
|
if(!getPrescalerAssignment()) { // Assigned to timer0
|
||||||
|
|||||||
@@ -8,22 +8,25 @@ public class Watchdog
|
|||||||
return watchdogTimer;
|
return watchdogTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void increaseWatchdogTimer()
|
public static void decreaseWatchdogTimer()
|
||||||
{
|
{
|
||||||
watchdogTimer++;
|
watchdogTimer--;
|
||||||
|
checkWatchdog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkWatchdog()
|
private static void checkWatchdog()
|
||||||
{
|
{
|
||||||
if(watchdogTimer > 18000)
|
if(watchdogTimer == 0)
|
||||||
{
|
{
|
||||||
|
System.out.println("Watchdog Time-Out");
|
||||||
|
Memory.setRegister(0x03, Memory.getRegister(0x03) & 0xEF); //Clear !TO in StatusReg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void resetProgram()
|
public static void resetProgram()
|
||||||
{
|
{
|
||||||
|
Memory.setRegister(0x03, Memory.getRegister(0x03) | 0x10);
|
||||||
|
watchdogTimer = 18000;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user