openlog("atomic,ui_writeram.pl", "", "local1");
syslog("INFO", "starting ui_writeram.pl");
-$ENV{'DAQOPSERVER'}="localhost:7";
+# $ENV{'DAQOPSERVER'}="localhost:7";
use Getopt::Long;
use HADES::TrbNet;
print "debug:" . $_[0];
}
}
-sub execute_shell_command {
- # input args: $command, $expected_output #, $success_string, $sending_button
-
- my $success = 0;
- my $command = $_[0];
- my $expected = $_[1];
- my $output = "";
- #my $success_string = $_[1];
- #my $sending_button = $_[2];
-
- #my $message= $sending_button->get_label;
- #reportd ( 'report_general', "attempting to $message");
- report( 'report_detailed' , "\nexec $command\n\n");
- if(not open ( SHELL , "$command 2>&1 |" )) {
- report( 'report_general' , "failed to execute command.");
- syslog("ERR", "command failed.");
- }
-
- while ( <SHELL> ) {
- report( 'report_detailed' , $_);
- $output.=$_;
-# if ( $_ =~ m/$success_string/ ) {
-# report( 'report_general' , " ...success!\n" );
-# my $success = 1;
-# }
- }
-# if ($success == 0) {
-# report( 'report_general', " ...unclear\n");
-# }
- if(!($output eq $expected)) {
- report('report_general', "unexpected output: ".$output."\n");
- syslog("ERR", "unexpected output: $output.");
- }
- report( 'report_detailed' , "\n----------------------------\n");
-}
-
-
-sub execute_shell_command_return {
- my $command = $_[0];
- report( 'report_detailed' , "\nexec $command\n\n");
- my $result = `$command 2>&1`;
- report( 'report_detailed' , $result);
- report( 'report_detailed' , "\n----------------------------\n");
- if($? != 0) {
- report('report_general', "command failed. output: $result");
- syslog('ERR', "command failed. output: $result.");
- }
- return $result;
-}
-
-my $num_words = 0;
-
-#this subroutine
-#changes parameter 0, which holds the file handle
-sub memfile_writeline($$$$) {
- my($memfile, $memfilenames, $memfiles_prefix, $line_string)=@_;
- my $filenum = floor($num_words/256);
- my $last_filenum = floor(($num_words-1)/256);
- my $filenum_str = sprintf "%0.2d", $filenum;
- my $memfilename = $memfiles_prefix.'.'.$filenum_str.".txt";
-
- if((!defined $_[0])) {
- if( -e ($memfilename)) {
- #die ("Error: RAM text file \"$memfile\" exists.");
- }
- $_[0] = FileHandle->new($memfilename, 'w');
- push(@{$_[1]}, $memfilename);
- }
- elsif($filenum!=$last_filenum) {
- $memfile->close();
- if( -e ($memfilename)) {
- #die ("Error: RAM text file \"$memfile\" exists.");
- }
- $_[0] = FileHandle->new($memfilename, 'w');
- push(@{$_[1]}, $memfilename);
- }
- my $fh = $_[0];
- print $fh $line_string;
- $num_words++;
-}
-
if(not( -e "/tmp/jtag_initmem")) {
#die ("Error: RAM text file \"$memfilename\" exists.");
}
if( not defined($opt_quiet)) { print "Opening $memfilename...\n"; }
- my $handle = FileHandle->new($memfilename, 'w');
+# my $handle = FileHandle->new($memfilename, 'w');
push(@memfilenames, $memfilename);
# write numregs + IRlen
my $word = scalar($this_irlen)<<16;
$word = $word + scalar @irs;
### $word = ($word<<16) + pack("L", scalar(@irs));
- print $handle "0x" . uc (substr(reverse(join('',unpack("h8", pack("L", $word)))),0,8)) . "\t# IRlen & numregs \n";
+# print $handle "0x" . uc (substr(reverse(join('',unpack("h8", pack("L", $word)))),0,8)) . "\t# IRlen & numregs \n";
push(@{$memhash->{$memfilename}},$word);
#####print $handle "0x" .uc (substr(reverse(join('',unpack("h8", pack("L", scalar($this_irlen))))),4,4)) . uc (substr(reverse(join('',unpack("h8", pack("L", scalar(@irs))))),4,4)) . "\t# IRlen & numregs \n";
#printf "crc0: %0.8X, crc0_rn: %0.8X, word: %0.8X\n", $crc0, $crc0_rn, $word;
# write DEV_ID
$word = 0x4D323601;
- print $handle "0x" . uc (substr(reverse(join('',unpack("h8", pack("L", $word)))),0,8)) . "\t# DEV_ID \n";
+# print $handle "0x" . uc (substr(reverse(join('',unpack("h8", pack("L", $word)))),0,8)) . "\t# DEV_ID \n";
push(@{$memhash->{$memfilename}},$word);
$crcword = pack("L", reverse32bit($word));
$crc0 = crc32($crcword, $crc0);
#print $handle "0x". uc (substr(reverse(join('',unpack("h8", pack("L", 0)))),4,4)) . uc (substr(reverse(join('',unpack("h8", pack("L", scalar($offset))))),4,4)) . "\t# Pointer + reserved\n";
$crcword = pack("L", reverse32bit($word));
$crc0 = crc32($crcword, $crc0);
- print $handle "0x" . uc (substr(reverse(join('',unpack("h8", pack("L", $word)))),0,8)) . "\t# Pointer + reserved \n";
+# print $handle "0x" . uc (substr(reverse(join('',unpack("h8", pack("L", $word)))),0,8)) . "\t# Pointer + reserved \n";
push(@{$memhash->{$memfilename}},$word);
$word = $drlen;
$crcword = pack("L", reverse32bit($word));
$crc0 = crc32($crcword, $crc0);
#print $handle "0x0000". uc (substr(reverse(join('',unpack("h8", pack("L", scalar($drlen))))),4,4)) . "\t# Length\n";
- print $handle "0x" . uc (substr(reverse(join('',unpack("h8",pack("L", $word)))),0,8)) . "\t# Length\n";
+# print $handle "0x" . uc (substr(reverse(join('',unpack("h8",pack("L", $word)))),0,8)) . "\t# Length\n";
push(@{$memhash->{$memfilename}},$word);
$offset += floor(($drlen+31)/32);
}
$crc0_rn = ~reverse32bit($crc0);
#printf "CRC: %0.8X.\n", $crc0_rn, 1;
my $line_crc = sprintf "%0.8X", $crc0_rn;
- print $handle "0x". substr($line_crc,length($line_crc)-8,8) . "\t# CRC-32\n";
- push(@{$memhash->{$memfilename}},$crc0_rn);
+# print $handle "0x". substr($line_crc,length($line_crc)-8,8) . "\t# CRC-32\n";
+ push(@{$memhash->{$memfilename}},$crc0_rn & 0xFFFFFFFF);
my $crc1 = 0xFFFFFFFF;
# write IRs
#print "ir=$ir.IR word: $word\n";
$crcword = pack("L", reverse32bit($word));
$crc1 = crc32($crcword, $crc1);
- print $handle "0x".("0"x(8-length($ir))).uc($ir) . "\t# IR\n";
+# print $handle "0x".("0"x(8-length($ir))).uc($ir) . "\t# IR\n";
push(@{$memhash->{$memfilename}},hex($ir));
}
$word = unpack("L", pack("h*", (scalar reverse uc($bypassreg)) ."000000"));
$crcword = pack("L", reverse32bit($word));
$crc1 = crc32($crcword, $crc1);
- print $handle "0x".("0"x(8-length($bypassreg))).uc($bypassreg) . "\t# IR BYPASS\n";
+# print $handle "0x".("0"x(8-length($bypassreg))).uc($bypassreg) . "\t# IR BYPASS\n";
push(@{$memhash->{$memfilename}},hex($bypassreg));
# write DRs
$crcword = pack("L", reverse32bit($word));
$crc1 = crc32($crcword, $crc1);
my $linestr = "0x". substr($drs[$reg_i],($numwords-$i-1)*8,8) . "\t# DR" . $reg_i . "\n";
- print $handle $linestr;
+# print $handle $linestr;
push(@{$memhash->{$memfilename}},hex(substr($drs[$reg_i],($numwords-$i-1)*8,8)));
}
}
#write CRC-32
my $crc1_rn = ~reverse32bit($crc1);
$line_crc = sprintf "%0.8X", $crc1_rn;
- print $handle "0x". substr($line_crc,length($line_crc)-8,8) . "\t# CRC-32\n";
- push(@{$memhash->{$memfilename}},$crc1_rn);
+# print $handle "0x". substr($line_crc,length($line_crc)-8,8) . "\t# CRC-32\n";
+ push(@{$memhash->{$memfilename}},$crc1_rn & 0xFFFFFFFF);
}
}
# my $numchips_hex = int_to_32bit_hex(scalar @sensors);
#if(not defined($opt_quiet)) { print "trbcmd w $fpga_addr $cmd_reg_addr 0x0000000A 2>&1\n"; } # CMD_STOP
#my $result = `trbcmd w $fpga_addr $cmd_reg_addr 0x0000000A 2>&1 \n`; # CMD_STOP
- trb_register_write($fpga_addr ,$cmd_reg_addr,0x0000000A);
+ trb_register_write($fpga_addr ,$cmd_reg_addr,0x0000000A) or die trb_strerror();
# execute_shell_command("trbcmd w $fpga_addr $cmd_reg_addr 0x0000000A", ""); # CMD_STOP
#if(not($? == 0)) {syslog("ERR", "trbcmd returned $?. Output: $result.")}
#if(not defined($opt_quiet)) { print "trbcmd w $fpga_addr $data_reg_addr 0x$numchips_hex\n"; } # ADDR_CONTROL_DATA_REGISTER
#$result = `trbcmd w $fpga_addr $data_reg_addr 0x$numchips_hex 2>&1\n`; # ADDR_CONTROL_DATA_REGISTER
- trb_register_write($fpga_addr ,$data_reg_addr,scalar @sensors);
+ trb_register_write($fpga_addr ,$data_reg_addr,scalar @sensors) or die trb_strerror();
# execute_shell_command("trbcmd w $fpga_addr $data_reg_addr 0x$numchips_hex", ""); # ADDR_CONTROL_DATA_REGISTER
#if(not defined($opt_quiet)) { print "trbcmd w $fpga_addr $cmd_reg_addr 0x00000033\n"; } # COMMAND: M26C_CMD_SET_NUMCHIPS_CONFIGURED
#$result = `trbcmd w $fpga_addr $cmd_reg_addr 0x00000033\n`; # COMMAND: M26C_CMD_SET_NUMCHIPS_CONFIGURED
- trb_register_write($fpga_addr ,$cmd_reg_addr,0x00000033);
+ trb_register_write($fpga_addr ,$cmd_reg_addr,0x00000033) or die trb_strerror();
# execute_shell_command("trbcmd w $fpga_addr $cmd_reg_addr 0x00000033", "");
for(my $i=0;$i<scalar @memfilenames;$i++) {
if(not defined($opt_quiet)) { print "set RAM base pointer: \n"; }
#if(not defined($opt_quiet)) { print "trbcmd w $fpga_addr $ram_base_addr 0x$ihex\n"; }
#$result = `trbcmd w $fpga_addr $ram_base_addr 0x$ihex\n`;
- trb_register_write($fpga_addr, $ram_base_addr, $i);
+ trb_register_write($fpga_addr, $ram_base_addr, $i) or die trb_strerror();
# execute_shell_command("trbcmd w $fpga_addr $ram_base_addr 0x$ihex", "");
# write to configuration RAM
if(not defined($opt_quiet)) { print "write max. 256 32-bit-words: \n"; }
#if(not defined($opt_quiet)) { print "trbcmd wm $fpga_addr $ram_addr 0 $memfilenames[$i]\n"; }
#$result = `trbcmd wm $fpga_addr $ram_addr 0 $memfilenames[$i]`;
- execute_shell_command("trbcmd wm $fpga_addr $ram_addr 0 $memfilenames[$i]", "");
+# execute_shell_command("trbcmd wm $fpga_addr $ram_addr 0 $memfilenames[$i]", "");
+ trb_register_write_mem($fpga_addr,$ram_addr,0,$memhash->{$memfilenames[$i]},scalar @{$memhash->{$memfilenames[$i]}}) or die trb_strerror();
- print "---------------\n";
- foreach my $s (@{$memhash->{$memfilenames[$i]}}) {
- printf("0x%08X\n",$s);
- }
- print "---------------\n";
+# print "---------------\n";
+# foreach my $s (@{$memhash->{$memfilenames[$i]}}) {
+# printf("0x%08X\n",$s);
+# }
+# print "---------------\n";
}
#if(not defined($opt_quiet)){ print "trbcmd w $fpga_addr $cmd_reg_addr 0x00000009\n"; } # CMD_START
#$result = `trbcmd w $fpga_addr $cmd_reg_addr 0x00000009\n`; # CMD_START
- trb_register_write($fpga_addr, $cmd_reg_addr, 0x00000009);
+ trb_register_write($fpga_addr, $cmd_reg_addr, 0x00000009) or die trb_strerror();
# execute_shell_command("trbcmd w $fpga_addr $cmd_reg_addr 0x00000009", ""); # CMD_START
if(not defined($opt_quiet)) { print "\n"; }