FIJI.pm 51.3 KB
Newer Older
1
2
3
#-----------------------------------------------------------------------
# Fault InJection Instrumenter (FIJI)
# https://embsys.technikum-wien.at/projects/vecs/fiji
Christian Fibich's avatar
Christian Fibich committed
4
#
5
6
# Copyright (C) 2017 Christian Fibich <fibich@technikum-wien.at>
# Copyright (C) 2017 Stefan Tauner <tauner@technikum-wien.at>
Christian Fibich's avatar
Christian Fibich committed
7
#
8
9
# This module is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
Christian Fibich's avatar
Christian Fibich committed
10
#
11
12
13
14
15
16
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See the LICENSE file for more details.
#-----------------------------------------------------------------------
Christian Fibich's avatar
Christian Fibich committed
17

18
## @file FIJI.pm
Christian Fibich's avatar
Christian Fibich committed
19
# @brief Contains class \ref FIJI
20

21
## @class FIJI
Christian Fibich's avatar
Christian Fibich committed
22
# @brief Various constants used in the FIJI packages.
23

24
25
package FIJI;

26
27
28
use strict;
use warnings;

29
use Cwd;
30
31
32
use Cwd 'realpath';
use File::Spec;
use Log::Log4perl qw(:easy);
Stefan Tauner's avatar
Stefan Tauner committed
33

34
use constant FIJI_DIR => realpath(File::Spec->rel2abs("..", $FindBin::Bin));
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

my $documentation_path;
BEGIN {
    my $pdf = 
        File::Spec->rel2abs(
            File::Spec->catfile(
                "..",
                "docs",
                "user_guide",
                "fiji_user_guide.pdf"
            ),
            $FindBin::Bin
        );
    
    eval { $pdf = realpath($pdf) };
    if ($@) {
        $pdf = undef;
    }
};
use constant FIJI_DOCUMENTATION_PATH => $documentation_path;
55

Stefan Tauner's avatar
Stefan Tauner committed
56
57
58
59
60
61
62
63
64
65
use constant FIJI_MEDIA_PATH => realpath(
    File::Spec->rel2abs(
        File::Spec->catfile(
            "..",
            "media",
        ),
        $FindBin::Bin
    )
);

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

my $version;
BEGIN {
    local $/ = undef;
    my $version_file = File::Spec->rel2abs(
        File::Spec->catfile(
            "..",
            "VERSION",
        ),
        $FindBin::Bin
    );
    open FILE, $version_file or die "Couldn't open VERSION file: $!";
    $version = <FILE>;
    close FILE;
};
use constant FIJI_VERSION => $version;

83
my @optimization_settings = qw(ALLOW OPT_OFF FIX_PLACEMENT);
84
use constant OPTIMIZATION_SETTINGS => \@optimization_settings;
85

86
87
88
89
90
91
#
# 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 => {
Christian Fibich's avatar
Christian Fibich committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
    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'],
155
156
};

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
use constant FIJI_LOGO => <<logo_end;
FIJIFIJIFIJIFIJIFIJIFIJIFIJIFIJIFIJIFIJI
FIJIFIJIFIJIFIJIF   FIJIFIJIFIJIFIJIFIJI
FIJIFIJIFIJIFIJ    IFIJIFIJIFIJIFIJIFIJI
FIJIF       FI           IJIFIJIFIJIFIJI
FIJIFIJIFI            JIFIJIFIJIFIJIFIJI
FIJIFIJI            FIJIFIJIFIJIFIJIFIJI
FIJIFI     I   IFI   IJIFIJIFIJIFIJIFIJI
FIJIF         JIFIJ   JIFIJIFIJIFIJIFIJI
FIJIFIJIFI   IJIFIJI   IFIJIFIJIFIJIFIJI
FIJIFIJIF    IJIFIJIFIJIFIJIFIJIFIJIFIJI
FIJIFIJI    FIJIFIJIFIJIFIJIFIJIFIJIFIJI
FIJIFIJ     FIJIF           FIJIFIJIFIJI
FIJIFI     IFI      Fault      IFIJIFIJI
FIJIF             InJection     FIJIFIJI
FIJ              Instrumenter    IJIFIJI
F                                    IJI
FIJIFIJIFIJIFIJIFIJIFIJIFIJIFIJIFIJIFIJI
logo_end

177
178
179
180
#** @var public %designmap Hash containing all FIJI::Settings
#
# Architecture from http://www.perlmonks.org/?node_id=1072731
#
181
# Fields:
182
183
#    - ini_name     key name in FIJI Settings file
#    - unit         (optional) physical unit
184
#    - type         enables type-specific conversions and tests:
185
186
187
188
#                   - natural: values must be oct, hex, binary strings looking like a real number.
#                   - hexadecimal: values must be hexadecimal numbers.
#                   - boolean: will be convert to a truth value by Perl semantics
#                   - net: name of a net from the input netlist
189
#                   FIXME: complete docs (e.g., dut_port, external_port)
190
191
#    - values       (optional) used to restrict valid values. Can be...
#                   - an array reference listing all valid values (emulates an enum)
192
193
#                   - a code reference to a function that gets the new plus old values
#                     (as well as the value of the dependency if there is one) and
194
195
196
#                     returns true if the new value is allowed, or false otherwise.
#    - phases_opt   (optional) list of phases (subset of "setup", "instrument", "download")
#                   where no value must be present in input (e.g. ID is only necessary while downloading).
197
198
#    - phases_moot  (optional) list of phases (subset of "setup", "instrument", "download")
#                   where values present in the input are not validated at all.
199
#    - depends_on   (optional) specifies the key of another constant.
200
#                   The respective constant is only relevant (and thus required as input)
201
#                   if the value of the referenced constant is true.
202
203
204
205
206
207
#    - group        (optional) specifies how to group this value in output. Value will not be displayed if undef
#    - order        (optional) specifies how to sort this value in output group
#    - noedit       (optional) display value, but don't allow to alter
#    - default      (optional) default value if not given in file and not determinable otherwise
#    - help         (optional) short help text, e.g. to be displayed via Tk:Balloon
#    - forbidden_by (optional) specifies the key of another constant
208
209
#                     The respective constant may not be enabled if the value
#                     of the referenced constant is true
210
my %designmap;
211

212
BEGIN {
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
    %designmap = (
        FIU_NUM => {
            description => "Number of FIUs",
            ini_name    => "FIU_NUM",
            type        => 'natural',
            phases_opt  => [qw(setup instrument download)],    # auto-generated if need be
        },
        FIU_CFG_BITS => {
            description => "Bits per FIU pattern",
            ini_name    => "FIU_CFG_BITS",
            default     => 3,
            type        => 'natural',
            phases_opt  => [qw(setup instrument download)],    # currently not user-configurable at all
        },
        CFGS_PER_MSG => {
228
            description => "Patterns sent per FIU configuration",
229
230
231
232
233
234
235
236
237
238
            ini_name    => "CFGS_PER_MSG",
            default     => 2,
            type        => 'natural',
            phases_opt  => [qw(setup instrument download)],    # currently not user-configurable at all
        },
        CLOCK_NET => {
            type        => 'net',
            description => "Clock net",
            help        => "Select a net in the DUT which shall be used to clock the FIJI logic",
            ini_name    => "CLOCK_NET",
239
            default     => "",
240
241
            phases_opt  => [qw(setup)],
            phases_moot => [qw(download)],
242
            group       => 'clock',
243
            order       => 10
244
245
246
247
248
249
250
251
252
253
254
255
256
257
        },
        FREQUENCY => {
            description => "Clock frequency",
            help        => "Enter the clock frequency in Hz.\n This information is needed e.g. to calculate the Baud rate prescaler",
            ini_name    => "FREQUENCY",
            default     => 50e6,
            type        => 'natural',
            phases_opt  => [qw(setup download)],
            unit        => 'Hz',
            group       => 'clock',
            order       => 20,
        },
        OUTPUT_DIR => {
            description => "Output directory",
258
            help        => "Output directory for FIJI Instrument (relative to location of FIJI settings file)",
259
            ini_name    => "OUTPUT_DIR",
260
            default     => ".",
261
262
263
264
265
            type        => 'dir',
            group       => 'general_control',
            phases_opt  => [qw(setup)],
            order       => 5,
        },
266
        INST_LOG => {
267
            description => "Instrumentation log file",
268
            help        => "Log file for FIJI Instrumentation tool (relative to location of FIJI settings file)",
269
            ini_name    => "INST_LOG",
270
271
272
273
274
275
            default     => "fiji_instrument.log",
            type        => 'file',
            group       => 'general_control',
            phases_opt  => [qw(setup)],
            order       => 6,
        },
276
277
278
279
280
281
282
283
284
        BAUDRATE => {
            description => "Baud rate",
            help        => "Enter the Baud rate for communication between Host and FIJI logic.",
            ini_name    => "BAUDRATE",
            default     => 115200,
            type        => 'natural',
            unit        => 'bps',
            group       => 'general_control',
            order       => 10,
285
286
287
288
289
290
291
292
            depends_on  => "FREQUENCY",
            values      => sub {
                my ($baud, $old, $fclk) = @_;
                if (defined $fclk) {
                    return $baud < $fclk;
                } else {
                    return 1;
                }
Christian Fibich's avatar
Christian Fibich committed
293
              }
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
        },
        ID => {
            description => "Design ID",
            help        => "The design ID is automatically calculated upon instrumentation.",
            ini_name    => "ID",
            type        => 'hexadecimal',
            phases_opt  => [qw(setup instrument)],                                              # generated in instrumentation
            noedit      => 1,
        },
        TIMER_WIDTH => {
            description => "Timer width",
            help        => "Enter the timer width in bytes.\n This influences the maximum fault duration.",
            ini_name    => "TIMER_WIDTH",
            default     => 4,
            type        => 'natural',
            unit        => 'bytes',
            values      => sub {
                my $val = shift;
Christian Fibich's avatar
Christian Fibich committed
312
                return ($val > 0 && $val <= 16);
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
            },
            group => 'general_control',
            order => 20,
        },
        LFSR_WIDTH => {
            description => "LFSR width",
            help        => "Enter the width of the LFSR in bits.\n The LFSR is used to emulate \"floating\" nets in the stuck-open model.",
            ini_name    => "LFSR_WIDTH",
            default     => 16,
            type        => 'natural',
            unit        => 'bits',
            values      => sub {
                my $val = shift;
                return $val > 0 && $val <= 64;
            },
            group => 'lfsr',
            order => 10,
        },
        LFSR_POLY => {
            description => "LFSR polynomial",
            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,
336
            type        => 'lfsrpoly',
337
            unit        => 'hex',
338
            depends_on  => 'LFSR_WIDTH',
339
            values      => sub {
340
341
342
                my ($val, $old, $top) = @_;
                $top = 64 if !defined $top;
                return $val > 0 && $val <= (2**($top) - 1);
343
344
345
346
347
348
349
350
351
352
            },
            group => 'lfsr',
            order => 20,
        },
        LFSR_SEED => {
            description => "LFSR seed value",
            help        => "Enter the starting value for the LFSR.\n The LFSR is used to emulate \"floating\" nets in the stuck-open model.",
            ini_name    => "LFSR_SEED",
            default     => 0xCAFE,
            type        => 'hexadecimal',
353
            unit        => 'hex',
354
            depends_on  => 'LFSR_WIDTH',
355
            values      => sub {
356
357
358
                my ($val, $old, $top) = @_;
                $top = 64 if !defined $top;
                return $val > 0 && $val <= (2**($top) - 1);
359
360
361
362
363
364
            },
            group => 'lfsr',
            order => 30,
        },

        # External reset
365
        RST_EXT_EN => {
366
367
            description => "Use external reset",
            help        => "If enabled, the FIJI logic can be reset using an FPGA pin.",
368
            ini_name    => "RST_EXT_EN",
369
            type        => 'boolean',
370
371
            default     => 0,
            phases_opt  => ['setup'],
372
373
374
            group       => 'reset_external',
            order       => 10,
        },
375
        RST_EXT_ACT => {
376
377
            description => "External Reset: Active level",
            help        => "If enabled, the FIJI logic can be reset using an FPGA pin.",
378
            ini_name    => "RST_EXT_ACT",
379
380
381
            type        => 'bit',
            values      => [qw(0 1)],
            default     => '1',
382
            phases_opt  => ['setup', 'download'],
383
            depends_on  => 'RST_EXT_EN',
384
385
386
            group       => 'reset_external',
            order       => 20,
        },
387
        RST_EXT_IN_NAME => {
388
389
            description => "External Reset: Port name",
            help        => "Specify the name of the external reset port in the wrapper.\nThis port name must not exist in the toplevel.",
390
            ini_name    => "RST_EXT_IN_NAME",
Christian Fibich's avatar
Christian Fibich committed
391
            default     => "s_fiji_reset_i",
392
393
            phases_opt  => [qw(setup)],
            phases_moot => [qw(download)],
Christian Fibich's avatar
Christian Fibich committed
394
            type        => "external_port",
395
            group       => 'reset_external',
396
            depends_on  => 'RST_EXT_EN',
397
398
399
400
            order       => 30,
        },

        # Reset from DUT
401
        RST_DUT_OUT_EN => {
402
403
            description  => "Enable DUT-to-FIJI reset",
            help         => "If enabled, a net in the DUT is used as a reset source for the FIJI logic.",
404
            ini_name     => "RST_DUT_OUT_EN",
405
            type         => 'boolean',
406
407
            default      => 0,
            phases_opt  => ['setup'],
408
            group        => 'reset_from_dut',
409
            forbidden_by => 'RST_DUT_IN_EN',
410
411
            order        => 10,
        },
412
        RST_DUT_OUT_NAME => {
413
            description => "Source for DUT-to-FIJI reset",
414
            help        => "If enabled, a net in the DUT is used as a reset source for the FIJI logic.",
415
416
            ini_name    => "RST_DUT_OUT_NAME",
            depends_on  => 'RST_DUT_OUT_EN',
417
            type        => 'net',
418
            default     => "",
419
420
            phases_opt  => [qw(setup)],
            phases_moot => [qw(download)],
421
422
423
            group       => 'reset_from_dut',
            order       => 30,
        },
424
        RST_DUT_OUT_ACT => {
425
            description => "Active level of DUT-to-FIJI reset",
426
            help        => "If enabled, a net in the DUT is used as a reset source for the FIJI logic.",
427
            ini_name    => "RST_DUT_OUT_ACT",
428
429
430
            type        => 'bit',
            values      => [qw(0 1)],
            default     => '1',
431
            phases_opt  => ['setup'],
432
            depends_on  => 'RST_DUT_OUT_EN',
433
434
435
436
437
            group       => 'reset_from_dut',
            order       => 20,
        },

        # Reset to DUT
438
        RST_DUT_IN_EN => {
439
440
            description  => "Enable FIJI-to-DUT reset",
            help         => "If enabled, the DUT will be reset from the FIJI logic.",
441
            ini_name     => "RST_DUT_IN_EN",
442
            type         => 'boolean',
443
444
            default      => 0,
            phases_opt  => ['setup'],
445
            group        => 'reset_to_dut',
446
            forbidden_by => 'RST_DUT_OUT_EN',
447
448
            order        => 10,
        },
449
        RST_DUT_IN_NAME => {
450
451
            description => "Port for FIJI-to-DUT reset",
            help        => "The specified DUT reset input will be connected\n to the FIJI logic's reset output.",
452
            ini_name    => "RST_DUT_IN_NAME",
453
            default     => "",
454
            phases_opt  => [qw(setup download)],
455
            depends_on  => 'RST_DUT_IN_EN',
456
            type        => 'dut_port',
457
458
459
            group       => 'reset_to_dut',
            order       => 40,
        },
460
        RST_DUT_IN_DUR => {
461
462
            description => "Duration for FIJI-to-DUT reset",
            help        => "Enter the duration of each FIJI-to-DUT reset operation in clock cycles.",
463
            ini_name    => "RST_DUT_IN_DUR",
464
465
            type        => 'natural',
            default     => 1,
466
            phases_opt  => ['setup'],
467
468
469
470
471
            unit        => 'cycles',
            values      => sub {
                my $val = shift;
                return $val > 0 && $val <= 2**32 - 1;
            },
472
            depends_on => 'RST_DUT_IN_EN',
473
474
475
            group      => 'reset_to_dut',
            order      => 30,
        },
476
        RST_DUT_IN_ACT => {
477
            description => "Active level of FIJI-to-DUT reset",
478
            help        => "Enter the level the FIJI-to-DUT reset signal shall be brought to during reset.",
479
            ini_name    => "RST_DUT_IN_ACT",
480
481
482
            type        => 'bit',
            values      => [qw(0 1)],
            default     => '1',
483
            phases_opt  => ['setup'],
484
            depends_on  => 'RST_DUT_IN_EN',
485
486
487
488
489
            group       => 'reset_to_dut',
            order       => 20,
        },

        # Trigger from DUT
490
        TRIG_DUT_EN => {
491
492
            description => "Enable DUT-to-FIJI trigger",
            help        => "If enabled, a signal in the DUT can be selected to trigger fault injection operations.\n" . "Once a pattern is downloaded with the INTERNAL trigger enabled, the FIJI logic waits for\n" . "an inactive-to-active transition on this signal before starting to count down duration t1.",
493
            ini_name    => "TRIG_DUT_EN",
494
            type        => 'boolean',
495
496
            default     => 0,
            phases_opt  => ['setup'],
497
498
499
            group       => 'trigger',
            order       => 10,
        },
500

501
        TRIG_DUT_ACT => {
502
            description => "Active level of DUT-to-FIJI trigger",
503
            help        => "Select the signal level to trigger fault injection.",
504
            ini_name    => "TRIG_DUT_ACT",
505
506
507
            type        => 'bit',
            values      => [qw(0 1)],
            default     => '1',
508
            phases_opt  => ['setup'],
509
            depends_on  => 'TRIG_DUT_EN',
510
            group       => 'trigger',
511
512
513
            order       => 20,
        },

514
        TRIG_DUT_NAME => {
515
516
            description => "Source net for DUT-to-FIJI trigger",
            help        => "Select the net in the DUT which shall be used to trigger fault injection operations.",
517
            ini_name    => "TRIG_DUT_NAME",
518
            default     => "",
519
520
            phases_opt  => [qw(setup)],
            phases_moot => [qw(download)],
521
            depends_on  => 'TRIG_DUT_EN',
522
523
            type        => 'net',
            group       => 'trigger',
524
525
526
527
            order       => 30,
        },

        # External trigger
528
        TRIG_EXT_EN => {
529
530
            description => "Enable external trigger",
            help        => "If enabled, an I/O port can be selected to trigger fault injection operations.\n" . "Once a pattern is downloaded with the EXTERNAL trigger enabled, the FIJI logic waits for \n" . "an inactive-to-active transition on this port before starting to count down duration t1. \n" . "The port is synchronized to the FIJI logic's clock, thus introducing a few clock cycles delay.",
531
            ini_name    => "TRIG_EXT_EN",
532
            type        => 'boolean',
533
534
            default     => 0,
            phases_opt  => ['setup'],
535
536
537
            group       => 'trigger',
            order       => 40,
        },
538
        TRIG_EXT_ACT => {
539
            description => "Active level of external trigger",
540
            help        => "Select the port level to trigger fault injection.",
541
            ini_name    => "TRIG_EXT_ACT",
542
543
544
            type        => 'bit',
            values      => [qw(0 1)],
            default     => '1',
545
            phases_opt  => ['setup'],
546
            depends_on  => 'TRIG_EXT_EN',
547
548
549
            group       => 'trigger',
            order       => 50,
        },
550
        TRIG_EXT_IN_NAME => {
551
            description => "External trigger port name",
552
            help        => "Specify the name of the external trigger port in the wrapper.\nThis port name must not exist in the toplevel.",
553
            ini_name    => "TRIG_EXT_IN_NAME",
Christian Fibich's avatar
Christian Fibich committed
554
            type        => "external_port",
555
            default     => "s_fiji_trig_ext_i",
556
557
            phases_opt  => [qw(setup)],
            phases_moot => [qw(download)],
558
            depends_on  => 'TRIG_EXT_EN',
559
560
561
            group       => "trigger",
            order       => 60,
        },
562
        FD_1_EN => {
563
564
            description => "Enable fault-detect bit 1",
            help        => "If enabled, a signal in the DUT can be selected as a return channel.\n" . "This could e.g. be the output of a fault detection unit. \n" . "The FIJI logic registers inactive-to-active transition on this signal and returns the status \n" . "in the serial communication messages to the host.",
565
            ini_name    => "FD_1_EN",
566
567
            type        => 'boolean',
            default     => 0,
568
            phases_opt  => ['setup'],
569
570
571
            group       => 'fault_detect',
            order       => 10,
        },
572
        FD_1_NAME => {
573
574
            description => "Source net for fault-detect bit 1",
            help        => "Select the net in the DUT which shall be used for the fault detection feature.",
575
            ini_name    => "FD_1_NAME",
576
            type        => 'net',
577
            default     => "",
578
579
            phases_opt  => [qw(setup)],
            phases_moot => [qw(download)],
580
            depends_on  => 'FD_1_EN',
581
582
583
            group       => 'fault_detect',
            order       => 20,
        },
584
        FD_1_INVERT => {
585
586
            description => "Invert fault detect bit 1",
            help        => "Specifies if the selected net shall be inverted prior to edge detection.\n" . "Leave unchecked if the net uses positive logic.",
587
            ini_name    => "FD_1_INVERT",
588
589
590
            type        => 'boolean',
            values      => [qw(0 1)],
            default     => '0',
591
            phases_opt  => ['setup'],
592
            depends_on  => 'FD_1_EN',
593
594
595
            group       => 'fault_detect',
            order       => 30,
        },
596
        FD_2_EN => {
597
598
            description => "Enable fault-detect bit 2",
            help        => "If enabled, a signal in the DUT can be selected as a return channel.\n" . "This could e.g. be the output of a fault detection unit. \n" . "The FIJI logic registers inactive-to-active transition on this signal and returns the status \n" . "in the serial communication messages to the host.",
599
            ini_name    => "FD_2_EN",
600
601
            type        => 'boolean',
            default     => 0,
602
            phases_opt  => ['setup'],
603
604
605
            group       => 'fault_detect',
            order       => 40,
        },
606
        FD_2_NAME => {
607
608
            description => "Source net for fault-detect bit 2",
            help        => "Select the net in the DUT which shall be used for the fault detection feature.",
609
            ini_name    => "FD_2_NAME",
610
            type        => 'net',
611
            default     => "",
612
613
            phases_opt  => [qw(setup)],
            phases_moot => [qw(download)],
614
            depends_on  => 'FD_2_EN',
615
616
617
            group       => 'fault_detect',
            order       => 50,
        },
618
        FD_2_INVERT => {
619
620
            description => "Invert fault detect bit 2",
            help        => "Specify if the selected net shall be inverted prior to edge detection.\n" . "Leave unchecked if the net uses positive logic.",
621
            ini_name    => "FD_2_INVERT",
622
623
624
            type        => 'boolean',
            values      => [qw(0 1)],
            default     => '0',
625
            phases_opt  => ['setup'],
626
            depends_on  => 'FD_2_EN',
627
628
629
630
631
            group       => 'fault_detect',
            order       => 60,
        },
        RX_IN_NAME => {
            description => "RX port name",
632
            help        => "Specify the name of the Host-to-FIJI serial RX port in the wrapper.\nThis port name must not exist in the toplevel.",
633
            ini_name    => "RX_IN_NAME",
Christian Fibich's avatar
Christian Fibich committed
634
            type        => "external_port",
635
            default     => "s_fiji_rx_i",
636
637
            phases_opt  => [qw(setup)],
            phases_moot => [qw(download)],
638
            group       => "general_control",
Stefan Tauner's avatar
Stefan Tauner committed
639
            order       => 11,
640
641
642
        },
        TX_OUT_NAME => {
            description => "TX port name",
643
            help        => "Specify the name of the FIJI-to-Host serial TX port in the wrapper.\nThis port name must not exist in the toplevel.",
644
            ini_name    => "TX_OUT_NAME",
Christian Fibich's avatar
Christian Fibich committed
645
            type        => "external_port",
646
            default     => "s_fiji_tx_o",
647
648
            phases_opt  => [qw(setup)],
            phases_moot => [qw(download)],
649
            group       => "general_control",
Stefan Tauner's avatar
Stefan Tauner committed
650
            order       => 12,
651
        },
652
        OPTIMIZATIONS => {
653
            description => "Optimization Settings",
654
            help        => "Specifies which set of constraints to use in synthesis/P&R to\n- prevent optimizations and/or\n- fix physical placement.",
655
            ini_name    => "OPTIMIZATIONS",
656
            type        => "dropdown",
657
            values      => \@optimization_settings,
658
            default     => "ALLOW",
659
            phases_opt  => [qw(setup)],
660
661
662
            group       => "general_control",
            order       => 50,
        },
663
664
665
666
667
668
669
670
671
672
673
        SYNTHESIS_TOOL => {
            description => "Synthesis Tool",
            help        => "The FPGA synthesis tool that will be used. Needed for generating appropriate constraints.",
            ini_name    => "SYNTHESIS_TOOL",
            type        => "dropdown",
            values      => ["SYNPLIFY_PRO"],
            default     => "SYNPLIFY_PRO",
            phases_opt  => [qw(setup)],
            group       => "general_control",
            order       => 60,
        },
674
        IMPL_TOOL => {
675
676
            description => "Implementation Tool",
            help        => "The FPGA implementation tool that will be used. Needed for generating appropriate constraints.",
677
            ini_name    => "IMPL_TOOL",
678
            type        => "dropdown",
Christian Fibich's avatar
Christian Fibich committed
679
            values      => ["ALTERA_QUARTUS", "XILINX_VIVADO"],
680
681
682
683
684
            default     => "ALTERA_QUARTUS",
            phases_opt  => [qw(setup)],
            group       => "general_control",
            order       => 70,
        },
685
    );
686
687
}

688
689
690
use constant \%designmap;
use constant DESIGNMAP => \%designmap;

Christian Fibich's avatar
Christian Fibich committed
691
692
693
694
695
696
697
#** @var public %displaygroups Hash containing groups for displaying \ref designmap
##
# Fields:
#    -title         Just a short title
#    -subtitle      ...
#    -description   Longer description
#    -order         The sorting order to display this group
698
my %displaygroups;
699

700
701
702
703
704
BEGIN {
    %displaygroups = (
        fault_detect => {
            title       => "Fault Detection Settings",
            subtitle    => "",
Christian Fibich's avatar
Christian Fibich committed
705
706
            description => "Settings concerning internal fault detection propagation",
            order       => 80,
707
708
709
710
        },
        trigger => {
            title       => "Trigger Settings",
            subtitle    => "",
Christian Fibich's avatar
Christian Fibich committed
711
712
            description => "Settings concerning internal and external fault injection triggers",
            order       => 70,
713
714
        },
        reset_to_dut => {
715
            title       => "Reset from FIJI to DUT",
716
            subtitle    => "",
Christian Fibich's avatar
Christian Fibich committed
717
718
            description => "Settings concerning FIJI's ability to reset the DUT",
            order       => 60,
719
720
        },
        reset_from_dut => {
721
            title       => "Reset from DUT to FIJI",
722
            subtitle    => "",
Christian Fibich's avatar
Christian Fibich committed
723
724
            description => "Settings concerning FIJI's internal (from DUT) reset feature",
            order       => 50,
725
726
        },
        reset_external => {
727
728
            title       => "External Reset",
            subtitle    => "",
Christian Fibich's avatar
Christian Fibich committed
729
730
            description => "Settings concerning FIJI's external (via pin) reset feature",
            order       => 40,
731
732
733
734
        },
        lfsr => {
            title       => "LFSR Settings",
            subtitle    => "",
Christian Fibich's avatar
Christian Fibich committed
735
736
            description => "Settings concerning the LFSR for Stuck-open emulation",
            order       => 30,
737
738
        },
        general_control => {
739
            title       => "General settings",
740
            subtitle    => "",
741
            description => "Settings concerning miscellaneous features of FIJI",
Christian Fibich's avatar
Christian Fibich committed
742
            order       => 10,
743
744
745
746
        },
        clock => {
            title       => "Clock settings",
            subtitle    => "",
Christian Fibich's avatar
Christian Fibich committed
747
748
            description => "Settings concerning the clocking of the FIJI logic",
            order       => 20,
749
750
751
752
753
754
        },
        fius => {
            title       => "FIUs",
            subtitle    => "",
            description => "Settings concerning Fault Injection Units",
            order       => 100
755
        }
756
    );
757
}
758

759
760
use constant \%displaygroups;
use constant DISPLAYGROUPS => \%displaygroups;
761
use constant DISPLAYGROUPS_FIU_KEY => 'fius';
762

Christian Fibich's avatar
Christian Fibich committed
763
764
765
766
767
768
769
770
771
## @var public %fiumap Hash containing all FIJI::Settings for FIUs
#
# Fields:
#    - ini_name     key name in FIJI Settings file
#    - unit         (optional) physical unit
#    - type         (optional) enables type-specific conversions and tests:
#                   - natural: values must be oct, hex, binary strings looking like a real number.
#                   - hexadecimal: values must be hexadecimal numbers.
#                   - boolean: will be convert to a truth value by Perl semantics
772
#                   - net: hierarchical path of a net from the input netlist
773
#                   - driver: driver-specific hierarchical path of a net from the input netlist
Christian Fibich's avatar
Christian Fibich committed
774
775
776
777
778
779
780
#    - values       (optional) used to restrict valid values. Can be...
#                   - an array reference listing all valid values (emulates an enum)
#                   - a code reference to a function that gets the new and old values and
#                     returns true if the new value is allowed, or false otherwise.
#    - phases_opt   (optional) list of phases (subset of "setup", "instrument", "download")
#                   where no value must be present in input (e.g. ID is only necessary while downloading).
#    - group        (optional) specifies how to group this value in output. Value will not be displayed if undef
781
782
783
#    - default      (optional) default value if not given in file and not determinable otherwise.
#                   Can either be a scalar or a function pointer expecting following parameters:
#                   related FIJI settings hash, the tool phase, FIJI design settings, FIU number.
784
my %fiumap;
785

786
BEGIN {
787
    %fiumap = (
788
789
790
791
792
793
        FIU_NAME => {
            ini_name => "NAME",
            default  => "",
            help     => "Display name for this FIU",
            phases_opt => [qw(setup instrument download)]
        },
794
795
796
        FIU_NET_NAME => {
            ini_name   => "NET_NAME",
            default    => "",
797
798
            type       => 'net',
            help       => "String representation of the instrumented net.",
799
800
            phases_opt  => [qw(setup)], # Either FIU or net name is strongly recommended during download
            phases_moot => [qw(download)],
801
802
803
804
        },
        FIU_DRIVER_TYPE => {
            ini_name   => "DRIVER_TYPE",
            values     => [qw(PIN PORT ASSIGN)],
805
            default    => "PIN",
806
807
808
809
810
            phases_opt => [qw(setup)],
        },
        FIU_DRIVER_PATH => {
            ini_name   => "DRIVER_PATH",
            default    => "",
811
            type       => 'driver',
812
            help       => "String representation of a driver.",
813
814
            phases_opt  => [qw(setup)], # Either FIU or net name is strongly recommended during download
            phases_moot => [qw(download)],
815
816
817
818
819
        },
        FIU_MODEL => {
            ini_name   => "FAULT_MODEL",
            default    => "RUNTIME",
            values     => [qw(RUNTIME PASS_THRU STUCK_AT_0 STUCK_AT_1 STUCK_OPEN DELAY SEU)],
820
            help       => "Possible fault models: no fault (PASS_THRU), a single mode that can be switched on and off, or selection and activation of the type at RUNTIME.",
821
822
823
824
            phases_opt => [qw(setup)],
        },
        FIU_LFSR_MASK => {
            ini_name   => "LFSR_MASK",
825
826
827
828
829
830
            default    => sub {
                my ($consts_ref, $phase, $design_ref, $i) = @_;
                $i = 0 if !defined($i);
                my $mask_width = defined($design_ref) && defined($design_ref->{'LFSR_WIDTH'}) ? $design_ref->{'LFSR_WIDTH'} : 1;
                return 1 << ($i % $mask_width);
            },
831
            type       => 'hexadecimal',
832
            help       => "Selects the bits of the LFSR that are ANDed together to determine the value of a floating net.",
833
834
835
            phases_opt => [qw(setup)],
        },
    );
836
837
838
839
}

use constant \%fiumap;
use constant FIUMAP => \%fiumap;
840

Christian Fibich's avatar
Christian Fibich committed
841
842
843
844
845
846
847
848
849
850
851
852
#** @var public %testconstmap Hash containing all global values of FIJI::Tests
#
# Fields:
#    - ini_name     key name in FIJI Tests file
#    - unit         (optional) physical unit
#    - type         (optional) enables type-specific conversions and tests:
#                   - natural: values must be oct, hex, binary strings looking like a real number.
#                   - hexadecimal: values must be hexadecimal numbers.
#                   - boolean: will be convert to a truth value by Perl semantics
#                   - net: name of a net from the input netlist
#    - values       (optional) used to restrict valid values. Can be...
#                   - an array reference listing all valid values (emulates an enum)
853
854
#                   - a code reference to a function that gets the old value and current settings and
#                     returns the allowed value(s).
Christian Fibich's avatar
Christian Fibich committed
855
856
857
858
859
860
861
#    - phases_opt   (optional) list of phases (subset of "setup", "instrument", "download")
#                   where no value must be present in input (e.g. ID is only necessary while downloading).
#    - gui_modes    (optional) specifies in which mode of {manual,auto,random} this key will be displayed in the GUI
#    - depends_on   (optional) specifies the key of another constant.
#                   The respective constant is only relevant (and thuse required as input)
#                   if the value of the referenced constant is true.
#    - order        (optional) specifies how to sort this value in output group
862
#    - default      (optional) default value if not given in file and not determinable otherwise.
863
#                   Can either be a scalar or a function pointer expecting a FIJI settings reference.
Christian Fibich's avatar
Christian Fibich committed
864
865
866
#    - help         (optional) short help text, e.g. to be displayed via Tk:Balloon
#                     The respective constant may not be enabled if the value
#                     of the referenced constant is true
867
my %testconstmap;
868

869
BEGIN {
870
871
872
873
874
875
876
877
878
    %testconstmap = (
        FIJI_CFG => {
            description => "FIJI Settings File",
            ini_name    => "FIJI_CFG",
            default     => "fiji.cfg",

            #gui_modes   => [qw (manual auto random)],
        },
        UART => {
879
            description => "Control UART",
880
            ini_name    => "UART",
881
882
883
884
            default     => sub {
                my $devs = FIJI::Utils::get_uart_devs();
                return (scalar(@$devs) > 0) ? @{$devs}[0] : "";
            },
Christian Fibich's avatar
Christian Fibich committed
885
            help        => "The host's serial port connected to FIJI.\nLinux/Unix: /dev/ttyUSBx, /dev/ttyACMx, /dev/ttySx\nWindows: COMx",
886
            type        => "autocomplete",
887
888
        },
        HALT_ON_FAULT_DETECT => {
Christian Fibich's avatar
Christian Fibich committed
889
890
891
892
893
894
895
            description           => "Halt on detected fault?",
            ini_name              => "HALT_ON_FAULT_DETECT",
            default               => 1,
            type                  => 'boolean',
            phases_opt            => [qw(manual)],
            gui_modes             => [qw (auto random)],
            order                 => 10,
896
            activated_by_settings => sub {
Christian Fibich's avatar
Christian Fibich committed
897
                my $settings = shift;
898
                return ($settings->{'design'}->{'FD_1_EN'} == 1 || $settings->{'design'}->{'FD_2_EN'} == 1);
899
            },
Christian Fibich's avatar
Christian Fibich committed
900
            help                  => "Specify if the injection campaign shall be aborted when a fault has been detected"
901
902
903
904
905
906
907
908
909
910
911
912
913
        },
        NUM_TESTS => {
            ini_name   => "NUM_TESTS",
            type       => 'natural',
            phases_opt => [qw(manual)],
        },
        REPEAT => {
            description => "Repeat Injection?",
            ini_name    => "REPEAT",
            default     => 0,
            type        => 'boolean',
            phases_opt  => [qw(manual)],
            gui_modes   => [qw (auto)],
914
            order       => 12,
Christian Fibich's avatar
Christian Fibich committed
915
            help        => "Specify if the injection campaign shall start again after the last test",
916
917
918
919
920
921
922
923
        },
        REPEAT_OFFSET => {
            description => "Repetition start pattern",
            ini_name    => "REPEAT_OFFSET",
            default     => 0,
            type        => 'natural',
            phases_opt  => [qw(manual)],
            gui_modes   => [qw (auto)],
924
            order       => 13,
925
            depends_on  => "REPEAT",
Christian Fibich's avatar
Christian Fibich committed
926
            help        => "Specify an offset for all repetitions except the first"
927
        },
928
929
930
931
932
933
934
935
936
937
938
939
        REPEAT_NUM => {
            description => "Number of repetitions",
            ini_name    => "REPEAT_NUM",
            default     => 0,
            type        => 'natural',
            phases_opt  => [qw(manual)],
            gui_modes   => [qw (auto)],
            order       => 14,
            depends_on  => "REPEAT",
            help        => "Specify a number of repetitions"
        },

940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
        HALT_ON_UART_ERROR => {
            ini_name   => "HALT_ON_UART_ERROR",
            default    => 1,
            type       => 'boolean',
            phases_opt => [qw(manual)],
        },
        HALT_ON_CRC_ERROR => {
            ini_name   => "HALT_ON_CRC_ERROR",
            default    => 1,
            type       => 'boolean',
            phases_opt => [qw(manual)],
        },
        HALT_ON_ID_ERROR => {
            ini_name   => "HALT_ON_ID_ERROR",
            default    => 1,
            type       => 'boolean',
            phases_opt => [qw(manual)],
        },
        HALT_ON_UNDERRUN => {
959
960
961
962
963
964
965
            description => "Halt on buffer underrun?",
            ini_name    => "HALT_ON_UNDERRUN",
            default     => 0,
            type        => 'boolean',
            phases_opt  => [qw(manual)],
            gui_modes   => [qw (auto random)],
            order       => 11,
Christian Fibich's avatar
Christian Fibich committed
966
            help        => "Specify if the injection campaign shall be halted when the FIC reported that a pattern did not arrive in time."
967
968
969
970
971
972
973
974
975
        },
        MULTIFAULT => {
            description => "Generate multiple faults per pattern?",
            ini_name    => "MULTIFAULT",
            default     => 1,
            type        => 'boolean',
            phases_opt  => [qw(manual auto)],
            gui_modes   => [qw (random)],
            order       => 60,
Christian Fibich's avatar
Christian Fibich committed
976
            help        => "Allow multiple FIUs to generate errors within one pattern"
977
        },
978
        MIN_DUR_T1 => {
979
            description => "Minimum Duration T1",
980
            ini_name    => "MIN_DUR_T1",
981
            default     => sub {shift->default_timer_value()},
982
983
984
            phases_opt  => [qw(manual auto)],
            gui_modes   => [qw (random)],
            type        => "min_duration",
985
            matching    => "MAX_DUR_T1",
986
            unit        => "cycles",
987
            order       => 20,
Christian Fibich's avatar
Christian Fibich committed
988
            help        => "Minimum duration before the first fault is applied."
989
        },
990
        MIN_DUR_T2 => {
991
            description => "Minimum Duration T2",
992
            ini_name    => "MIN_DUR_T2",
993
            default     => sub {shift->default_timer_value()},
994
995
996
            phases_opt  => [qw(manual auto)],
            gui_modes   => [qw (random)],
            type        => "min_duration",
997
            matching    => "MAX_DUR_T2",
998
            unit        => "cycles",
999
            order       => 40,
Christian Fibich's avatar
Christian Fibich committed
1000
            help        => "Minimum duration to keep the first fault is enabled."
1001
        },
1002
        MAX_DUR_T1 => {
1003
            description => "Maximum Duration T1",
1004
            ini_name    => "MAX_DUR_T1",
1005
            default     => sub {10 * shift->default_timer_value()},
1006
1007
1008
            phases_opt  => [qw(manual auto)],
            gui_modes   => [qw (random)],
            type        => "max_duration",
1009
            matching    => "MIN_DUR_T1",
1010
            unit        => "cycles",
1011
            order       => 30,
Christian Fibich's avatar
Christian Fibich committed
1012
            help        => "Maximum duration before the first fault is applied."
1013
        },
1014
        MAX_DUR_T2 => {
1015
            description => "Maximum Duration T2",
1016
            ini_name    => "MAX_DUR_T2",
1017
            default     => sub {10 * shift->default_timer_value()},