my $sleep_time = 0.2;
my $accepted_dark_rate = 10;
-my $number_of_iterations = 40; # at least 15 are recommended
+my $number_of_iterations = 30; # at least 15 are recommended
my $endpoint = 0x0303;
my $mode = "padiwa";
my $opt_skip = 99;
my $polarity = 1;
my @channels = ();
+my $channel_to_set = undef;
+my $channel_by_channel = false;
my $channel32 = undef;
my $opt_finetune = false;
my $result = GetOptions (
"h|help" => \$help,
"c|chain=i" => \$chain,
+ "channel_to_set=i" => \$channel_to_set,
+ "channel_by_channel" => \$channel_by_channel,
"e|endpoint=s" => \$endpoint,
"m|mode=s" => \$mode,
"p|polarity=i" => \$polarity,
my $rh_res;
my $old_rh_res;
+my $outermost_channel_loop_counter = 0;
+
+#set default values
+my @zero_array = (0) x 16;
+write_thresholds($mode, $chain, \@zero_array);
+
+if($channel_by_channel == true) {
+ $outermost_channel_loop_counter = 15;
+}
+
+my @outermost_channel_loop = (0);
+
+if($channel_by_channel) {
+ @outermost_channel_loop = (0 .. $outermost_channel_loop_counter);
+}
+
+#print "channellist:\n";
+#print Dumper \@outermost_channel_loop;
+
+foreach my $current_channel_outer_loop (@outermost_channel_loop) {
+
+if($channel_by_channel) {
+ $channel_to_set = $current_channel_outer_loop;
+ write_thresholds($mode, $chain, \@zero_array);
+}
+
+$number_of_steps = 0;
+
while ($number_of_steps < $number_of_iterations ||
grep({$_ == 0} @best_thresh) > 0
) {
if ($mode eq "padiwa") {
- write_thresholds($mode, $chain, \@current_thresh);
+ write_thresholds($mode, $chain, \@current_thresh, $channel_to_set);
# wait settling time, experimentally determined to 0.04 seconds
select(undef, undef, undef, 0.05);
#print Dumper $rh_res;
#print Dumper $old_rh_res;
+ my @iterate_loop = (0..15);
+ if($channel_by_channel) {
+ @iterate_loop = ($current_channel_outer_loop);
+ }
- foreach my $i (0..15) {
+ foreach my $i (@iterate_loop) {
$interval_step = $interval_step[$i];
my $cur_hitreg = $rh_res->{$endpoint}->[$i*$hitchannel_multiplicator];
"new thresh: " . sprintf("0x%x", $current_thresh[$i]) .
", step_size: " . sprintf ("0x%04x best: 0x%04x", $interval_step[$i], $best_thresh[$i]);
+ #print "$str\n";
$logger->info($str);
} # end of loop over 15 channel
} #end of loop over steps
+
map { $_-= $offset } @best_thresh;
-write_thresholds($mode, $chain, \@best_thresh);
+write_thresholds($mode, $chain, \@best_thresh, $channel_to_set);
my $uid;
-foreach my $i (reverse (0..3)) {
+foreach my $i (reverse (0 .. 3)) {
#print "send command: $endpoint , i: $i\n";
+ # read uids
$rh_res = Dmon::PadiwaSendCmd(0x10000000 | $i * 0x10000, $endpoint, $chain);
$uid .= sprintf("%04x", $rh_res->{$endpoint} &0xffff);
#print $uid;
my $str;
#$logger_data->info("thresholds have been set to the following values:");
#$logger_data->info(sprintf "endpoint: %04x, chain: %02d, uid: $uid", $endpoint, $chain);
-$logger_data->info("\t".time);
-foreach my $i (0..15) {
- $logger_data->info(sprintf "endpoint: 0x%04x, chain: %02d, channel: %2d threshold: 0x%04x, uid: %s", $endpoint, $chain, $i, $best_thresh[$i], $uid );
+#$logger_data->info("\t".time);
+
+my @range = (0 .. 15);
+
+if($channel_by_channel) {
+ @range = ($current_channel_outer_loop .. $current_channel_outer_loop);
}
+#print "range2: ";
+#print Dumper @range;
+
+foreach my $i (@range) {
+ my $str = sprintf "endpoint: 0x%04x, chain: %02d, channel: %2d threshold: 0x%04x, uid: %s", $endpoint, $chain, $i, $best_thresh[$i], $uid;
+ #print "$str\n";
+ $logger_data->info($str);
+}
+
+} # end of channel_by_channel loop
+
exit;
# my $rh_res = trb_register_write($endpoint,0xd410, 1 << $chain);
- foreach my $current_channel (0..15) {
+ foreach my $current_channel (0 .. 15) {
my $command;
my $fixed_bits;
sub write_thresholds {
- (my $mode, my $chain, my $ra_thresh) = @_;
+ (my $mode, my $chain, my $ra_thresh, my $channel_to_set) = @_;
$share->store($chain);
### old and wrong way #my $rh_res = trb_register_write($endpoint,0xd410, 1 << $chain);
- foreach my $current_channel (0..15) {
+ my @range = (0 .. 15);
+ if (defined $channel_to_set && $channel_to_set <16 ) {
+ @range = ($channel_to_set .. $channel_to_set);
+ #print "range: \n";
+ }
+
+ #print Dumper \@range;
+ foreach my $current_channel (@range) {
my $command;
my $fixed_bits;