Commit d48a6180 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

fiji_scripts: add support for enums in FIJI Settings

parent 93621f1b
......@@ -8,9 +8,10 @@ package FIJI;
# Architecture from http://www.perlmonks.org/?node_id=1072731
# Fields:
# name = key name in FIJI Settings file
# ini_name = key name in FIJI Settings file
# is_numeric = (optional) enables conversion of oct, hex, binary
# strings and checking that the value is really a number.
# values = (optional) an array reference listing all valid values (emulates an enum)
# default = (optional) default value if not given in file and not determinable otherwise
my %designmap;
BEGIN {
......@@ -62,6 +63,7 @@ BEGIN {
FIU_MODEL => {
ini_name => "FAULT_MODEL",
default => "RUNTIME",
values => [qw(RUNTIME STUCK_AT_0 STUCK_AT_1 DELAY SEU STUCK_OPEN PASS_THRU)],
},
FIU_LFSR_EN => {
ini_name => "ENABLED_BY_LFSR",
......
......@@ -110,15 +110,20 @@ sub _set_defaults {
}
}
my $orig = $new_hash->{$k};
# convert non-decimal (hexadecimal, binary, octal) values to decimal
if ($map_ref->{$k}->{'is_numeric'}) {
my $orig = $new_hash->{$k};
$new_hash->{$k} = oct($orig) if $orig =~ /^0/;
$logger->trace("Converted value of $k (\"$orig\") to \"$new_hash->{$k}\".") if ($orig ne $new_hash->{$k});
if (!looks_like_number($new_hash->{$k})) {
$logger->error("$orig does not look like a number.");
return undef;
}
} elsif (defined($map_ref->{$k}->{'values'})) {
if (!grep {$_ eq $new_hash->{$k}} @{$map_ref->{$k}->{'values'}}) {
$logger->error("$new_hash->{$k} is not allowed. Allowed values are: " . join(", ", @{$map_ref->{$k}->{'values'}}));
return undef;
}
}
}
return $new_hash;
......
......@@ -12,23 +12,29 @@ LFSR_BIT_FOR_STUCK_OPEN=1
LFSR_MASK=0x0000
[FIU1]
NET_NAME = bla1
NET_NAME=bla1
FAULT_MODEL=PASS_THRU
[FIU2]
NET_NAME = bla2
NET_NAME=bla2
FAULT_MODEL=STUCK_OPEN
[FIU3]
NET_NAME = bla3
NET_NAME=bla3
FAULT_MODEL=SEU
[FIU4]
NET_NAME = bla4
NET_NAME=bla4
FAULT_MODEL=STUCK_AT_1
[FIU5]
NET_NAME = bla5
NET_NAME=bla5
FAULT_MODEL=STUCK_AT_0
[FIU6]
NET_NAME = bla6
NET_NAME=bla6
FAULT_MODEL=DELAY
[FIU7]
NET_NAME = bla7
NET_NAME=bla7
# FAULT_MODEL=FAIL
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment