1
0
Эх сурвалжийг харах

Add flag to ignore feedbacks

Baglio Tabifata 5 жил өмнө
parent
commit
02882f2e9c

+ 34 - 13
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/formatter/EspressoFormatter.java

@@ -14,18 +14,27 @@ public class EspressoFormatter {
     private EspressoFormatter() {};
 
     public static String formatEspressoTableHeader(PALSpecs pSpecs, int ioAsOutMask) {
+        return formatEspressoTableHeader(pSpecs, ioAsOutMask, false);
+    }
+
+    public static String formatEspressoTableHeader(PALSpecs pSpecs, int ioAsOutMask, boolean ignoreFeedbacks) {
         StringBuffer strBuf = new StringBuffer();
         int ioAsOut_W = BitUtils.scatterBitField(BitUtils.consolidateBitField(ioAsOutMask, pSpecs.getMask_IO_R()), pSpecs.getMask_IO_W());
-        int outCount = pSpecs.getPinCount_O() + BitUtils.countBits(ioAsOutMask);
+        int io_outCount = BitUtils.countBits(ioAsOutMask);
+        int io_inCount = BitUtils.countBits(pSpecs.getMask_IO_R() & ~ioAsOutMask);
+        
+        int outCount = pSpecs.getPinCount_O() + io_outCount + pSpecs.getPinCount_RO();
+        int outCount_oe = pSpecs.getPinCount_O() + io_outCount;
+        int inCount = pSpecs.getPinCount_IN() + io_inCount + (ignoreFeedbacks ? 0 : io_outCount) + pSpecs.getPinCount_RO();
 
         strBuf.append("# " + pSpecs.toString() + "\n");
-        strBuf.append(".i " + (pSpecs.getPinCount_IN() + pSpecs.getPinCount_IO() + pSpecs.getPinCount_RO()) + "\n"); // Inputs, IO as inputs, IO as outputs (as feedbacks), registered outputs (as feedbacks)
-        strBuf.append(".o " + ((outCount*2)+pSpecs.getPinCount_RO()) + "\n"); // Outputs, IO as outputs, Registered Outputs, then an out for all of those as OE
+        strBuf.append(".i " + inCount + "\n"); // Inputs, IO as inputs, IO as outputs (as feedbacks), registered outputs (as feedbacks)
+        strBuf.append(".o " + (outCount_oe + outCount) + "\n"); // Outputs, IO as outputs, Registered Outputs, then an out for all of those as OE
         
         strBuf.append(".ilb ");
         for(int idx = 0; idx < 32; idx++) if(((pSpecs.getMask_IN() >> idx) & 0x01) > 0) strBuf.append(pSpecs.getLabels_IN()[idx] + " ");
         for(int idx = 0; idx < 32; idx++) if((((pSpecs.getMask_IO_W() & ~ioAsOut_W) >> idx) & 0x01) > 0) strBuf.append(pSpecs.getLabels_IO()[idx] + " ");
-        for(int idx = 0; idx < 32; idx++) if((((pSpecs.getMask_IO_W() & ioAsOut_W) >> idx) & 0x01) > 0) strBuf.append("f" + pSpecs.getLabels_IO()[idx] + " ");
+        if(!ignoreFeedbacks) for(int idx = 0; idx < 32; idx++) if((((pSpecs.getMask_IO_W() & ioAsOut_W) >> idx) & 0x01) > 0) strBuf.append("f" + pSpecs.getLabels_IO()[idx] + " ");
         for(int idx = 0; idx < 32; idx++) if(((pSpecs.getMask_RO_W() >> idx) & 0x01) > 0) strBuf.append("ps"+pSpecs.getLabels_RO()[idx] + " ");
         strBuf.append("\n");
         
@@ -38,14 +47,18 @@ public class EspressoFormatter {
         strBuf.append("\n");
        
         strBuf.append(".phase ");
-        for(int idx = 0; idx < outCount+pSpecs.getPinCount_RO(); idx++) strBuf.append(pSpecs.isActiveLow() ? '0' : '1');
-        for(int idx = 0; idx < outCount; idx++) strBuf.append('1');
+        for(int idx = 0; idx < outCount; idx++) strBuf.append(pSpecs.isActiveLow() ? '0' : '1');
+        for(int idx = 0; idx < outCount_oe; idx++) strBuf.append('1');
         strBuf.append("\n\n");
         
         return strBuf.toString();
     }
-   
+  
     public static String[] formatEspressoTable(PALSpecs pSpecs, int ioAsOutMask, OutState[] states) {
+        return formatEspressoTable(pSpecs, ioAsOutMask, states, false);
+    }
+    
+    public static String[] formatEspressoTable(PALSpecs pSpecs, int ioAsOutMask, OutState[] states, boolean ignoreFeedbacks) {
         int ioAsOut_W = BitUtils.scatterBitField(BitUtils.consolidateBitField(ioAsOutMask, pSpecs.getMask_IO_R()), pSpecs.getMask_IO_W());
         HashSet<String> tableRows = new HashSet<>();
 
@@ -73,10 +86,14 @@ public class EspressoFormatter {
                 int io_fio_count = BitUtils.countBits(pSpecs.getMask_IO_R() & ioAsOutMask);
                 for(int idx = 0; idx < pSpecs.getPinCount_IN(); idx++) strBuf.append((char)(((ins >> idx) & 0x01) + 0x30));
                 for(int idx = 0; idx < io_ins_count; idx++) strBuf.append((char)(((io_ins >> idx) & 0x01) + 0x30));
-                for(int idx = 0; idx < io_fio_count; idx++) {
-                    boolean fio_pin_hiz = ((io_fio_hiz >> idx) & 0x01) != 0;
-                    strBuf.append(fio_pin_hiz ? '-' : (char)(((io_fio >> idx) & 0x01) + 0x30));
+
+                if(!ignoreFeedbacks) {
+                    for(int idx = 0; idx < io_fio_count; idx++) {
+                        boolean fio_pin_hiz = ((io_fio_hiz >> idx) & 0x01) != 0;
+                        strBuf.append(fio_pin_hiz ? '-' : (char)(((io_fio >> idx) & 0x01) + 0x30));
+                    }
                 }
+
                 for(int idx = 0; idx < pSpecs.getPinCount_RO(); idx++) strBuf.append((char)(((ro_ps >> idx) & 0x01) + 0x30));
 
                 strBuf.append(' ');
@@ -120,10 +137,14 @@ public class EspressoFormatter {
                 int io_fio_count = BitUtils.countBits(pSpecs.getMask_IO_R() & ioAsOutMask);
                 for(int idx = 0; idx < pSpecs.getPinCount_IN(); idx++) strBuf.append((char)(((ins >> idx) & 0x01) + 0x30));
                 for(int idx = 0; idx < io_ins_count; idx++) strBuf.append((char)(((io_ins >> idx) & 0x01) + 0x30));
-                for(int idx = 0; idx < io_fio_count; idx++) {
-                    boolean fio_pin_hiz = ((io_fio_hiz >> idx) & 0x01) != 0;
-                    strBuf.append(fio_pin_hiz ? '-' : (char)(((io_fio >> idx) & 0x01) + 0x30));
+
+                if(!ignoreFeedbacks) {
+                    for(int idx = 0; idx < io_fio_count; idx++) {
+                        boolean fio_pin_hiz = ((io_fio_hiz >> idx) & 0x01) != 0;
+                        strBuf.append(fio_pin_hiz ? '-' : (char)(((io_fio >> idx) & 0x01) + 0x30));
+                    }
                 }
+                
                 for(int idx = 0; idx < pSpecs.getPinCount_RO(); idx++) strBuf.append((char)(((ro_ps >> idx) & 0x01) + 0x30));
                 
                 strBuf.append(' ');

+ 26 - 0
src/test/java/info/hkzlab/dupal/analyzer/FormattersTest.java

@@ -24,6 +24,13 @@ public class FormattersTest {
                 + ".ob o19 o12 io18 io17 o19oe o12oe io18oe io17oe \n" + ".phase 00001111\n\n";
 
         assertEquals("EspressoFormatter should build a correct 16L8 header", expectedHeader, header);
+
+        header = EspressoFormatter.formatEspressoTableHeader(pSpecs, ioAsOutMask, true);
+        expectedHeader = "# PAL16L8\n" + ".i 14\n" + ".o 8\n"
+                + ".ilb i1 i2 i3 i4 i5 i6 i7 i8 i9 i11 io16 io15 io14 io13 \n"
+                + ".ob o19 o12 io18 io17 o19oe o12oe io18oe io17oe \n" + ".phase 00001111\n\n";
+
+        assertEquals("EspressoFormatter should build a correct 16L8 header ignoring feedback IOs", expectedHeader, header);        
     }
 
     @Test
@@ -70,5 +77,24 @@ public class FormattersTest {
         Arrays.sort(rows);
 
         assertArrayEquals("EspressoFormatter should build the correct truth table for specified states", expected, rows);
+
+        rows = EspressoFormatter.formatEspressoTable(pSpecs, ioAsOutMask, states, true);
+        expected = new String[] {
+            "0000000000000 --11111000\n",
+            "0000000000011 0110-00001\n",
+            
+            "1110000000000 0110-00001\n",
+            "0010000000000 0000000000\n",
+            
+            "1001000000000 0000000000\n",
+            "0000000000010 0110-00001\n",
+            "0010000000000 0110-00001\n",
+        };
+
+        // Sort them, as we cannot guarantee the order of the formatted espresso table
+        Arrays.sort(expected);
+        Arrays.sort(rows);
+
+        assertArrayEquals("EspressoFormatter should build the correct truth table for specified states when ignoring feedback IOs", expected, rows);
     }
 }