瀏覽代碼

Add code for PAL16L8

Baglio Tabifata 4 年之前
父節點
當前提交
63c5c8f701

+ 4 - 1
src/main/java/info/hkzlab/dupal/analyzer/App.java

@@ -21,7 +21,7 @@ public class App {
         if(args.length < 3) {
             logger.error("Wrong number of arguments passed.\n"+
                         "dupal_analyzer <serial_port> <pal_type> <output_dir> [hex_output_mask]\n" +
-                        "Where <pal_type> can be: 16R8, 16R6, 16R4\n");
+                        "Where <pal_type> can be: 16R8, 16R6, 16R4, 16L8\n");
 
             return;
         }
@@ -52,6 +52,9 @@ public class App {
             case "16R4":
                 pspecs = new PAL16R4Specs();
                 break;
+            case "16L8":
+                pspecs = new PAL16L8Specs();
+                break;
             default:
                 logger.error("Invalid PAL type selected.");
                 System.exit(-1);

+ 18 - 12
src/main/java/info/hkzlab/dupal/analyzer/board/boardio/DuPALAnalyzer.java

@@ -157,7 +157,7 @@ public class DuPALAnalyzer {
          */
 
         int read, out_pins = 0;
-        for(int idx = 0; idx <= inmask; idx+=2) { // Pin 1 (bit 0 of the idx) is the clock and we'd skip it anyway, so we'll increment by 2
+        for(int idx = 0; idx <= inmask; idx++) { // Try all input combinations
             if((idx & ~inmask) != 0) continue; // We're trying to set a pin that is neither an input nor an IO
 
             if(out_pins == pspecs.getIO_READMask()) break; // Apparently we found that all the IOs are outputs...
@@ -165,7 +165,7 @@ public class DuPALAnalyzer {
             logger.info("run " + Integer.toHexString(idx >> 1) + " | inmask: 0x"+String.format("%06X", inmask)+" guessed outs: 0x" + String.format("%02X", out_pins) + " / " + Integer.toBinaryString(out_pins)+"b");
 
             int new_inmask, write_addr;
-            for(int i_idx = 0; i_idx <= inmask; i_idx+=2) { // Now, try all the input combinations for this state
+            for(int i_idx = 0; i_idx <= inmask; i_idx++) { // Now, try all the input combinations for this state
                 if((i_idx & ~inmask) != 0) continue; // We need to skip this round
                 if(out_pins == pspecs.getIO_READMask()) break; // Stop checking, we already found that all IOs are outputs...
                 
@@ -184,6 +184,9 @@ public class DuPALAnalyzer {
                 logger.debug("internal loop: " + Integer.toBinaryString(i_idx) + " outs:" + String.format("%02X", out_pins));
             }
 
+
+            if(pspecs.getCLKPinMask() == 0) break; // We have lo CLK pin, nothing to pulse, no need to try multiple states
+
             // pulse the clock to try and move to a random new state
             pulseClock(idx & ~pspecs.getOEPinMask());
         }
@@ -212,17 +215,17 @@ public class DuPALAnalyzer {
         logger.info("Device: " + pspecs + " Outs: " + Integer.toBinaryString(IOasOUT_Mask | pspecs.getOUT_READMask())+"b");
         int pins, mstate_idx;
 
-        writePINs(0x00); // Set the address to 0, enable the /OE pin and leave clock to low
+        writePINs(0x00); // Set the pins to to 0, this would leave the /OE pin and clock to low
         pins = readPINs();
 
         int rout_state = pins & pspecs.getROUT_READMask();
-        logger.info("Registered outputs at start: " + String.format("%02X", rout_state));
+        if(pspecs.getNumROUTPins() > 0) logger.info("Registered outputs at start: " + String.format("%02X", rout_state));
 
         mstate_idx = rout_state >> pspecs.getROUT_READMaskShift();
         MacroState ms = null, nms = null;
         
         if(mStates[mstate_idx] == null) {
-            ms = new MacroState(buildTag(mstate_idx), mstate_idx, pspecs.getNumROUTPins(), (pspecs.getNumINPins()  + pspecs.getNumIOPins() - additionalOUTs));
+            ms = new MacroState(buildTag(mstate_idx), mstate_idx, pspecs.getNumROUTPins(), (pspecs.getNumINPins()  + (pspecs.getNumIOPins() - additionalOUTs)));
             mStates[mstate_idx] = ms;
             logger.info("Added MacroState [" + ms + "] at index " + mstate_idx);
         } else {
@@ -504,6 +507,8 @@ public class DuPALAnalyzer {
 
         int idx_mask = buildInputMask();
 
+        if(pspecs.getNumROUTPins() == 0) return null; // We have no registered outputs, no need to check for other MacroStates
+
         logger.debug("Now check if we have a new StateLink to try...");
         if(ms.link_count == ms.links.length) return null;
 
@@ -523,7 +528,7 @@ public class DuPALAnalyzer {
             StateLink sl = null;
 
             if(nms == null) {
-                nms = new MacroState(buildTag(mstate_idx), mstate_idx, pspecs.getNumROUTPins(), (pspecs.getNumINPins() + pspecs.getNumIOPins() - additionalOUTs));
+                nms = new MacroState(buildTag(mstate_idx), mstate_idx, pspecs.getNumROUTPins(), (pspecs.getNumINPins() + (pspecs.getNumIOPins() - additionalOUTs)));
                 mStates[mstate_idx] = nms;
             }
             sl = new StateLink(ms.tag, ms.last_link_idx, nms);
@@ -552,7 +557,7 @@ public class DuPALAnalyzer {
     }
 
     private int buildInputMask() {
-        return (pspecs.getROUT_WRITEMask() | pspecs.getOEPinMask() | pspecs.getCLKPinMask() | (IOasOUT_Mask << PALSpecs.READ_WRITE_SHIFT));
+        return (pspecs.getROUT_WRITEMask() | pspecs.getOEPinMask() | pspecs.getCLKPinMask() | pspecs.getOUT_WRITEMask() | (IOasOUT_Mask << PALSpecs.READ_WRITE_SHIFT));
     }
 
     private boolean[] writeAddrToBooleans(int addr, int mask) {
@@ -629,7 +634,7 @@ public class DuPALAnalyzer {
         Byte[] out_state_arr = out_state.toArray(new Byte[out_state.size()]);
 
         int ss_idx = SubState.calculateSubStateIndex(instate);
-        int ss_key = SubState.calculateSubStateKey(iout_state_arr) ^ SubState.calculateSubStateKey(out_state_arr);
+        int ss_key = SubState.calculateHashFromArrays(new Byte[][] {iout_state_arr, out_state_arr});
             
         logger.debug("SubState index: " + ss_idx + " key: " + ss_key);
 
@@ -651,10 +656,9 @@ public class DuPALAnalyzer {
         logger.debug("Input mask " + Integer.toBinaryString(idx_mask) + "b");
 
         int maxidx = pspecs.getIO_WRITEMask() | pspecs.getINMask();
-        for(int idx = 0; idx <= maxidx; idx+=2) {
+        for(int idx = 0; idx <= maxidx; idx++) {
             if((idx & idx_mask) != 0) continue; // Skip this run
 
-            logger.debug("Testing combination 0x" + Integer.toHexString(idx));
             generateSubState(ms, idx, idx_mask);
         }
 
@@ -712,13 +716,13 @@ public class DuPALAnalyzer {
             out.write(("MacroState ["+mStates[ms_idx]+"]\n").getBytes(StandardCharsets.US_ASCII));
             out.write(("\tPrinting SubStates\n").getBytes(StandardCharsets.US_ASCII));
             for(int ss_idx = 0; ss_idx < mStates[ms_idx].substates.length; ss_idx++) {
-                out.write(("\t\tSubState ("+ss_idx+") ["+mStates[ms_idx].substates[ss_idx]+"]\n").getBytes(StandardCharsets.US_ASCII));
+                if(mStates[ms_idx].substates[ss_idx] != null) out.write(("\t\tSubState ("+ss_idx+") ["+mStates[ms_idx].substates[ss_idx]+"]\n").getBytes(StandardCharsets.US_ASCII));
             }
             out.write(("\n").getBytes(StandardCharsets.US_ASCII));
 
             out.write(("\tPrinting StateLinks\n").getBytes(StandardCharsets.US_ASCII));
             for(int sl_idx = 0; sl_idx < mStates[ms_idx].links.length; sl_idx++) {
-                out.write(("\t\tStateLink ("+sl_idx+") ["+mStates[ms_idx].links[sl_idx]+"] -> ["+mStates[ms_idx].links[sl_idx].destMS+"]\n").getBytes(StandardCharsets.US_ASCII));
+                if(mStates[ms_idx].links[sl_idx] != null) out.write(("\t\tStateLink ("+sl_idx+") ["+mStates[ms_idx].links[sl_idx]+"] -> ["+mStates[ms_idx].links[sl_idx].destMS+"]\n").getBytes(StandardCharsets.US_ASCII));
             }
             out.write(("\n").getBytes(StandardCharsets.US_ASCII));
         }
@@ -846,5 +850,7 @@ public class DuPALAnalyzer {
                 }
             }
         }
+
+        out.write(".e\n".getBytes(StandardCharsets.US_ASCII));
     }
 }

+ 109 - 0
src/main/java/info/hkzlab/dupal/analyzer/devices/PAL16L8Specs.java

@@ -0,0 +1,109 @@
+package info.hkzlab.dupal.analyzer.devices;
+
+public class PAL16L8Specs implements PALSpecs {
+    private static final String[] ROUT_PIN_NAMES = { null, null , null, null, null, null, null, null };
+    private static final String[] IN_PIN_NAMES = { "i1", "i2", "i3", "i4", "i5", "i6", "i7", "i8", "i9", "i11" };
+    private static final String[] IO_PIN_NAMES = { "io18", "io17", "io16", "io15", "io14", "io13", null, null };
+    private static final String[] OUT_PIN_NAMES = { null, null, null, null, null, null, "o19", "o12" };
+
+
+    @Override
+    public int getNumINPins() {
+        return 10;
+    }
+
+    @Override
+    public int getNumIOPins() {
+        return 6;
+    }
+
+    @Override
+    public int getNumROUTPins() {
+        return 0;
+    }
+
+    @Override
+    public int getNumOUTPins() {
+        return 2;
+    }
+    
+    @Override
+    public int getCLKPinMask() {
+        return 0x00;
+    }
+
+    @Override
+    public int getOEPinMask() {
+        return 0x00;
+    }
+
+    @Override
+    public int getINMask() {
+        return 0x000003FF;
+    }
+
+    @Override
+    public int getIO_READMask() {
+        return 0x3F;
+    }
+
+    @Override
+    public int getIO_WRITEMask() {
+        return getIO_READMask() << READ_WRITE_SHIFT;
+    }
+
+    @Override
+    public int getROUT_READMask() {
+        return 0x00;
+    }
+
+    @Override
+    public int getROUT_WRITEMask() {
+        return getROUT_READMask() << READ_WRITE_SHIFT;
+    }
+
+    @Override
+    public int getOUT_READMask() {
+        return 0xC0;
+    }
+
+    @Override
+    public int getOUT_WRITEMask() {
+        return getOUT_READMask() << READ_WRITE_SHIFT;
+    }
+
+    @Override
+    public String toString() {
+        return "PAL16L8";
+    }
+
+    @Override
+    public int getROUT_READMaskShift() {
+        return 0;
+    }
+
+    @Override
+    public String[] getROUT_PinNames() {
+        return ROUT_PIN_NAMES;
+    }
+
+    @Override
+    public String[] getIN_PinNames() {
+        return IN_PIN_NAMES;
+    }
+
+    @Override
+    public String[] getIO_PinNames() {
+        return IO_PIN_NAMES;
+    }
+
+    @Override
+    public String[] getOUT_PinNames() {
+        return OUT_PIN_NAMES;
+    }
+
+    @Override
+    public boolean isActiveLow() {
+        return true;
+    }
+}

+ 13 - 15
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/SubState.java

@@ -48,7 +48,19 @@ public class SubState implements Serializable {
 
     @Override
     public int hashCode() {
-        return calculateSubStateKey(IOpin_status) ^ calculateSubStateKey(Opin_status) ^ tag.hashCode();
+        return calculateHashFromArrays(new Byte[][] {IOpin_status, Opin_status});
+    }
+
+    static public int calculateHashFromArrays(Byte[][] arrays) {
+        int hash = 7;
+
+        for(Byte[] arr : arrays) {
+            for(int idx = 0; idx < arr.length; idx++) {
+                hash = hash*31 + arr[idx];
+            }
+        }
+
+        return hash;
     }
 
     @Override
@@ -74,18 +86,4 @@ public class SubState implements Serializable {
 
         return index;
     }
-
-    /**
-     * 
-     */
-    public static int calculateSubStateKey(final Byte[] out_comb) {
-        int hash = 0;
-
-        for(int idx = 0; idx < out_comb.length; idx++) {
-            int byte_idx = idx % 4;
-            hash ^= (out_comb[idx] & 0xFF) << (8 * byte_idx);
-        }
-
-        return hash;       
-    }
 }