From 712649dd01768d483fadb51fafb20b81f5b0d271 Mon Sep 17 00:00:00 2001 From: Hades DAQ Date: Sun, 3 Mar 2019 18:33:48 +0100 Subject: [PATCH] recover dead slow channels in ecal, mt --- tools/ecal_flip_flop_slow_thresholds.pl | 130 ++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100755 tools/ecal_flip_flop_slow_thresholds.pl diff --git a/tools/ecal_flip_flop_slow_thresholds.pl b/tools/ecal_flip_flop_slow_thresholds.pl new file mode 100755 index 0000000..b57cea2 --- /dev/null +++ b/tools/ecal_flip_flop_slow_thresholds.pl @@ -0,0 +1,130 @@ +#!/usr/bin/perl +use warnings; +use strict; +use HADES::TrbNet; +use Time::HiRes qw(usleep); +use Data::Dumper; + +use lib "/home/hadaq/trbsoft/daqtools/dmon/code"; +use Dmon; + +my $dirich = 0x1234; +my $std_thresh = 0x6800; + +$dirich = $ARGV[0]; +if($ARGV[1]) { + $std_thresh = $ARGV[1]; + $std_thresh = hex($std_thresh); +} + +unless ($ARGV[0]) { + print "usage: $0 [std_threshold]]\n"; + exit; +} + +$dirich = hex($dirich); + +my $throffset = 0xa000; +#my $monitor = 0xdfc0; +my $monitor = 0xc001; + +my $first_channel = 0; +my $last_channel = 47; + +my $default_threshold = 0x6000; + +#my $absolute_max_threshold = 0x8000; +my $absolute_min_threshold = 0x1000; + +my @res; my $res; my $rh_res; + +trb_init_ports() or die trb_strerror(); + +# enable monitor counters +$res = trb_register_write($dirich, 0xdf80 , 0xffffffff); +if(!defined $res) { + $res = trb_strerror(); + print "error output: $res\n"; +} + + +my $command; +my $chain=0; + +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 $rh_thresh; + +for my $channel (0 .. $last_channel) { +# if($channel%2 == 0) { +# next; +# } + $chain = int($channel/16); + $command = ($channel&0xf)<<$REGNR | $READ ; + #print "$command\n"; + my $res = Dmon::PadiwaSendCmd($command,$dirich, $chain); + foreach my $cur_dirich (keys %$res) { + #print "cur_dirich: $cur_dirich\n"; + #my $value = $res->{$dirich} & 0xffff; + $rh_thresh->{$cur_dirich}->[$channel] = $res->{$cur_dirich} &0xffff; + #usleep(30E1); + #print Dumper $; + } +} + +#print Dumper $rh_thresh->{0x6024}; +#print Dumper $rh_thresh; +#exit; + +for my $channel (0 .. $last_channel) { + if($channel%2 == 0) { + next; + } + + #foreach my $cur_dirich (keys %$rh_thresh) { + #my $ra_channels = $rh_thresh->{$cur_dirich}; + #my $channel = 0; + #foreach my $cur_value (@$ra_channels) { + $chain = int($channel/16); + $command = ($channel&0xf)<<$REGNR | $WRITE | 0x1ff; + #print "write: chain: $chain, Channel: $channel, value: $cur_value\n"; + Dmon::PadiwaSendCmd($command,$dirich, $chain); + +# usleep(30E4); +# $command = ($channel&0xf)<<$REGNR | $WRITE | 0x0; +# Dmon::PadiwaSendCmd($command,$dirich, $chain); + #} + +} + +usleep(30E3); +#sleep; + +for my $channel (0 .. $last_channel) { + if($channel%2 == 0) { + next; + } + + #print "channel: $channel\n"; + foreach my $cur_dirich (keys %$rh_thresh) { + #my $ra_channels = $rh_thresh->{$cur_dirich}; + #my $channel = 0; + my $cur_value = $rh_thresh->{$cur_dirich}->[$channel]; + #foreach my $cur_value (@$ra_channels) { + $chain = int($channel/16); + + #printf "want to write: $cur_value to ecal: %x, chain %d\n",$cur_dirich,$chain; + $command = ($channel&0xf)<<$REGNR | $WRITE | $cur_value; + #print "write: chain: $chain, Channel: $channel, value: $cur_value\n"; + Dmon::PadiwaSendCmd($command,$cur_dirich, $chain); + #usleep(30E1); + } + +} + + + +exit; + -- 2.43.0