mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 06:22:48 -04:00
Fixed some bug concerning switches
added a 16-Bit SRAM example
This commit is contained in:
parent
66d9813c7c
commit
b28e97b305
4522
src/main/dig/cmos/sram.dig
Normal file
4522
src/main/dig/cmos/sram.dig
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,9 +9,10 @@ public interface PinDescription {
|
||||
|
||||
/**
|
||||
* The possible pull resistor configurations
|
||||
* "both" is an error condition which can happen if nets are merged
|
||||
*/
|
||||
enum PullResistor {
|
||||
none, pullUp, pullDown
|
||||
none, pullUp, pullDown, both
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,31 +54,36 @@ public abstract class AbstractBusHandler {
|
||||
public void recalculate() {
|
||||
long value = 0;
|
||||
burn = false;
|
||||
boolean highz = true;
|
||||
for (ObservableValue input : getInputs()) {
|
||||
if (!input.isHighZ()) {
|
||||
if (highz) {
|
||||
highz = false;
|
||||
value = input.getValue();
|
||||
} else {
|
||||
if (value != input.getValue())
|
||||
burn = true;
|
||||
if (getResistor().equals(PinDescription.PullResistor.both)) {
|
||||
burn = true;
|
||||
set(0, true);
|
||||
} else {
|
||||
boolean highz = true;
|
||||
for (ObservableValue input : getInputs()) {
|
||||
if (!input.isHighZ()) {
|
||||
if (highz) {
|
||||
highz = false;
|
||||
value = input.getValue();
|
||||
} else {
|
||||
if (value != input.getValue())
|
||||
burn = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (highz) {
|
||||
switch (getResistor()) {
|
||||
case pullUp:
|
||||
set(-1, false);
|
||||
break;
|
||||
case pullDown:
|
||||
set(0, false);
|
||||
break;
|
||||
default:
|
||||
set(value, true);
|
||||
}
|
||||
} else
|
||||
set(value, false);
|
||||
}
|
||||
if (highz) {
|
||||
switch (getResistor()) {
|
||||
case pullUp:
|
||||
set(-1, false);
|
||||
break;
|
||||
case pullDown:
|
||||
set(0, false);
|
||||
break;
|
||||
default:
|
||||
set(value, highz);
|
||||
}
|
||||
} else
|
||||
set(value, highz);
|
||||
|
||||
// if burn condition and not yet added for post step check add for post step check
|
||||
if (burn && (obs.getVersion() != addedVersion)) {
|
||||
@ -89,7 +94,7 @@ public abstract class AbstractBusHandler {
|
||||
|
||||
/**
|
||||
* Called to check if this net is in a burn condition.
|
||||
* A burn condition does not immediately throw an exception, because intermediate burn condition are
|
||||
* A burn condition does not immediately throw an exception, because intermediate burn conditions are
|
||||
* unavoidable. So this method is called if the step is completed. If a step ends with a burn condition
|
||||
* an exception is thrown.
|
||||
*/
|
||||
|
@ -97,6 +97,7 @@ public final class BusModelStateObserver implements ModelStateObserver {
|
||||
h1.addNet(h2);
|
||||
for (CommonBusValue v : h2.getValues())
|
||||
netMap.put(v, h1);
|
||||
createdHandlers.remove(h2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.neemann.digital.core.wiring.bus;
|
||||
|
||||
import de.neemann.digital.core.BurnException;
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.element.PinDescription;
|
||||
|
||||
@ -43,8 +42,8 @@ public final class ConnectedBusHandler extends AbstractBusHandler {
|
||||
resistor = net.getResistor();
|
||||
} else {
|
||||
if (!resistor.equals(net.getResistor())) {
|
||||
// ToDo different resistors!
|
||||
throw new BurnException(inputs);
|
||||
// set error condition
|
||||
resistor = PinDescription.PullResistor.both;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package de.neemann.digital.core.wiring.bus;
|
||||
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.element.PinDescription;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Created by hneemann on 05.03.17.
|
||||
*/
|
||||
public class ConnectedBusHandlerTest extends TestCase {
|
||||
|
||||
public void testNets() {
|
||||
BusModelStateObserver obs = new BusModelStateObserver();
|
||||
ConnectedBusHandler cbh = new ConnectedBusHandler(obs);
|
||||
|
||||
cbh.addNet(new CommonBusValue(1, obs, PinDescription.PullResistor.none, new ObservableValue[]{}));
|
||||
assertEquals(PinDescription.PullResistor.none, cbh.getResistor());
|
||||
cbh.addNet(new CommonBusValue(1, obs, PinDescription.PullResistor.pullUp, new ObservableValue[]{}));
|
||||
assertEquals(PinDescription.PullResistor.pullUp, cbh.getResistor());
|
||||
cbh.addNet(new CommonBusValue(1, obs, PinDescription.PullResistor.pullDown, new ObservableValue[]{}));
|
||||
assertEquals(PinDescription.PullResistor.both, cbh.getResistor());
|
||||
cbh.addNet(new CommonBusValue(1, obs, PinDescription.PullResistor.pullDown, new ObservableValue[]{}));
|
||||
assertEquals(PinDescription.PullResistor.both, cbh.getResistor());
|
||||
cbh.addNet(new CommonBusValue(1, obs, PinDescription.PullResistor.pullUp, new ObservableValue[]{}));
|
||||
assertEquals(PinDescription.PullResistor.both, cbh.getResistor());
|
||||
cbh.addNet(new CommonBusValue(1, obs, PinDescription.PullResistor.none, new ObservableValue[]{}));
|
||||
assertEquals(PinDescription.PullResistor.both, cbh.getResistor());
|
||||
}
|
||||
|
||||
}
|
@ -28,7 +28,7 @@ public class TestExamples extends TestCase {
|
||||
*/
|
||||
public void testDistExamples() throws Exception {
|
||||
File examples = new File(Resources.getRoot().getParentFile().getParentFile(), "/main/dig");
|
||||
assertEquals(99, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(100, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(51, testCasesInFiles);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user