my $endpoint;
my $chain;
my $channel;
-my $execute;
+my $execute="";
my $register;
my $data;
my $ref_voltage = 3300;
+my $filename;
+my $flashcmd;
+my $flashaddress;
+my $enablecfgflash;
+my $dumpcfgflash;
+
+my $time;
+
+my $READ = 0x0<<20; # bits to set for a read command
+my $WRITE = 0x8<<20; # bits to set for a write command
+my $REGNR = 24; # number of bits to shift for the register number
my $result = GetOptions (
- "h|help" => \$help,
- "c|chain=i" => \$chain,
- "n|channel=i" => \$channel,
- "e|endpoint=s" => \$endpoint,
- "x|execute=s" => \$execute,
- "r|register=s" => \$register,
- "v|ref_voltage=s" => \$ref_voltage,
- "d|data=s" => \$data,
+ "h|help" => \$help,
+ "c|chain=i" => \$chain,
+ "n|channel=i" => \$channel,
+ "e|endpoint=s" => \$endpoint,
+ "x|execute=s" => \$execute,
+ "r|register=s" => \$register,
+ "v|ref_voltage=s" => \$ref_voltage,
+ "d|data=s" => \$data,
+ "f|filename=s" => \$filename,
+ "flashcmd=s" => \$flashcmd,
+ "flashaddress=s" => \$flashaddress,
+ "enablecfgflash=i" => \$enablecfgflash,
+ "dumpcfgflash" => \$dumpcfgflash,
+ "time" => \$time,
);
sub conv_input_string_to_number {
}
-sub usage {
- print "usage: padiwa_amps2.pl <--endpoint|e=0xYYYY> <--chain|c=N> <--execute|x=command> [--register=number] [--data=number]
+sub usage {
+ print <<EOF;
+usage: padiwa_amps2.pl <--endpoint|e=0xYYYY> <--chain|c=N> [--register=number] [--data=number]
+
+examples: padiwa_amps2.pl -e 0x1212 -c 0 -x time # reads the compile time of 0x1212, chain 0
+ padiwa_amps2.pl -e 0x1212 -c 0 -x pwm --channel=1 # reads the threshold setting of channel 1
+ padiwa_amps2.pl -e=0x1212 -c=0 -x=inputenable --data=0xa55a # disables some channels
+ padiwa_amps2.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert -d 0xff # sets the dischargedelayinvert bits
+ padiwa_amps2.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert # reads the dischargedelayinvert register
+ padiwa_amps2.pl -e 0x1212 -c 0 --enablecfgflash=1 # enables the access to the config-flash
+ padiwa_amps2.pl --endpoint=0x1212 --chain=0 --dumpcfgflash > flash_dump.txt
commands:
-\t uid \t\t read unique ID, no options
-\t time \t\t read compile time. no options
-\t temp \t\t read temperature, no optionsy
-\t resettemp \t resets the 1-wire logic
-\t dac \t\t set LTC-DAC data. options: \$channel, \$data
-\t pwm \t\t set PWM data. options: \$channel, \$data
-\t comp \t\t set temperature compensation data. options: \$data
-\t discdisable \t set input diable. options: \$mask
-\t discharge \t Disables the discharge signal if set. options: \$mask
-\t discoverride \t Set discharge signal if disabled. options: \$mask
-\t dischighz \t Set discharge signal to highZ. options: \$mask
-\t discdelayinvert \t Invert signal used for delay generation. options: \$mask
-\t inputenable \t\t read inputenable register. If option \"data\" given: write input enable bits
-\t \t\t bits: 0: enable, 1: disable
-\t counter\t input signal counter. options: \$channel
-\t invert \t set invert status. options: \$mask
-\t led \t\t set led status. options: mask (5 bit, highest bit is override enable)
-\t \t\t read LED status. no options
-\t ledoff\t\t turn off LEDs: First reads firmware-version and according to that turns
-\t monitor \t set input for monitor output. options: mask (4 bit).
-\t\t\t 0x10: OR of all channels, 0x18: or of all channels, extended to 16ns
-\t stretch \t set stretcher status.
-\t ram \t\t writes the RAM content, options: 16 byte in hex notation, separated by space, no 0x.
-\t \t\t read the RAM content (16 Byte)
-\t flash \t\t execute flash command, options: \$command, \$page. See manual for commands.
-\t enablecfg\t enable or disable access to configuration flash, options: 1/0
-\t erasecfg\t erases the config flash
-\t dumpcfg \t Dump content of configuration flash. Pipe output to file
-\t writecfg \t Write content of configuration flash. options: \$filename
-\t fifo \t\t Read a byte from the test fifo (if present, no options)
-\t writereg|wr \t\t Write to a register
-\t readreg|rr \t\t Read a register
-";
+ uid read unique ID, no options
+ time read compile time. no options
+ temp read temperature, no optionsy
+ resettemp resets the 1-wire logic
+ dac set LTC-DAC data. options: \$channel, \$data
+ pwm set PWM data. options: \$channel, \$data
+ compensation read/set temperature compensation data. options: \$data
+ dischargedisable set input diable. options: \$data
+ dischargeoverride Set discharge signal if disabled. options: \$data
+ dischargehighz Set discharge signal to highZ. options: \$data
+ dischargedelayinvert Invert signal used for delay generation. options: \$data
+ dischargedelayiselect options: \$data, 4 bits
+ inputenable read inputenable register. If option \"data\" given: write input enable bits
+ bits: 0: enable, 1: disable
+ counter input signal counter. options: \$channel
+ invert set invert status. options: \$data
+ led set led status. options: data (5 bit, highest bit is override enable)
+ read LED status. no options
+ ledoff turn off LEDs: First reads firmware-version and according to that turns
+ monitor set input for monitor output. options: data (4 bit).
+ 0x10: OR of all channels, 0x18: or of all channels, extended to 16ns
+ stretch read/set stretcher status.
+ ram writes the RAM content, options: 16 byte in hex notation, separated by space, no 0x.
+ read the RAM content (16 Byte)
+ flash execute flash command, options: \$command, \$page. See manual for commands.
+ enablecfgflash enable or disable access to configuration flash, options: 1/0
+ erasecfgflash erases the config flash
+ dumpcfgflash Dump content of configuration flash. Pipe output to file
+ writecfgflash Write content of configuration flash. options: \$filename
+ fifo Read a byte from the test fifo (if present, no options)
+ writereg|wr Write to a register
+ readreg|rr Read a register
+EOF
+
exit;
}
-if ($help || !defined $endpoint || !defined $chain || !defined $execute) {
+if ($help || !defined $endpoint || !defined $chain) {
usage();
}
-$endpoint = &conv_input_string_to_number($endpoint, "endpoint", "hex");
-$chain = &conv_input_string_to_number($chain, "chain");
-
-$register = &conv_input_string_to_number($register, "register") if (defined $register);
-#&conv_input_string_to_number(\$execute, "execute") if (defined $execute);
-$channel = &conv_input_string_to_number($channel, "channel") if (defined $channel);
-$data = &conv_input_string_to_number($data, "data") if (defined $data);
-
-$ref_voltage = &conv_input_string_to_number($ref_voltage, "ref_voltage") if (defined $ref_voltage);
+$endpoint = &conv_input_string_to_number($endpoint, "endpoint", "hex");
+$chain = &conv_input_string_to_number($chain, "chain");
+$register = &conv_input_string_to_number($register, "register") if (defined $register);
+$channel = &conv_input_string_to_number($channel, "channel") if (defined $channel);
+$data = &conv_input_string_to_number($data, "data") if (defined $data);
+$ref_voltage = &conv_input_string_to_number($ref_voltage, "ref_voltage") if (defined $ref_voltage);
+$flashcmd = &conv_input_string_to_number($flashcmd, "flashcmd") if (defined $flashcmd);
+$flashaddress = &conv_input_string_to_number($flashaddress, "flashaddress") if (defined $flashaddress);
+$enablecfgflash = &conv_input_string_to_number($enablecfgflash, "enablecfgflash") if (defined $enablecfgflash);
#print "execute: $execute\n";
#exit;
my @cmd = @_;
my $c = [@cmd,1<<$chain,16+0x80];
# print Dumper $c;
- trb_register_write_mem($board,0xd400,0,$c,scalar @{$c});
+ trb_register_write_mem($endpoint,0xd400,0,$c,scalar @{$c});
usleep(1000);
}
sub sendcmd {
my ($cmd) = @_;
$sendcmd_executed_once = 1;
- #print "endpoint: $endpoint, chain: $chain\n";
+ #printf("endpoint: 0x%x, chain: 0x%x, cmd: 0x%x\n", $endpoint, $chain, $cmd);
return Dmon::PadiwaSendCmd($cmd,$endpoint,$chain);
- # my $c = [$cmd,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1<<$chain,1];
- # trb_register_write_mem($board,0xd400,0,$c,scalar @{$c});
- # trb_register_write($board,0xd410,1<<$chain) or die "trb_register_write: ", trb_strerror();
- # trb_register_write($board,0xd411,1);
- # usleep(1000);
- # return trb_register_read($board,0xd412);
}
sub flash_is_busy {
- sendcmd(0x50800000);
- my $b = sendcmd(0x40000000);
- return (($b->{$board} >> 15) & 0x1);
+ my $b = sendcmd(0x5C<<$REGNR | $READ );
+ return (($b->{$endpoint} >> 2) & 0x1);
}
if ($execute eq "temp") {
}
-if ($execute eq "uid") {
+if ($execute eq "uid" || defined $time) {
my $ids;
for (my $i = 0; $i <= 3; $i++) {
- my $b = sendcmd( (0x10+$i)<<24 );
+ my $b = sendcmd( (0x10+$i)<<$REGNR );
#print "uid: send done\n";
#exit;
foreach my $e (sort keys %$b) {
if ($execute eq "dac" && defined $ARGV[4]) {
die("not implemented");
- my $b = sendcmd(0x00300000+$ARGV[3]*0x10000+($value&0xffff));
+ #my $b = sendcmd(0x00300000+$ARGV[3]*0x10000+($value&0xffff));
print "Wrote PWM settings.\n";
}
if ($execute eq "pwm") {
+ die "the command pwm needs an --channel option." if (!defined $channel);
if(!defined $data) {
- my $b = sendcmd($channel << 24 | 0x0<<20);
+ my $b = sendcmd($channel<<$REGNR | $READ);
foreach my $e (sort keys %$b) {
printf("endpoint: 0x%04x chain: %d channel: %d raw: 0x%04x voltage: %4.2f mV\n",
$e, $chain, $channel, $b->{$e}&0xffff, ($b->{$e}&0xffff)*$ref_voltage/65536 );
}
else {
- my $b = sendcmd($channel << 24 | 0x8<<20 | ($data&0xffff));
- }
-}
-
-if ($execute eq "comp" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x20860000+($mask&0xffff));
- print "Wrote Temperature Compensation settings.\n";
-}
-
-if ($execute eq "comp") {
- die("not implemented");
- my $b = sendcmd(0x20060000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0xffff);
- }
-}
-
-if ($execute eq "discdisable" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x20870000+($mask&0x00ff));
- print "Wrote Discharge Disable settings.\n";
-}
-
-if ($execute eq "discdisable") {
- die("not implemented");
- my $b = sendcmd(0x20070000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0xff);
- }
-}
-
-if ($execute eq "discoverride" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x20880000+($mask&0x00ff));
- print "Wrote Discharge Disable settings.\n";
-}
-
-if ($execute eq "discoverride") {
- die("not implemented");
- my $b = sendcmd(0x20080000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0xff);
- }
-}
-
-if ($execute eq "dischighz" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x20890000+($mask&0x00ff));
- print "Wrote Discharge Disable settings.\n";
-}
-
-if ($execute eq "dischighz") {
- die("not implemented");
- my $b = sendcmd(0x20090000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0xff);
- }
-}
-
-
-if ($execute eq "discdelayinvert" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x208a0000+($mask&0x00ff));
- print "Wrote Discharge Disable settings.\n";
-}
-
-if ($execute eq "discdelayinvert") {
- die("not implemented");
- my $b = sendcmd(0x200a0000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0xff);
- }
-}
-
-
-if ($execute eq "disable" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x20800000+($mask&0xffff));
- print "Wrote Input Disable settings.\n";
-}
-
-if ($execute eq "disable") {
- die("not implemented");
- my $b = sendcmd(0x20000000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0xffff);
- }
-}
-
-
-if ($execute eq "invert" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x20840000+($mask&0xffff));
- print "Wrote Input Invert settings.\n";
-}
-
-if ($execute eq "invert") {
- die("not implemented");
- my $b = sendcmd(0x20040000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0xffff);
+ my $b = sendcmd($channel<<$REGNR | $WRITE | ($data&0xffff));
}
}
-if ($execute eq "stretch" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x20850000+($mask&0xffff));
- print "Wrote Input Stretcher settings.\n";
-}
-
-if ($execute eq "stretch") {
- die("not implemented");
- my $b = sendcmd(0x20050000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0xffff);
- }
-}
+sub check_std_io {
+ (my $command, my $register) = @_;
-if ($execute eq "inputenable") {
- if(!defined $data) {
- my $b = sendcmd(0x20 << 24 | 0x0 << 20);
- foreach my $e (sort keys %$b) {
- printf("endpoint: 0x%04x chain: %d inputenable: 0x%04x\n",
- $e, $chain, $b->{$e}&0xffff);
+ if ($execute eq $command) {
+ if(!defined $data) {
+ my $b = sendcmd($register<<$REGNR | $READ);
+ foreach my $e (sort keys %$b) {
+ printf("endpoint: 0x%04x chain: %d $command: 0x%04x\n",$e,$chain,$b->{$e}&0xffff);
+ }
+ }
+ else {
+ my $b = sendcmd($register<<$REGNR | $WRITE | ($data & 0xffff));
}
- }
- else {
- my $b = sendcmd(0x20 << 24 | 0x8 << 20 | ($data&0xffff) );
}
}
-if ($execute eq "inputstatus") {
- my $b = sendcmd(0x21 << 24 | 0x0 << 20);
- foreach my $e (sort keys %$b) {
- printf("endpoint: 0x%04x chain: %d inputstatus: 0x%04x\n",
- $e, $chain, $b->{$e}&0xffff);
- }
-}
+check_std_io("inputenable", 0x20);
+check_std_io("inputstatus", 0x21);
+check_std_io("led", 0x22);
+check_std_io("monitor", 0x23);
+check_std_io("invert", 0x24);
+check_std_io("stretch", 0x25);
+check_std_io("compensation", 0x26);
+check_std_io("dischargedisable", 0x27);
+check_std_io("dischargeoverride", 0x28);
+check_std_io("dischargehighz", 0x29);
+check_std_io("dischargedelayinvert", 0x2a);
+check_std_io("dischargedelayselect", 0x2b);
if ($execute eq "ledoff") {
- die("not implemented");
- my $ids;
- for (my $i = 0; $i <= 1; $i++) {
- my $b = sendcmd(0x21000000 + $i*0x10000);
- #print Dumper $b;
- $ids->{$board}->{$i} = $b->{$board}&0xffff;
- }
-
- my $unix_compile_time = $ids->{$board}->{1}*2**16+$ids->{$board}->{0};
- if ($unix_compile_time >= 0x546f1960) {
- $mask = 0x0;
- } else {
- $mask =0x10;
- }
-
- if (!defined &trb_init_ports()) {
- die("can not connect to trbnet-daemon on the $ENV{'DAQOPSERVER'}");
- }
-
- my $b = sendcmd(0x20820000+($mask&0x1ff));
- printf "turned LEDs off with command 0x%02x after reading firmware version\n",$mask;
-}
-
-
-if ($execute eq "led" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x20820000+($mask&0x1ff));
- print "Wrote LED settings.\n";
-}
-
-if ($execute eq "led") {
- die("not implemented");
- my $b = sendcmd(0x20020000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0x1ff);
- }
+ my $b = sendcmd(0x22<<$REGNR | $WRITE | 0);
}
if ($execute eq "counter" && defined $ARGV[3]) {
}
-if ($execute eq "monitor" && defined $ARGV[3]) {
- die("not implemented");
- my $b = sendcmd(0x20830000+($mask&0x1f));
- print "Wrote monitor settings.\n";
-}
-
-if ($execute eq "monitor") {
- die("not implemented");
- my $b = sendcmd(0x20030000);
- foreach my $e (sort keys %$b) {
- printf("0x%04x\t%d\t0x%04x\n",$e,$chain,$b->{$e}&0x1f);
- }
-}
-
if ($execute eq "readreg" || $execute eq "rr" ) {
if (!defined $register) {
print "for the command readreg an option --register|r is missing.\n";
usage;
}
- my $b = sendcmd($register<<24 | 0x0 << 20);
+ my $b = sendcmd($register<<$REGNR | $READ);
foreach my $e (sort keys %$b) {
printf("0x%x\n", ($b->{$e}) & 0xffff);
}
print "for the command writereg an option --data|d is missing.\n";
usage;
}
- my $b = sendcmd($register << 24 | 0x8 << 20 | ($data & 0xffff) );
+ my $b = sendcmd($register<<$REGNR | $WRITE | ($data & 0xffff) );
}
if ($execute eq "time") {
my $ids;
for (my $i = 0; $i <= 2; $i++) {
- my $b = sendcmd( (0x30+$i) << 24 );
+ my $b = sendcmd( (0x30+$i)<<$REGNR | $READ );
foreach my $e (sort keys %$b) {
$ids->{$e}->{$i} = $b->{$e}&0xffff;
}
}
foreach my $e (sort keys %$ids) {
- printf("endpoint: 0x%04x chain: %d version: 0x%02x raw: 0x%04x%04x\t%s\n",
+ printf("endpoint: 0x%04x chain: %d version: 0x%02x raw: 0x%04x%04x %s\n",
$e, $chain, $ids->{$e}->{2}, $ids->{$e}->{1}, $ids->{$e}->{0},
time2str('%Y-%m-%d %H:%M', ( ($ids->{$e}->{1})<<16 | ($ids->{$e}->{0}) )) );
}
}
if ($execute eq "ram" && defined $ARGV[18]) {
-
+ die("not implemented");
my @a;
for (my $i=0;$i<16;$i++) {
push(@a,0x40800000+hex($ARGV[3+$i])+($i << 16));
}
if ($execute eq "ram") {
+ die("not implemented");
for (my $i=0;$i<16;$i++) {
my $b = sendcmd(0x40000000 + ($i << 16));
foreach my $e (sort keys %$b) {
printf("\n");
}
-if ($execute eq "flash" && defined $ARGV[4]) {
- my $c = 0x50800000+(($mask&0xe)<< 12)+($value&0x1fff);
+###################################################################################################
+if (defined $flashcmd) {
+ #my $c = 0x50800000 + (($mask&0xe)<< 12) + ($value&0x1fff);
+ if (!defined $flashaddress) {
+ $flashaddress=0;
+ }
+ my $c = 0x50<<$REGNR | $WRITE | (($flashcmd&0xe)<< 12) + ($flashaddress&0x1fff);
my $b = sendcmd($c);
- printf("Sent command\n");
+ printf("Sent flash command $flashcmd\n");
}
-if ($execute eq "dumpcfg") {
+###################################################################################################
+if (defined $enablecfgflash) {
+ die "--enableccfgflash can only be 0 or 1\n" unless ($enablecfgflash == 0 || $enablecfgflash == 1);
+ my $c = 0x5C<<$REGNR | $WRITE | $enablecfgflash;
+ my $b = sendcmd($c);
+ my $str = ($enablecfgflash) ? "enabled" : "disabled";
+ printf("$str cfgflash.\n");
+}
+
+###################################################################################################
+if (defined $dumpcfgflash) {
for (my $p = 0; $p<5760; $p++) { #5758
- sendcmd(0x50800000 + $p);
+ sendcmd(0x50<<$REGNR | $WRITE | $p); # read page $p
printf("0x%04x:\t",$p);
for (my $i=0;$i<16;$i++) {
- my $b = sendcmd(0x40000000 + ($i << 16));
+ my $b = sendcmd( (0x40+$i)<<$REGNR | $READ );
foreach my $e (sort keys %$b) {
printf(" %02x ",$b->{$e}&0xff);
}
printf(STDERR "\r%d / 5760",$p) if(!($p%10));
}
}
+###################################################################################################
-if ($execute eq "enablecfg" && defined $ARGV[3]) {
- my $c = 0x5C800000 + $ARGV[3];
- my $b = sendcmd($c);
- printf("Sent command.\n");
-}
-
-if ($execute eq "erasecfg") {
+if ($execute eq "erasecfgflash") {
while (flash_is_busy()) {
printf(" busy - try again\n");
usleep(300000);
}
- ;
- sendcmd(0x5080E000);
+ sendcmd(0x50<<$REGNR | $WRITE | 0xE000);
printf("Sent Erase command.\n");
}
-if ($execute eq "writecfg" && defined $ARGV[3]) {
- open(INF,$ARGV[3]) or die "Couldn't read file : $!\n";
+if ($execute eq "writecfgflash") {
+ if (!defined $filename) {
+ print "for the command writecfgflash an option --filename is missing.\n";
+ #usage;
+ }
+ open(INF, $filename) or die "Couldn't read file : $!\n";
while (flash_is_busy()) {
printf(" busy - try again\n");
usleep(300000);
}
- ;
my $p = 0;
while (my $s = <INF>) {
my @t = split(' ',$s);
if ($sendcmd_executed_once == 0) {
+ print "no command was executed. Given command \"$execute\" seems to be unknown. use \"-h\" for help.\n";
# no command found
- usage();
+ #usage();
+ exit;
}