]> jspc29.x-matter.uni-frankfurt.de Git - hades_mdc_settings.git/commitdiff
add first scripts to generate and load pasttrec settings from db file
authorJan Michel <j.michel@gsi.de>
Mon, 22 Aug 2022 07:47:50 +0000 (09:47 +0200)
committerJan Michel <j.michel@gsi.de>
Mon, 22 Aug 2022 07:47:50 +0000 (09:47 +0200)
12 files changed:
pasttrec/pasttrec_baseline.db
scripts/README.md
scripts/generate_address_settings.pl [new file with mode: 0755]
scripts/generate_pasttrec_settings.pl [new file with mode: 0755]
scripts/merge_and_flash_settings.pl [new file with mode: 0755]
settings/README.md [deleted file]
settings_oep/.gitignore [moved from settings/.gitignore with 85% similarity]
settings_oep/README.md [new file with mode: 0644]
settings_tdc/.gitignore [new file with mode: 0644]
settings_tdc/README.md [new file with mode: 0644]
settings_tdc/common_50_settingsselect.trbcmd [new file with mode: 0644]
settings_tdc/final_99_init_pasttrec.trbcmd [new file with mode: 0644]

index 86afaacba9151cf40b49013ab7f30ff308fcf76f..bf7c53ab878967a7c416e258e23ec93d934b0734 100644 (file)
    60031      2       0x04     0x04     0x04     0x04     0x04     0x04     0x04     0x04
    60031      3       0x01     0x01     0x01     0x01     0x01     0x01     0x01     0x01
 
+   70031      0       0x02     0x02     0x02     0x02     0x02     0x02     0x02     0x02
+   70031      1       0x03     0x03     0x03     0x03     0x03     0x03     0x03     0x03
+   70031      2       0x04     0x04     0x04     0x04     0x04     0x04     0x04     0x04
+   70031      3       0x01     0x01     0x01     0x01     0x01     0x01     0x01     0x01
    
+   60161      0       0x02     0x02     0x02     0x02     0x02     0x02     0x02     0x02
+   60161      1       0x03     0x03     0x03     0x03     0x03     0x03     0x03     0x03
+#   60161      2       0x04     0x04     0x04     0x04     0x04     0x04     0x04     0x04
+   60161      3       0x01     0x01     0x01     0x01     0x01     0x01     0x01     0x01
+
+#   70161      0       0x02     0x02     0x02     0x02     0x02     0x02     0x02     0x02
+#   70161      1       0x03     0x03     0x03     0x03     0x03     0x03     0x03     0x03
+#   70161      2       0x04     0x04     0x04     0x04     0x04     0x04     0x04     0x04
+#   70161      3       0x01     0x01     0x01     0x01     0x01     0x01     0x01     0x01
index f809f1677ad2012ae58169453662344cd2940f49..47d732346c8730c26104ac8a6e794575d31a5e0d 100644 (file)
@@ -1,5 +1,15 @@
-##Scripts
+#Scripts#
 
-* `XYZ` generates trbcmd files from the common baseline database
-* `ABC` generates and loads settings from the 'settings' directory to the FPGAs flashes
-* `DEF` loads all settings from the 'settings' directory to the FPGA directly
+* `generate_pasttrec_settings.pl` prepares data from common baseline database
+ * loads settings to FPGA directly
+ * 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_address_settings.pl` makes the files needed to automatically set the board addresses from Flash ROM
+
+
+##Notes##
+All scripts assume that the daqtool repository is available next to this repository.
diff --git a/scripts/generate_address_settings.pl b/scripts/generate_address_settings.pl
new file mode 100755 (executable)
index 0000000..c81c4cc
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/perl -w
+use warnings;
+no warnings "portable";
+use FileHandle;
+use Getopt::Long;
+use Data::Dumper;
+use HADES::TrbNet;
+
+my $DEBUG = 0;       #print debug messages
+trb_init_ports() or die trb_strerror();
+
+###############################################################################
+#Find available boards & write address setting files for each of them
+###############################################################################
+system("mkdir -p ../settings_oep/auto");
+system("rm ../settings_oep/auto/????_02_network_address.trbcmd");
+
+my $boards = trb_read_uid(0xfe90);
+
+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, 0x80000000+$addr);
+
+    my $filename = sprintf("../settings_oep/auto/%04x_02_network_address.trbcmd",$addr);
+    open(FILE, '>', $filename) or die $!;
+    print FILE $str;
+    close FILE;    
+    }
+  }
+
+system("mkdir -p ../settings_tdc/auto");  
+system("rm ../settings_tdc/auto/????_02_network_address.trbcmd");
+
+$boards = trb_read_uid(0xfe91);
+
+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, 0x80000000+$addr);
+
+    my $filename = sprintf("../settings_tdc/auto/%04x_02_network_address.trbcmd",$addr);
+    open(FILE, '>', $filename) or die $!;
+    print FILE $str;
+    close FILE;    
+    }
+  }  
diff --git a/scripts/generate_pasttrec_settings.pl b/scripts/generate_pasttrec_settings.pl
new file mode 100755 (executable)
index 0000000..d9d26d5
--- /dev/null
@@ -0,0 +1,120 @@
+#!/usr/bin/perl -w
+use warnings;
+no warnings "portable";
+use FileHandle;
+use Getopt::Long;
+use Data::Dumper;
+use HADES::TrbNet;
+
+my $DEBUG = 0;       #print debug messages
+my $LOAD_DIRECT = 1; #load settings and initialize 
+my $WRITE_FILES = 1; #write configration files
+
+my @default_settings = (0x50018,
+                        0x5011e,
+                        0x50215,
+                        0x5030a,
+                        0x50400,0x50500,0x50600,0x50700,0x50800,0x50900,0x50a00,0x50b00,
+                        0,0,0,0);
+
+
+my $baselines; #serial->pt->@baselines (in hex!)
+my $serials;   #uid -> serial
+my $addresses; #addr -> serial
+my $settings;  #addr -> @registers(0xa040-0xa07F)
+
+###############################################################################
+#Read baseline file and store values
+###############################################################################
+open FILE, "../pasttrec/pasttrec_baseline.db" or die $!."\npasttrec_baseline.db not found.";
+while (my $a = <FILE>) {
+  if(my @values = $a =~ /^\s*(\d+)\s+(\d)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s+0x(\w\w)\s*$/) {
+    my $s = shift @values;
+    my $pt = shift @values;
+    $baselines->{$s}{$pt}=\@values;
+    }
+  }
+close FILE;
+
+###############################################################################
+#Read serials file and store values
+###############################################################################
+open FILE, "../serials/serials_mdcmbo.db" or die $!."\nserials_mdcmbo.db not found.";
+while (my $a = <FILE>) {
+  if(my @values = $a =~ /^\s*(\d+)\s+0x([\w]{16})\s*$/) {
+    my $s   = shift @values;
+    my $uid = shift @values;
+    $serials->{hex($uid)} = $s;
+    }
+  }
+close FILE;
+
+###############################################################################
+#Find available boards
+###############################################################################
+trb_init_ports() or die trb_strerror();
+my $boards = trb_read_uid(0xfe91);
+foreach my $uid (keys %$boards) {
+  foreach my $k (keys %{$boards->{$uid}}) {
+    $addresses->{$boards->{$uid}{$k}} = $serials->{$uid};
+    }
+  }
+
+###############################################################################
+#Loop over available boards, generate settings for each
+###############################################################################
+foreach my $a (keys %$addresses) {
+  if(!defined $baselines->{$addresses->{$a}}) {
+    printf("Baselines for FPGA %04x not found.\n",$a);
+    }
+  else {
+    printf("board %04x found.\n",$a) if $DEBUG;
+    foreach my $pt (0..3) {                                      #for each PT
+      foreach my $i (0..15) {                                    #copy default settings
+        $settings->{$a}[$pt*16+$i] = $default_settings[$i];
+        }
+      if(!defined $baselines->{$addresses->{$a}}{$pt}) {
+        printf("Baseline for FPGA %04x, PT %i not found.\n",$a,$pt);
+        }
+      else{  
+        foreach my $i (0..7) {                                     #replace baselines
+          my $t  = $settings->{$a}[$pt*16+4+$i];
+            $t &= 0xFFF00;
+            $t += hex($baselines->{$addresses->{$a}}{$pt}[$i]);
+          $settings->{$a}[$pt*16+4+$i] = $t;
+          }
+        }  
+      }
+    }
+  }
+  
+############################################################################### 
+#Load settings via trbcmd
+###############################################################################
+if($LOAD_DIRECT) {
+  foreach my $a (keys %$settings) {
+    trb_register_write_mem($a,0xa002,0,[0x4c504c40,0x4c704c60],2);#set register sets
+    trb_register_write_mem($a,0xa040,0,$settings->{$a},64);       #write settings
+    trb_register_write($a,0xaa00,1);                              #init Pasttrec
+    }
+  }
+
+###############################################################################
+#Write configuration files
+###############################################################################
+if($WRITE_FILES) {
+  system("mkdir -p ../settings_tdc/auto");
+  system("rm ../settings_tdc/auto/????_10_pasttrec_settings.trbcmd");
+  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]);
+      }
+    my $filename = sprintf("../settings_tdc/auto/%04x_10_pasttrec_settings.trbcmd",$a);
+    open(FILE, '>', $filename) or die $!;
+    print FILE $str;
+    close FILE;
+    }
+  }
+
+
diff --git a/scripts/merge_and_flash_settings.pl b/scripts/merge_and_flash_settings.pl
new file mode 100755 (executable)
index 0000000..e69de29
diff --git a/settings/README.md b/settings/README.md
deleted file mode 100644 (file)
index 5bfb4b9..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-##Temporary Files to be loaded to Flash
-
-* All settings that should be stored in Flash need to be present in this directory.
-* All files should be valid trbcmd files that can be loaded directly with `trbcmd -f`
-
-* Filenames need to start with the four digits (lower case) of the board address they should be loaded to.
-* Extension of all files should be .trbcmd.
-* Multiple files for the same target can exist with arbitrary additional characters in the file name.
-* Automatically generated files should have a filename ending in 'baseline' or 'auto' to be ignored by git.
-
-* Files that start with "common" are loaded to all boards. 
-* Common files are loaded first, so that settings can be overwritten with addressed files
-
-* Manually created files should be added to the git repository. Automatically generated files (e.g. baselines) should not be added.
-
similarity index 85%
rename from settings/.gitignore
rename to settings_oep/.gitignore
index ee72d9412664baa685f03c1ce60a514b1e7d2894..b962241eec6b92461b0fd8ce92141927ec25e3f8 100644 (file)
@@ -1,2 +1,3 @@
 *baseline.trbcmd
 *auto.trbcmd
+auto
diff --git a/settings_oep/README.md b/settings_oep/README.md
new file mode 100644 (file)
index 0000000..3daa85d
--- /dev/null
@@ -0,0 +1,24 @@
+##Temporary Files to be loaded to Flash##
+
+* All settings that should be stored in Flash need to be present in this directory.
+* All files should be valid trbcmd files that can be loaded directly with `trbcmd -f`
+
+* Filenames need to start with the four digits (lower case) of the board address they should be loaded to.
+* Filenames starting with "common" or "final" are loaded to all boards. 
+* Extension of all files should be .trbcmd.
+* Multiple files for the same target can exist with arbitrary additional characters in the file name.
+ * files in the same group are loaded in alphabetic order. Add a two digit number in front of the descriptive text for obvious sorting order.
+
+* Automatically generated files will be in the "auto" directory.
+* Manually created files should be added to the git repository. Automatically generated files (e.g. baselines) should not be added.
+
+###Loading Order###
+ * "common" files in the auto directory
+ * "common" files in the main directory  (so that settings can be overwritten with addressed files)
+ * Addressed files in the auto directory
+ * Addressed files in the main directory
+ * "final" files in the auto directory
+ * "final" files in the main directory
+
+Within each group, files are sorted alphabetically, e.g. 2123_10_xyz.trbcmd will be loaded before 2123_99_abc.trbcmd
+
diff --git a/settings_tdc/.gitignore b/settings_tdc/.gitignore
new file mode 100644 (file)
index 0000000..b962241
--- /dev/null
@@ -0,0 +1,3 @@
+*baseline.trbcmd
+*auto.trbcmd
+auto
diff --git a/settings_tdc/README.md b/settings_tdc/README.md
new file mode 100644 (file)
index 0000000..3daa85d
--- /dev/null
@@ -0,0 +1,24 @@
+##Temporary Files to be loaded to Flash##
+
+* All settings that should be stored in Flash need to be present in this directory.
+* All files should be valid trbcmd files that can be loaded directly with `trbcmd -f`
+
+* Filenames need to start with the four digits (lower case) of the board address they should be loaded to.
+* Filenames starting with "common" or "final" are loaded to all boards. 
+* Extension of all files should be .trbcmd.
+* Multiple files for the same target can exist with arbitrary additional characters in the file name.
+ * files in the same group are loaded in alphabetic order. Add a two digit number in front of the descriptive text for obvious sorting order.
+
+* Automatically generated files will be in the "auto" directory.
+* Manually created files should be added to the git repository. Automatically generated files (e.g. baselines) should not be added.
+
+###Loading Order###
+ * "common" files in the auto directory
+ * "common" files in the main directory  (so that settings can be overwritten with addressed files)
+ * Addressed files in the auto directory
+ * Addressed files in the main directory
+ * "final" files in the auto directory
+ * "final" files in the main directory
+
+Within each group, files are sorted alphabetically, e.g. 2123_10_xyz.trbcmd will be loaded before 2123_99_abc.trbcmd
+
diff --git a/settings_tdc/common_50_settingsselect.trbcmd b/settings_tdc/common_50_settingsselect.trbcmd
new file mode 100644 (file)
index 0000000..11bf737
--- /dev/null
@@ -0,0 +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
diff --git a/settings_tdc/final_99_init_pasttrec.trbcmd b/settings_tdc/final_99_init_pasttrec.trbcmd
new file mode 100644 (file)
index 0000000..edfcd57
--- /dev/null
@@ -0,0 +1 @@
+0xfe91 0xaa00 0