From: Benedikt Gutsche Date: Fri, 9 Dec 2022 11:58:35 +0000 (+0100) Subject: added --help and more cmd-tools X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=219ba09972d2c92ccd2c102926403c0b4a2509de;p=mimosis_chain.git added --help and more cmd-tools --- diff --git a/scripts/Mimosis.pm b/scripts/Mimosis.pm index 02d025d..c6145b3 100644 --- a/scripts/Mimosis.pm +++ b/scripts/Mimosis.pm @@ -4,105 +4,84 @@ use warnings; no warnings "portable"; use HADES::TrbNet; use Time::HiRes qw(usleep); + #use FileHandle; #use Data::Dumper; - sub adc_i2c_command { - my ($fpga, $addr, $cmd, $data, $readwrite, $skipcmd, $wordbyte) = @_; + my ( $fpga, $addr, $cmd, $data, $readwrite, $skipcmd, $wordbyte ) = @_; - $reg_data = ($data << 16) + ($cmd << 8) + 0x80 + $addr; - $reg_flag = ($readwrite << 8) + ($skipcmd << 4) + $wordbyte; + $reg_data = ( $data << 16 ) + ( $cmd << 8 ) + 0x80 + $addr; + $reg_flag = ( $readwrite << 8 ) + ( $skipcmd << 4 ) + $wordbyte; - if($readwrite == 0) { - trb_register_write_mem($fpga,0xd681,0,[$reg_flag,$reg_data],2); - } - elsif($readwrite == 1) { - trb_register_write_mem($fpga,0xd681,0,[$reg_flag,$reg_data],2); - usleep(1000); - my $reg_return = trb_register_read($fpga,0xd684); - return $reg_return->{$fpga} & 0xffff; - } + if ( $readwrite == 0 ) { + trb_register_write_mem( $fpga, 0xd681, 0, [ $reg_flag, $reg_data ], 2 ); + } + elsif ( $readwrite == 1 ) { + trb_register_write_mem( $fpga, 0xd681, 0, [ $reg_flag, $reg_data ], 2 ); + usleep(1000); + my $reg_return = trb_register_read( $fpga, 0xd684 ); + return $reg_return->{$fpga} & 0xffff; + } } +sub mimosis_i2c_command { -sub adc_register_write { - my ($fpga, $mimosis_reg, $mimosis_data) = @_; - my ($addr, $cmd, $data); - - $addr = 0x12; - $cmd = ($mimosis_reg >> 8); - $data = (($mimosis_reg & 0xff) << 8) + $mimosis_data; - -# printf("%x %x\n", $cmd, $data); - adc_i2c_command($fpga, $addr, $cmd, $data, 0, 0, 1); -} + my ( $fpga, $addr, $cmd, $data, $readwrite, $skipcmd, $wordbyte ) = @_; + $reg_data = ( $data << 16 ) + ( $cmd << 8 ) + ( $addr << 1 ); + $reg_flag = ( $readwrite << 8 ) + ( $skipcmd << 4 ) + $wordbyte; -sub adc_register_read { - my ($fpga, $mimosis_reg) = @_; - my ($addr, $cmd, $data); + if ( $readwrite == 0 ) { - $addr = 0x12; - $cmd = ($mimosis_reg >> 8); - $data = ($mimosis_reg & 0xff); + # printf( "%x %x %x %x\n", $fpga, $addr, $cmd, $data ); + # printf( "%x %x\n", $reg_flag, $reg_data ); + trb_register_write_mem( $fpga, 0xde01, 0, + [ $reg_flag, $reg_data, 0x1 ], 3 ); + } + elsif ( $readwrite == 1 ) { -# printf("%x %x\n", $cmd, $data); - $val = adc_i2c_command($fpga, $addr, $cmd, $data, 1, 0, 1); - return $val; + # printf( "%x %x %x %x\n", $fpga, $addr, $cmd, $data ); + trb_register_write_mem( $fpga, 0xde01, 0, + [ $reg_flag, $reg_data, 0x1 ], 3 ); + usleep(1000); + my $reg_return = trb_register_read( $fpga, 0xde04 ); + return $reg_return->{$fpga} & 0xffff; + } } -sub mimosis_i2c_command { - - my ($fpga, $addr, $cmd, $data, $readwrite, $skipcmd, $wordbyte) = @_; - - $reg_data = ($data << 16) + ($cmd << 8) + ($addr << 1); - $reg_flag = ($readwrite << 8) + ($skipcmd << 4) + $wordbyte; - - if($readwrite == 0) { - trb_register_write_mem($fpga,0xde01,0,[$reg_flag,$reg_data,0x1],3); - } - elsif($readwrite == 1) { - trb_register_write_mem($fpga,0xde01,0,[$reg_flag,$reg_data,0x1],3); - usleep(1000); - my $reg_return = trb_register_read($fpga,0xde04); - return $reg_return->{$fpga} & 0xffff; - } -} - - sub mimosis_register_write { - my ($fpga, $mimosis_reg, $mimosis_data) = @_; - my ($addr, $cmd, $data); + my ( $fpga, $mimosis_reg, $mimosis_data ) = @_; + my ( $addr, $cmd, $data ); $addr = 0x12; - $cmd = ($mimosis_reg >> 8); - $data = (($mimosis_reg & 0xff) << 8) + $mimosis_data; + $cmd = ( $mimosis_reg >> 8 ); + $data = ( ( $mimosis_reg & 0xff ) << 8 ) + $mimosis_data; -# printf("%x %x\n", $cmd, $data); - mimosis_i2c_command($fpga, $addr, $cmd, $data, 0, 0, 1); + # printf( "%x %x\n", $cmd, $data ); + mimosis_i2c_command( $fpga, $addr, $cmd, $data, 0, 0, 1 ); + usleep(1000); } - sub mimosis_register_read { - my ($fpga, $mimosis_reg) = @_; - my ($addr, $cmd, $data); + my ( $fpga, $mimosis_reg ) = @_; + my ( $addr, $cmd, $data ); $addr = 0x12; - $cmd = ($mimosis_reg >> 8); - $data = ($mimosis_reg & 0xff); - mimosis_i2c_command($fpga, $addr, $cmd, $data, 0, 0, 0); + $cmd = ( $mimosis_reg >> 8 ); + $data = ( $mimosis_reg & 0xff ); + mimosis_i2c_command( $fpga, $addr, $cmd, $data, 0, 0, 0 ); + + # printf( "%x %x %x %x\n", $fpga, $addr, $cmd, $data ); usleep(1000); -# printf("%x %x\n", $cmd, $data); $addr = 0x15; - $val = mimosis_i2c_command($fpga, $addr, 0, 0, 1, 1, 0); + $val = mimosis_i2c_command( $fpga, $addr, 0, 0, 1, 1, 0 ); + + # printf( "%x\n", $val ); return $val; } 1; - - - __END__ diff --git a/scripts/adc_i2c_cmd.pl b/scripts/adc_i2c_cmd.pl new file mode 100755 index 0000000..d8cfaef --- /dev/null +++ b/scripts/adc_i2c_cmd.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl -I. + +use warnings; +use Getopt::Long; +use HADES::TrbNet; +use Time::HiRes qw(usleep); +use lib "."; +use Mimosis; + +my ( $fpga, $addr, $cmd, $cmd_t, $data, $data_t, $word ); + +Getopt::Long::Configure(qw(gnu_getopt)); +GetOptions( + "fpga|f=s" => \$fpga, + "addr|a=s" => \$addr, + "cmd|c=s" => \$cmd_t, + "data|d=s" => \$data_t, + "word|w" => \$word, +); + +trb_init_ports() or die trb_strerror(); + +defined($fpga) ? $fpga = hex($fpga) : die print("Must provide FPGA address.\n"); +defined($addr) ? $addr = hex($addr) : die print("Must provide I2C address.\n"); +$cmd = defined($cmd_t) ? hex($cmd_t) : 0x0; +$data = defined($data_t) ? hex($data_t) : 0x0; + +$val = + Mimosis::adc_i2c_command( $fpga, $addr, $cmd, $data, !defined($data_t), + !defined($cmd_t), defined($word) ); +if ( not defined($data_t) ) { + printf( "%x\n", $val ); +} diff --git a/scripts/basicsettings.pl b/scripts/basicsettings.pl index 1f028c5..51f187b 100755 --- a/scripts/basicsettings.pl +++ b/scripts/basicsettings.pl @@ -1,48 +1,43 @@ #!/usr/bin/perl use warnings; +use Getopt::Long; +use HADES::TrbNet; use lib "."; use Mimosis; -my $fpga = 0xa000; -my $addr = 0x12; - -my @list = ( - [0x00, 0x2040], - [0x00, 0x216e], - [0x00, 0x2200], - [0x00, 0x2300], - [0x00, 0x2400], - [0x00, 0x2500], - [0x00, 0x2600], - [0x00, 0x2701], - [0x00, 0x2801], - [0x00, 0x2916], - [0x00, 0x2a00], - [0x00, 0x2b00], - [0x00, 0x2c15], - [0x00, 0x2d00], - [0x00, 0x2e17], - [0x00, 0x2f00], - - [0x00, 0x4040], - [0x00, 0x4134], - [0x00, 0x421c], - [0x00, 0x43ab], - [0x00, 0x4446], - [0x00, 0x4600], - [0x00, 0x4743], - [0x00, 0x4878], - [0x00, 0x4978], - [0x00, 0x4a78], - [0x00, 0x4b6d], - [0x00, 0x4c3c], - [0x00, 0x4d37], - [0x00, 0x4e7d] - ); - -for my $arr (@list) { - - # send_i2c_command($fpga, $addr, @$arr[0], @$arr[1], 0, 0, 1); - # printf("%x\n", @$arr[1]); +my $fpga = 0xa000; +my @config = do $ARGV[0]; + +Getopt::Long::Configure(qw(gnu_getopt)); +GetOptions( + "fpga|f=s" => \$fpga, + "file|d=s" => \$file, + "help|h" => \$help, +); + +if ($help) { + my $message = <<'END_MESSAGE'; +-f, --fpga -> Hex address of the FPGA. Must be provided. +-d, --file -> File with configurations. Must be provided. +-h, --help -> Print this help. +END_MESSAGE + print $message; + exit(); +} + +defined($fpga) ? $fpga = hex($fpga) : die print("Must provide FPGA address.\n"); +defined($file) + ? @config = do $file + : die print("Must provide path to config file.\n"); + +trb_init_ports() or die trb_strerror(); + +foreach my $a (@config) { + if ( defined( @$a[1] ) ) { + + Mimosis::mimosis_register_write( $fpga, @$a[0], @$a[1] ); + + # printf( "%x %x %x\n", $fpga, @$a[0], @$a[1] ); + } } diff --git a/scripts/dac_scan/dac_scan.pl b/scripts/dac_scan/dac_scan.pl index 67f898e..afe78bd 100755 --- a/scripts/dac_scan/dac_scan.pl +++ b/scripts/dac_scan/dac_scan.pl @@ -9,34 +9,51 @@ use Time::HiRes qw(usleep); my $fpga = 0xa000; my %vdac = ( - - 3 => 0x004c, - - 4 => 0x0047, - - 5 => 0x004d, - - 7 => 0x0048, - - 8 => 0x0049, - - 9 => 0x004a, - + 3 => 0x004c, + 4 => 0x0047, + 5 => 0x004d, + 7 => 0x0048, + 8 => 0x0049, + 9 => 0x004a, 10 => 0x004b, ); +my %vdac_reset = ( + 3 => 0x53, + 4 => 0x43, + 5 => 0x32, + 7 => 0x53, + 8 => 0x53, + 9 => 0x53, + 10 => 0x53, +); + my %idac = ( 1 => 0x0040, 2 => 0x0042, 3 => 0x0041, ); +my %idac_reset = ( + 1 => 0x40, + 2 => 0x1c, + 3 => 0x34, +); + my %odac = ( 1 => 0x0045, 2 => 0x0044, 6 => 0x0043, ); +my %odac_reset = ( + 1 => 0x68, + 2 => 0x57, + 6 => 0xab, +); + +$conv_f = ( 2 * 4096 ) / 2**16; + trb_init_ports() or die trb_strerror(); my $vmon_file = "vmon_data.csv"; @@ -60,9 +77,13 @@ for my $dac ( sort keys %vdac ) { #loop over voltage DACs $volt_raw = Mimosis::adc_i2c_command( $fpga, 0x48, 0x0, 0x0, 1, 0, 1 ); # printf( "%x\t%i\t%i\n", $vdac{$dac}, $setv, $volt_raw ); - printf( v_FH "%x\t%i\t%i\n", $vdac{$dac}, $setv, $volt_raw ); + printf( v_FH "%x\t%f\t%i\n", $vdac{$dac}, $setv, $volt_raw * $conv_f ); } + Mimosis::mimosis_register_write( $fpga, $vdac{$dac}, $vdac_reset{$dac} ); + + usleep(10000); + # printf("\n\n"); printf( v_FH "\n\n" ); } @@ -86,14 +107,18 @@ for my $dac ( sort keys %idac ) { #loop over current DACs $curr_raw = Mimosis::adc_i2c_command( $fpga, 0x48, 0x0, 0x0, 1, 0, 1 ); # printf( "%x\t%i\t%i\n", $idac{$dac}, $seti, $curr_raw ); - printf( i_FH "%x\t%i\t%i\n", $idac{$dac}, $seti, $curr_raw ); + printf( i_FH "%x\t%i\t%i\n", $idac{$dac}, $seti, $curr_raw * $conv_f ); } + Mimosis::mimosis_register_write( $fpga, $idac{$dac}, $idac_reset{$dac} ); + usleep(10000); + # printf("\n\n"); printf( i_FH "\n\n" ); } close(i_FH); + open( o_FH, '>', $other_file ) or die $!; #MONVOLT_others @@ -111,9 +136,12 @@ for my $dac ( sort keys %odac ) { $volt_raw = Mimosis::adc_i2c_command( $fpga, 0x48, 0x0, 0x0, 1, 0, 1 ); # printf( "%x\t%i\t%i\n", $odac{$dac}, $setv, $volt_raw ); - printf( o_FH "%x\t%i\t%i\n", $odac{$dac}, $setv, $volt_raw ); + printf( o_FH "%x\t%i\t%i\n", $odac{$dac}, $setv, $volt_raw * $conv_f ); } + Mimosis::mimosis_register_write( $fpga, $odac{$dac}, $odac_reset{$dac} ); + usleep(10000); + # printf("\n\n"); printf( o_FH "\n\n" ); } diff --git a/scripts/i2c_cmd.pl b/scripts/i2c_cmd.pl index 8d9730b..11720fc 100755 --- a/scripts/i2c_cmd.pl +++ b/scripts/i2c_cmd.pl @@ -7,16 +7,27 @@ use Time::HiRes qw(usleep); use lib "."; use Mimosis; -my ($fpga, $addr, $cmd, $cmd_t, $data, $data_t, $word); +my ( $fpga, $addr, $cmd, $cmd_t, $data, $data_t, $word ); Getopt::Long::Configure(qw(gnu_getopt)); GetOptions( "fpga|f=s" => \$fpga, "addr|a=s" => \$addr, - "cmd|c=s" => \$cmd_t, + "cmd|c=s" => \$cmd_t, "data|d=s" => \$data_t, - "word|w" => \$word, - ); + "word|w" => \$word, + "help|h" => \$help_t, +); + +if ($help_t) { + print("Usage:\n"); + print("-f, --fpga:\n"); + print("-a, --addr:\n"); + print("-c, --cmd:\n"); + print("-d, --data:\n"); + print("-w, --word:\n"); + print("-h, --help:\n"); +} trb_init_ports() or die trb_strerror(); @@ -25,7 +36,8 @@ defined($addr) ? $addr = hex($addr) : die print("Must provide I2C address.\n"); $cmd = defined($cmd_t) ? hex($cmd_t) : 0x0; $data = defined($data_t) ? hex($data_t) : 0x0; -$val = Mimosis::send_i2c_command($fpga, $addr, $cmd, $data, !defined($data_t), !defined($cmd_t), defined($word)); -if(not defined($data_t)) { - printf("%x\n", $val); +$val = Mimosis::send_i2c_command( $fpga, $addr, $cmd, $data, !defined($data_t), + !defined($cmd_t), defined($word) ); +if ( not defined($data_t) ) { + printf( "%x\n", $val ); } diff --git a/scripts/mimosis_i2c_cmd.pl b/scripts/mimosis_i2c_cmd.pl new file mode 100755 index 0000000..13a13fd --- /dev/null +++ b/scripts/mimosis_i2c_cmd.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl -I. + +use warnings; +use Getopt::Long; +use HADES::TrbNet; +use Time::HiRes qw(usleep); +use lib "."; +use Mimosis; + +my ( $fpga, $addr, $cmd, $cmd_t, $data, $data_t, $word ); + +Getopt::Long::Configure(qw(gnu_getopt)); +GetOptions( + "fpga|f=s" => \$fpga, + "mimosis-reg|r=s" => \$reg_t, + "mimosis-data|d=s" => \$data_t, + "help|h" => \$help_t, +); + +if ($help_t) { + my $message = <<'END_MESSAGE'; +-f, --fpga -> Hex address of the FPGA. +-r, --mimosis-reg -> Hex register to write to. +-d, --mimosis-data -> Data to write, if specified. If not, data will be red. Hex or dec values allowed. +-h, --help -> Print this help. +END_MESSAGE + print $message; + exit(); +} + +defined($fpga) ? $fpga = hex($fpga) : die print("Must provide FPGA address.\n"); +defined($reg_t) + ? $reg_t = hex($reg_t) + : die print("Must provide Mimosis register.\n"); + +trb_init_ports() or die trb_strerror(); + +if ( defined($data_t) ) { + $data_t = hex($data_t) if ( $data_t =~ /^0x/ ); + Mimosis::mimosis_register_write( $fpga, $reg_t, $data_t ); + exit(); +} +else { + printf "%x\n", Mimosis::mimosis_register_read( $fpga, $reg_t ); + exit(); +}