]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
added verify
authorIngo Froehlich <ingo@nomail.fake>
Fri, 25 Jan 2019 12:20:50 +0000 (13:20 +0100)
committerIngo Froehlich <ingo@nomail.fake>
Fri, 25 Jan 2019 12:20:50 +0000 (13:20 +0100)
tools/spi_slave.pl

index 38c71146b73a9b43734653f2adc05074d8a13395..985a037637a3be83e56feb1bbb7b643d52e9e09f 100755 (executable)
@@ -35,6 +35,8 @@ my $enablecfgflash;
 my $dumpcfgflash;
 my $erasecfgflash;
 my $writecfgflash;
+my $verifycfgflash;
+my $verify;
 my $dumpuserflash;
 my $writeuserflash;
 my $rr;
@@ -68,6 +70,8 @@ my $result = GetOptions (
                          "dumpcfgflash"     => \$dumpcfgflash,
                          "erasecfgflash"    => \$erasecfgflash,
                          "writecfgflash"    => \$writecfgflash,
+                         "verifycfgflash"   => \$verifycfgflash,
+                         "verifypage"       => \$verify,
                          "dumpuserflash:s"  => \$dumpuserflash,
                          "writeuserflash:s" => \$writeuserflash,
                          "eraseuserflash"   => \$eraseuserflash,
@@ -473,12 +477,31 @@ if ($execute eq "writecfgflash" | defined $writecfgflash) {
     while (my $s = <INF>) {
        my @t = split(' ',$s);
        my @a;
-       for (my $i=0;$i<16;$i++) {
-           push(@a,0x40<<$REGNR | $i << $REGNR | $WRITE | (hex($t[$i+1]) & 0xff));
-       }
-       sendcmd16(@a);
-       sendcmd(0x51<<$REGNR | $WRITE | 0x4);
-       sendcmd(0x50<<$REGNR | $WRITE | $p);
+        my $ok = 0;
+        while ($ok eq 0) {
+            for (my $i=0;$i<16;$i++) {
+                push(@a,0x40<<$REGNR | $i << $REGNR | $WRITE | (hex($t[$i+1]) & 0xff));
+            }
+            sendcmd16(@a);
+
+            $ok = 1;
+            #page verify
+            if (defined($verify)) {
+                for (my $i=0;$i<16;$i++) {
+                    my $b = sendcmd( (0x40+$i)<<$REGNR | $READ );
+                    foreach my $e (sort keys %$b) {
+                        if (($b->{$e} & 0xff) ne (hex($t[$i+1]) & 0xff)) {
+                            printf("\nByte %i differs in page %x: %02x %02x -> REDO page\n", $i, $p, $b->{$e}&0xff, hex($t[$i+1]) & 0xff);
+                            $ok = 0;
+                        }
+                    }
+                }
+            }
+        }
+
+        #flash only if RAM ok
+        sendcmd(0x51<<$REGNR | $WRITE | 0x4);
+        sendcmd(0x50<<$REGNR | $WRITE | $p);
        
        $p++;
        printf(STDERR "\r%d ",$p) if(!($p%10));
@@ -501,6 +524,60 @@ if ($execute eq "writecfgflash" | defined $writecfgflash) {
     } 
 }
 
+if ($execute eq "verifycfgflash" | defined $verifycfgflash) {
+    printf("Verify with file: %s \n", $filename);
+    if (!defined($filename)) {$filename=$verifycfgflash;}
+    if (!defined $filename) {
+        die "for the command verifycfgflash an option or --filename is missing.\n";
+    }
+    if (length($filename)==0) {
+        die "for the command verifycfgflash an option or --filename is missing.\n";
+    }
+    open(INF, $filename) or die "verifycfgflash: Couldn't read file : $filename\n";
+    my $b = sendcmd(0xFF<<$REGNR | $READ);
+    my $version = $b->{$endpoint};
+    if (($version & 0xFF00) eq 0x100) {
+       printf("Dirich2 threshold FGPA detected.\n");
+    } elsif (($version & 0xFF00) eq 0x200) {
+       printf("Padiwa amps2 detected.\n");
+    } else {
+       die "No valid SPI slave detected";
+    }
+
+    my $p = 0;
+    my $ok = 1;
+    while (my $s = <INF>) {
+               my @t = split(' ',$s);
+
+       sendcmd(0x51<<$REGNR | $WRITE | 0x0);
+       sendcmd(0x50<<$REGNR | $WRITE | $p);      # read page $p
+#      printf("0x%04x:\t",$p);
+       for (my $i=0;$i<16;$i++) {
+           my $b = sendcmd( (0x40+$i)<<$REGNR | $READ );
+           foreach my $e (sort keys %$b) {
+               if (($b->{$e} & 0xff) ne (hex($t[$i+1]) & 0xff)) {
+                    printf("\nByte %i differs in page %x: flash: %02x file: %02x\n", $i, $p, $b->{$e}&0xff, hex($t[$i+1]) & 0xff);
+                    $ok = 0;
+                }
+           }
+       }
+#      printf("\n");
+       printf(STDERR "\r%d",$p) if(!($p%10));
+       
+#      my @a;#
+#      for (my $i=0;$i<16;$i++) {
+#          push(@a,0x40<<$REGNR | $i << $REGNR | $WRITE | (hex($t[$i+1]) & 0xff));
+#      }
+       
+        $p++;
+    } 
+    if ($ok eq 0) {
+        printf("\nVerification failed!!!\n");
+    } else {
+        printf("\nVerification OK\n");
+    }
+}
+
 ###############################################################################
 
 sub eraseuserflash {