Commit d1434c5e authored by Christian Fibich's avatar Christian Fibich Committed by Stefan Tauner
Browse files

Implemented some ToDos

parent 5707ffb8
......@@ -23,6 +23,7 @@
#
# Various constants used in the FIJI packages.
package FIJI;
use Cwd;
use strict;
use warnings;
......@@ -83,6 +84,7 @@ BEGIN {
ini_name => "CLOCK_NET",
phases_opt => [qw(setup download)],
group => 'clock',
order => 10,
},
FREQUENCY => {
description => "Clock frequency",
......@@ -93,6 +95,17 @@ BEGIN {
phases_opt => [qw(setup download)],
unit => 'Hz',
group => 'clock',
order => 20,
},
OUTPUT_DIR => {
description => "Output directory",
help => "Output directory for FIJI Instrument",
ini_name => "OUTPUT_DIR",
default => getcwd(),
type => 'dir',
group => 'general_control',
phases_opt => [qw(setup)],
order => 5,
},
BAUDRATE => {
description => "Baud rate",
......@@ -102,6 +115,7 @@ BEGIN {
type => 'natural',
unit => 'bps',
group => 'general_control',
order => 10,
},
ID => {
description => "Design ID",
......@@ -123,6 +137,7 @@ BEGIN {
return ($val > 0 && $val <= 16);
},
group => 'general_control',
order => 20,
},
LFSR_WIDTH => {
description => "LFSR width",
......@@ -136,6 +151,7 @@ BEGIN {
return $val > 0 && $val <= 64;
},
group => 'lfsr',
order => 10,
},
LFSR_POLY => {
description => "LFSR polynomial",
......@@ -148,6 +164,7 @@ BEGIN {
return $val > 0 && $val <= (2**64 - 1);
},
group => 'lfsr',
order => 20,
},
LFSR_SEED => {
description => "LFSR seed value",
......@@ -160,6 +177,7 @@ BEGIN {
return $val >= 0 && $val <= (2**64 - 1);
},
group => 'lfsr',
order => 30,
},
# External reset
RESET_EXT_EN => {
......@@ -169,6 +187,7 @@ BEGIN {
default => 0,
type => 'boolean',
group => 'reset_external',
order => 10,
},
RESET_EXT_ACTIVE => {
description => "External Reset: Active level",
......@@ -179,6 +198,7 @@ BEGIN {
default => '1',
depends_on => 'RESET_EXT_EN',
group => 'reset_external',
order => 20,
},
RESET_EXT_IN_NAME => {
description => "External Reset: Port name (prefix)",
......@@ -190,6 +210,7 @@ BEGIN {
group => 'reset_external',
depends_on => 'RESET_EXT_EN',
phases_opt => [qw(instrument download)],
order => 30,
},
# Reset from DUT
RESET_DUT_OUT_EN => {
......@@ -200,6 +221,7 @@ BEGIN {
type => 'boolean',
group => 'reset_from_dut',
forbidden_by => 'RESET_DUT_IN_EN',
order => 10,
},
RESET_DUT_OUT_NAME => {
description => "Source net for DUT-to-FIJI reset",
......@@ -208,6 +230,7 @@ BEGIN {
depends_on => 'RESET_DUT_OUT_EN',
type => 'net',
group => 'reset_from_dut',
order => 30,
},
RESET_DUT_OUT_ACTIVE => {
description => "Active level for DUT-to-FIJI reset",
......@@ -218,6 +241,7 @@ BEGIN {
default => '1',
depends_on => 'RESET_DUT_OUT_EN',
group => 'reset_from_dut',
order => 20,
},
# Reset to DUT
RESET_DUT_IN_EN => {
......@@ -228,6 +252,7 @@ BEGIN {
type => 'boolean',
group => 'reset_to_dut',
forbidden_by => 'RESET_DUT_OUT_EN',
order => 10,
},
RESET_DUT_IN_NAME => {
description => "Port for FIJI-to-DUT reset",
......@@ -236,6 +261,7 @@ BEGIN {
depends_on => 'RESET_DUT_IN_EN',
type => 'toplevel_port',
group => 'reset_to_dut',
order => 40,
},
RESET_DUT_IN_DURATION => {
description => "Duration for FIJI-to-DUT reset",
......@@ -250,6 +276,7 @@ BEGIN {
},
depends_on => 'RESET_DUT_IN_EN',
group => 'reset_to_dut',
order => 30,
},
RESET_DUT_IN_ACTIVE => {
description => "Active level for FIJI-to-DUT reset",
......@@ -260,6 +287,7 @@ BEGIN {
default => '1',
depends_on => 'RESET_DUT_IN_EN',
group => 'reset_to_dut',
order => 20,
},
# Trigger from DUT
TRIGGER_DUT_EN => {
......@@ -271,6 +299,7 @@ BEGIN {
default => 0,
type => 'boolean',
group => 'trigger',
order => 10,
},
TRIGGER_DUT_NAME => {
description => "Source net for DUT-to-FIJI trigger",
......@@ -279,6 +308,7 @@ BEGIN {
depends_on => 'TRIGGER_DUT_EN',
type => 'net',
group => 'trigger',
order => 20,
},
TRIGGER_DUT_ACTIVE => {
description => "Active level for DUT-to-FIJI trigger",
......@@ -289,6 +319,7 @@ BEGIN {
default => '1',
depends_on => 'TRIGGER_DUT_EN',
group => 'trigger',
order => 30,
},
# External trigger
TRIGGER_EXT_EN => {
......@@ -301,6 +332,7 @@ BEGIN {
default => 0,
type => 'boolean',
group => 'trigger',
order => 40,
},
TRIGGER_EXT_ACTIVE => {
description => "Active level for external trigger",
......@@ -311,6 +343,7 @@ BEGIN {
default => '1',
depends_on => 'TRIGGER_EXT_EN',
group => 'trigger',
order => 50,
},
TRIGGER_EXT_IN_NAME => {
description => "External trigger port name (prefix)",
......@@ -321,6 +354,7 @@ BEGIN {
default => "s_fiji_trigger_ext",
depends_on => 'TRIGGER_EXT_EN',
group => "trigger",
order => 60,
},
FAULT_DETECT_1_EN => {
description => "Enable fault-detect bit 1",
......@@ -332,6 +366,7 @@ BEGIN {
type => 'boolean',
default => 0,
group => 'fault_detect',
order => 10,
},
FAULT_DETECT_1_NAME => {
description => "Source net for fault-detect bit 1",
......@@ -340,6 +375,7 @@ BEGIN {
type => 'net',
depends_on => 'FAULT_DETECT_1_EN',
group => 'fault_detect',
order => 20,
},
FAULT_DETECT_1_INVERT => {
description => "Invert fault detect bit 1",
......@@ -351,6 +387,7 @@ BEGIN {
default => '0',
depends_on => 'FAULT_DETECT_1_EN',
group => 'fault_detect',
order => 30,
},
FAULT_DETECT_2_EN => {
description => "Enable fault-detect bit 2",
......@@ -362,6 +399,7 @@ BEGIN {
type => 'boolean',
default => 0,
group => 'fault_detect',
order => 40,
},
FAULT_DETECT_2_NAME => {
description => "Source net for fault-detect bit 2",
......@@ -370,6 +408,7 @@ BEGIN {
type => 'net',
depends_on => 'FAULT_DETECT_2_EN',
group => 'fault_detect',
order => 50,
},
FAULT_DETECT_2_INVERT => {
description => "Invert fault detect bit 2",
......@@ -381,6 +420,7 @@ BEGIN {
default => '0',
depends_on => 'FAULT_DETECT_2_EN',
group => 'fault_detect',
order => 60,
},
RX_IN_NAME => {
description => "RX port name",
......@@ -389,6 +429,7 @@ BEGIN {
default => "s_fiji_rx_i",
phases_opt => [qw(instrument download)],
group => "general_control",
order => 30,
},
TX_OUT_NAME => {
description => "TX port name",
......@@ -397,6 +438,7 @@ BEGIN {
phases_opt => [qw(instrument download)],
default => "s_fiji_tx_o",
group => "general_control",
order => 40,
},
);
}
......@@ -410,42 +452,50 @@ BEGIN {
fault_detect => {
title => "Fault Detection Settings",
subtitle => "",
description => "Settings concerning internal fault detection propagation"
description => "Settings concerning internal fault detection propagation",
order => 80,
},
trigger => {
title => "Trigger Settings",
subtitle => "",
description => "Settings concerning internal and external fault injection triggers"
description => "Settings concerning internal and external fault injection triggers",
order => 70,
},
reset_to_dut => {
title => "Reset from FIC to DUT",
subtitle => "",
description => "Settings concerning FIJI's ability to reset the DUT"
description => "Settings concerning FIJI's ability to reset the DUT",
order => 60,
},
reset_from_dut => {
title => "Reset from DUT to FIC",
subtitle => "",
description => "Settings concerning FIJI's internal (from DUT) reset feature"
description => "Settings concerning FIJI's internal (from DUT) reset feature",
order => 50,
},
reset_external => {
title => "External Reset",
subtitle => "",
description => "Settings concerning FIJI's external (via pin) reset feature"
description => "Settings concerning FIJI's external (via pin) reset feature",
order => 40,
},
lfsr => {
title => "LFSR Settings",
subtitle => "",
description => "Settings concerning the LFSR for Stuck-open emulation"
description => "Settings concerning the LFSR for Stuck-open emulation",
order => 30,
},
general_control => {
title => "General FIC settings",
subtitle => "",
description => "Settings concerning miscellanous features of FIJI"
description => "Settings concerning miscellanous features of FIJI",
order => 10,
},
clock => {
title => "Clock settings",
subtitle => "",
description => "Settings concerning the clocking of the FIJI logic"
description => "Settings concerning the clocking of the FIJI logic",
order => 20,
}
)
}
......@@ -501,6 +551,7 @@ BEGIN {
ini_name => "UART",
default => "/dev/ttyUSB0",
gui_modes => [qw (manual auto random)],
order => 120,
},
NUM_TESTS => {
ini_name => "NUM_TESTS",
......@@ -514,6 +565,7 @@ BEGIN {
type => 'boolean',
phases_opt => [qw(manual)],
gui_modes => [qw (auto)],
order => 11,
},
REPEAT_OFFSET => {
description => "Repetition start pattern",
......@@ -522,6 +574,7 @@ BEGIN {
type => 'natural',
phases_opt => [qw(manual)],
gui_modes => [qw (auto)],
order => 12,
},
HALT_ON_FAULT_DETECT => {
description => "Halt on detected fault",
......@@ -530,6 +583,7 @@ BEGIN {
type => 'boolean',
phases_opt => [qw(manual)],
gui_modes => [qw (auto random)],
order => 10,
},
HALT_ON_UART_ERROR => {
ini_name => "HALT_ON_UART_ERROR",
......@@ -562,30 +616,43 @@ BEGIN {
type => 'boolean',
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
order => 60,
},
MIN_DURATION_T1 => {
description => "Minimum Duration T1",
ini_name => "MIN_DURATION_T1",
phases_opt => [qw(manual auto)],
description => "Minimum Duration T1",
ini_name => "MIN_DURATION_T1",
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
type => "min_duration",
matching => "MAX_DURATION_T1",
order => 20,
},
MIN_DURATION_T2 => {
description => "Minimum Duration T2",
ini_name => "MIN_DURATION_T2",
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
type => "min_duration",
matching => "MAX_DURATION_T2",
order => 40,
},
MAX_DURATION_T1 => {
description => "Maximum Duration T1",
ini_name => "MAX_DURATION_T1",
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
type => "max_duration",
matching => "MIN_DURATION_T1",
order => 30,
},
MAX_DURATION_T2 => {
description => "Maximum Duration T2",
ini_name => "MAX_DURATION_T2",
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
type => "max_duration",
matching => "MIN_DURATION_T1",
order => 50,
},
PROB_STUCK_AT_0 => {
description => "Probability of stuck-at-0 fault",
......@@ -594,6 +661,7 @@ BEGIN {
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
fault => "STUCK_AT_0",
order => 70,
},
PROB_STUCK_AT_1 => {
description => "Probability of stuck-at-1 fault",
......@@ -602,6 +670,7 @@ BEGIN {
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
fault => "STUCK_AT_1",
order => 80,
},
PROB_DELAY => {
description => "Probability of delay fault",
......@@ -610,6 +679,7 @@ BEGIN {
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
fault => "DELAY",
order => 90,
},
PROB_SEU => {
description => "Probability of single event upset",
......@@ -618,6 +688,7 @@ BEGIN {
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
fault => "SEU",
order => 100,
},
PROB_STUCK_OPEN => {
description => "Probability of stuck-open fault",
......@@ -626,6 +697,7 @@ BEGIN {
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
fault => "STUCK_OPEN",
order => 110,
},
);
}
......@@ -698,6 +770,7 @@ sub REVERSE_FIU_ENUM {
return "NONE";
}
use constant {HOST_TO_FIC_LATENCY => 1.0e-3}; # 1 ms minimum latency
## @function ini2constkey ($ini_name, %$map_ref)
#
......@@ -721,7 +794,7 @@ our @EXPORT = (keys(%designmap), keys(%fiumap), keys(%testpatmap), keys(%te
our @EXPORT_OK = (keys(%designmap), 'DESIGNMAP', keys(%fiumap), 'FIUMAP', keys(%testpatmap),
'TESTPATMAP', keys(%testconstmap), 'TESTCONSTMAP', keys(%fiuenum), 'FIUENUM',
'REVERSE_FIU_ENUM','DISPLAYGROUPS',keys(%displaygroups),
'TESTGUIMODES', keys(%testguimodes));
'TESTGUIMODES', keys(%testguimodes), 'HOST_TO_FIC_LATENCY');
## @var @EXPORT_TAGS Export Tags
#
......
......@@ -467,7 +467,7 @@ sub _rcv_bitstream {
last;
} else {
$todo -= $count;
push($buf_ref, unpack('C*', $tmp));
push(@{$buf_ref}, unpack('C*', $tmp));
}
}
......
......@@ -140,11 +140,15 @@ sub _test_fi_uart {
sub download_auto ($) {
my $msg;
my $logger = get_logger();
my ($self,$portname) = @_;
my ($self,$portname,$intermediate_cb) = @_;
my $fiji_tests = $self->{'fiji_tests'};
my $fiji_design_consts = $self->{'fiji_settings'}->{'design'};
if (!defined $intermediate_cb) {
$intermediate_cb = sub {return 1;};
}
$portname = $fiji_tests->{'design'}->{'UART'} if (!defined $portname);
my $port =
FIJI::Connection->init( $portname, $fiji_design_consts->{'BAUDRATE'} )
......@@ -176,6 +180,13 @@ sub download_auto ($) {
$logger->error($rv) if defined ($rv);
return $recv_msg;
}
if(&$intermediate_cb($recv_msg) == 0) {
my $rv = $fiji_tests->export_as_sim_script("sim.script",$ti,$ri,$self->{'fiji_settings'});
$logger->info("Fulfilling halt request after test: $ti, repetition $ri.");
return $recv_msg;
}
}
# FIXME Repeat information comes from tests config file. OK?
......@@ -205,17 +216,16 @@ sub download_auto ($) {
# portname Optional serial port to use
sub download_random ($$$;$) {
my $logger = get_logger();
my ($self,$testref,$portname, $rmsg_ref) = @_;
my ($self,$testref,$portname, $intermediate_cb) = @_;
my $fiji_design_consts = $self->{'fiji_settings'}->{'design'};
print $rmsg_ref;
$testref = clone($self->{'fiji_tests'});
print $portname." ".$fiji_design_consts->{'BAUDRATE'}."\n";
$portname = $testref->{'design'}->{'UART'} if (!defined $portname);
print $portname." ".$fiji_design_consts->{'BAUDRATE'}."\n";
if (!defined $intermediate_cb) {
$intermediate_cb = sub {return 1;};
}
my $port =
FIJI::Connection->init( $portname, $fiji_design_consts->{'BAUDRATE'} )
......@@ -226,22 +236,30 @@ sub download_random ($$$;$) {
my @tests;
my $ti = 0;
my $recv_msg;
my $check = 0;
my $cont;
do {
@tests[$ti] = $testref->make_random_test($self->{'fiji_settings'});
my $temp_test = $testref->make_random_test($self->{'fiji_settings'});
return $temp_test if(!ref($temp_test));
@tests[$ti] = $temp_test;
$logger->info("=== Test $ti ===");
$recv_msg = $self->_download_test($tests[$ti++],$port);
$$rmsg_ref = 5;
} while ($self->_check_halt($recv_msg) != 1);
$logger->error("Halt because of HALT_ON_xxx. Failed test: ".($ti-1));
$testref->{'design'}->{'NUM_TESTS'} = $ti;
$testref->{'design'}->{'REPEAT'} = 0;
$testref->{'design'}->{'REPEAT_OFFSET'} = 0;
$testref->{'tests'} = \@tests;
$testref->export_as_sim_script("sim.script",$ti-1,0,$self->{'fiji_settings'});
$testref->save("fiji_tests_random.cfg");
return "UART transaction failed." if (ref($recv_msg) ne "HASH");
$check = $self->_check_halt($recv_msg);
$cont = &$intermediate_cb($recv_msg);
} while ($check != 1 && $cont != 0);
$logger->error("Halt because of HALT_ON_xxx. Failed test: ".($ti-1)) if $check == 1;
$logger->info("Fulfilling halt request after test: ".($ti-1)) if $cont == 0;
# FIXME does not work with threads...
# $testref->{'design'}->{'NUM_TESTS'} = $ti;
# $testref->{'design'}->{'REPEAT'} = 0;
# $testref->{'design'}->{'REPEAT_OFFSET'} = 0;
# $testref->{'tests'} = \@tests;
# $testref->export_as_sim_script("sim.script",$ti-1,0,$self->{'fiji_settings'});
# $testref->save("fiji_tests_random.cfg");
return $recv_msg;
}
......@@ -410,7 +428,12 @@ sub download_test ($$) {
or $logger->fatal("Could not init UART.")
and return "Could not init UART.";
return $self->_download_test($test,$port);
my $rmsg = $self->_download_test($test,$port);
$rmsg = "UART transaction failed." if(ref($rmsg) ne "HASH");
return $rmsg;
}
sub update_rnd($) {
......
......@@ -226,7 +226,7 @@ sub _check_name_in_hierarchy {
# function the function of this port in FIJI (FIJI::VHDL->FIJI_PORTTYPE_xxx)
# index for ORIGINAL,MODIFIED and FAULT_DETECT: the index of this net
# (indent just for formatting output)
sub _add_port_to_hierarchy($$$;$) {
sub _add_port_to_hierarchy {
my $logger = get_logger();
my ($startmod,$name,$function,$index,$indent) = @_;
my $nl = $startmod->netlist;
......
......@@ -39,6 +39,8 @@ use List::Util qw(max);
use FIJI qw(:all);
my @base_resources;
## @function new ($phase, $fiji_ini_file, $existing_settings)
# Create a new settings instance.
#
......@@ -83,6 +85,12 @@ sub new ($;$$) {
$fiji_settings_ref->{'fius'} = [];
}
@base_resources = _est_resources(DESIGNMAP->{'FREQUENCY'}->{'default'},
DESIGNMAP->{'BAUDRATE'}->{'default'},
DESIGNMAP->{'TIMER_WIDTH'}->{'default'},
DESIGNMAP->{'RESET_DUT_IN_DURATION'}->{'default'},
DESIGNMAP->{'LFSR_WIDTH'}->{'default'},0,"logarithmic");
return $fiji_settings_ref;
}
......@@ -644,6 +652,101 @@ sub _log2 {
return ($val > 0) ? (log($val)/log(2)) : 0;
}
## Determined by experiment & fitted by scipy.optimize.curve_fit
#
sub _est_resources {
my $logger = get_logger();
my ($FREQUENCY, $BAUD, $TIMER_WIDTH, $RESET_CYCLES, $LFSR_WIDTH, $FIU_NUM, $algo) = @_;
$algo = "logarithmic" if (!defined $algo);
my $registers;
my $lutsum;
my $lut6;
my $comb;
$logger->debug("FREQUENCY $FREQUENCY out of range (1000000 - 500000000)") if ($FREQUENCY < 1000000 || $FREQUENCY > 500000000);
$logger->debug("BAUD $BAUD out of range (9600 - 3000000)") if ($BAUD < 9600 || $BAUD > 3000000);
$logger->debug("TIMER_WIDTH $TIMER_WIDTH out of range (1 - 8)") if ($TIMER_WIDTH < 1 || $TIMER_WIDTH > 8);
$logger->debug("RESET_CYCLES $RESET_CYCLES out of range (1 - 16)") if ($RESET_CYCLES < 1 || $RESET_CYCLES > 16);
$logger->debug("LFSR_WIDTH $LFSR_WIDTH out of range (16 - 64)") if ($LFSR_WIDTH < 16 || $LFSR_WIDTH > 64);
$logger->debug("FIU_NUM $FIU_NUM out of range (0 - 64)") if ($FIU_NUM < 1 || $FIU_NUM > 64);
if ($algo eq "logarithmic") {
$registers = 105.90215234;
$registers += (-8.78501935753e-10)*($FREQUENCY) + (2.02400278472)*(_log2($FREQUENCY));
$registers += (-1.92362445319e-08)*($BAUD) + (-1.99903895447)*(_log2($BAUD));
$registers += (25.294652022)*($TIMER_WIDTH) + (-3.6942823707)*(_log2($TIMER_WIDTH));
$registers += (-0.0388887762348)*($RESET_CYCLES) + (1.12647034117)*(_log2($RESET_CYCLES));
$registers += (1.0012871074)*($LFSR_WIDTH) + (-0.035302419887)*(_log2($LFSR_WIDTH));
$registers += (13.0019033469)*($FIU_NUM) + (-1.06808285072)*(_log2($FIU_NUM));
$lutsum = 141.184641269;
$lutsum += (5.14383788335e-09)*($FREQUENCY) + (4.44319121639)*(_log2($FREQUENCY));
$lutsum += (8.15160754702e-07)*($BAUD) + (-4.96956691254)*(_log2($BAUD));
$lutsum += (21.280632646)*($TIMER_WIDTH) + (-7.40399315196)*(_log2($TIMER_WIDTH));
$lutsum += (0.0181923149046)*($RESET_CYCLES) + (1.33545547133)*(_log2($RESET_CYCLES));
$lutsum += (0.0264092868862)*($LFSR_WIDTH) + (-0.817645982805)*(_log2($LFSR_WIDTH));
$lutsum += (3.88874581602)*($FIU_NUM) + (0.262418360097)*(_log2($FIU_NUM));
# $lut6 = 108.374524207;
# $lut6 += (2.01487096337e-09)*($FREQUENCY) + (1.83543879998)*(_log2($FREQUENCY));
# $lut6 += (-3.30317499662e-07)*($BAUD) + (-2.11380910663)*(_log2($BAUD));
# $lut6 += (11.2173091132)*($TIMER_WIDTH) + (-4.43369929787)*(_log2($TIMER_WIDTH));
# $lut6 += (-0.154956213792)*($RESET_CYCLES) + (1.35245013922)*(_log2($RESET_CYCLES));
# $lut6 += (0.0215685459865)*($LFSR_WIDTH) + (-0.668625639476)*(_log2($LFSR_WIDTH));
# $lut6 += (2.42277105024)*($FIU_NUM) + (0.194734794118)*(_log2($FIU_NUM));