Interrupts

This commit is contained in:
2024-06-02 16:37:53 +02:00
parent c49a073cfd
commit 2294f81766
10 changed files with 83 additions and 54 deletions

View File

@ -47,7 +47,7 @@ public class Commands {
switch (instruction & 0x3800){
case 0b10000000000000:
System.out.println("CALL: " + j);
CALL (j);
CALL (j, true);
addExecutionTime(2);
return;
case 0b10100000000000:
@ -258,6 +258,7 @@ public class Commands {
}
public static void RETFIE() {
DataRegister.setBit(DataRegister.getINTCON(), 7); // GIE wieder setzen
DataRegister.setPC(ProgramStack.pop());
}
@ -270,12 +271,14 @@ public class Commands {
DataRegister.setPC(jump-1);
}
public static void CALL(int jump) {
public static void CALL(int jump, boolean normalUse) {
ProgramStack.push(DataRegister.getPC()+1);
DataRegister.setPC(jump-1);
if (normalUse)
DataRegister.setPC(jump-1);
else
DataRegister.setPC(jump);
addExecutionTime(1);
}
public static void MOVWF(int file) {

View File

@ -96,26 +96,26 @@ public class Controller_Frontend {
return isSleeping;
}
public static void stopRunFromBackend(String message){
public static void stopRunFromBackend(String message, boolean resetPC){
isAutoRunActive = false;
if (isSleeping)
isSleeping = false;
else
else if (resetPC)
DataRegister.resetPC();
Stage stoppedStage = new Stage();
stoppedStage.setTitle("Programm unterbrochen!");
VBox vbox = new VBox();
vbox.setAlignment(javafx.geometry.Pos.CENTER);
Label grundlabel = new Label("Grund: " + message);
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
Label ueberlabel = new Label("Programm unterbrochen!");
vbox.getChildren().add(ueberlabel);
vbox.getChildren().add(grundlabel);
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
Scene scene = new Scene(vbox, 300, 90);
stoppedStage.setAlwaysOnTop(true);
stoppedStage.setScene(scene);
stoppedStage.show();
// Stage stoppedStage = new Stage();
// stoppedStage.setTitle("Programm unterbrochen!");
// VBox vbox = new VBox();
// vbox.setAlignment(javafx.geometry.Pos.CENTER);
// Label grundlabel = new Label("Grund: " + message);
// grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
// Label ueberlabel = new Label("Programm unterbrochen!");
// vbox.getChildren().add(ueberlabel);
// vbox.getChildren().add(grundlabel);
// VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
// Scene scene = new Scene(vbox, 300, 90);
// stoppedStage.setAlwaysOnTop(true);
// stoppedStage.setScene(scene);
// stoppedStage.show();
}
public static void sleep() {

View File

@ -19,7 +19,6 @@ public class CreateWindow extends Application {
public static GridPane grid = new GridPane();
@Override
public void start(Stage primaryStage) throws IOException {
DataRegister.initDataRegister();
table = Table.refresh();

View File

@ -83,7 +83,7 @@ public class EEPROM {
public static void registerTime(boolean reset) {
if (reset)
startTime = getTotalExecutionTime();
else if ((getTotalExecutionTime() >= (startTime + 1000)) && writeControl) {
else if ((getTotalExecutionTime() >= (startTime + 1)) && writeControl) {
eecon2stages = new boolean[]{false, false};
DataRegister.setDirectBit(EECON1, EEIF, 1);
DataRegister.setDirectBit(EECON1, WR, 0);

View File

@ -156,10 +156,14 @@ public class IOPorts {
int bit = params[1];
int value = params [2];
value = (value == 1) ? 0 : 1;
int oldValue = DataRegister.getDirectBit(port, bit);
DataRegister.setDirectBit(port, bit, value);
refreshPorts();
refreshTable(parent);
if (port == PORTB && bit >= 4)
Interrupts.triggerRBInterrupt(oldValue, value);
else if (port == PORTB && bit == 0)
Interrupts.triggerRB0Interrupt(oldValue, value);
}
public static void setLEDs (boolean[] leds) {

View File

@ -0,0 +1,52 @@
package fabrik.simulator.pic16f84;
public class Interrupts {
private static final int INTCON = 0xB;
private static final int T0IF = 0x2;
private static final int ISR = 0x4;
private static final int GIE = 0x7;
private static final int T0IE = 0x5;
private static final int RBIE = 0x3;
private static final int RBIF = 0x0;
private static final int INTEDG = 0x6;
private static final int OPTION = 0x81;
private static final int INTE = 0x4;
private static final int INTF = 0x1;
public static void triggerTMR0() {
triggerInterrupt(T0IF, T0IE);
}
private static void triggerInterrupt(int flag, int enableFlag) {
DataRegister.setBit(INTCON, flag);
enableFlag = DataRegister.getDirectBit(INTCON, enableFlag);
int globalFlag = DataRegister.getDirectBit(INTCON, GIE);
if (globalFlag == 1 && enableFlag == 1) {
DataRegister.clearBit(INTCON, GIE);
Commands.CALL(ISR, false);
Controller_Frontend.stopRunFromBackend("Interrupt", false);
}
}
public static void triggerRBInterrupt(int oldValue, int newValue) {
if (newValue != oldValue){
triggerInterrupt(RBIF, RBIE);
}
}
public static void triggerRB0Interrupt(int oldValue, int newValue){
if (newValue != oldValue){
int intedg = DataRegister.getDirectBit(OPTION, INTEDG);
if (intedg == 1) {
if (oldValue == 0 && newValue == 1)
triggerInterrupt(INTF, INTE);
} else {
if (oldValue == 1 && newValue == 0)
triggerInterrupt(INTF, INTE);
}
}
}
}

View File

@ -32,6 +32,5 @@ public class PreScaler {
scaler = getFactor();
Timer.increment();
}
System.err.println("VT: " + scaler);
}
}

View File

@ -1,26 +0,0 @@
package fabrik.simulator.pic16f84;
public class RBInterruptHandler {
public static void handleRB4Interrupt() {
System.out.println("RB4 Interrupt durchgeführt");
}
public static void handleRB5Interrupt() {
// Aktion durchegfürht
System.out.println("RB5 Interrupt durchgeführt");
}
public static void handleRB6Interrupt() {
// Aktion durchegfürht
System.out.println("RB6 Interrupt durchgeführt");
}
public static void handleRB7Interrupt() {
// Aktion durchegfürht
System.out.println("RB7 Interrupt durchgeführt");
}
}

View File

@ -2,10 +2,8 @@ package fabrik.simulator.pic16f84;
public class Timer {
private static final int TIMERREG = 0x1;
private static final int T0IF = 0x2;
private static final int T0SE = 0x4;
private static final int T0CS = 0x5;
private static final int INTCON = 0x0B;
private static final int OPTION = 0x81;
private static int oldpin = 0;
@ -55,8 +53,8 @@ public class Timer {
int timer = DataRegister.getDirectRegister(TIMERREG);
timer++;
if (timer > 0xFF){
Interrupts.triggerTMR0 ();
DataRegister.setDirectRegister(TIMERREG, 0);
DataRegister.setBit(INTCON, T0IF);
} else {
DataRegister.setDirectRegister(1, timer);
}

View File

@ -15,7 +15,7 @@ public class WatchdogTimer {
if (Commands.getTotalExecutionTime() >= (watchdogTime + lastReset - 1)) {
DataRegister.clearBit(3, 4);
lastReset = Commands.getTotalExecutionTime();
Controller_Frontend.stopRunFromBackend("Watchdog Timer");
Controller_Frontend.stopRunFromBackend("Watchdog Timer", true);
}
}
}