use Storable;
my $openocd_remote = shift @ARGV || 'picam:4444';
-my $bsdl_file = $ENV{BSDL} || '_3128at100.bsd';
-#$bsdl_file = '3064at44.bsd'; # XXX
-my $tap = $ENV{TAP} || 'x300.tap';
+my $bsdl_file = $ENV{BSDL} ||
+ 'EP4CE6E22.bsd';
+# '_3128at100.bsd';
+# '3064at44.bsd'; # XXX
+my $tap = $ENV{TAP} || 'tb276.tap';
my $BOUNDARY_LENGTH = 288;
my $entity;
my $io2bit;
my $pin2io;
-my $in_pin_map = 0;
-my $pin_map = '';
+my $parse;
+my $parse_in = 0;
+my $parse_regex = join('|', qw(
+ PIN_MAP_STRING
+ INSTRUCTION_OPCODE
+));
$|=1; # flush stdout
open(my $bsdl, '<', $bsdl_file);
while(<$bsdl>) {
- if ( m/PIN_MAP_STRING/ ) {
- $pin_map .= $_;
- $in_pin_map = 1;
- } elsif ( $in_pin_map ) {
+ if ( m/($parse_regex)/ ) {
+ $parse_in = $1;
+ $parse->{$1} .= $_;
+ } elsif ( $parse_in ) {
next if m/^\s*--/;
- $pin_map .= $_;
- $in_pin_map = 0 if m/;/;
+ $parse->{$parse_in} .= $_;
+ $parse_in = 0 if m/;/;
} elsif ( m/"(\d+)\s+\(BC_\d+,\s+(\S+),\s+(\S+)/ ) {
$bit2pin->{$1} = [ $2, $3 ];
push @{ $io2bit->{$2} }, $1;
warn "# bit2pin = ",dump($bit2pin);
warn "# io2bit = ",dump($io2bit);
-$pin_map =~ s/"\s*\&\s*"/ /gs;
-$pin_map =~ s/^.*?:=\s*"//;
-$pin_map =~ s/"\s*;\s*$//s;
+foreach my $chunk ( keys %$parse ) {
+ $parse->{$chunk} =~ s/"\s*\&\s*"/ /gs; # concat lines back to single line
+ $parse->{$chunk} =~ s/^.+?"//s; # strip upto first quote
+ $parse->{$chunk} =~ s/"\s*;.*?$//s; # strip everything after closing
+ $parse->{$chunk} =~ s/\s+/ /gs;
+}
+
+warn "# parse = ",dump($parse);
+
+my $pin_map = $parse->{PIN_MAP_STRING} || die "no PIN_MAP_STRING in ",dump($parse);
sub str_comma {
my $t = shift;
#store \$pin2io, $bsdl_file . '.pin2io.storable';
store \$pin2io, $entity . '.pin2io.storable';
+
+my $opcode;
+my $o = $parse->{INSTRUCTION_OPCODE} || die "no INSTRUCTION_OPCODE in ",dump($parse);
+warn "XXX [$o]";
+
+foreach ( split(/\)\s*,\s*/, $o) ) {
+ s/\s+\(/ /g;
+ s/\s*\)\s*$//g;
+ warn "XXX [$_]\n";
+ my ( $inst_opcode, $bin ) = split(/\s+/, $_);
+ $opcode->{$inst_opcode} = sprintf "0x%02x", eval '0b' . $bin;
+}
+warn "# opcode = ",dump($opcode);
+
+foreach (qw(SAMPLE EXTEST)) {
+ die "missing INSTRUCTION_OPCODE $_ in ",dump($opcode) unless $opcode->{$_};
+}
+
my $pin_desc;
foreach my $pin_file ( glob "pins/$entity*.tsv" ) {
open(my $fh, '<', $pin_file);
my $BSR;
# first sample
-print $sock "irscan $tap 0x55\n"; # SAMPLE/PRELOAD
+print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD
print $sock "drscan $tap $BOUNDARY_LENGTH 0\n";
while(1) {
diff_bits( $BSR, $b ), $/;
-# print $sock "irscan $tap 0x55\n"; # SAMPLE/PRELOAD
+# print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD
print $sock "drscan $tap $BOUNDARY_LENGTH 0x", bin2hex($b), "\n";
- print $sock "irscan $tap 0x00\n"; # EXTEST
+ print $sock "irscan $tap $opcode->{EXTEST}\n"; # EXTEST
# print $sock "drscan $tap $BOUNDARY_LENGTH 0x", bin2hex($b), "\n";
} elsif ( $cmd =~ m/\?/ ) {
$last_bits = '';
- print $sock "irscan $tap 0x55\n"; # SAMPLE/PRELOAD
+ print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD
print $sock "drscan $tap $BOUNDARY_LENGTH 0\n";
} else {
gpio::cmd( $cmd );
- print $sock "irscan $tap 0x55\n"; # SAMPLE/PRELOAD
+ print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD
print $sock "drscan $tap $BOUNDARY_LENGTH 0\n";
}