]> jspc29.x-matter.uni-frankfurt.de Git - mimosis_chain.git/commitdiff
added --help and more cmd-tools
authorBenedikt Gutsche <b.gutsche@gsi.de>
Fri, 9 Dec 2022 11:58:35 +0000 (12:58 +0100)
committerBenedikt Gutsche <b.gutsche@gsi.de>
Fri, 9 Dec 2022 11:58:35 +0000 (12:58 +0100)
scripts/Mimosis.pm
scripts/adc_i2c_cmd.pl [new file with mode: 0755]
scripts/basicsettings.pl
scripts/dac_scan/dac_scan.pl
scripts/i2c_cmd.pl
scripts/mimosis_i2c_cmd.pl [new file with mode: 0755]

index 02d025d5a69ed91faddf1d6ba7a1565f1876b4ce..c6145b38cf747067d79c0666b3c337bb49f7db06 100644 (file)
@@ -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 (executable)
index 0000000..d8cfaef
--- /dev/null
@@ -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 );
+}
index 1f028c5a8bd60208d585f924efe9cd605e7d024a..51f187bdace2af9c24cc16f544582d8d9fd89403 100755 (executable)
@@ -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] );
+    }
 }
index 67f898e7de9069a52cd59a9acbe93b673f43c1d3..afe78bd85695ff7ded433db11b28041b47587274 100755 (executable)
@@ -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" );
 }
index 8d9730b41481eb40d944f6b2d4c29c13fa72c37e..11720fcce2e0772bf5cd436382c44734142335a8 100755 (executable)
@@ -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 (executable)
index 0000000..13a13fd
--- /dev/null
@@ -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();
+}