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

Added feature to autocomplete LFSR_POLY field with maximal polynomials for entered

LFSR length.
Addresses issue #36
parent 3b291579
......@@ -46,6 +46,77 @@ use constant FIJI_DOCUMENTATION_PATH =>
my @optimization_settings = qw(ALLOW OPTIMIZATION_OFF FIX_PLACEMENT);
use constant OPTIMIZATION_SETTINGS => \@optimization_settings;
#
# Maximal period polynomials for LFSRs of given lengths
# Thank you http://www.eej.ulst.ac.uk/~ian/modules/EEE515/files/old_files/lfsr/lfsr_table.pdf
# Our LFSR uses bit numbers are mirrored compared to the document above.
#
use constant LFSR_POLY_CHOICES => {
2 => ["0x3"],
3 => ["0x3"],
4 => ["0x3"],
5 => ["0x5", "0xF"],
6 => ["0x3", "0x1B"],
7 => ["0x3", "0xF"],
8 => ["0x1D"],
9 => ["0x11", "0x1B"],
10 => ["0x9", "0x1B"],
11 => ["0x5", "0x17"],
12 => ["0x53"],
13 => ["0x1B"],
14 => ["0x2B"],
15 => ["0x3", "0x17"],
16 => ["0x2D"],
17 => ["0x9", "0xF"],
18 => ["0x81", "0x27"],
19 => ["0x27"],
20 => ["0x9", "0x53"],
21 => ["0x5", "0x27"],
22 => ["0x3", "0x39"],
23 => ["0x21", "0x2B"],
24 => ["0x1B"],
25 => ["0x9", "0xF"],
26 => ["0x47"],
27 => ["0x27"],
28 => ["0x9", "0x53"],
29 => ["0x5", "0x17"],
30 => ["0x53"],
31 => ["0x9", "0xF"],
32 => ["0xC5"],
33 => ["0x2001", "0x53"],
34 => ["0x119"],
35 => ["0x5", "0x183"],
36 => ["0x801", "0x183"],
37 => ["0x53"],
38 => ["0x63"],
39 => ["0x11", "0x93"],
40 => ["0x39"],
41 => ["0x9", "0xF"],
42 => ["0xA5"],
43 => ["0x63"],
44 => ["0x65"],
45 => ["0x1B"],
46 => ["0x1C1"],
47 => ["0x21", "0x33"],
48 => ["0x291"],
49 => ["0x201", "0x71"],
50 => ["0x1D"],
51 => ["0x4B"],
52 => ["0x9", "0x4B"],
53 => ["0x47"],
54 => ["0x149"],
55 => ["0x1000001", "0x47"],
56 => ["0x95"],
57 => ["0x81", "0x2D"],
58 => ["0x80001", "0x63"],
59 => ["0x95"],
60 => ["0x3", "0x35"],
61 => ["0x27"],
62 => ["0x69"],
63 => ["0x3", "0x33"],
64 => ["0x1B"],
};
#** @var public %designmap Hash containing all FIJI::Settings
#
......@@ -201,7 +272,7 @@ BEGIN {
help => "Enter the polynomial for the LFSR.\n The LFSR is used to emulate \"floating\" nets in the stuck-open model.",
ini_name => "LFSR_POLY",
default => 0x2D,
type => 'hexadecimal',
type => 'lfsrpoly',
depends_on => 'LFSR_WIDTH',
values => sub {
my ($val, $old, $top) = @_;
......@@ -1054,7 +1125,7 @@ sub ini2constkey {
use base 'Exporter';
our @EXPORT = (keys(%designmap), keys(%fiumap), keys(%testpatmap), keys(%testconstmap), keys(%fiuenum), keys(%displaygroups), keys(%testguimodes));
our @EXPORT_OK = ('FIJI_DOCUMENTATION_PATH', 'FIJI_DIR', keys(%designmap), 'DESIGNMAP', keys(%fiumap), 'FIUMAP', keys(%testpatmap), 'TESTPATMAP', keys(%testconstmap), 'TESTCONSTMAP', keys(%fiuenum), 'FIUENUM', 'REVERSE_FIU_ENUM', 'DISPLAYGROUPS', keys(%displaygroups), 'TESTGUIMODES', keys(%testguimodes), 'HOST_TO_FIJI_LATENCY', 'DEFAULT_TIMER_VALUE', 'OPTIMIZATIONS');
our @EXPORT_OK = ('FIJI_DOCUMENTATION_PATH', 'FIJI_DIR', keys(%designmap), 'DESIGNMAP', keys(%fiumap), 'FIUMAP', keys(%testpatmap), 'TESTPATMAP', keys(%testconstmap), 'TESTCONSTMAP', keys(%fiuenum), 'FIUENUM', 'REVERSE_FIU_ENUM', 'DISPLAYGROUPS', keys(%displaygroups), 'TESTGUIMODES', keys(%testguimodes), 'HOST_TO_FIJI_LATENCY', 'DEFAULT_TIMER_VALUE', 'OPTIMIZATIONS', 'LFSR_POLY_CHOICES');
## @var @EXPORT_TAGS Export Tags
#
......
......@@ -101,7 +101,7 @@ sub _export_value {
if (defined($map_ref->{$k}->{'type'})) {
my $orig = ${$v_ref};
if ($map_ref->{$k}->{'type'} eq 'hexadecimal') {
if ($map_ref->{$k}->{'type'} eq 'hexadecimal' || $map_ref->{$k}->{'type'} eq 'lfsrpoly') {
${$v_ref} = sprintf("0x%x", $orig);
# } elsif ($map_ref->{$k}->{'type'} eq 'natural') {
......@@ -392,7 +392,7 @@ sub validate_value {
# @TODO: check syntax? there is nothing more to do in here unless we supply allowed nets...
# which is actually possible because the input netlist is stored in the settings as well
} elsif ($map_ref->{$k}->{'type'} eq 'hexadecimal') {
} elsif ($map_ref->{$k}->{'type'} eq 'hexadecimal' || $map_ref->{$k}->{'type'} eq 'lfsrpoly' ) {
if ($orig !~ /^(0|(0[xX][[:xdigit:]]+))$/) {
$log_func->($logger, "$k: $orig does not look like a natural hexadecimal number.");
return 0;
......
......@@ -104,6 +104,7 @@ sub Populate {
}
# @FIXME: add an option to store a CODE reference that is called when any field is invalid
$self->{'lfsr_poly_choices'} = [];
$self->SUPER::Populate($args);
$self->_populate_widget($self);
$self->ConfigSpecs(
......@@ -272,15 +273,27 @@ sub update {
my $orig_ref = \$self->{'settings'}->{'design'}->{$k};
my $type = DESIGNMAP->{$k}->{'type'};
my $orig = $$orig_ref;
my $val = defined($type) && $type eq 'hexadecimal' ? sprintf("0x%x", $orig) : $orig;
my $autocomplete_choices = defined($type) && $type eq 'toplevel_port' ? $toplevel_port_choices : $net_choices;
my $val = defined($type) && ($type eq 'hexadecimal' || $type eq 'lfsrpoly') ? sprintf("0x%x", $orig) : $orig;
my $autocomplete_choices;
if (defined $type) {
if ($type eq 'toplevel_port') {
$autocomplete_choices = $toplevel_port_choices;
} elsif ($type eq 'net') {
$autocomplete_choices = $net_choices;
} elsif ($type eq 'lfsrpoly') {
$orig_ref = $val;
}
}
# Update widgets depending on their type
if (ref($valw) eq 'Tk::CompleteEntry') {
# Update CompleteEntry Fields with the new choices
# Update CompleteEntry Fields with the new choices if defined
$valw->configure(
'-choices' => $autocomplete_choices,
) if defined ($autocomplete_choices);
$valw->configure(
'-textvariable' => $orig_ref
);
my $valid = $valw->validate();
......@@ -580,6 +593,18 @@ sub _populate_widget {
-column => 2,
'-sticky' => 'ew'
);
} elsif (defined($type) && $type eq 'lfsrpoly') {
# entry for the LFSR poly
$entry = $config_frame->CompleteEntry();
$entry->configure(
'-validate' => 'focusout',
'-validatecommand' => [\&_validate_design_entry, $self, $entry, $k],
);
$entry->grid(
-row => $row,
-column => 2,
'-sticky' => 'ew'
);
} elsif (defined($type) && $type eq 'boolean') {
# checkbutton for values which can only be "enabled" or "disabled"
......@@ -1297,12 +1322,27 @@ sub _validate_entry {
# The following line is needed to re-enable validation IFF the value is
# changed via -textvariable or insert().
# $widget->configure('-validate' => 'key');
# $widget->configure('-validate' => 'key')
if ($ok) {
$$old_ref = $$new_ref;
}
# if we are validating the LFSR WIDTH widget, update the list of
# suggested polynomials
if ($name eq 'LFSR_WIDTH') {
for my $depending_widget (grep {ref($_) eq "Tk::CompleteEntry"} @{$self->{'depends'}->{$name}}) {
my $lpc = LFSR_POLY_CHOICES;
my $c = $lpc->{$$new_ref};
if (defined $c) {
$depending_widget->configure(-choices => $c);
} else {
$logger->debug("No LFSR_POLY suggestion for LFSR_LENGTH $$new_ref");
$depending_widget->configure(-choices => []);
}
}
}
$self->_update_resources();
return 1; # always allow the new value and show the user what happened.
......
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