From c49a073cfd731d516bdd4342e73b2df630b491f8 Mon Sep 17 00:00:00 2001 From: luca Date: Sun, 2 Jun 2024 15:16:01 +0200 Subject: [PATCH] Laufzeit und Watchdog und Timer --- .../fabrik/simulator/pic16f84/Commands.java | 11 +- .../pic16f84/Controller_Frontend.java | 135 +++++++++++++++++- .../fabrik/simulator/pic16f84/IOPorts.java | 24 ++-- .../pic16f84/RBInterruptHandler.java | 26 ++++ .../java/fabrik/simulator/pic16f84/Timer.java | 1 + .../java/fabrik/simulator/pic16f84/styles.css | 10 ++ .../fabrik/simulator/pic16f84/frontend.fxml | 17 ++- 7 files changed, 209 insertions(+), 15 deletions(-) create mode 100644 src/main/java/fabrik/simulator/pic16f84/RBInterruptHandler.java create mode 100644 src/main/java/fabrik/simulator/pic16f84/styles.css diff --git a/src/main/java/fabrik/simulator/pic16f84/Commands.java b/src/main/java/fabrik/simulator/pic16f84/Commands.java index a17ccad..91f1549 100644 --- a/src/main/java/fabrik/simulator/pic16f84/Commands.java +++ b/src/main/java/fabrik/simulator/pic16f84/Commands.java @@ -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) { diff --git a/src/main/java/fabrik/simulator/pic16f84/Controller_Frontend.java b/src/main/java/fabrik/simulator/pic16f84/Controller_Frontend.java index 14e8ba9..200208d 100644 --- a/src/main/java/fabrik/simulator/pic16f84/Controller_Frontend.java +++ b/src/main/java/fabrik/simulator/pic16f84/Controller_Frontend.java @@ -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 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() { @Override protected void updateItem(String item, boolean empty) { @@ -205,6 +259,10 @@ public class Controller_Frontend { }); } + //////////////testeteet + private Set 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, ListCell> createBreakpointCell() { + return listView -> new ListCell() { + 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 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()); + } diff --git a/src/main/java/fabrik/simulator/pic16f84/IOPorts.java b/src/main/java/fabrik/simulator/pic16f84/IOPorts.java index 2ae9487..91b6117 100644 --- a/src/main/java/fabrik/simulator/pic16f84/IOPorts.java +++ b/src/main/java/fabrik/simulator/pic16f84/IOPorts.java @@ -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; diff --git a/src/main/java/fabrik/simulator/pic16f84/RBInterruptHandler.java b/src/main/java/fabrik/simulator/pic16f84/RBInterruptHandler.java new file mode 100644 index 0000000..59781cb --- /dev/null +++ b/src/main/java/fabrik/simulator/pic16f84/RBInterruptHandler.java @@ -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"); + } +} diff --git a/src/main/java/fabrik/simulator/pic16f84/Timer.java b/src/main/java/fabrik/simulator/pic16f84/Timer.java index d8e1a18..f5be2e2 100644 --- a/src/main/java/fabrik/simulator/pic16f84/Timer.java +++ b/src/main/java/fabrik/simulator/pic16f84/Timer.java @@ -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; diff --git a/src/main/java/fabrik/simulator/pic16f84/styles.css b/src/main/java/fabrik/simulator/pic16f84/styles.css new file mode 100644 index 0000000..8c6a5a1 --- /dev/null +++ b/src/main/java/fabrik/simulator/pic16f84/styles.css @@ -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; +} diff --git a/src/main/resources/fabrik/simulator/pic16f84/frontend.fxml b/src/main/resources/fabrik/simulator/pic16f84/frontend.fxml index dbaedf1..0b2125c 100644 --- a/src/main/resources/fabrik/simulator/pic16f84/frontend.fxml +++ b/src/main/resources/fabrik/simulator/pic16f84/frontend.fxml @@ -25,10 +25,15 @@ + + + - + + +