From 748dba1e81f33afd3c5eead5717242b7aae94c84 Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Fri, 19 Jul 2013 18:27:00 +0200 Subject: [PATCH] WriteRAM via perl-Lib working --- soft/toolbox/jtag_atomic/ui.pl | 24 ++-- soft/toolbox/jtag_atomic/ui_generators.pl | 4 +- soft/toolbox/jtag_atomic/ui_writeram.pl | 130 +++++----------------- 3 files changed, 40 insertions(+), 118 deletions(-) diff --git a/soft/toolbox/jtag_atomic/ui.pl b/soft/toolbox/jtag_atomic/ui.pl index 87d4ea0..86f3f3a 100755 --- a/soft/toolbox/jtag_atomic/ui.pl +++ b/soft/toolbox/jtag_atomic/ui.pl @@ -156,18 +156,18 @@ sub execute_shell_command { } -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; -} +# 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 $boardsfile= 'boards.ini'; $boardsfile = $ENV{'JTAGCONFIGPATH'}."/".$boardsfile if defined($ENV{'JTAGCONFIGPATH'}); diff --git a/soft/toolbox/jtag_atomic/ui_generators.pl b/soft/toolbox/jtag_atomic/ui_generators.pl index 3b904b5..69513c2 100644 --- a/soft/toolbox/jtag_atomic/ui_generators.pl +++ b/soft/toolbox/jtag_atomic/ui_generators.pl @@ -111,7 +111,9 @@ sub generate_h_prog_ram { my($chain) = @_; # return sub { init_msg("program RAM $chain."); - execute_shell_command("./ui_writeram.pl -c $chain", "$chain: done.\n"); # load sensor*.ini + my $cmd = "./ui_writeram.pl -c $chain"; + qx($cmd); + return 1; # } } diff --git a/soft/toolbox/jtag_atomic/ui_writeram.pl b/soft/toolbox/jtag_atomic/ui_writeram.pl index de91726..a8881d8 100755 --- a/soft/toolbox/jtag_atomic/ui_writeram.pl +++ b/soft/toolbox/jtag_atomic/ui_writeram.pl @@ -10,7 +10,7 @@ use Data::Dumper; 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; @@ -128,89 +128,8 @@ sub reportd { 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 ( ) { - 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")) { @@ -317,13 +236,13 @@ foreach my $chain (keys %allchains) { #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"; @@ -335,7 +254,7 @@ foreach my $chain (keys %allchains) { #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); @@ -349,14 +268,14 @@ foreach my $chain (keys %allchains) { #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); } @@ -365,8 +284,8 @@ foreach my $chain (keys %allchains) { $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 @@ -377,7 +296,7 @@ foreach my $chain (keys %allchains) { #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)); } @@ -385,7 +304,7 @@ foreach my $chain (keys %allchains) { $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 @@ -400,30 +319,30 @@ foreach my $chain (keys %allchains) { $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{$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"; } -- 2.43.0