Laufzeit und Watchdog und Timer

This commit is contained in:
2024-06-02 15:16:01 +02:00
parent 45f9878047
commit c49a073cfd
7 changed files with 209 additions and 15 deletions

View File

@ -5,6 +5,8 @@ public class Commands {
static long totalExecutionTime = 0;
public static int get_wRegister() {
return wRegister;
}
@ -23,6 +25,12 @@ public class Commands {
totalExecutionTime = 0;
}
public static void decode(int instruction){
final int jumpaddr = 0x7FF;
final int fileregaddr = 0x7F;
@ -265,8 +273,9 @@ public class Commands {
public static void CALL(int jump) {
ProgramStack.push(DataRegister.getPC()+1);
DataRegister.setPC(jump-1);
addExecutionTime(1);
}
public static void MOVWF(int file) {

View File

@ -11,8 +11,6 @@ import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.RadialGradient;
import javafx.scene.shape.Circle;
import javafx.stage.FileChooser;
@ -27,9 +25,12 @@ import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import javafx.util.Callback;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class Controller_Frontend {
@ -37,6 +38,14 @@ public class Controller_Frontend {
private int [][] read;
private int [] ind;
private double executionTimeMultiplier = 1;
@FXML
private ComboBox<String> executionTimeComboBox;
@FXML
@ -78,6 +87,8 @@ public class Controller_Frontend {
@FXML
private CheckBox wdtCheck;
private static volatile boolean isAutoRunActive = false;
private static volatile boolean isSleeping = false;
@ -117,6 +128,9 @@ public class Controller_Frontend {
}
@FXML
private void autoRunGUI(ActionEvent event) {
if (!isAutoRunActive) {
@ -141,9 +155,37 @@ public class Controller_Frontend {
});
autoRunThread.setDaemon(true);
autoRunThread.start();
}
private void updateExecutionTimeMultiplier() {
String selectedOption = executionTimeComboBox.getValue();
switch (selectedOption) {
case "8 MHZ":
executionTimeMultiplier = 0.5;
break;
case "4 MHZ":
executionTimeMultiplier = 1;
break;
case "1 MHZ":
executionTimeMultiplier = 4;
break;
case "500 HZ":
executionTimeMultiplier = 8;
break;
case "100 HZ":
executionTimeMultiplier = 40;
break;
case "32 HZ":
executionTimeMultiplier = 125;
break;
}
}
@FXML
private void stepintoButton(ActionEvent event) throws IOException {
if (lstContentListView.getItems().isEmpty()) {
@ -158,6 +200,14 @@ public class Controller_Frontend {
else
currentIndex = ind[DataRegister.getPC()]-1;
// Überprüfen, ob ein Breakpoint gesetzt ist testte
if (breakpoints.contains(currentIndex)) {
stopAutoRun(null);
System.out.println("Breakpoint erreicht bei Zeile: " + currentIndex);
return;
}
// Scrollen zur ausgewählten Zeile
lstContentListView.scrollTo(currentIndex -2);
@ -173,7 +223,8 @@ public class Controller_Frontend {
markSelectedRow(currentIndex, selectedRowStyle);
// Befehle ausführen
if (!isSleeping) {
Commands.decode(prog[DataRegister.getPC()]);
DataRegister.increasePC();
@ -187,10 +238,13 @@ public class Controller_Frontend {
Stage stage = (Stage) stepintoButton.getScene().getWindow();
CreateWindow.refreshTable(stage);
IOPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
totalExecutionTimeLabel.setText("Total Execution Time: " + Commands.getTotalExecutionTime() + "µs");
long totalExecutionTime = Commands.getTotalExecutionTime();
double adjustedTotalExecutionTime = totalExecutionTime * executionTimeMultiplier;
totalExecutionTimeLabel.setText("Total Execution Time: " + adjustedTotalExecutionTime + "µs");
}
private void markSelectedRow(int currentIndex, String selectedRowStyle){
private void markSelectedRow(int currentIndex, String selectedRowStyle) {
lstContentListView.setCellFactory(column -> new ListCell<String>() {
@Override
protected void updateItem(String item, boolean empty) {
@ -205,6 +259,10 @@ public class Controller_Frontend {
});
}
//////////////testeteet
private Set<Integer> breakpoints = new HashSet<>();
@FXML
protected void selectFileLST(ActionEvent event) throws IOException {
@ -234,9 +292,68 @@ public class Controller_Frontend {
System.out.println(Arrays.toString(Arrays.stream(prog).toArray()));
displayLSTFileContent(selectedFile);
markSelectedRow(0, "-fx-background-color: red; -fx-text-fill: white;");
initializeBreakpoints();
}
}
private void initializeBreakpoints() {
lstContentListView.setCellFactory(createBreakpointCell());
}
private boolean checkBreakpoint(int pc) {
// Hier wird überprüft, ob ein Breakpoint am angegebenen Programmzähler gesetzt ist
return breakpoints.contains(pc);
}
private Callback<ListView<String>, ListCell<String>> createBreakpointCell() {
return listView -> new ListCell<String>() {
private final CheckBox breakpointCheckBox = new CheckBox();
{
breakpointCheckBox.setOnAction(event -> {
int index = getIndex();
if (breakpointCheckBox.isSelected()) {
breakpoints.add(index);
} else {
breakpoints.remove(index);
}
});
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setGraphic(null);
} else {
setText(item);
setGraphic(breakpointCheckBox);
breakpointCheckBox.setSelected(breakpoints.contains(getIndex()));
}
}
};
}
@FXML
protected void loadLSTFileContent(String fileContent) {
ObservableList<String> items = FXCollections.observableArrayList(fileContent.split("\n"));
lstContentListView.setItems(items);
}
private File chooseLSTFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open LST File");
@ -340,6 +457,7 @@ public class Controller_Frontend {
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allTRISButtons[i]);
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allPORTButtons[i]);
}
ledCheckA.setSelected(false);
ledCheckB.setSelected(false);
setTRISbuttons(allTRISButtons);
@ -350,6 +468,13 @@ public class Controller_Frontend {
autoRunGUI.setOnAction(this::autoRunGUI);
stopButton.setOnAction(this::stopAutoRun);
executionTimeComboBox.setItems(FXCollections.observableArrayList("8 MHZ", "4 MHZ", "1 MHZ", "500 HZ", "100 HZ", "32 HZ"));
executionTimeComboBox.setValue("4 MHZ");
executionTimeComboBox.setOnAction(event -> updateExecutionTimeMultiplier());
lstContentListView.setCellFactory(createBreakpointCell());
}

View File

@ -26,6 +26,13 @@ public class IOPorts {
private static Circle[] allLEDsA;
private static Circle[] allLEDsB;
private static int RB4 = 0x10;
private static int RB5 = 0x20;
private static int RB6 = 0x40;
private static int RB7 = 0x80;
public static void setBit (int address, int bit){
if (address < 7) {
dataLatch[address - PORTA] |= (1 << bit);
@ -113,10 +120,10 @@ public class IOPorts {
else
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
else
if (val || DataRegister.getDirectBit(PORTB, index - 8) == 0)
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
else
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
if (val || DataRegister.getDirectBit(PORTB, index - 8) == 0)
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
else
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
}
}
@ -152,6 +159,7 @@ public class IOPorts {
DataRegister.setDirectBit(port, bit, value);
refreshPorts();
refreshTable(parent);
}
public static void setLEDs (boolean[] leds) {
@ -192,10 +200,10 @@ public class IOPorts {
else
fileAddress = TRISB;
else
if (group.contains("A"))
fileAddress = PORTA;
else
fileAddress = PORTB;
if (group.contains("A"))
fileAddress = PORTA;
else
fileAddress = PORTB;
char index =group.charAt(group.length()-1);
int bit = Integer.parseInt(String.valueOf(index));
int value = (toggles.get(0).isSelected()) ? 1 : 0;

View File

@ -0,0 +1,26 @@
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

@ -23,6 +23,7 @@ public class Timer {
}
}
public static void incrementFromPin (int register){
if ((DataRegister.getDirectBit(OPTION, T0CS) == 1) && !Controller_Frontend.isSleeping()){
int newpin = (register >> 4) & 1;

View File

@ -0,0 +1,10 @@
.breakpoint-icon {
-fx-background-color: transparent;
-fx-shape: "M 0 0 L 10 5 L 0 10 Z"; /* Dreieck-Symbol */
-fx-background-insets: 0;
-fx-padding: 0;
-fx-background-radius: 0;
-fx-shape-padding: 0;
-fx-scale-shape: false;
-fx-cursor: hand;
}

View File

@ -25,10 +25,15 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<?import javafx.collections.FXCollections?>
<?import javafx.scene.control.ComboBox?>
<?import java.lang.String?>
<AnchorPane stylesheets="@styles.css" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fabrik.simulator.pic16f84.Controller_Frontend">
<children>
<ListView fx:id="lstContentListView" layoutY="31.0" prefHeight="645.0" prefWidth="550.0" />
<ListView fx:id="lstContentListView" layoutY="31.0" prefHeight="645.0" prefWidth="550.0">
</ListView>
<HBox layoutY="688.0" prefHeight="24.0" prefWidth="550.0">
<children>
<Button fx:id="stepintoButton" mnemonicParsing="false" onAction="#stepintoButton" text="Step IN">
@ -50,6 +55,16 @@
</HBox>
<VBox layoutX="14.0" layoutY="727.0">
<children>
<ComboBox fx:id="executionTimeComboBox">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="4 MHZ" />
<String fx:value=" 8 MHZ" />
<String fx:value=" 16 MHZ" />
</FXCollections>
</items>
</ComboBox>
<Label fx:id="totalExecutionTimeLabel" text="Total Execution Time: 0µs" />
<CheckBox fx:id="wdtCheck" mnemonicParsing="false" onAction="#toggleWatchdog" text="Watchdog-Timer">
<VBox.margin>