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
###############################################################################
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;
}
###############################################################################
#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 @_;
$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)
-#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
* 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.
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 $!;
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 $!;
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
###############################################################################
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);
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";
}
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);
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";
}
#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");
}
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 $!;
--- /dev/null
+#!/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");
+
+ }
#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
-0xfe91 0xaa00 0
+0xaa00 0