Fixed some bug concerning switches

added a 16-Bit SRAM example
This commit is contained in:
hneemann 2017-03-05 21:34:03 +01:00
parent 66d9813c7c
commit b28e97b305
7 changed files with 4586 additions and 28 deletions

4522
src/main/dig/cmos/sram.dig Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9,9 +9,10 @@ public interface PinDescription {
/** /**
* The possible pull resistor configurations * The possible pull resistor configurations
* "both" is an error condition which can happen if nets are merged
*/ */
enum PullResistor { enum PullResistor {
none, pullUp, pullDown none, pullUp, pullDown, both
} }
/** /**

View File

@ -54,6 +54,10 @@ public abstract class AbstractBusHandler {
public void recalculate() { public void recalculate() {
long value = 0; long value = 0;
burn = false; burn = false;
if (getResistor().equals(PinDescription.PullResistor.both)) {
burn = true;
set(0, true);
} else {
boolean highz = true; boolean highz = true;
for (ObservableValue input : getInputs()) { for (ObservableValue input : getInputs()) {
if (!input.isHighZ()) { if (!input.isHighZ()) {
@ -75,10 +79,11 @@ public abstract class AbstractBusHandler {
set(0, false); set(0, false);
break; break;
default: default:
set(value, highz); set(value, true);
} }
} else } else
set(value, highz); set(value, false);
}
// if burn condition and not yet added for post step check add for post step check // if burn condition and not yet added for post step check add for post step check
if (burn && (obs.getVersion() != addedVersion)) { if (burn && (obs.getVersion() != addedVersion)) {
@ -89,7 +94,7 @@ public abstract class AbstractBusHandler {
/** /**
* Called to check if this net is in a burn condition. * 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 * unavoidable. So this method is called if the step is completed. If a step ends with a burn condition
* an exception is thrown. * an exception is thrown.
*/ */

View File

@ -97,6 +97,7 @@ public final class BusModelStateObserver implements ModelStateObserver {
h1.addNet(h2); h1.addNet(h2);
for (CommonBusValue v : h2.getValues()) for (CommonBusValue v : h2.getValues())
netMap.put(v, h1); netMap.put(v, h1);
createdHandlers.remove(h2);
} }
} }
} }

View File

@ -1,6 +1,5 @@
package de.neemann.digital.core.wiring.bus; package de.neemann.digital.core.wiring.bus;
import de.neemann.digital.core.BurnException;
import de.neemann.digital.core.ObservableValue; import de.neemann.digital.core.ObservableValue;
import de.neemann.digital.core.element.PinDescription; import de.neemann.digital.core.element.PinDescription;
@ -43,8 +42,8 @@ public final class ConnectedBusHandler extends AbstractBusHandler {
resistor = net.getResistor(); resistor = net.getResistor();
} else { } else {
if (!resistor.equals(net.getResistor())) { if (!resistor.equals(net.getResistor())) {
// ToDo different resistors! // set error condition
throw new BurnException(inputs); resistor = PinDescription.PullResistor.both;
} }
} }
} }

View File

@ -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());
}
}

View File

@ -28,7 +28,7 @@ public class TestExamples extends TestCase {
*/ */
public void testDistExamples() throws Exception { public void testDistExamples() throws Exception {
File examples = new File(Resources.getRoot().getParentFile().getParentFile(), "/main/dig"); 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); assertEquals(51, testCasesInFiles);
} }