added test for GAL22v10 JEDEC compiler

This commit is contained in:
helmut.neemann 2016-06-06 15:20:57 +02:00
parent 17cb526117
commit 15094afeaa
3 changed files with 186 additions and 10 deletions

View File

@ -30,7 +30,7 @@ public class Gal22v10JEDECExporter implements ExpressionExporter<Gal22v10JEDECEx
* Creates new instance
*/
public Gal22v10JEDECExporter() {
map = new FuseMap(2194);
map = new FuseMap(5892);
filler = new FuseMapFiller(map, 22);
builder = new BuilderCollector() {
@ -46,8 +46,6 @@ public class Gal22v10JEDECExporter implements ExpressionExporter<Gal22v10JEDECEx
.setAvailInputs(2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
.setAvailOutputs(14, 15, 16, 17, 18, 19, 20, 21, 22, 23);
for (int i = 0; i < 10; i++) // set all OLMC to active high
map.setFuse(S0 + i * 2);
}
@Override
@ -68,13 +66,14 @@ public class Gal22v10JEDECExporter implements ExpressionExporter<Gal22v10JEDECEx
}
for (String o : builder.getOutputs()) {
int i = 23 - pinMap.getOutputFor(o);
filler.addVariable(i * 2 + 1, new Variable(o));
filler.addVariableReverse(i * 2 + 1, new Variable(o));
}
for (String o : builder.getOutputs()) {
int olmc = 23 - pinMap.getOutputFor(o);
int offs = oeFuseNumByOLMC[olmc];
for (int j = 0; j < 44; j++) map.setFuse(offs + j); // turn on OE
map.setFuse(S0 + olmc * 2); // set olmc to active high
if (builder.getCombinatorial().containsKey(o)) {
map.setFuse(S1 + olmc * 2);
filler.fillExpression(offs + 44, builder.getCombinatorial().get(o), productsByOLMC[olmc]);

View File

@ -19,7 +19,7 @@ public class FuseMapFiller {
private final FuseMap fuseMap;
private final int varsConnectedToMap;
private final HashMap<Variable, Integer> varMap;
private final HashMap<Variable, MapEntry> varMap;
/**
* Creates a new instance
@ -43,7 +43,21 @@ public class FuseMapFiller {
* @return this for chained calls
*/
public FuseMapFiller addVariable(int index, Variable var) {
varMap.put(var, index);
varMap.put(var, new MapEntry(index, false));
return this;
}
/**
* Adds a variable to the matrix
* In difference to addVariable() the inverted column comes first and the non inverted column follows.
* So the both columns are in reverse order compared to addVariable()
*
* @param index number in matrix
* @param var the variable
* @return this for chained calls
*/
public FuseMapFiller addVariableReverse(int index, Variable var) {
varMap.put(var, new MapEntry(index, true));
return this;
}
@ -104,13 +118,12 @@ public class FuseMapFiller {
} else
throw new FuseMapFillerException("only VAR or NOT VAR allowed!");
Integer i = varMap.get(var);
MapEntry entry = varMap.get(var);
if (i == null)
if (entry == null)
throw new FuseMapFillerException("VAR " + var + " not found in term list!");
int fuse = i * 2;
if (invert) fuse++;
int fuse = entry.getFuse(invert);
fuseMap.setFuse(offs + fuse, false);
}
@ -120,4 +133,22 @@ public class FuseMapFiller {
}
private class MapEntry {
private final int index;
private final boolean swap;
public MapEntry(int index, boolean swap) {
this.index = index;
this.swap = swap;
}
public int getFuse(boolean invert) {
int fuse=index*2;
if (swap) {
if (!invert) fuse++;
} else
if (invert) fuse++;
return fuse;
}
}
}

View File

@ -0,0 +1,146 @@
package de.neemann.digital.builder.Gal22v10;
import de.neemann.digital.analyse.expression.Expression;
import de.neemann.digital.analyse.expression.Variable;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import static de.neemann.digital.analyse.expression.Not.not;
import static de.neemann.digital.analyse.expression.Operation.and;
import static de.neemann.digital.analyse.expression.Operation.or;
/**
* Created by helmut.neemann on 06.06.2016.
*/
public class Gal22v10JEDECExporterTest extends TestCase {
// stepper control; sequential and combinatorial
public void testSequential() throws Exception {
Variable D = new Variable("D");
Variable Q0 = new Variable("Q0");
Variable Q1 = new Variable("Q1");
Variable Q2 = new Variable("Q2");
//Q0.d = !Q0;
Expression Q0d = not(Q0);
//Q1.d = !D & !Q1 & Q0 # !D & Q1 & !Q0 # D & !Q1 & !Q0 # D & Q1 & Q0;
Expression Q1d = or(and(not(D), not(Q1), Q0), and(not(D), Q1, not(Q0)), and(D, not(Q1), not(Q0)), and(D, Q1, Q0));
//Q2.d = !D & !Q2 & Q1 & Q0 #
// !D & Q2 & !Q1 #
// Q2 & Q1 & !Q0 #
// D & !Q2 & !Q1 & !Q0 #
// D & Q2 & Q0;
Expression Q2d = or(
and(not(D), not(Q2), Q1, Q0),
and(not(D), Q2, not(Q1)),
and(Q2, Q1, not(Q0)),
and(D, not(Q2), not(Q1), not(Q0)),
and(D, Q2, Q0));
//P0 = !Q2 & !Q1 # Q2 & Q1 & Q0;
Expression P0 = or(
and(not(Q2), not(Q1)),
and(Q2, Q1, Q0));
//P1 = !Q2 & Q0 # !Q2 & Q1;
Expression P1 = or(
and(not(Q2), Q0),
and(not(Q2), Q1));
//P2 = !Q2 & Q1 & Q0 # Q2 & !Q1;
Expression P2 = or(
and(not(Q2), Q1, Q0),
and(Q2, not(Q1)));
//P3 = Q2 & Q0 # Q2 & Q1;
Expression P3 = or(
and(Q2, Q0),
and(Q2, Q1));
Gal22v10JEDECExporter gal = new Gal22v10JEDECExporter();
gal.getBuilder()
.addSequential("Q0", Q0d)
.addSequential("Q1", Q1d)
.addSequential("Q2", Q2d)
.addCombinatorial("P0", P0)
.addCombinatorial("P1", P1)
.addCombinatorial("P2", P2)
.addCombinatorial("P3", P3);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
gal.writeTo(baos);
assertEquals("\u0002Digital GAL22v10 assembler*\r\n" +
"QF5892*\r\n" +
"G0*\r\n" +
"F0*\r\n" +
"L1472 00000000000000000000000011111111*\r\n" + // CUPL output
"L1504 11111111111111111111111111111111*\r\n" +
"L1536 11111111111111111111111111111111*\r\n" +
"L1568 11101111111011111111111111111111*\r\n" +
"L1600 11111111111111101110111111110000*\r\n" +
"L2144 00000000000011111111111111111111*\r\n" +
"L2176 11111111111111111111111111111111*\r\n" +
"L2208 11111111111111111111110111101110*\r\n" +
"L2240 11111111111111111111111111111111*\r\n" +
"L2272 11101101111111110000000000000000*\r\n" +
"L2880 00000000000000000000000011111111*\r\n" +
"L2912 11111111111111111111111111111111*\r\n" +
"L2944 11111111111111111111111111111111*\r\n" +
"L2976 11011111111011111111111111111111*\r\n" +
"L3008 11111111111111011110111111110000*\r\n" +
"L3648 00001111111111111111111111111111*\r\n" +
"L3680 11111111111111111111111111111111*\r\n" +
"L3712 11111111111111101110111011111111*\r\n" +
"L3744 11111111111111111111111111011101*\r\n" +
"L3776 11111111000000000000000000000000*\r\n" +
"L4288 00000000000000000000000011111111*\r\n" +
"L4320 11111111111111111111111111111111*\r\n" +
"L4352 11111111101111111111111111111111*\r\n" +
"L4384 11011110111011111111101111111111*\r\n" +
"L4416 11111111111111101101111111111111*\r\n" +
"L4448 01111111111111111111111111011101*\r\n" +
"L4480 11011111111101111111111111111111*\r\n" +
"L4512 11111110111111101111111111111111*\r\n" +
"L4544 11111111111111111110111011011111*\r\n" +
/* CUPL uses other product term ordering
"L4384 11011110111011111111011111111111*\r\n" +
"L4416 11111111111111011101110111111111*\r\n" +
"L4448 01111111111111111111111111101110*\r\n" +
"L4480 11111111111110111111111111111111*\r\n" +
"L4512 11111110111111011111111111111111*\r\n" +
"L4544 11111111111111111110110111101111*\r\n" +*/
"L4864 00000000000000000000111111111111*\r\n" +
"L4896 11111111111111111111111111111111*\r\n" +
"L4928 11111011111111111111111111111111*\r\n" +
"L4960 11011110111111111011111111111111*\r\n" +
"L4992 11111111111111101101111111110111*\r\n"+
/* CUPL uses other product term ordering
"L4960 11101101111111111011111111111111*\r\n" +
"L4992 11111111111111011110111111110111*\r\n" +*/
"L5024 11111111111111111111111111011101*\r\n" +
"L5056 11111111011111111111111111111111*\r\n" +
"L5088 11111110111011110000000000000000*\r\n" +
"L5344 00000000000000000000000011111111*\r\n" +
"L5376 11111111111111111111111111111111*\r\n" +
"L5408 11111111111111111111111111111111*\r\n" +
"L5440 11111111110111110000000000000000*\r\n" +
"L5792 00000000000000000000001111111110*\r\n" +
"L5824 10100000000000000000000000000000*\r\n" +
/* CUPL writes some data to the signature
"L5824 10100011000000110000001000000000*\r\n" +
*/
"C8241*\r\n" +
"\u000353C9", baos.toString());
}
}