watchdog #33
@@ -5,7 +5,7 @@ public class Cycles {
|
|||||||
|
|
||||||
public static void incCycles()
|
public static void incCycles()
|
||||||
{
|
{
|
||||||
Timer.increaseTimer();
|
Timer.decreasePrescaler();
|
||||||
cycles++;
|
cycles++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ public class Memory
|
|||||||
setDataFromIndirectAddress(indirectAddress, data);
|
setDataFromIndirectAddress(indirectAddress, data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(address == 0x01) //Reset PrescalerCounter if change on Option or Timer Register
|
if(address == 0x01 && !Timer.getPrescalerAssignment()) //Reset PrescalerCounter if change on Option or Timer
|
||||||
|
// Register
|
||||||
{
|
{
|
||||||
Timer.resetTimeToTimerIncrease();
|
Timer.resetTimeToTimerIncrease();
|
||||||
Timer.setCyclesToTimerIncrease(Timer.getCyclesToTimerIncrease() - 1); //Decrease by one to account for
|
Timer.setCyclesToTimerIncrease(Timer.getCyclesToTimerIncrease() - 1); //Decrease by one to account for
|
||||||
@@ -86,7 +87,7 @@ public class Memory
|
|||||||
|
|
||||||
private static void setDataFromIndirectAddress(int address, int data)
|
private static void setDataFromIndirectAddress(int address, int data)
|
||||||
{
|
{
|
||||||
if(address == 0x81 || address == 0x01) //Reset PrescalerCounter if change on Option or Timer Register
|
if((address == 0x81 || address == 0x01) && !Timer.getPrescalerAssignment()) //Reset PrescalerCounter if change on Option or Timer Register
|
||||||
{
|
{
|
||||||
Timer.resetTimeToTimerIncrease();
|
Timer.resetTimeToTimerIncrease();
|
||||||
Timer.setCyclesToTimerIncrease(Timer.getCyclesToTimerIncrease() - 1); //Decrease by one to account for
|
Timer.setCyclesToTimerIncrease(Timer.getCyclesToTimerIncrease() - 1); //Decrease by one to account for
|
||||||
|
|||||||
@@ -36,4 +36,9 @@ public class ProgramCounter
|
|||||||
pc++;
|
pc++;
|
||||||
Memory.setPCL(pc & 0x00FF);
|
Memory.setPCL(pc & 0x00FF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void resetProgramCounter() {
|
||||||
|
pc = 0;
|
||||||
|
Memory.setPCL(0x0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class Timer
|
|||||||
cyclesToTimerIncrease = getPrescalerFactor();
|
cyclesToTimerIncrease = getPrescalerFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getPrescalerAsssignment() {
|
public static boolean getPrescalerAssignment() {
|
||||||
return (Memory.getOption() & 0x08) == 0x08;
|
return (Memory.getOption() & 0x08) == 0x08;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ public class Timer
|
|||||||
final int MULTIPLIER = 2;
|
final int MULTIPLIER = 2;
|
||||||
int prescalerPower = Memory.getOption() & 0x07;
|
int prescalerPower = Memory.getOption() & 0x07;
|
||||||
int prescaler = (int)Math.pow(2, prescalerPower);
|
int prescaler = (int)Math.pow(2, prescalerPower);
|
||||||
if(!getPrescalerAsssignment())
|
if(!getPrescalerAssignment())
|
||||||
{
|
{
|
||||||
return prescaler * MULTIPLIER;
|
return prescaler * MULTIPLIER;
|
||||||
}
|
}
|
||||||
@@ -50,17 +50,27 @@ public class Timer
|
|||||||
Memory.setTimer(timerRegister);
|
Memory.setTimer(timerRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void increaseTimer()
|
public static void decreasePrescaler()
|
||||||
{
|
{
|
||||||
if(!timerEnabled())
|
if(getPrescalerAssignment()) { // Assigned to WatchdogTimer
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cyclesToTimerIncrease--;
|
cyclesToTimerIncrease--;
|
||||||
if(cyclesToTimerIncrease == 0)
|
if(cyclesToTimerIncrease == 0) {
|
||||||
{
|
|
||||||
resetTimeToTimerIncrease();
|
resetTimeToTimerIncrease();
|
||||||
increaseTimerRegister();
|
Watchdog.increaseWatchdogTimer();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Watchdog.increaseWatchdogTimer();
|
||||||
|
}
|
||||||
|
if(timerEnabled()) {
|
||||||
|
if(!getPrescalerAssignment()) { // Assigned to timer0
|
||||||
|
cyclesToTimerIncrease--;
|
||||||
|
if(cyclesToTimerIncrease == 0) {
|
||||||
|
resetTimeToTimerIncrease();
|
||||||
|
Timer.increaseTimerRegister();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Timer.increaseTimerRegister();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
de/darkress/pic16f84sim/microcontroller/Watchdog.java
Normal file
29
de/darkress/pic16f84sim/microcontroller/Watchdog.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package de.darkress.pic16f84sim.microcontroller;
|
||||||
|
|
||||||
|
public class Watchdog
|
||||||
|
{
|
||||||
|
private static int watchdogTimer = 18000;
|
||||||
|
public static int getWatchdogTimer()
|
||||||
|
{
|
||||||
|
return watchdogTimer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void increaseWatchdogTimer()
|
||||||
|
{
|
||||||
|
watchdogTimer++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkWatchdog()
|
||||||
|
{
|
||||||
|
if(watchdogTimer > 18000)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetProgram()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user