]> jspc29.x-matter.uni-frankfurt.de Git - hades_mdc_settings.git/commitdiff
update scripts, libraries and settings files
authorJan Michel <michel@physik.uni-frankfurt.de>
Mon, 16 Jan 2023 15:34:53 +0000 (16:34 +0100)
committerJan Michel <michel@physik.uni-frankfurt.de>
Mon, 16 Jan 2023 15:34:53 +0000 (16:34 +0100)
scripts/MDC.pm
scripts/README.md
scripts/generate_address_settings.pl
scripts/generate_merged_settings.pl [moved from scripts/merge_and_flash_settings.pl with 86% similarity]
scripts/generate_pasttrec_settings.pl
scripts/load_flash_settings.pl [new file with mode: 0755]
settings_tdc/common_50_settingsselect.trbcmd
settings_tdc/final_99_init_pasttrec.trbcmd

index d705cfebe6d9ee95af83bb3f4038226370e636d4..f65bcea660d63db5978decffd6862c2e013dd1ae 100644 (file)
@@ -7,6 +7,12 @@ use Getopt::Long;
 use Data::Dumper;
 
 
+
+my $longboards = [[0,1,1,0,0,0,1,1,0,0,1,0,1,0],
+                  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],
+                  [1,0,0,0,0,1,1,0,0,0,0,1,0,1,1,0],
+                  [0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0]];  
+
 ###############################################################################
 #returns address of chip at (plane,sector,board,fpga)
 #fpga = 5 for OEP, 0..2 for TDC
@@ -14,7 +20,11 @@ use Data::Dumper;
 ###############################################################################
 sub get_address {
   my ($p,$s,$b,$e) = @_;
-
+  
+  if($e == 2) {
+    if($longboards->[$p][$b]==0) { return(0);}
+    }
+    
   if($e == 5) {
     return 0x8000 + ($p<2?0x0e00:0x0f00) + ($p%2 ? $s*16+96 : $s*16) + $b;
     }
@@ -25,7 +35,7 @@ sub get_address {
   
 ###############################################################################
 #returns the position of chip with (address) as (plane,sector,board,fpga)
-#all counting from 0
+#all counting from 0, assumes valid address
 ###############################################################################
 sub get_position {
   my $addr = shift @_;
@@ -45,9 +55,22 @@ sub get_position {
     $p = (($addr>>12)==0x01)?0:2;
     $p += 1 if (($addr>>8)&0xf)>=6;
     }
+    
+  if($e == 2) {
+    if($longboards->[$p][$b]==0) { return(-1,-1,-1,-1); }
+    }
   return ($p,$s,$b,$e);
   }
 
+###############################################################################
+#returns if board in given position (plane,sector,board,fpga) is a long one
+###############################################################################
+sub is_long_board {
+  my ($p,$s,$b,$e) = @_;
+  return $longboards->[$p][$b];
+  }
+  
+  
 ###############################################################################  
 #get the correct power output for MBO with (address).
 #returns (hostname,board,output)
index 0b6cfc94a528de3b0d900eb8f4318a0c916c4ade..1223e8e1a4e7f3d3092237eb7a9b0e67dbc7c455 100644 (file)
@@ -1,4 +1,4 @@
-#Scripts
+# Scripts
 
 * `generate_address_list.pl` takes the list of installed MBO serial numbers and generates the address.db file for DAQ
 * `generate_address_settings.pl` makes the files needed to automatically set the board addresses from Flash ROM
@@ -7,19 +7,21 @@
   * writes trbcmd files for later writing to Flash ROM
   * settings are written for boards currently in the system (otherwise serial number / uid can't be matched to addresses)
   * default PASTTREC registers are currently hardcoded (!)
-* `merge_and_flash_settings.pl` generates and loads settings from the 'settings' directory to the FPGAs flashes
+* `generate_merged_settings.pl` generates indiidual settings from the 'settings' directory
+* `load_flash_settings.pl` flashes settings to one or all FPGA
 
-##Pasttrec Settings
+## Pasttrec Settings
 * `pasttrec_set_threshold.pl` sets an identical threshold to all Pasttrec (temporarily)
 * `pasttrec_baseline_finder.pl` basic baseline finder script
 
-##Voltages
+## Voltages
 * `mdc_voltage.pl` set voltages and update voltage database file
 * `mdc_powerboard.pl` send commands to MDC power board
+* `check_voltages.pl` reads voltages and suggests changes
 
-#Packages
+# Packages
 * `MDC.pm` Library with common functions, like address lookup
 * `MDCPower.pm` Library with common functions related to power setting and switching
 
-#Notes
-All scripts assume that the daqtools repository is available next to this repository.
+# Notes
+All scripts assume that the daqtools and avr repositories are available next to this repository.
index f6c5e24369ea67ba8d8ab4c602ff2ee3a6f9757c..2de50c4efc7fc7e531fc4d83070c0a7507390d03 100755 (executable)
@@ -21,7 +21,7 @@ foreach my $uid (keys %$boards) {
   foreach my $k (keys %{$boards->{$uid}}) {
     my $addr = $boards->{$uid}{$k};
     
-    my $str = sprintf("0x%04x 0x7001 0x%08x\n", $addr, 0x80900000+$addr);
+    my $str = sprintf("0x7001 0x%08x\n", 0x80900000+$addr);
 
     my $filename = sprintf("../settings_oep/auto/%04x_02_network_address.trbcmd",$addr);
     open(FILE, '>', $filename) or die $!;
@@ -39,7 +39,7 @@ foreach my $uid (keys %$boards) {
   foreach my $k (keys %{$boards->{$uid}}) {
     my $addr = $boards->{$uid}{$k};
     
-    my $str = sprintf("0x%04x 0x7001 0x%08x\n", $addr, 0x80910000+$addr);
+    my $str = sprintf("0x7001 0x%08x\n", 0x80910000+$addr);
 
     my $filename = sprintf("../settings_tdc/auto/%04x_02_network_address.trbcmd",$addr);
     open(FILE, '>', $filename) or die $!;
similarity index 86%
rename from scripts/merge_and_flash_settings.pl
rename to scripts/generate_merged_settings.pl
index e9dbcfd6db2e5693142d062ade7566550f7e6dad..6033b597c31d430c5372a36a816e3a413fb09e32 100755 (executable)
@@ -10,16 +10,6 @@ use HADES::TrbNet;
 trb_init_ports() or die trb_strerror();
 
 
-sub get_file {
-  my $file = $_[0];
-  
-  local $/=undef;
-  open FILE, "$file" or die "Couldn't open file: $!";
-  my $string = <FILE>;
-  close FILE;
-  return $string;
-  }
-
 ###############################################################################
 #Find available boards & generate files for each of them
 ###############################################################################
@@ -37,7 +27,6 @@ my $boards = trb_register_read(0xfe91,0);
 foreach my $addr (keys %$boards) {
   my $filename = sprintf("%04x.trbcmd",$addr);
   my $saddr = sprintf("%04x",$addr);
-#   open(FILE, '>', $filename) or die $!;
 
   my @files;
   push(@files, sort grep { /\.\.\/settings_tdc\/auto\/common.*\.trbcmd/ } @inputs);
@@ -46,11 +35,11 @@ foreach my $addr (keys %$boards) {
   push(@files, sort grep { /\.\.\/settings_tdc\/$saddr.*\.trbcmd/ } @inputs);
   push(@files, sort grep { /\.\.\/settings_tdc\/auto\/final.*\.trbcmd/ } @inputs);
   push(@files, sort grep { /\.\.\/settings_tdc\/final.*\.trbcmd/ } @inputs);
-
+  next if scalar @files == 0;
   system("cat ".join(' ',@files)."> ../settings_merged/auto/$filename");
   
-  print Dumper @files;
-  print "----\n";
+  print Dumper @files;
+  print "----\n";
   }
   
 
@@ -59,7 +48,6 @@ $boards = trb_register_read(0xfe90,0);
 foreach my $addr (keys %$boards) {
   my $filename = sprintf("%04x.trbcmd",$addr);
   my $saddr = sprintf("%04x",$addr);
-#   open(FILE, '>', $filename) or die $!;
 
   my @files;
   push(@files, sort grep { /\.\.\/settings_oep\/auto\/common.*\.trbcmd/ } @inputs);
@@ -68,11 +56,11 @@ foreach my $addr (keys %$boards) {
   push(@files, sort grep { /\.\.\/settings_oep\/$saddr.*\.trbcmd/ } @inputs);
   push(@files, sort grep { /\.\.\/settings_oep\/auto\/final.*\.trbcmd/ } @inputs);
   push(@files, sort grep { /\.\.\/settings_oep\/final.*\.trbcmd/ } @inputs);
-
+  next if scalar @files == 0;
   system("cat ".join(' ',@files)."> ../settings_merged/auto/$filename");
   
-  print Dumper @files;
-  print "----\n";
+  print Dumper @files;
+  print "----\n";
   }
   
   
@@ -80,7 +68,8 @@ foreach my $addr (keys %$boards) {
 #Cleanup files
 ###############################################################################  
 foreach my $f (glob("../settings_merged/auto/*.trbcmd")) {
-  system("sed -i '/^\s*#/d' $f");
+#   print "Fix $f\n";
+  system("sed -i '/^\\s*#/d' $f");
 
   }
 
index 2462004f60fadfc5f8540ff24dca352404f18d75..fc76dbe483717ff10d2eb72451e844a77df00d27 100755 (executable)
@@ -133,7 +133,7 @@ if(! $NO_WRITE_FILES) {
   foreach my $a (keys %$settings) {
     my $str ="";
     foreach my $i (0..63) {
-      $str .= sprintf("0x%04x 0x%04x 0x%08x\n", $a, 0xa040+$i, $settings->{$a}[$i]);
+      $str .= sprintf("0x%04x 0x%08x\n", 0xa040+$i, $settings->{$a}[$i]);
       }
     my $filename = sprintf("../settings_tdc/auto/%04x_10_pasttrec_settings.trbcmd",$a);
     open(FILE, '>', $filename) or die $!;
diff --git a/scripts/load_flash_settings.pl b/scripts/load_flash_settings.pl
new file mode 100755 (executable)
index 0000000..cfa3f37
--- /dev/null
@@ -0,0 +1,84 @@
+#!/usr/bin/perl -w
+use warnings;
+no warnings "portable";
+use FileHandle;
+use Getopt::Long;
+use Data::Dumper;
+use HADES::TrbNet;
+use lib '.';
+use MDC;
+
+my $help;
+my $board;
+my $full;
+my $all;
+
+Getopt::Long::Configure(qw(gnu_getopt));
+GetOptions(
+           'help|h'      => \$help,
+           'board|b=s'   => \$board,
+           'full|f'      => \$full,
+           'all|a'       => \$all,
+          ) ;
+
+
+if($help) {
+print <<HELP;
+load_flash_settings.pl [(-board|-b) 0xnnnn ] [-f] [-a]
+
+Loads board settings to Flash. Either for given FPGA address, for all FPGA of a board (-f) or for all available FPGA (-a).
+HELP
+
+exit;
+}
+
+  
+if (defined $board){
+  $board = hex($board);
+
+  load_board($board);
+  
+  if(defined $full) {
+    my ($p,$s,$b,$e) = MDC::get_position($board);
+    load_board(MDC::get_address($p,$s,$b,0));
+    load_board(MDC::get_address($p,$s,$b,1));
+    load_board(MDC::get_address($p,$s,$b,2)) if MDC::is_long_board($p,$s,$b,2);
+    }
+  }
+  
+elsif (defined $all) {
+  trb_init_ports() or die trb_strerror();
+  my $boards = trb_read_uid(0xfe90);
+  foreach my $uid (keys %$boards) {
+    foreach my $k (keys %{$boards->{$uid}}) {
+      my $addr = $boards->{$uid}{$k};
+      load_board($addr);
+      }
+    }
+  $boards = trb_read_uid(0xfe91);
+  foreach my $uid (keys %$boards) {
+    foreach my $k (keys %{$boards->{$uid}}) {
+      my $addr = $boards->{$uid}{$k};
+      load_board($addr);
+      }
+    }
+  }
+  
+
+  
+  
+sub load_board {
+  my $board = $_[0];
+  my $sboard = sprintf('%04x',$board);
+  my $file = "../settings_merged/auto/$sboard.trbcmd";
+
+  if(! -e $file) {
+    print "\n\nERROR: No file for this board found: $sboard\n\n" ;
+    return;
+    }
+
+    
+  print "\nNote: Loading $sboard\n" ;
+  system("../../daqtools/tools/flash_settings.pl -y -p 0x3000 0x$sboard $file");
+  
+  }
index 11bf737009d31e99b6526b2dc6f22d20e895a409..33a5a83bc8fdcfea3e740f4c7c1ec3514e58534e 100644 (file)
@@ -1,3 +1,3 @@
 #Select memory location 40,50,60,70 for the four Pasttrec chips, activate autoload of 12 values
-0xfe91 0xa002 0x4c504c40
-0xfe91 0xa003 0x4c704c60
+0xa002 0x4c504c40
+0xa003 0x4c704c60
index edfcd575a567e0b4b301c9f11d887126e27a7c04..bd602eae75fdfd76e16d62c69fb8e12317a3dc92 100644 (file)
@@ -1 +1 @@
-0xfe91 0xaa00 0
+0xaa00 0