fix pin manipulation
[x300-pci] / openocd-jtag-boundary-scan.pl
index dafd874..acb4a5d 100755 (executable)
@@ -9,6 +9,7 @@ use Storable;
 
 my $openocd_remote = shift @ARGV || 'picam:4444';
 
+
 my $bit2pin;
 my $io2bit;
 
@@ -70,6 +71,8 @@ sub print_io {
        my $bits = shift;
        $bits = reverse $bits; # make substr work as expected
 
+       return if $last_bits eq $bits;
+
        print "pin off io___ ICO prv | " x 4, $openocd_remote,"\n";
        foreach my $i ( 0 .. ($#$pin2io/4)-1 ) {
                foreach my $j ( 0 .. 3 ) {
@@ -154,9 +157,17 @@ sub diff_bits {
        print "# diff_bits $diff\n";
 }
 
-print "[press enter]\n";
-my $cmd = <STDIN>;
+my $cmd = '';
+if ( $ENV{SLEEP} ) {
+       sleep $ENV{SLEEP};
+       $cmd = <DATA>;
+       exit if ! $cmd;
+} else {
+       print "[press enter]\n";
+       $cmd = <STDIN>;
+}
 chomp $cmd;
+
 if ( $cmd =~ /(\d+)=(\d)/ ) {
        my ( $pin, $v ) = ( $1, $2 );
        warn "# pin $pin = $v\n";
@@ -164,11 +175,14 @@ if ( $cmd =~ /(\d+)=(\d)/ ) {
        my $io = $pin2io->[$pin];
        my $bit = $io2bit->{$io}->[0];
 
-       my $b = substr($BSR,0,$bit+1)
-               . ( substr($BSR,$bit+1,1) ^ 1 )
+       my $old_bsr = reverse $BSR;
+
+       my $b = substr($old_bsr,0,$bit+1)
+               . ( substr($old_bsr,$bit+1,1) ^ 1 )
                . ( $v & 1 )
-               . substr($BSR,$bit+3)
+               . substr($old_bsr,$bit+3)
                ;
+       $b = reverse $b;
 
        diff_bits( $BSR, $b ), $/;
 
@@ -183,3 +197,73 @@ if ( $cmd =~ /(\d+)=(\d)/ ) {
 
 
 }#while(1)
+
+__DATA__
+5=1
+a
+b
+c
+d
+e
+f
+a
+a
+a
+a
+a
+a
+a
+a
+a
+b
+c
+d
+e
+f
+b
+c
+d
+e
+f
+b
+c
+d
+e
+f
+b
+c
+d
+e
+f
+b
+c
+d
+e
+f
+b
+c
+d
+e
+f
+b
+c
+d
+e
+f
+b
+c
+d
+e
+f
+b
+c
+d
+e
+f
+5=0
+a
+b
+c
+d
+e
+f