Downloader.pm 18.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#-------------------------------------------------------------------------------
#  University of Applied Sciences Technikum Wien
#
#  Department of Embedded Systems
#  http://embsys.technikum-wien.at
#
#  Josef Ressel Center for Verification of Embedded Computing Systems
#  http://vecs.technikum-wien.at
#
#-------------------------------------------------------------------------------
#  File:              Downloader.pm
#  Created on:        01.07.2015
#  $LastChangedBy$
#  $LastChangedDate$
#
#  Description:
#  FIJI Downloader class
#-------------------------------------------------------------------------------

package FIJI::Downloader;

use strict;
use warnings;

use Log::Log4perl qw(get_logger :easy);
use FIJI::Tests;
use FIJI::Settings;
use FIJI::Connection;
use FIJI qw(:all);
use Data::Dumper;
Christian Fibich's avatar
Christian Fibich committed
31
use Clone 'clone';
32
33
use threads;
use threads::shared;
34

Christian Fibich's avatar
Christian Fibich committed
35
36
sub new(;$$) {
    my $logger = get_logger();
37
    my ( $class, $testsname, $existing_tests, $cfgname, $existing_cfg ) = @_;
38
    my $self = {};
39
    my $rv = "Constructor has no means of obtaining a FIJI::Tests/Settings object" . bless $self, $class;
Christian Fibich's avatar
Christian Fibich committed
40

41
    if ( defined $existing_cfg ) {
Christian Fibich's avatar
Christian Fibich committed
42
        $rv = $self->existing_settings($existing_cfg);
43
    } elsif ( defined $cfgname ) {
Christian Fibich's avatar
Christian Fibich committed
44
45
        $rv = $self->settings_from_file($cfgname);
    }
46
47

    if ( defined $existing_tests ) {
Christian Fibich's avatar
Christian Fibich committed
48
        $rv = $self->existing_tests($existing_tests);
49
50
    } elsif ( defined $testsname ) {
        $rv = $self->tests_from_file( $self->{'fiji_settings'}->{'design'}->{'CFGS_PER_MSG'}, $self->{'fiji_settings'}->{'design'}->{'FIU_NUM'}, $testsname );
51
    }
Christian Fibich's avatar
Christian Fibich committed
52

53
    $logger->error($rv) if ( !ref $rv );
54
55
56
    return $self;
}

Christian Fibich's avatar
Christian Fibich committed
57
58
sub settings_from_file {
    my $rv;
59
    my ( $self, $cfgname ) = @_;
Christian Fibich's avatar
Christian Fibich committed
60
61
62
63
64
65
66
67
68
69
70
    my $fiji_settings = FIJI::Settings->new( "download", $cfgname );
    if ( !ref($fiji_settings) ) {
        $rv = $fiji_settings . " Aborting.\n";
    } else {
        $rv = $self->{'fiji_settings'} = $fiji_settings;
    }
    return $rv;
}

sub existing_settings {
    my $rv;
71
72
    my ( $self, $existing_cfg ) = @_;
    if ( ref($existing_cfg) eq "FIJI::Settings" ) {
Christian Fibich's avatar
Christian Fibich committed
73
74
75
76
77
78
79
80
        $rv = $self->{'fiji_settings'} = $existing_cfg;
    } else {
        $rv = "Given Settings are not of type FIJI::Settings";
    }
}

sub tests_from_file {
    my $rv;
81
    my ( $self, $msgs_per_cfg, $fiu_num, $cfgname ) = @_;
Christian Fibich's avatar
Christian Fibich committed
82
83
84
85
86
87
88
89
90
91
92
    my $fiji_tests = FIJI::Tests->new( "automatic", $msgs_per_cfg, $fiu_num, $cfgname );
    if ( !ref($fiji_tests) ) {
        $rv = $fiji_tests . " Aborting.\n";
    } else {
        $rv = $self->{'fiji_tests'} = $fiji_tests;
    }
    return $rv;
}

sub existing_tests {
    my $rv;
93
94
    my ( $self, $existing_tests ) = @_;
    if ( ref($existing_tests) eq "FIJI::Tests" ) {
Christian Fibich's avatar
Christian Fibich committed
95
96
97
98
99
100
        $rv = $self->{'fiji_tests'} = $existing_tests;
    } else {
        $rv = "Given Tests are not of type FIJI::Tests";
    }
}

Christian Fibich's avatar
Christian Fibich committed
101
102
103
## Wrapper for port->send_config
# Generates a configuration hash from discrete parameters
#
104
sub _test_fi_uart {
105
    my $logger = get_logger();
106
    my ( $port, $payload_ref, $t1_duration, $t2_duration, $trigger_en, $trigger_ext, $reset, $fiji_consts ) = @_;
107

108
    # my @payload = map hex($_), $cfg_str =~ /(..)/g; # TODO: how to do this with unpack?
109
110
111
112
113
114
115
116
117
    my %config = (
        payload     => $payload_ref,
        t1_duration => $t1_duration,
        t2_duration => $t2_duration,
        trigger_en  => $trigger_en,
        trigger_ext => $trigger_ext,
        reset       => $reset,
        consts      => $fiji_consts,
    );
118

119
120
    # FIXME not sure if this is correct:
    #       total timeout = 1sec + sum of durations in sec
121

122
    my $timeout = ( ( ( $t1_duration + $t2_duration ) / $fiji_consts->{'FREQUENCY'} ) * 1000 ) + 1000;
123

124
    if ( $trigger_en == 1 ) {
125
126
127
128
        $logger->debug("Trigger specified, no timeout set.");
    }

    return $port->send_config( \%config, $timeout, 0, 1 );
129
130
}

Christian Fibich's avatar
Christian Fibich committed
131
132
133
## Download tests contained in the .cfg file
# Params
#   portname Optional serial port to use
Christian Fibich's avatar
Christian Fibich committed
134
sub download_auto ($) {
135
136
    my $msg;
    my $logger = get_logger();
137
    my ( $self, $testref, $portname, $intermediate_cb ) = @_;
138

139
    my $fiji_tests         = $self->{'fiji_tests'};
Christian Fibich's avatar
Christian Fibich committed
140
    my $fiji_design_consts = $self->{'fiji_settings'}->{'design'};
141

142
143
    my @tests;

144
145
    if ( !defined $intermediate_cb ) {
        $intermediate_cb = sub { return 1; };
Christian Fibich's avatar
Christian Fibich committed
146
147
    }

148
149
    $portname = $fiji_tests->{'design'}->{'UART'} if ( !defined $portname );
    my $port = FIJI::Connection->init( $portname, $fiji_design_consts->{'BAUDRATE'} )
150
151
152
153
154
155
156
157
158
      or $logger->fatal("Could not init UART.")
      and return "Could not init UART.";

    my $toff = 0;
    my $ri   = 0;
    my $halt;

    $logger->info("Downloading in auto mode.");

159
160
161
    my $recv_msg;
    my $ti;

Christian Fibich's avatar
Christian Fibich committed
162
    # download tests until halted
163
164
    while (1) {
        for ( $ti = $toff ; $ti < @{ $fiji_tests->{'tests'} } ; $ti++ ) {
165
166
167

            $logger->info("Downloading test $ti.");

168
            $recv_msg = $self->_download_test( @{ $fiji_tests->{'tests'} }[$ti], $port );
169

170
            if ( ref($recv_msg) ne "HASH" ) {
171
172
173
174
                $msg = "UART transaction failed.";
                return $msg;
            }

175
            push @tests, @{ $fiji_tests->{'tests'} }[$ti];
176

177
            if ( $self->_check_halt($recv_msg) == 1 ) {
Christian Fibich's avatar
Christian Fibich committed
178
                $logger->error("Halt because of HALT_ON_xxx. Failed test: $ti, repetition $ri.");
179
                goto END;
180
            }
181
182

            if ( &$intermediate_cb($recv_msg) == 0 ) {
Christian Fibich's avatar
Christian Fibich committed
183
                $logger->info("Fulfilling halt request after test: $ti, repetition $ri.");
184
                goto END;
Christian Fibich's avatar
Christian Fibich committed
185
186
            }

187
        }
188

Christian Fibich's avatar
Christian Fibich committed
189
        # FIXME Repeat information comes from tests config file. OK?
190
        if ( $fiji_tests->{'design'}->{'REPEAT'} == 0 ) {
191
192
193
194
195
196
197
            last;
        } else {
            $toff = $fiji_tests->{'design'}->{'REPEAT_OFFSET'};
            $logger->info("Repeat tests beginning with $toff.");
            $ri++;
        }
    }
198

199
200
201
202
  END:
    $$testref                                = clone( $self->{'fiji_tests'} );
    $$testref->{'design'}->{'NUM_TESTS'}     = $ti;
    $$testref->{'design'}->{'REPEAT'}        = 0;
203
    $$testref->{'design'}->{'REPEAT_OFFSET'} = 0;
204
205
    if ( is_shared($$testref) ) {
        $$testref->{'tests'} = shared_clone( \@tests );
206
207
208
209
210
    } else {
        $$testref->{'tests'} = \@tests;
    }

    return $recv_msg;
211
212
}

Christian Fibich's avatar
Christian Fibich committed
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
## Download randomly generated tests
# Params
#   cfg Configuration hash
#        cfg->{'min_duration'}[0..n]   Minimum duration constraints for patterns
#        cfg->{'max_duration'}[0..n]   Maximum duration constraints for patterns
#        cfg->{'probabilities'}[FIJI::FIUENUM->{'NONE'}]        Probability of fault-free case
#        cfg->{'probabilities'}[FIJI::FIUENUM->{'STUCK_AT_0'}]  Probability of stuck-at-0 error
#        cfg->{'probabilities'}[FIJI::FIUENUM->{'STUCK_AT_1'}]  Probability of stuck-at-1 error
#        cfg->{'probabilities'}[FIJI::FIUENUM->{'DELAY'}]       Probability of delay error
#        cfg->{'probabilities'}[FIJI::FIUENUM->{'SEU'}]         Probability of seu error
#        cfg->{'probabilities'}[FIJI::FIUENUM->{'STUCK_OPEN'}]  Probability of stuck-open error
#   testref  Reference where download_random() places the modified FIJI::Tests object
#            after the test execution
#   portname Optional serial port to use
sub download_random ($$$;$) {
    my $logger = get_logger();
229
    my ( $self, $testref, $portname, $intermediate_cb ) = @_;
Christian Fibich's avatar
Christian Fibich committed
230
    my $fiji_design_consts = $self->{'fiji_settings'}->{'design'};
Christian Fibich's avatar
Christian Fibich committed
231

232
    $portname = $$testref->{'design'}->{'UART'} if ( !defined $portname );
Christian Fibich's avatar
Christian Fibich committed
233

234
235
    if ( !defined $intermediate_cb ) {
        $intermediate_cb = sub { return 1; };
Christian Fibich's avatar
Christian Fibich committed
236
    }
Christian Fibich's avatar
Christian Fibich committed
237

238
    my $port = FIJI::Connection->init( $portname, $fiji_design_consts->{'BAUDRATE'} )
Christian Fibich's avatar
Christian Fibich committed
239
240
241
242
243
244
245
      or $logger->fatal("Could not init UART.")
      and return "Could not init UART.";

    $logger->info("Downloading in random mode.");
    my @tests;
    my $ti = 0;
    my $recv_msg;
Christian Fibich's avatar
Christian Fibich committed
246
247
    my $check = 0;
    my $cont;
Christian Fibich's avatar
Christian Fibich committed
248
249

    do {
250
251
        my $temp_test = $self->{'fiji_tests'}->make_random_test( $self->{'fiji_settings'} );
        return $temp_test if ( !ref($temp_test) );
Christian Fibich's avatar
Christian Fibich committed
252
        @tests[$ti] = $temp_test;
Christian Fibich's avatar
Christian Fibich committed
253
        $logger->info("=== Test $ti ===");
254
255
        $recv_msg = $self->_download_test( $tests[ $ti++ ], $port );
        return "UART transaction failed." if ( ref($recv_msg) ne "HASH" );
Christian Fibich's avatar
Christian Fibich committed
256
        $check = $self->_check_halt($recv_msg);
257
258
        $cont  = &$intermediate_cb($recv_msg);
    } while ( $check != 1 && $cont != 0 );
Christian Fibich's avatar
Christian Fibich committed
259

260
261
    $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;
Christian Fibich's avatar
Christian Fibich committed
262

263
264
265
    $$testref                                = clone( $self->{'fiji_tests'} );
    $$testref->{'design'}->{'NUM_TESTS'}     = $ti;
    $$testref->{'design'}->{'REPEAT'}        = 0;
266
    $$testref->{'design'}->{'REPEAT_OFFSET'} = 0;
267
268
    if ( is_shared($$testref) ) {
        $$testref->{'tests'} = shared_clone( \@tests );
269
270
271
    } else {
        $$testref->{'tests'} = \@tests;
    }
Christian Fibich's avatar
Christian Fibich committed
272
273

    return $recv_msg;
Christian Fibich's avatar
Christian Fibich committed
274
275
276
277
278
}

## Download manually defined tests prompted from <STDIN>
#   portname Optional serial port to use
sub download_manual ($;$) {
279
280
281
    my $msg;
    my $logger = get_logger();

282
    my ( $self, $portname ) = @_;
283

284
    my $fiji_tests         = $self->{'fiji_tests'};
Christian Fibich's avatar
Christian Fibich committed
285
    my $fiji_design_consts = $self->{'fiji_settings'}->{'design'};
286

Christian Fibich's avatar
Christian Fibich committed
287
    # FIXME UART information can be defined in tests config file. OK?
288
    $portname = $fiji_design_consts->{'UART'} if ( !defined $portname );
289

290
    my $port = FIJI::Connection->init( $portname, $fiji_design_consts->{'BAUDRATE'} )
291
292
293
294
295
296
297
298
      or $logger->fatal("Could not init UART.")
      and return "Could not init UART.";

    $logger->info("Downloading in manual mode.");

    my $tests = ();

    while (1) {
299

300
        my $test = $self->_get_test_from_stdin();
301
302
303
304
305
        my $recv_msg = $self->_download_test( $test, $port );

        push @$tests, $test;

        if ( ref($recv_msg) ne "HASH" ) {
306
307
308
309
310
311
312
313
314
315
316
317
318
319
            $msg = "UART transaction failed.";
            last;
        }

        if ( $self->_check_halt($recv_msg) == 1 ) {
            $msg = "Halt because of HALT_ON_xxx.";
            return $msg;
        }

    }

    return $msg;
}

Christian Fibich's avatar
Christian Fibich committed
320
321
322
## Prompt tests from <STDIN>
# Params
#
323
324
325
326
sub _get_test_from_stdin {
    my $logger = get_logger();
    my ($self) = @_;

Christian Fibich's avatar
Christian Fibich committed
327
    my $fiji_design_consts = $self->{'fiji_settings'}->{'design'};
328
    my $test               = {};
329
330
331
332
333
334

    my $cfg_mask    = 2**$fiji_design_consts->{'FIU_CFG_BITS'} - 1;
    my $default_cfg = $cfg_mask;

    for ( my $i = 0 ; $i < $fiji_design_consts->{'FIU_NUM'} ; $i++ ) {
        for ( my $t = 1 ; $t <= $fiji_design_consts->{'CFGS_PER_MSG'} ; $t++ ) {
335
            printf( "Enter configuration for FIU #%d in t%d (default: 0x%x): ", $i, $t, $default_cfg );
336
337
338
339

            my $cfg_str = <STDIN>;
            last unless defined $cfg_str;
            $cfg_str =~ s/\R//g;    # remove line breaks globally
340
341
342
343
344
345
                                    # $cfg_str =~ s/^0x//i; # remove optional 0x prefix
                                    # if ($cfg_str !~ m/^[0-9A-F]+$|^$/i) {
                                    # printf("This is not hexadecimal.\n");
                                    # next;
                                    # }
            my $cur_cfg = ( length($cfg_str) == 0 ) ? $default_cfg : $cfg_str;
346
            $cur_cfg = oct($cur_cfg) if $cur_cfg =~ /^0/;
347
            $logger->debug( sprintf( "Configuration of FIU #%d in t%d is 0x%x.", $i, $t, $cur_cfg ) );
348
            $test->{"FIU_${i}_FAULT_${t}"} = REVERSE_FIU_ENUM($cur_cfg);
349
350
351
352
353
354
355
356
357
358
359
        }
    }

    # default t1 is maximum/2
    my $default_t1_dur =
      oct( "0x" . ( "FF" x ( $fiji_design_consts->{'TIMER_WIDTH'} / 8 ) ) ) / 2;
    printf( "Enter duration t1 (default: 0x%x): ", $default_t1_dur );
    $test->{'TIMER_VALUE_1'} = <STDIN>;
    last unless defined $test->{'TIMER_VALUE_1'};
    $test->{'TIMER_VALUE_1'} =~ s/\R//g;    # remove line breaks globally
    $test->{'TIMER_VALUE_1'} =
360
361
362
      int( ( length( $test->{'TIMER_VALUE_1'} ) == 0 ) ? $default_t1_dur : $test->{'TIMER_VALUE_1'} );
    $test->{'TIMER_VALUE_1'} = oct( $test->{'TIMER_VALUE_1'} ) if $test->{'TIMER_VALUE_1'} =~ /^0/;
    $logger->debug( sprintf( "t1 duration is %d (0x%x).", $test->{'TIMER_VALUE_1'}, $test->{'TIMER_VALUE_1'} ) );
363
364
365
366
367
368
369
370
371

    # default t2 duration to maximum/2
    my $default_t2_dur =
      oct( "0x" . ( "FF" x ( $fiji_design_consts->{'TIMER_WIDTH'} / 8 ) ) ) / 2;
    printf( "Enter duration t2 (default: 0x%x): ", $default_t2_dur );
    $test->{'TIMER_VALUE_2'} = <STDIN>;
    last unless defined $test->{'TIMER_VALUE_2'};
    $test->{'TIMER_VALUE_2'} =~ s/\R//g;    # remove line breaks globally
    $test->{'TIMER_VALUE_2'} =
372
373
374
      int( ( length( $test->{'TIMER_VALUE_2'} ) == 0 ) ? $default_t2_dur : $test->{'TIMER_VALUE_2'} );
    $test->{'TIMER_VALUE_2'} = oct( $test->{'TIMER_VALUE_2'} ) if $test->{'TIMER_VALUE_2'} =~ /^0/;
    $logger->debug( sprintf( "t2 duration is %d (0x%x).", $test->{'TIMER_VALUE_2'}, $test->{'TIMER_VALUE_2'} ) );
375
376
377
378

    printf("Enable trigger (default: 0)? ");
    my $trigger_en = <STDIN>;
    last unless defined $trigger_en;
379
    $trigger_en =~ s/\R//g;                 # remove line breaks globally
380
    $trigger_en = ( $trigger_en =~ /1|yes|y/i ) ? 1 : 0;
381
    $logger->debug( sprintf( "trigger is %sabled.", $trigger_en == 0 ? "dis" : "en" ) );
382
383
384
385
386
387

    my $trigger_ext = 0;
    if ($trigger_en) {
        printf("Use external/not internal trigger (default: 0)? ");
        $trigger_ext = <STDIN>;
        last unless defined $trigger_ext;
388
        $trigger_ext =~ s/\R//g;            # remove line breaks globally
389
        $trigger_ext = ( $trigger_ext =~ /1|yes|y/i ) ? 1 : 0;
390
391
        $logger->debug( sprintf( "External trigger is %sabled, internal trigger is %sabled.", $trigger_ext == 0 ? "dis" : "en", $trigger_ext != 0 ? "dis" : "en" ) );
        if ( $trigger_ext == 1 ) {
392
393
394
395
396
397
398
399
400
401
402
403
404
            $test->{'TRIGGER'} = "EXT";
        } else {
            $test->{'TRIGGER'} = "INT";
        }
    } else {
        $test->{'TRIGGER'} = "NONE";
    }

    printf("Enable reset (default: 0)? ");
    $test->{'RESET_DUT_AFTER_CONFIG'} = <STDIN>;
    last unless defined $test->{'RESET_DUT_AFTER_CONFIG'};
    $test->{'RESET_DUT_AFTER_CONFIG'} =~ s/\R//g;    # remove line breaks globally
    $test->{'RESET_DUT_AFTER_CONFIG'} = ( $test->{'RESET_DUT_AFTER_CONFIG'} =~ /1|yes|y/i ) ? 1 : 0;
405
    $logger->debug( sprintf( "reset is %sabled.", $test->{'RESET_DUT_AFTER_CONFIG'} == 0 ? "dis" : "en" ) );
406
407
408
409

    return $test;
}

Christian Fibich's avatar
Christian Fibich committed
410
411
sub download_test ($$) {
    my $logger = get_logger();
412
413
414
    my ( $self, $test, $portname ) = @_;

    my $port = FIJI::Connection->init( $portname, $self->{'fiji_settings'}->{'design'}->{'BAUDRATE'} )
Christian Fibich's avatar
Christian Fibich committed
415
416
417
      or $logger->fatal("Could not init UART.")
      and return "Could not init UART.";

418
419
420
    my $rmsg = $self->_download_test( $test, $port );

    $rmsg = "UART transaction failed." if ( ref($rmsg) ne "HASH" );
Christian Fibich's avatar
Christian Fibich committed
421
422
423

    return $rmsg;

Christian Fibich's avatar
Christian Fibich committed
424
425
426
}

sub update_rnd($) {
427
428
    my ( $self, $rnd ) = @_;
    for my $k ( keys( %{$rnd} ) ) {
Christian Fibich's avatar
Christian Fibich committed
429
430
431
432
        $self->{'fiji_tests'}->{'design'}->{$k} = $rnd->{$k};
    }
}

Christian Fibich's avatar
Christian Fibich committed
433
434
435
436
437
## Download a single test defined by a test hash
# Params
#   test The hash defining the test
#       test->{'TIMER_VALUE_1'}
#       test->{'TIMER_VALUE_2'}
438
#       test->{"FIU_[0..FIU_NUM]_FAULT_[0..CFGS_PER_MSG]"}
Christian Fibich's avatar
Christian Fibich committed
439
440
#       test->{'RESET_DUT_AFTER_CONFIG'}
#       test->{'TRIGGER'}
Christian Fibich's avatar
Christian Fibich committed
441
442
#   port serial port to use
sub _download_test ($$) {
443
    my $logger = get_logger();
444
    my ( $self, $test, $port ) = @_;
445

446
    my $fiji_tests         = $self->{'fiji_tests'};
Christian Fibich's avatar
Christian Fibich committed
447
    my $fiji_design_consts = $self->{'fiji_settings'}->{'design'};
448
449
    my @payload;

Christian Fibich's avatar
Christian Fibich committed
450
451
    # first generate FIU configuration payload

452
453
454
    for ( my $i = 0 ; $i < $fiji_design_consts->{'FIU_NUM'} ; $i++ ) {
        for ( my $t = 1 ; $t <= $fiji_design_consts->{'CFGS_PER_MSG'} ; $t++ ) {
            my $k       = "FIU_${i}_FAULT_${t}";
455
456
            my $cur_cfg = FIUENUM->{ $test->{$k} };
            $cur_cfg = oct($cur_cfg) if $cur_cfg =~ /^0/;
457
            $logger->debug( sprintf( "Configuration of FIU #%d in t%d is 0x%x.", $i, $t, $cur_cfg ) );
458
459
460
461
            push( @payload, $cur_cfg );
        }
    }

Christian Fibich's avatar
Christian Fibich committed
462
    # then generate fixed configuration part (timers,trigger,reset)
463

464
    my $t1_duration = $test->{'TIMER_VALUE_1'};
465
    $logger->debug( sprintf( "t1 duration is %d (0x%x).", $t1_duration, $t1_duration ) );
466
467

    my $t2_duration = $test->{'TIMER_VALUE_2'};
468
    $logger->debug( sprintf( "t2 duration is %d (0x%x).", $t2_duration, $t2_duration ) );
469
470
471
472
473

    my $trigger_en  = ( $test->{'TRIGGER'} ne "NONE" ) ? 1 : 0;
    my $trigger_ext = ( $test->{'TRIGGER'} eq "EXT" )  ? 1 : 0;
    my $reset       = $test->{'RESET_DUT_AFTER_CONFIG'};

474
    $logger->debug( sprintf( "trigger is %sabled.", $trigger_en == 0 ? "dis" : "en" ) );
475
    if ( $trigger_en == 1 ) {
476
        $logger->debug( sprintf( "External trigger is %sabled, internal trigger is %sabled.", $trigger_ext == 0 ? "dis" : "en", $trigger_ext != 0 ? "dis" : "en" ) );
477
478
    }

479
    $logger->debug( sprintf( "reset is %sabled.", $reset == 0 ? "dis" : "en" ) );
480

Christian Fibich's avatar
Christian Fibich committed
481
482
    # download test via serial

483
    my $recv_msg = _test_fi_uart( $port, \@payload, $t1_duration, $t2_duration, $trigger_en, $trigger_ext, $reset, $fiji_design_consts );
Christian Fibich's avatar
Christian Fibich committed
484
485

    return $recv_msg;
486
487
}

Christian Fibich's avatar
Christian Fibich committed
488
489
490
491
492
## Check the hash returned by _test_fi_uart() against HALT_ON_xxx-conditions
# Params
#   recv_msg The hash returned by _test_fi_uart() containing the decoded
#            return message
# Returns 1 if execution shall be halted and 0 otherwise
493
sub _check_halt ($) {
494
    my $halt   = 0;
495
    my $logger = get_logger();
496
    my ( $self, $recv_msg ) = @_;
497
498
499

    my $fiji_tests = $self->{'fiji_tests'};

Christian Fibich's avatar
Christian Fibich committed
500
501
    # FIXME HALT_on_xxx information is defined in tests config file. OK?

502
    if ( $recv_msg->{'msg_type'} eq "UNDERRUN" ) {
503
        $logger->info( "UNDERRUN message received. HALT_ON_UNDERRUN = " . $fiji_tests->{'design'}->{'HALT_ON_UNDERRUN'} . "." );
504
505
        $halt |= $fiji_tests->{'design'}->{'HALT_ON_UNDERRUN'};
    }
506
507
    if ( $recv_msg->{'error'}->{'U'} ) {
        $logger->info( "UART error. HALT_ON_UART_ERROR = " . $fiji_tests->{'design'}->{'HALT_ON_UART_ERROR'} . "." );
508
509
        $halt |= $fiji_tests->{'design'}->{'HALT_ON_UART_ERROR'};
    }
510
511
    if ( $recv_msg->{'error'}->{'I'} ) {
        $logger->info( "ID error. HALT_ON_ID_ERROR = " . $fiji_tests->{'design'}->{'HALT_ON_ID_ERROR'} . "." );
512
513
        $halt |= $fiji_tests->{'design'}->{'HALT_ON_ID_ERROR'};
    }
514
515
    if ( $recv_msg->{'error'}->{'C'} ) {
        $logger->info( "CRC error. HALT_ON_CRC_ERROR = " . $fiji_tests->{'design'}->{'HALT_ON_CRC_ERROR'} . "." );
516
517
        $halt |= $fiji_tests->{'design'}->{'HALT_ON_CRC_ERROR'};
    }
518
    for my $ei ( 1 .. 2 ) {
519
        if ( $recv_msg->{'fault_detect'}->{$ei} ) {
520
            $logger->info( "FAULT detected (Bit $ei). HALT_ON_FAULT_DETECT = " . $fiji_tests->{'design'}->{'HALT_ON_FAULT_DETECT'} . "." );
521
522
523
524
525
526
527
            $halt |= $fiji_tests->{'design'}->{'HALT_ON_FAULT_DETECT'};
        }
    }

    return $halt;
}

528
1;