This commit is contained in:
WickedJack99
2022-05-03 18:04:02 +02:00
parent e68b0e743c
commit 03cc7b3afd
17 changed files with 58 additions and 36 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -2,12 +2,33 @@ package Model.Microcontroller;
public class EepromThread extends Thread {
public EepromThread() {
private Eeprom oEeprom;
private int iMethodCall = 0;
public EepromThread(Eeprom oEeprom, int iMethodToCall) {
this.oEeprom = oEeprom;
iMethodCall = iMethodToCall;
}
@Override
public void run() {
switch (iMethodCall) {
case 1: {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
oEeprom.writeToFile();
}break;
case 2: {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
oEeprom.readFromFile();
}break;
}
}
}

View File

@@ -13,30 +13,30 @@ public class Pic {
* Parts of PIC.
* Objects are written with a large starting letter.
*/
private PROGRAMMEMORY ProgramMemory;
private RAM Ram;
private STACK Stack;
private ProgramMemory ProgramMemory;
private Ram Ram;
private Stack Stack;
private int WRegister;
private TIME Runtimer;
private Time Runtimer;
private Alu ArithmeticLogicUnit;
private Eeprom Eeprom;
private Eeprom oEeprom;
private int iStateMachineWriteEeprom = 0;
public Pic() {
//Initialising objects of PIC.
ProgramMemory = new PROGRAMMEMORY();
Ram = new RAM();
Stack = new STACK();
Runtimer = new TIME(Ram);
ProgramMemory = new ProgramMemory();
Ram = new Ram();
Stack = new Stack();
Runtimer = new Time(Ram);
WRegister = 0;
ArithmeticLogicUnit = new Alu();
Eeprom = new Eeprom();
oEeprom = new Eeprom();
}
public synchronized void resetPIC() {
Ram = new RAM();
Stack = new STACK();
Runtimer = new TIME(Ram);
Ram = new Ram();
Stack = new Stack();
Runtimer = new Time(Ram);
WRegister = 0;
}
@@ -74,19 +74,19 @@ public class Pic {
return WRegister;
}
public synchronized RAM getRam() {
public synchronized Ram getRam() {
return Ram;
}
public synchronized PROGRAMMEMORY getEeprom() {
public synchronized ProgramMemory getEeprom() {
return ProgramMemory;
}
public synchronized STACK getStack() {
public synchronized Stack getStack() {
return Stack;
}
public synchronized TIME getRuntimer() {
public synchronized Time getRuntimer() {
return Runtimer;
}
@@ -359,8 +359,8 @@ public class Pic {
iStateMachineWriteEeprom = 4;
} else if ((iStateMachineWriteEeprom == 4) && (bitaddress == 7) && (registerFileAddress == 0x0B)) {
if (Ram.get_WREN()) {
//TODO start thread
Eeprom.writeToFile();
EepromThread oEepromThread = new EepromThread(oEeprom, 1);
oEepromThread.run();
}
} else {
iStateMachineWriteEeprom = 0;

View File

@@ -7,19 +7,19 @@ package Model.Microcontroller;
/**
* ProgramMemory of the PIC (Programmspeicher)
*/
public class PROGRAMMEMORY
public class ProgramMemory
{
private int[][] aiiProgramMemory;
private int iProgramMemoryLength = 1024;
private int[] aiProgramLines;
public PROGRAMMEMORY()
public ProgramMemory()
{
aiiProgramMemory = new int[iProgramMemoryLength][2];
}
public PROGRAMMEMORY(int iLength) {
public ProgramMemory(int iLength) {
aiiProgramMemory = new int[iLength][2];
}

View File

@@ -13,7 +13,7 @@ package Model.Microcontroller;
*
* Page 13 datasheet parts of RAM.
*/
public class RAM {
public class Ram {
//Bank0 of the PIC-RAM
private int[] bank0;
@@ -32,7 +32,7 @@ public class RAM {
* Constructor of RAM
* Initializes two banks as two int arrays of size 128.
*/
public RAM() {
public Ram() {
//Bank0 of the PIC-RAM
bank0 = new int[128];
@@ -206,6 +206,7 @@ public class RAM {
* @param value to set TMR0 to.
*/
public synchronized void set_TMR0(int value) {
iPrescaledTMR0 = 0;
value &= 255;
bank0[1] = value;
}
@@ -225,9 +226,9 @@ public class RAM {
//Increment TMR0 by 1, set T0IF at overflow.
if ((iValTMR0 + 1) > 255) {
set_T0IF(true);
set_TMR0((iValTMR0 + 1) & 255);
bank0[1] = (iValTMR0 + 1) & 255;
} else {
set_TMR0(iValTMR0 + 1);
bank0[1] = (iValTMR0 + 1) & 255;
}
//Prescaler assigned to TMR0, increment TMR0 if prescaled TMR0 equals TMR0 prescaler-rate.
} else {
@@ -238,9 +239,9 @@ public class RAM {
//Increment TMR0 by 1, set T0IF at overflow.
if ((iValTMR0 + 1) > 255) {
set_T0IF(true);
set_TMR0((iValTMR0 + 1) & 255);
bank0[1] = (iValTMR0 + 1) & 255;
} else {
set_TMR0(iValTMR0 + 1);
bank0[1] = (iValTMR0 + 1) & 255;
}
}
}

View File

@@ -10,7 +10,7 @@ import java.util.EmptyStackException;
/**
* Datasheet Page 18
*/
public class STACK
public class Stack
{
private int stackpointer;
private int[] stack;
@@ -21,7 +21,7 @@ public class STACK
/**
* Constructor of STACK.
*/
public STACK() //
public Stack() //
{
stackpointer = 0;
//Initialize stack with -1 to decide wether the stack is empty or not, because 0 could be a return address.

View File

@@ -1,6 +1,6 @@
package Model.Microcontroller;
public class TIME {
public class Time {
private double dRuntime;
private double dMaxWatchdog;
private double dOldMaxWatchdog;
@@ -9,9 +9,9 @@ public class TIME {
private boolean WDTE = false;
private RAM oRam;
private Ram oRam;
public TIME(RAM oRam) {
public Time(Ram oRam) {
dWatchdogTimer = dMaxWatchdog = dOldMaxWatchdog = 18000;
this.oRam = oRam;
}