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

fiji_scripts: fix loading of FIJI Settings

- minor bug slipped in when introducing the cloning the existing settings
- add support for the 'depends_on' property of FIJI constants
parent c6d2206d
......@@ -44,14 +44,14 @@ BEGIN {
},
CLOCK_NET => {
ini_name => "CLOCK_NET",
phases_opt => [qw(setup)],
phases_opt => [qw(setup download)],
type => 'net',
},
FREQUENCY => {
ini_name => "FREQUENCY",
default => 50e6,
type => 'natural',
phases_opt => [qw(setup)],
phases_opt => [qw(setup download)],
unit => 'Hz',
},
BAUDRATE => {
......
......@@ -48,14 +48,12 @@ sub new ($;$$) {
$fiji_settings_ref = _clone($existing_settings);
}
# If there is a file given, try to read it. Else just add an empty FIUs array.
if (defined($fiji_ini_file)) {
$fiji_settings_ref = read_settingsfile($phase, $fiji_ini_file, $fiji_settings_ref);
if (!ref($fiji_settings_ref)) {
return $fiji_settings_ref; # actually an error message
}
if (defined($existing_settings)) {
return $existing_settings;
}
} else {
$fiji_settings_ref->{'FIUs'} = ();
}
......@@ -278,7 +276,7 @@ sub read_settingsfile {
}
splice(@{$fiji_settings_ref->{'FIUs'}}, $fiu_num);
$logger->info("Successfully read in design constants and $fiu_num FIU definitions from FIJI Settings file.");
$logger->info("Successfully read in design constants and $fiu_num FIU definitions from FIJI Settings file \"$fiji_ini_file\".");
return $fiji_settings_ref;
}
......@@ -482,6 +480,13 @@ sub _sanitize_fiu ($;$) {
}
sub _disabled_via_dependency ($$$) {
my ($map_ref, $consts_ref, $k) = @_;
my $dependency = $map_ref->{$k}->{'depends_on'};
return defined($dependency) && !$consts_ref->{$dependency};
}
sub _validate_hashmap ($$;$) {
my $logger = get_logger();
my ($map_ref, $consts_ref, $phase) = @_;
......@@ -494,9 +499,10 @@ sub _validate_hashmap ($$;$) {
next;
}
# mark constant key as done
@map_keys = grep {$_ ne $entry_key} @map_keys;
if (!validate_value($map_ref, $entry_key, \$consts_ref->{$entry_key})) {
@map_keys = grep {$_ ne $entry_key} @map_keys; # mark constant key as done
if (_disabled_via_dependency($map_ref, $consts_ref, $entry_key)) {
$logger->debug(sprintf("Key %s is disabled via %s. Skipping validation.", $entry_key, $map_ref->{$entry_key}->{'depends_on'}));
} elsif (!validate_value($map_ref, $entry_key, \$consts_ref->{$entry_key})) {
my $msg = sprintf("%s = %s is invalid.", $entry_key, !defined($consts_ref->{$entry_key}) ? "<undef>" : $consts_ref->{$entry_key});
$logger->error($msg);
return $msg;
......@@ -513,7 +519,11 @@ sub _validate_hashmap ($$;$) {
# Iterate over the constants defined in FIJI.pm that apparently are
# not contained in $consts_ref.
foreach my $k (@map_keys) {
if (scalar(grep {$_ eq $phase} @{$map_ref->{$k}->{'phases_opt'}}) == 0) {
my $dependency = $map_ref->{$k}->{'depends_on'};
if (
scalar(grep {$_ eq $phase} @{$map_ref->{$k}->{'phases_opt'}}) == 0 && # mandatory in current phase
!_disabled_via_dependency($map_ref, $consts_ref, $k) # no dependency or dependency is enabled
) {
my $msg = "$k is mandatory in phase $phase.";
$logger->error($msg);
return $msg;
......
Markdown is supported
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