]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
added loop over chains
authorIngo Froehlich <ingo@nomail.fake>
Mon, 13 May 2019 14:37:38 +0000 (16:37 +0200)
committerIngo Froehlich <ingo@nomail.fake>
Mon, 13 May 2019 14:37:38 +0000 (16:37 +0200)
tools/spi_slave.pl

index 7aa866adcf80700b0beeea229dad4a82e50a3145..39b6f620c7a307d34ed25651cc872ad3fbd8cbf3 100755 (executable)
@@ -22,7 +22,7 @@ if (!defined &trb_init_ports()) {
 my $help;
 
 my $endpoint;
-my $chain;
+my $rchain;
 my $channel;
 my $execute="";
 my $register;
@@ -53,9 +53,11 @@ my $READ  = 0x0<<20; # bits to set for a read command
 my $WRITE = 0x8<<20; # bits to set for a write command
 my $REGNR = 24; # number of bits to shift for the register number
 
+my $severe = 0;
+
 my $result = GetOptions (
                          "h|help"           => \$help,
-                         "c|chain=i"        => \$chain,
+                         "c|chain=s"        => \$rchain,
                          "n|channel=i"      => \$channel,
                          "e|endpoint=s"     => \$endpoint,
                          "x|execute=s"      => \$execute,
@@ -167,7 +169,7 @@ EOF
   exit;
 }
 
-if ($help || !defined $endpoint || !defined $chain) {
+if ($help || !defined $endpoint || !defined $rchain) {
   usage();
 }
 
@@ -176,7 +178,7 @@ if (defined $enablecfgflash and (defined $erasecfgflash or defined $dumpcfgflash
 }
 
 $endpoint       = &conv_input_string_to_number($endpoint,       "endpoint", "hex");
-$chain          = &conv_input_string_to_number($chain,          "chain");
+#$chain          = &conv_input_string_to_number($chain,          "chain");
 $register       = &conv_input_string_to_number($register,       "register")       if (defined $register);
 $channel        = &conv_input_string_to_number($channel,        "channel")        if (defined $channel);
 $data           = &conv_input_string_to_number($data,           "data")           if (defined $data);
@@ -187,10 +189,17 @@ $enablecfgflash = &conv_input_string_to_number($enablecfgflash, "enablecfgflash"
 $rr             = &conv_input_string_to_number($rr,             "readreg")        if (defined $rr);
 $wr             = &conv_input_string_to_number($wr,             "writereg")       if (defined $wr);
 
+my $sendcmd_executed_once = 0;
 
 #print "execute: $execute\n";
 #exit;
 
+my $chain = 0;
+
+my @qchain = (eval $rchain);
+foreach my $dchain (@qchain) {
+    $chain = $dchain;
+    #printf("*** %i \n", $chain);
 
 sub sendcmd16 {
   my @cmd = @_;
@@ -200,7 +209,7 @@ sub sendcmd16 {
   usleep(1000);
 }
 
-my $sendcmd_executed_once = 0;
+
 sub sendcmd {
   my ($cmd) = @_;
   $sendcmd_executed_once = 1;
@@ -393,25 +402,35 @@ if (defined $flashcmd) {
 sub checkcfgflash {
     my $b = sendcmd(0x5C<<$REGNR | $READ);
     foreach my $e (sort keys %$b) {
-       printf(" %x ",$b->{$e}&0xfff);
+       #printf(" %x ",$b->{$e}&0xfff);
        if (($b->{$e}&0xfff) ne 0x101) {
-           die "config flash not enabled";
+           if ($severe eq 0) {
+               die "config flash not enabled, maybe timeout? \n";
+           } else {
+               printf(" ************************************** \n");
+               printf(" a severe error happened !!! \n");
+               printf(" most likely the cfg flash is corrupted\n");
+               printf(" don't make a power cycle unless the\n");
+               printf(" problem is solved\n");
+               printf(" **************************************\n");
+               die;
+           }
        }
     }
 }
 
 sub enableccfgflash {
-    sendcmd(0x51<<$REGNR | $WRITE | 0x8);
-    sendcmd(0x50<<$REGNR | $WRITE | 0x0);
     sendcmd(0x5C<<$REGNR | $WRITE | 0x103);
     sendcmd(0x5C<<$REGNR | $WRITE | 0x105);
     sendcmd(0x5C<<$REGNR | $WRITE | 0x101);
+    sendcmd(0x51<<$REGNR | $WRITE | 0x8);
+    sendcmd(0x50<<$REGNR | $WRITE | 0x0);
 }
 
 sub enableuserflash {
+    sendcmd(0x5C<<$REGNR | $WRITE | 0x100);
     sendcmd(0x51<<$REGNR | $WRITE | 0x8);
     sendcmd(0x50<<$REGNR | $WRITE | 0x0);
-    sendcmd(0x5C<<$REGNR | $WRITE | 0x100);
 }
 
 if ($execute eq "enableccfgflash" | defined $enablecfgflash) {
@@ -496,6 +515,8 @@ if ($execute eq "writecfgflash" | defined $writecfgflash) {
        printf(" busy - try again\n");
        usleep(300000);
     }
+    $severe=1;
+    checkcfgflash();
     my $p = 0;
     while (my $s = <INF>) {
        my @t = split(' ',$s);
@@ -523,6 +544,7 @@ if ($execute eq "writecfgflash" | defined $writecfgflash) {
         }
 
         #flash only if RAM ok
+       checkcfgflash();
         sendcmd(0x51<<$REGNR | $WRITE | 0x4);
         sendcmd(0x50<<$REGNR | $WRITE | $p);
        
@@ -749,6 +771,7 @@ if ($execute eq "fifo" || $execute eq "ffarr") {
   }
 }
 
+}
 
 if ($sendcmd_executed_once == 0) {
   print "no command was executed. Given command \"$execute\" seems to be unknown. use \"-h\" for help.\n";