]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
add command line tool to run I2C commands
authorJan Michel <michel@physik.uni-frankfurt.de>
Fri, 27 Sep 2024 08:32:12 +0000 (10:32 +0200)
committerJan Michel <michel@physik.uni-frankfurt.de>
Fri, 27 Sep 2024 08:32:23 +0000 (10:32 +0200)
tools/i2c_cmd.pl [new file with mode: 0755]

diff --git a/tools/i2c_cmd.pl b/tools/i2c_cmd.pl
new file mode 100755 (executable)
index 0000000..5a6719b
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+
+use Getopt::Long;
+use HADES::TrbNet;
+use Time::HiRes qw(usleep);
+
+Getopt::Long::Configure(qw(gnu_getopt));
+GetOptions(
+    "fpga|f=s" => \$fpga_t,
+    "addr|a=s" => \$addr_t,
+    "cmd|c=s" => \$cmd_t,
+    "data|d=s" => \$data_t,
+    "word|w" => \$word,
+    );
+
+trb_init_ports() or die trb_strerror();
+
+$fpga = defined($fpga_t) ? hex($fpga_t) : 0x0;
+$addr = defined($addr_t) ? hex($addr_t) : 0x0;
+$cmd  = defined($cmd_t)  ? hex($cmd_t)  : 0x0;
+$data = defined($data_t) ? hex($data_t) : 0x0;
+
+$reg_data = ($data << 16) + ($cmd << 8) + 0x80 + ($addr >> 1);
+$reg_flag;
+
+if(not defined($fpga_t)) {
+    die print("Must provide FPGA address.\n");
+}
+
+if(defined($cmd_t)) {
+    $reg_flag = $word == 1 ? 0x001 : 0x000;
+    }
+elsif(not defined($cmd_t)) {
+    $reg_flag = $word == 1 ? 0x011 : 0x010;
+    }
+
+
+if(defined($data_t) and defined($addr_t)) {
+    trb_register_write_mem($fpga,0xd681,0,[$reg_flag,$reg_data],2);
+}
+elsif(not defined($data_t) and defined($addr_t)) {
+    $reg_flag |= 0x100;
+    trb_register_write_mem($fpga,0xd681,0,[$reg_flag,$reg_data],2);
+    usleep(1000);
+    $reg_return = trb_register_read($fpga,0xd684);
+    printf("%04x\t(%x)\n", $reg_return->{$fpga}&($word?0xffff:0xff), $reg_return->{$fpga} >> 16);
+}
+
+# printf("%x\n", $reg_data);
+# printf("%x\n", $reg_flag);