From c642d871f8fb6b3e85cec373646d018c34f6a03f Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Mon, 22 Aug 2022 09:47:50 +0200 Subject: [PATCH] add first scripts to generate and load pasttrec settings from db file --- pasttrec/pasttrec_baseline.db | 13 ++ scripts/README.md | 18 ++- scripts/generate_address_settings.pl | 49 ++++++++ scripts/generate_pasttrec_settings.pl | 120 +++++++++++++++++++ scripts/merge_and_flash_settings.pl | 0 settings/README.md | 15 --- {settings => settings_oep}/.gitignore | 1 + settings_oep/README.md | 24 ++++ settings_tdc/.gitignore | 3 + settings_tdc/README.md | 24 ++++ settings_tdc/common_50_settingsselect.trbcmd | 3 + settings_tdc/final_99_init_pasttrec.trbcmd | 1 + 12 files changed, 252 insertions(+), 19 deletions(-) create mode 100755 scripts/generate_address_settings.pl create mode 100755 scripts/generate_pasttrec_settings.pl create mode 100755 scripts/merge_and_flash_settings.pl delete mode 100644 settings/README.md rename {settings => settings_oep}/.gitignore (85%) create mode 100644 settings_oep/README.md create mode 100644 settings_tdc/.gitignore create mode 100644 settings_tdc/README.md create mode 100644 settings_tdc/common_50_settingsselect.trbcmd create mode 100644 settings_tdc/final_99_init_pasttrec.trbcmd diff --git a/pasttrec/pasttrec_baseline.db b/pasttrec/pasttrec_baseline.db index 86afaac..bf7c53a 100644 --- a/pasttrec/pasttrec_baseline.db +++ b/pasttrec/pasttrec_baseline.db @@ -15,4 +15,17 @@ 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 diff --git a/scripts/README.md b/scripts/README.md index f809f16..47d7323 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -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 index 0000000..c81c4cc --- /dev/null +++ b/scripts/generate_address_settings.pl @@ -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 index 0000000..d9d26d5 --- /dev/null +++ b/scripts/generate_pasttrec_settings.pl @@ -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 = ) { + 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 = ) { + 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 index 0000000..e69de29 diff --git a/settings/README.md b/settings/README.md deleted file mode 100644 index 5bfb4b9..0000000 --- a/settings/README.md +++ /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. - diff --git a/settings/.gitignore b/settings_oep/.gitignore similarity index 85% rename from settings/.gitignore rename to settings_oep/.gitignore index ee72d94..b962241 100644 --- a/settings/.gitignore +++ b/settings_oep/.gitignore @@ -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 index 0000000..3daa85d --- /dev/null +++ b/settings_oep/README.md @@ -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 index 0000000..b962241 --- /dev/null +++ b/settings_tdc/.gitignore @@ -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 index 0000000..3daa85d --- /dev/null +++ b/settings_tdc/README.md @@ -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 index 0000000..11bf737 --- /dev/null +++ b/settings_tdc/common_50_settingsselect.trbcmd @@ -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 index 0000000..edfcd57 --- /dev/null +++ b/settings_tdc/final_99_init_pasttrec.trbcmd @@ -0,0 +1 @@ +0xfe91 0xaa00 0 -- 2.43.0