Added WinCUPL support for ATF1502

This commit is contained in:
helmut.neemann 2016-12-20 14:46:46 +01:00
parent 12f9f13956
commit e51c1f75b0
7 changed files with 170 additions and 23 deletions

View File

@ -0,0 +1,47 @@
package de.neemann.digital.builder.ATF1502;
import de.neemann.digital.builder.Gal16v8.Gal16v8CuplExporter;
import de.neemann.digital.builder.PinMap;
import java.io.IOException;
import java.io.Writer;
import java.util.Date;
/**
* Creates a CUPL file
*
* @author hneemann
*/
public class ATF1502CuplExporter extends Gal16v8CuplExporter {
/**
* Creates a new project name
*/
public ATF1502CuplExporter() {
this(System.getProperty("user.name"), new Date());
}
/**
* Creates a new project name
*
* @param username user name
* @param date date
*/
public ATF1502CuplExporter(String username, Date date) {
super(username, date, "f1502plcc44", new PinMap()
.setAvailInputs(4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 16)
.setAvailOutputs(17, 18, 19, 20, 21, 24, 25, 26, 27, 28));
setClockPin(43);
}
@Override
protected void headerWritten(Writer out) throws IOException {
out.write("\r\nar = 'b'0 ;\r\n");
}
@Override
protected void sequentialWritten(Writer out, String name) throws IOException {
out.write(name + ".ck = CLK ;\r\n");
out.write(name + ".ar = ar ;\r\n");
}
}

View File

@ -0,0 +1,6 @@
/**
* Classes to handle a ATF1502.
*
* @author hneemann
*/
package de.neemann.digital.builder.ATF1502;

View File

@ -36,6 +36,7 @@ public class Gal16v8CuplExporter implements ExpressionExporter<Gal16v8CuplExport
private final String devName;
private String projectName;
private int clockPin = 1;
/**
* Creates a new project name
@ -56,6 +57,15 @@ public class Gal16v8CuplExporter implements ExpressionExporter<Gal16v8CuplExport
.setAvailOutputs(12, 13, 14, 15, 16, 17, 18, 19));
}
/**
* Sets the clock pin.
*
* @param clockPin the clock pin
*/
protected void setClockPin(int clockPin) {
this.clockPin = clockPin;
}
/**
* Creates a new instance
*
@ -118,7 +128,7 @@ public class Gal16v8CuplExporter implements ExpressionExporter<Gal16v8CuplExport
out.append("\r\n/* inputs */\r\n");
if (!builder.getRegistered().isEmpty())
out.append("PIN 1 = CLK;\r\n");
out.append("PIN " + clockPin + " = CLK;\r\n");
for (String in : builder.getInputs())
out.append("PIN ").append(Integer.toString(pinMap.getInputFor(in))).append(" = ").append(in).append(";\r\n");

View File

@ -14,6 +14,7 @@ import de.neemann.digital.analyse.expression.modify.NOr;
import de.neemann.digital.analyse.expression.modify.TwoInputs;
import de.neemann.digital.analyse.format.TruthTableFormatterLaTeX;
import de.neemann.digital.analyse.quinemc.BoolTableIntArray;
import de.neemann.digital.builder.ATF1502.ATF1502CuplExporter;
import de.neemann.digital.builder.*;
import de.neemann.digital.builder.Gal16v8.Gal16v8CuplExporter;
import de.neemann.digital.builder.Gal16v8.Gal16v8JEDECExporter;
@ -86,7 +87,7 @@ public class TableDialog extends JDialog {
font = label.getFont().deriveFont(20.0f);
label.setFont(font);
table = new JTable(model);
JComboBox<String> comboBox = new JComboBox<String>(TruthTableTableModel.STATENAMES);
JComboBox<String> comboBox = new JComboBox<>(TruthTableTableModel.STATENAMES);
table.setDefaultEditor(Integer.class, new DefaultCellEditor(comboBox));
table.setDefaultRenderer(Integer.class, new CenterDefaultTableCellRenderer());
table.setRowHeight(25);
@ -392,6 +393,17 @@ public class TableDialog extends JDialog {
}.setToolTip(Lang.get("menu_table_create_jedec_tt")).createJMenuItem());
hardware.add(gal22v10);
JMenu atf1502 = new JMenu("ATF1502");
atf1502.add(new ToolTipAction(Lang.get("menu_table_createCUPL")) {
@Override
public void actionPerformed(ActionEvent actionEvent) {
createCUPL(new ATF1502CuplExporter());
}
}.setToolTip(Lang.get("menu_table_createCUPL_tt")).createJMenuItem());
hardware.add(atf1502);
createMenu.add(hardware);
return createMenu;
@ -435,28 +447,27 @@ public class TableDialog extends JDialog {
}
private void createCUPL(Gal16v8CuplExporter cupl) {
JFileChooser fileChooser = new JFileChooser();
if (filename != null && filename.getName().endsWith(".dig")) {
try {
if (filename == null)
throw new IOException(Lang.get("err_noFileNameAvailable"));
String name = filename.getName();
File cuplPath = new File(filename.getParentFile(), "cupl");
File file = new File(cuplPath, name.substring(0, name.length() - 3) + "PLD");
if (!cuplPath.exists())
cuplPath.mkdirs();
fileChooser.setSelectedFile(file);
}
fileChooser.setFileFilter(new FileNameExtensionFilter("PLD", "PLD"));
if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
File f = Main.checkSuffix(fileChooser.getSelectedFile(), "PLD");
cupl.setProjectName(f.getName());
cupl.getPinMapping().addAll(pinMap);
new BuilderExpressionCreator(cupl.getBuilder(), ExpressionModifier.IDENTITY).create();
try (FileOutputStream out = new FileOutputStream(f)) {
cupl.writeTo(out);
}
} catch (ExpressionException | FormatterException | RuntimeException | IOException | FuseMapFillerException | PinMapException e) {
new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e).show();
if (name.endsWith(".dig")) name = name.substring(0, name.length() - 4);
File cuplPath = new File(filename.getParentFile(), "CUPL_" + name);
if (!cuplPath.mkdirs())
if (!cuplPath.exists())
throw new IOException(Lang.get("err_couldNotCreateFolder_N0", cuplPath.getPath()));
File f = new File(cuplPath, "CUPL.PLD");
cupl.setProjectName(f.getName());
cupl.getPinMapping().addAll(pinMap);
new BuilderExpressionCreator(cupl.getBuilder(), ExpressionModifier.IDENTITY).create();
try (FileOutputStream out = new FileOutputStream(f)) {
cupl.writeTo(out);
}
} catch (ExpressionException | FormatterException | RuntimeException | IOException | FuseMapFillerException | PinMapException e) {
new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e).show();
}
}
@ -675,5 +686,4 @@ public class TableDialog extends JDialog {
return this;
}
}
}

View File

@ -258,6 +258,9 @@ Zur Analyse können Sie die Schaltung im Gatterschrittmodus ausführen.</string>
<string name="err_openingDocumentation">Browser konnte nicht geöffnet werden.</string>
<string name="err_splitterDoesNotSupportHighZInputs">Der Splitter unterstützt keine HighZ Eingänge! Verwenden Sie einen PullUp- oder PullDown-Widerstand</string>
<string name="err_splitterAllowsOnlyOneHighZInput">Ein Splitter der hochohmige Eingänge erlaubt, kann nur einen Eingang haben!</string>
<string name="err_noFileNameAvailable">Die Datei wurde noch nicht gespeichert!</string>
<string name="err_couldNotCreateFolder_N0">Konnte den Order '{0}' nicht erzeugen!</string>
<string name="key_AddrBits">Adress-Bits</string>
<string name="key_AddrBits_tt">Anzahl der Adress-Bits die verwendet werden.</string>
<string name="key_Bits">Daten-Bits</string>

View File

@ -251,6 +251,8 @@ To analyse you can run the circuit in single gate step mode.</string>
<string name="err_openingDocumentation">Could not open the browser.</string>
<string name="err_splitterDoesNotSupportHighZInputs">The splitter does not support high z inputs! Use a pull up or pull down resisitor.</string>
<string name="err_splitterAllowsOnlyOneHighZInput">A splitter which allows high z inputs can only have one input!</string>
<string name="err_noFileNameAvailable">File not saved already! There is no filename avaiable!</string>
<string name="err_couldNotCreateFolder_N0">Could not create folder '{0}'!</string>
<string name="key_AddrBits">Address Bits</string>
<string name="key_AddrBits_tt">Number of address bits used.</string>

View File

@ -0,0 +1,69 @@
package de.neemann.digital.builder.ATF1502;
import de.neemann.digital.analyse.expression.Expression;
import de.neemann.digital.analyse.expression.Variable;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.util.Date;
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 20.12.2016.
*/
public class ATF1502CuplExporterTest extends TestCase {
public void testCUPLExporter() throws Exception {
Variable y0 = new Variable("Y_0");
Variable y1 = new Variable("Y_1");
// counter
Expression y0s = not(y0);
Expression y1s = or(and(not(y0), y1), and(y0, not(y1)));
ATF1502CuplExporter ce = new ATF1502CuplExporter("user", new Date(0));
ce.setProjectName("test");
ce.getBuilder()
.addSequential("Y_0", y0s)
.addSequential("Y_1", y1s)
.addCombinatorial("A", and(y0, y1));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ce.writeTo(baos);
assertEquals("Name test ;\r\n" +
"PartNo 00 ;\r\n" +
"Date 01.01.1970 ;\r\n" +
"Revision 01 ;\r\n" +
"Designer user ;\r\n" +
"Company unknown ;\r\n" +
"Assembly None ;\r\n" +
"Location unknown ;\r\n" +
"Device f1502plcc44 ;\r\n" +
"\r\n" +
"ar = 'b'0 ;\r\n" +
"\r\n" +
"/* inputs */\r\n" +
"PIN 43 = CLK;\r\n" +
"\r\n" +
"/* outputs */\r\n" +
"PIN 17 = Y_0;\r\n" +
"PIN 18 = Y_1;\r\n" +
"PIN 19 = A;\r\n" +
"\r\n" +
"/* sequential logic */\r\n" +
"Y_0.D = !Y_0;\r\n" +
"Y_0.ck = CLK ;\r\n" +
"Y_0.ar = ar ;\r\n" +
"Y_1.D = (!Y_0 & Y_1) # (Y_0 & !Y_1);\r\n" +
"Y_1.ck = CLK ;\r\n" +
"Y_1.ar = ar ;\r\n" +
"\r\n" +
"/* combinatorial logic */\r\n" +
"A = Y_0 & Y_1;\r\n", baos.toString());
}
}