Watchdog-Checkbox

This commit is contained in:
2024-05-14 11:45:35 +02:00
parent b842d6eb05
commit 8f35f4f914
6 changed files with 78 additions and 210 deletions

View File

@ -45,11 +45,9 @@ public class Controller_Frontend {
@FXML
private TableView<Table.DataEntry> tableView;
@FXML
private ListView<String> lstContentListView;
@FXML
private Label pclLabel;
@ -77,20 +75,20 @@ public class Controller_Frontend {
@FXML
private Label totalExecutionTimeLabel;
private volatile boolean isAutoRunActive = true;
@FXML
private void stopAutoRun(ActionEvent event) {
private CheckBox wdtCheck;
private static volatile boolean isAutoRunActive = true;
public static void stopRunFromBackend(){
isAutoRunActive = false;
}
@FXML
private void stopAutoRun(ActionEvent event) {
isAutoRunActive = false;
}
@FXML
@ -123,8 +121,6 @@ public class Controller_Frontend {
}
@FXML
private void stepintoButton(ActionEvent event) throws IOException {
if (lstContentListView.getItems().isEmpty()) {
@ -204,37 +200,11 @@ public class Controller_Frontend {
}
@FXML
private void stepThroughFile(ActionEvent event) {
if (lstContentListView.getItems().isEmpty()) {
// Datei ist nicht geladen oder leer
return;
}
// Aktuelle Zeile abrufen
int currentIndex = lstContentListView.getSelectionModel().getSelectedIndex();
// if (currentIndex == )
// Wenn keine Zeile ausgewählt ist, starte von der ersten Zeile
if (currentIndex == -1) {
currentIndex = 1;
} else {
// Gehe zur nächsten Zeile
currentIndex++;
}
// Überprüfen, ob currentIndex innerhalb der Grenzen liegt
if (currentIndex >= lstContentListView.getItems().size()) {
// Wenn das Ende der Datei erreicht ist, zeige eine Meldung an
System.out.println("End of file reached.");
return;
}
// Zeile auswählen und anzeigen
lstContentListView.scrollTo(currentIndex);
lstContentListView.getSelectionModel().select(currentIndex + 1);
lstContentListView.scrollTo(currentIndex + 1);
public void toggleWatchdog(ActionEvent actionEvent) {
if (wdtCheck.isSelected())
WatchdogTimer.enable();
else
WatchdogTimer.disable();
}
@FXML
@ -248,12 +218,6 @@ public class Controller_Frontend {
@FXML
private ToggleButtonGroup bgTRISA4;
@FXML
private ToggleButtonGroup bgTRISA5;
@FXML
private ToggleButtonGroup bgTRISA6;
@FXML
private ToggleButtonGroup bgTRISA7;
@FXML
private ToggleButtonGroup bgTRISB0;
@FXML
private ToggleButtonGroup bgTRISB1;
@ -280,12 +244,6 @@ public class Controller_Frontend {
@FXML
private ToggleButtonGroup bgPORTA4;
@FXML
private ToggleButtonGroup bgPORTA5;
@FXML
private ToggleButtonGroup bgPORTA6;
@FXML
private ToggleButtonGroup bgPORTA7;
@FXML
private ToggleButtonGroup bgPORTB0;
@FXML
private ToggleButtonGroup bgPORTB1;
@ -306,9 +264,9 @@ public class Controller_Frontend {
private static ToggleButtonGroup[] allPORTbuttons;
public void initialize() {
ToggleButtonGroup [] allTRISButtons = {bgTRISA0, bgTRISA1, bgTRISA2, bgTRISA3, bgTRISA4, bgTRISA5, bgTRISA6, bgTRISA7, bgTRISB0, bgTRISB1, bgTRISB2, bgTRISB3, bgTRISB4, bgTRISB5, bgTRISB6, bgTRISB7};
ToggleButtonGroup [] allPORTButtons = {bgPORTA0, bgPORTA1, bgPORTA2, bgPORTA3, bgPORTA4, bgPORTA5, bgPORTA6, bgPORTA7, bgPORTB0, bgPORTB1, bgPORTB2, bgPORTB3, bgPORTB4, bgPORTB5, bgPORTB6, bgPORTB7};
for (int i = 0; i<16; i++) {
ToggleButtonGroup [] allTRISButtons = {bgTRISA0, bgTRISA1, bgTRISA2, bgTRISA3, bgTRISA4, bgTRISB0, bgTRISB1, bgTRISB2, bgTRISB3, bgTRISB4, bgTRISB5, bgTRISB6, bgTRISB7};
ToggleButtonGroup [] allPORTButtons = {bgPORTA0, bgPORTA1, bgPORTA2, bgPORTA3, bgPORTA4, bgPORTB0, bgPORTB1, bgPORTB2, bgPORTB3, bgPORTB4, bgPORTB5, bgPORTB6, bgPORTB7};
for (int i = 0; i<allPORTButtons.length; i++) {
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allTRISButtons[i]);
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allPORTButtons[i]);
}
@ -317,7 +275,6 @@ public class Controller_Frontend {
lstContentListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
lstContentListView.getStylesheets().add(Objects.requireNonNull(getClass().getResource("styles.css")).toExternalForm());
autoRunGUI.setOnAction(this::autoRunGUI);
stopButton.setOnAction(this::stopAutoRun);
}
@ -339,6 +296,7 @@ public class Controller_Frontend {
public static ToggleButtonGroup [] getPORTbuttons() {
return allPORTbuttons;
}
}

View File

@ -11,6 +11,7 @@ import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.Objects;
public class CreateWindow extends Application {
@ -33,6 +34,7 @@ public class CreateWindow extends Application {
grid.relocate(0, 0);
grid.getStylesheets().add(Objects.requireNonNull(getClass().getResource("styles.css")).toExternalForm());
Scene scene = new Scene(grid, 1800, 800);
primaryStage.setScene(scene);
primaryStage.setTitle("Simulator");

View File

@ -53,7 +53,7 @@ public class IOPorts {
}
private static void refreshPorts() {
DataRegister.setDirectRegister(PORTA, ((~((~dataLatch[A])&0xFF | trisLatch[A])) | (trisLatch[A] & DataRegister.getDirectRegister(PORTA))) & 0xFF);
DataRegister.setDirectRegister(PORTA, ((~((~dataLatch[A])&0x1F | trisLatch[A])) | (trisLatch[A] & DataRegister.getDirectRegister(PORTA))) & 0xFF);
DataRegister.setDirectRegister(PORTB, ((~((~dataLatch[B])&0xFF | trisLatch[B])) | (trisLatch[B] & DataRegister.getDirectRegister(PORTB))) & 0xFF);
DataRegister.setDirectRegister(TRISA, trisLatch[A]);
DataRegister.setDirectRegister(TRISB, trisLatch[B]);

View File

@ -3,18 +3,20 @@ package fabrik.simulator.pic16f84;
public class WatchdogTimer {
private static long watchdogTime;
private static long lastReset = 0;
private static boolean enabled = false;
private static long getTimeFromRegister() {
return (PreScaler.isPrescalerOnTimer()) ? 18L : PreScaler.getFactor() * 18L;
}
public static void testAndTrigger () {
public static void testAndTrigger() {
watchdogTime = getTimeFromRegister() * 1000;
if (!PreScaler.isPrescalerOnTimer() && (Commands.getTotalExecutionTime() >= (watchdogTime + lastReset))){
if (enabled && (Commands.getTotalExecutionTime() >= (watchdogTime + lastReset - 1))){
DataRegister.resetPC();
System.err.println("Watchdog Timer triggered");
DataRegister.clearBit(3, 4);
lastReset = Commands.getTotalExecutionTime();
Controller_Frontend.stopRunFromBackend();
}
}
@ -24,4 +26,12 @@ public class WatchdogTimer {
DataRegister.setBit(3, 3);
DataRegister.setBit(3, 4);
}
public static void enable() {
enabled = true;
}
public static void disable() {
enabled = false;
}
}

View File

@ -1,5 +0,0 @@
.list-cell:selected {
-fx-background-color: yellow;
}