Bladeren bron

Optimize the IO guess code

Baglio Tabifata 4 jaren geleden
bovenliggende
commit
379564fdc0

+ 1 - 1
src/net/hkzlab/devices/PAL16R4Specs.java

@@ -39,7 +39,7 @@ public class PAL16R4Specs implements PALSpecs {
 
     @Override
     public int getIO_WRITEMask() {
-        return 0x00038400;
+        return getIO_READMask() << 10;
     }
 
     @Override

+ 1 - 1
src/net/hkzlab/devices/PAL16R6Specs.java

@@ -39,7 +39,7 @@ public class PAL16R6Specs implements PALSpecs {
 
     @Override
     public int getIO_WRITEMask() {
-        return 0x00030000;
+        return getIO_READMask() << 10;
     }
 
     @Override

+ 3 - 1
src/net/hkzlab/dupal/App.java

@@ -1,5 +1,6 @@
 package net.hkzlab.dupal;
 
+import net.hkzlab.devices.PAL16R4Specs;
 import net.hkzlab.devices.PAL16R6Specs;
 import net.hkzlab.devices.PALSpecs;
 import net.hkzlab.dupal.boardio.DuPALAnalyzer;
@@ -8,7 +9,8 @@ import net.hkzlab.dupal.boardio.DuPALManager;
 public class App {
     public static void main(String[] args) throws Exception {
         DuPALManager dpm = new DuPALManager("/dev/ttyUSB0");
-        PALSpecs pspecs = new PAL16R6Specs();
+        //PALSpecs pspecs = new PAL16R6Specs();
+        PALSpecs pspecs = new PAL16R4Specs();
         DuPALAnalyzer dpan = new DuPALAnalyzer(dpm, pspecs);
 
         if(!dpm.enterRemoteMode()) {

+ 16 - 11
src/net/hkzlab/dupal/boardio/DuPALAnalyzer.java

@@ -54,26 +54,31 @@ public class DuPALAnalyzer {
         logger.info("inmask: " + Integer.toHexString(inmask));
 
         int read, out_pins = 0;
-        for(int idx = 0; idx <= inmask; idx++) {
+        for(int idx = 0; idx <= inmask; idx+=2) { // Pin 1 is the clock and we'll skip it anyway
             if((idx & ~inmask) != 0) continue; // We need to skip this round
 
             if(out_pins == pspecs.getIO_READMask()) break; // Apparently we found that all the IOs are outputs...
 
-            logger.debug("run " + Integer.toHexString(idx >> 1) + " current guessed outs: 0x" + Integer.toHexString(out_pins) + " / " + Integer.toBinaryString(out_pins)+"b");
+            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");
 
-            for(int i_idx = 0; i_idx <= inmask; i_idx++) {
+            int new_inmask, write_addr;
+            for(int i_idx = 0; i_idx <= inmask; i_idx+=2) {
                 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...
-
-                logger.debug("internal loop: " + (i_idx >> 1));
-                
-                writePINs((i_idx | pspecs.getIO_WRITEMask()) & ~(pspecs.getOEPinMask() | pspecs.getCLKPinMask()));
-                read = readPINs();
-                out_pins |= (read ^ pspecs.getIO_READMask()) & pspecs.getIO_READMask();
                 
-                writePINs(i_idx & ~(pspecs.getOEPinMask() | pspecs.getCLKPinMask() | pspecs.getIO_WRITEMask()));
+                write_addr = i_idx & ~(pspecs.getOEPinMask() | pspecs.getCLKPinMask());
+                writePINs(write_addr);
                 read = readPINs();
-                out_pins |= ((read ^ ~pspecs.getIO_READMask())) & pspecs.getIO_READMask();
+                out_pins |= (read ^ (write_addr >> 10)) & pspecs.getIO_READMask();
+               
+                // Check if we need to update the input mask
+                new_inmask = inmask & ~(out_pins << 10);
+                if(new_inmask != inmask) {
+                    inmask = new_inmask;
+                    logger.info("Updated input mask, now -> " + String.format("%06X", inmask) + " outs: " + String.format("%02X", out_pins));
+                }
+                    
+                logger.debug("internal loop: " + Integer.toBinaryString(i_idx) + " outs:" + String.format("%02X", out_pins));
             }
 
             pulseClock(idx & ~pspecs.getOEPinMask());