OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [perl_gui/] [lib/] [perl/] [emulator.pl] - Blame information for rev 28

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 alirezamon
#! /usr/bin/perl -w
2
use Glib qw/TRUE FALSE/;
3
use strict;
4
use warnings;
5
use Gtk2;
6
use Gtk2::Ex::Graph::GD;
7
use GD::Graph::Data;
8
use emulator;
9
use IO::CaptureOutput qw(capture qxx qxy);
10
use GD::Graph::colour qw/:colours/;
11
use Proc::Background;
12
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep  clock_gettime clock_getres clock_nanosleep clock stat );
13
 
14
use File::Basename;
15
use File::Path qw/make_path/;
16 28 alirezamon
use File::Copy;
17
use File::Find::Rule;
18 25 alirezamon
 
19
require "widget.pl";
20
require "emulate_ram_gen.pl";
21
require "mpsoc_gen.pl";
22
require "mpsoc_verilog_gen.pl";
23
require "readme_gen.pl";
24
 
25
use List::MoreUtils qw(uniq);
26
 
27
 
28 28 alirezamon
# hardware parameters taken from noc_emulator.v
29
use constant PCK_CNTw =>30;  # packet counter width in bits (results in maximum of 2^30 = 1  G packets)
30
use constant PCK_SIZw =>14;  # packet size width in bits (results in maximum packet size of 2^14 = 16 K flit)
31
use constant MAXXw    =>4;   # maximum nodes in x dimention is 2^MAXXw equal to 16 nodes in x dimention
32
use constant MAXYw    =>4;   # 16 nodes in y dimention : hence max emulator size is 16X16
33
use constant MAXCw    =>4;   # 16 message classes  
34
use constant RATIOw   =>7;   # log2(100)
35
use constant MAX_PATTERN => 124;
36
use constant RAM_SIZE => (MAX_PATTERN+4);
37 25 alirezamon
 
38 28 alirezamon
 
39
#use constant MAX_PCK_NUM => (2**PCK_CNTw)-1;
40
use constant MAX_PCK_NUM => (2**PCK_CNTw)-1;
41
use constant MAX_PCK_SIZ => (2**PCK_SIZw)-1;
42
use constant MAX_SIM_CLKs=> 100000000; # simulation end at if clock counter reach this number           
43 25 alirezamon
 
44 28 alirezamon
use constant EMULATION_RTLS => "/mpsoc/src_emulate/rtl/noc_emulator.v , /mpsoc/src_peripheral/jtag/jtag_wb/ , /mpsoc/src_peripheral/ram/generic_ram.v, /mpsoc/src_noc/";
45 25 alirezamon
 
46 28 alirezamon
 
47
 
48
 
49
 
50 25 alirezamon
sub gen_chart {
51
        my $emulate=shift;
52
        my($width,$hight)=max_win_size();
53
        my $graph_w=$width/2.5;
54
        my $graph_h=$hight/2.5;
55
        my $graph = Gtk2::Ex::Graph::GD->new($graph_w, $graph_h, 'linespoints');
56
        my @x;
57
        my @legend_keys;
58
        my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
59
        my $scale= $emulate->object_get_attribute("graph_scale",undef);
60
        my @results;
61
        $results[0]=[0];
62
        $results[1]= [0];
63
my $legend_info="This attribute controls placement of the legend within the graph image. The value is supplied as a two-letter string, where the first letter is placement (a B or an R for bottom or right, respectively) and the second is alignment (L, R, C, T, or B for left, right, center, top, or bottom, respectively). ";
64
 
65
my @ginfo = (
66
{ label=>"Graph Title", param_name=>"G_Title", type=>"Entry", default_val=>undef, content=>undef, info=>undef, param_parent=>'graph_param', ref_delay=>undef },
67
{ label=>"Y Axix Title", param_name=>"Y_Title", type=>"Entry", default_val=>'Latency (clock)', content=>undef, info=>undef, param_parent=>'graph_param', ref_delay=>undef },
68
  { label=>"X Axix Title", param_name=>"X_Title", type=>"Entry", default_val=>'Load per router (flits/clock (%))', content=>undef, info=>undef, param_parent=>'graph_param',ref_delay=>undef },
69
  { label=>"legend placement", param_name=>"legend_placement", type=>'Combo-box', default_val=>'BL', content=>"BL,BC,BR,RT,RC,RB", info=>$legend_info, param_parent=>'graph_param', ref_delay=>undef},
70
 { label=>"Y min", param_name=>"Y_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"Y axix minimum value", param_parent=>'graph_param', ref_delay=> 5},
71
 { label=>"X min", param_name=>"X_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"X axix minimum value", param_parent=>'graph_param', ref_delay=> 5},
72
 { label=>"Line Width", param_name=>"LINEw", type=>'Spin-button', default_val=>3, content=>"1,20,1", info=>undef, param_parent=>'graph_param', ref_delay=> 5},
73
 
74
 
75
);
76
 
77 28 alirezamon
 
78
 
79
 
80
 
81 25 alirezamon
        if(defined  $sample_num){
82
                my @color;
83
                my $min_y=200;
84
                for (my $i=1;$i<=$sample_num; $i++) {
85
                        my $color_num=$emulate->object_get_attribute("sample$i","color");
86
                        my $l_name= $emulate->object_get_attribute("sample$i","line_name");
87
                        $legend_keys[$i-1]= (defined $l_name)? $l_name : "NoC$i";
88
                        $color_num=$i+1 if(!defined $color_num);
89
                        push(@color, "my_color$color_num");
90
                        my $ref=$emulate->object_get_attribute ("sample$i","result");
91
                        if(defined $ref) {
92
                                push(@x, sort {$a<=>$b} keys $ref);
93
                        }
94
 
95
                }#for
96
        my  @x1;
97
        @x1 =  uniq(sort {$a<=>$b} @x) if (scalar @x);
98 28 alirezamon
        #print "\@x1=@x1\n";
99 25 alirezamon
        if (scalar @x1){
100
                $results[0]=\@x1;
101
                for (my $i=1;$i<=$sample_num; $i++) {
102
                        my $j=0;
103
                        my $ref=$emulate->object_get_attribute ("sample$i","result");
104
                        if(defined $ref){
105 28 alirezamon
                                #print "$i\n";
106 25 alirezamon
                                my %line=%$ref;
107
                                foreach my $k (@x1){
108
                                        $results[$i][$j]=$line{$k};
109
                                        $min_y= $line{$k} if (defined $line{$k} && $line{$k}!=0 && $min_y > $line{$k});
110
                                        $j++;
111
                                }#$k
112 28 alirezamon
                        }#if
113
                        else {
114
                                $results[$i][$j]=undef;
115
 
116
                        }
117 25 alirezamon
                }#$i
118
 
119
        }#if
120
 
121
        my $max_y=$min_y*$scale;
122
 
123
 
124
 
125
        my $graphs_info;
126
        foreach my $d ( @ginfo){
127
                $graphs_info->{$d->{param_name}}=$emulate->object_get_attribute( 'graph_param',$d->{param_name});
128
                $graphs_info->{$d->{param_name}}= $d->{default_val} if(!defined $graphs_info->{$d->{param_name}});
129
        }
130
 
131 28 alirezamon
 
132 25 alirezamon
 
133
        $graph->set (
134
                x_label         => $graphs_info->{X_Title},
135
                y_label         => $graphs_info->{Y_Title},
136
                y_max_value     => $max_y,
137
                y_min_value     => $graphs_info->{Y_MIN},
138
                x_min_value     => $graphs_info->{X_MIN}, # dosent work?
139
                title           => $graphs_info->{G_Title},
140
                bar_spacing     => 1,
141
                shadowclr       => 'dred',
142
                transparent     => 0,
143
                                line_width              => $graphs_info->{LINEw},
144
                                cycle_clrs              => 'blue',
145
                                legend_placement => $graphs_info->{legend_placement},
146
                                dclrs=>\@color,
147
                );
148
     }#if
149
        $graph->set_legend(@legend_keys);
150
 
151
 
152
        my $data = GD::Graph::Data->new(\@results) or die GD::Graph::Data->error;
153
        my $image = my_get_image($emulate,$graph,$data);
154
 
155
 
156
 
157
 
158
 
159
 
160
 
161
 
162
        my $table = Gtk2::Table->new (25, 10, FALSE);
163
 
164
 
165
                my $box = Gtk2::HBox->new (TRUE, 2);
166
                my $filename;
167
                $box->set_border_width (4);
168
                my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
169
                my $frame = Gtk2::Frame->new;
170
                $frame->set_shadow_type ('in');
171
                $frame->add ($image);
172
                $align->add ($frame);
173
 
174
 
175
                my $plus = def_image_button('icons/plus.png',undef,TRUE);
176
                my $minues = def_image_button('icons/minus.png',undef,TRUE);
177
                my $setting = def_image_button('icons/setting.png',undef,TRUE);
178
                my $save = def_image_button('icons/save.png',undef,TRUE);
179
 
180
                $minues -> signal_connect("clicked" => sub{
181
                        $emulate->object_add_attribute("graph_scale",undef,$scale+0.5);
182
                        set_gui_status($emulate,"ref",1);
183
                });
184
 
185
                $plus  -> signal_connect("clicked" => sub{
186
                        $emulate->object_add_attribute("graph_scale",undef,$scale-0.5) if( $scale>0.5);
187
                        set_gui_status($emulate,"ref",5);
188
                });
189
 
190
                $setting -> signal_connect("clicked" => sub{
191
                        get_graph_setting ($emulate,\@ginfo);
192
                });
193
 
194
                $save-> signal_connect("clicked" => sub{
195
                         my $G = $graph->{graph};
196
                         my @imags=$G->export_format();
197
                        save_graph_as ($emulate,\@imags);
198
                });
199
 
200
 
201
 
202
 
203
                $table->attach_defaults ($align , 0, 9, 0, 25);
204
                my $row=0;
205
                $table->attach ($plus , 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
206
                $table->attach ($minues, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
207
                $table->attach ($setting, 9, 10, $row,  $row+1,'shrink','shrink',2,2); $row++;
208
                $table->attach ($save, 9, 10, $row,  $row+1,'shrink','shrink',2,2); $row++;
209
                while ($row<10){
210
 
211
                        my $tmp=gen_label_in_left('');
212
                        $table->attach_defaults ($tmp, 9, 10, $row,  $row+1);$row++;
213
                }
214
 
215
        return $table;
216
 
217
}
218
 
219
 
220
##############
221
#       save_graph_as
222
##############
223
 
224
sub save_graph_as {
225
        my ($emulate,$ref)=@_;
226
 
227
        my $file;
228
        my $title ='Save as';
229
 
230
 
231
 
232
        my @extensions=@$ref;
233
        my $open_in=undef;
234
        my $dialog = Gtk2::FileChooserDialog->new(
235
                'Save file', undef,
236
                'save',
237
                'gtk-cancel' => 'cancel',
238
                'gtk-ok'     => 'ok',
239
                );
240
        # if(defined $extension){
241
 
242
                foreach my $ext (@extensions){
243
                        my $filter = Gtk2::FileFilter->new();
244
                        $filter->set_name($ext);
245
                        $filter->add_pattern("*.$ext");
246
                        $dialog->add_filter ($filter);
247
                }
248
 
249
        # }
250
          if(defined  $open_in){
251
                $dialog->set_current_folder ($open_in);
252
                # print "$open_in\n";
253
 
254
        }
255
 
256
        if ( "ok" eq $dialog->run ) {
257
                        $file = $dialog->get_filename;
258
                        my $ext = $dialog->get_filter;
259
                        $ext=$ext->get_name;
260
                        my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
261
                        $file = ($suffix eq ".$ext" )? $file : "$file.$ext";
262
 
263
                        $emulate->object_add_attribute("graph_save","name",$file);
264
                        $emulate->object_add_attribute("graph_save","extension",$ext);
265
                        $emulate->object_add_attribute("graph_save","save",1);
266
                        set_gui_status($emulate,"ref",1);
267
 
268
 
269
 
270
                         }
271
                        $dialog->destroy;
272
 
273
 
274
 
275
 
276
 
277
 
278
}
279
 
280
 
281
 
282
 
283
sub my_get_image {
284
        my ($emulate,$self, $data) = @_;
285
        $self->{graphdata} = $data;
286
        my $graph = $self->{graph};
287
        my $gd1=$graph->plot($data) or warn $graph->error;
288
        my $loader = Gtk2::Gdk::PixbufLoader->new;
289
 
290
 
291
 
292
        #my $gd2=$graph->plot([[0],[0]]) or warn $graph->error;
293
        #$gd2->copy( $gd1, 0, 20, 0, 20, 500, 230 );
294
 
295
 
296
        $loader->write ($gd1->png);
297
        $loader->close;
298
 
299
        my $save=$emulate->object_get_attribute("graph_save","save");
300
        $save=0 if (!defined $save);
301
        if ($save ==1){
302
                my $file=$emulate->object_get_attribute("graph_save","name");
303
                my $ext=$emulate->object_get_attribute("graph_save","extension");
304
                $emulate->object_add_attribute("graph_save","save",0);
305
 
306
 
307
                open(my $out, '>', $file);
308
                if (tell $out )
309
                {
310
                        warn "Cannot open '$file' for write: $!";
311
                }else
312
                {
313
                        #my @extens=$graph->export_format();
314
                        binmode $out;
315
                        print $out $gd1->$ext;# if($ext eq 'png');
316
                        #print $out  $gd1->gif  if($ext eq 'gif');
317
                        close $out;
318
                }
319
 
320
        }
321
 
322
 
323
 
324
        my $image = Gtk2::Image->new_from_pixbuf($loader->get_pixbuf);
325
        $self->{graphimage} = $image;
326
        my $hotspotlist;
327
        if ($self->{graphtype} eq 'bars' or
328
                $self->{graphtype} eq 'lines' or
329
                $self->{graphtype} eq 'linespoints') {
330
                foreach my $hotspot ($graph->get_hotspot) {
331
                        push @$hotspotlist, $hotspot if $hotspot;
332
                }
333
        }
334
        $self->{hotspotlist} = $hotspotlist;
335
        my $eventbox = $self->{eventbox};
336
        my @children = $eventbox->get_children;
337
        foreach my $child (@children) {
338
                $eventbox->remove($child);
339
        }
340
 
341
 
342
 
343
 
344
        $eventbox->add ($image);
345
 
346
        $eventbox->signal_connect ('button-press-event' =>
347
                sub {
348
                        my ($widget, $event) = @_;
349
                        return TRUE;
350
                        return FALSE unless $event->button == 3;
351
                        $self->{optionsmenu}->popup(
352
                                undef, # parent menu shell
353
                                undef, # parent menu item
354
                                undef, # menu pos func
355
                                undef, # data
356
                                $event->button,
357
                                $event->time
358
                        );
359
                }
360
        );
361
        $eventbox->show_all;
362
        return $eventbox;
363
}
364
 
365
 
366
############
367
#       get_graph_setting
368
###########
369
 
370
sub get_graph_setting {
371
        my ($emulate,$ref)=@_;
372
        my($width,$hight)=max_win_size();
373
        my $window=def_popwin_size($width/3,$hight/3,'Graph Setting');
374
        my $table = def_table(10, 2, FALSE);
375
        my $row=0;
376
 
377
 
378
my @data=@$ref;
379
foreach my $d (@data) {
380
        $row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
381
}
382
 
383
 
384
 
385
 
386
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
387
        $scrolled_win->set_policy( "automatic", "automatic" );
388
        $scrolled_win->add_with_viewport($table);
389
        my $ok = def_image_button('icons/select.png',' OK ');
390
 
391
 
392
        my $mtable = def_table(10, 1, FALSE);
393
        $mtable->attach_defaults($scrolled_win,0,1,0,9);
394
        $mtable->attach($ok,0,1,9,10,'shrink','shrink',2,2);
395
        $window->add ($mtable);
396
        $window->show_all();
397
 
398
        $ok-> signal_connect("clicked" => sub{
399
                $window->destroy;
400
                set_gui_status($emulate,"ref",1);
401
        });
402
 
403
 
404
 
405
}
406
 
407
 
408
 
409
 
410
 
411
 
412
 
413
 
414
 
415
 
416
 
417
 
418
 ################
419
 # get_color_window
420
 ###############
421
 
422
 sub get_color_window{
423
         my ($emulate,$atrebute1,$atrebute2)=@_;
424
         my $window=def_popwin_size(800,600,"Select line color");
425
         my ($r,$c)=(4,8);
426
         my $table= def_table(5,6,TRUE);
427
         for (my $col=0;$col<$c;$col++){
428
                  for (my $row=0;$row<$r;$row++){
429
                        my $color_num=$row*$c+$col;
430
                        my $color=def_colored_button("    ",$color_num);
431
                        $table->attach_defaults ($color, $col, $col+1, $row, $row+1);
432
                        $color->signal_connect("clicked"=> sub{
433
                                $emulate->object_add_attribute($atrebute1,$atrebute2,$color_num);
434
                                #print "$emulate->object_add_attribute($atrebute1,$atrebute2,$color_num);\n";
435
                                set_gui_status($emulate,"ref",1);
436
                                $window->destroy;
437
                        });
438
                 }
439
         }
440
 
441
         $window->add($table);
442
 
443
        $window->show_all();
444
 
445
}
446
 
447
 
448
 
449
 
450
sub check_inserted_ratios {
451
                my $str=shift;
452
                my @ratios;
453
 
454
            my @chunks=split(',',$str);
455
            foreach my $p (@chunks){
456
                        if($p !~ /^[0-9.:,]+$/){ message_dialog ("$p has invalid character(S)" ); return undef; }
457
                        my @range=split(':',$p);
458
                        my $size= scalar @range;
459
                        if($size==1){ # its a number
460
                                if ( $range[0] <= 0 || $range[0] >100  ) { message_dialog ("$range[0] is out of boundery (1:100)" ); return undef; }
461
                                push(@ratios,$range[0]);
462
                        }elsif($size ==3){# its a range
463
                                my($min,$max,$step)=@range;
464
                                if ( $min <= 0 || $min >100  ) { message_dialog ("$min in  $p is out of boundery (1:100)" ); return undef; }
465
                                if ( $max <= 0 || $max >100  ) { message_dialog ("$max in  $p is out of boundery (1:100)" ); return undef; }
466
                                for (my $i=$min; $i<=$max; $i=$i+$step){
467
                                                push(@ratios,$i);
468
                                }
469
 
470
                        }else{
471
                                 message_dialog ("$p has invalid format. The correct format for range is \$min:\$max:\$step" );
472
 
473
                        }
474
 
475
 
476
 
477
                }#foreach
478
                my @r=uniq(sort {$a<=>$b} @ratios);
479
                return \@r;
480
 
481
}
482
 
483
 
484
 
485
 
486
 
487
 
488
 
489
sub get_injection_ratios{
490
                my ($emulate,$atrebute1,$atrebute2)=@_;
491
                my $box = Gtk2::HBox->new( FALSE, 0 );
492
                my $init=$emulate->object_get_attribute($atrebute1,$atrebute2);
493
                my $entry=gen_entry($init);
494
                my $button=def_image_button("icons/right.png",'Check');
495
                $button->signal_connect("clicked" => sub {
496
                        my $text= $entry->get_text();
497
                        my $r=check_inserted_ratios($text);
498
                        if(defined      $r){
499
                                my $all=  join (',',@$r);
500
                                message_dialog ("$all" );
501
                        }
502
 
503
 
504
                });
505
                $entry->signal_connect ("changed" => sub {
506
                        my $text= $entry->get_text();
507
                        $emulate->object_add_attribute($atrebute1,$atrebute2,$text);
508
 
509
                });
510
                $box->pack_start( $entry, 1,1, 0);
511
                $box->pack_start( $button, 0, 1, 3);
512
                return  $box;
513
}
514
 
515
 
516
 
517
sub get_noc_configuration{
518 28 alirezamon
        my ($emulate,$n) =@_;
519
        my($width,$hight)=max_win_size();
520
        my $win=def_popwin_size($width/2.5,$hight*.8,"NoC configuration setting");
521
        my $table=def_table(10,2,FALSE);
522
        my $row=0;
523 25 alirezamon
 
524
 
525 28 alirezamon
        my $traffics="tornado,transposed 1,transposed 2,bit reverse,bit complement,random"; #TODO hot spot 
526
 
527
        my $dir = Cwd::getcwd();
528
        my $open_in       = abs_path("$ENV{PRONOC_WORK}/emulate/sof");
529
        attach_widget_to_table ($table,$row,gen_label_in_left("SoF file:"),gen_button_message ("Select the SRAM Object File (sof) for this NoC configration.","icons/help.png"), get_file_name_object ($emulate,"sample$n","sof_file",'sof',$open_in)); $row++;
530 25 alirezamon
 
531 28 alirezamon
 
532
 
533
        my @siminfo = (
534
        { label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>"NoC$n", content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>"sample$n", ref_delay=> undef},
535
 
536
        { label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>"sample$n", ref_delay=>undef},
537
 
538
{ label=>"Packet size in flit:", param_name=>'PCK_SIZE', type=>'Spin-button', default_val=>4, content=>"2,".MAX_PCK_SIZ.",1", info=>undef, param_parent=>"sample$n", ref_delay=>undef},
539
 
540
        { label=>"Packet number limit:", param_name=>'PCK_NUM_LIMIT', type=>'Spin-button', default_val=>1000000, content=>"2,".MAX_PCK_NUM.",1", info=>"Each node stops sending packets when it reaches packet number limit  or simulation clock number limit", param_parent=>"sample$n", ref_delay=>undef},
541
 
542
{ label=>"Emulation clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>MAX_SIM_CLKs, content=>"2,".MAX_SIM_CLKs.",1", info=>"Each node stops sending packets when it reaches packet number limit  or simulation clock number limit", param_parent=>"sample$n", ref_delay=>undef},
543
 
544
 
545
);
546
        foreach my $d ( @siminfo) {
547
        $row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
548
}
549
 
550
 
551
 
552
 
553
                my $l= "Define injection ratios. You can define individual ratios seprating by comma (\',\') or define a range of injection ratios with \$min:\$max:\$step format.
554
                        As an example defining 2,3,4:10:2 will result in (2,3,4,6,8,10) injection ratios." ;
555
                my $u=get_injection_ratios ($emulate,"sample$n","ratios");
556 25 alirezamon
 
557 28 alirezamon
attach_widget_to_table ($table,$row,gen_label_in_left("Injection ratios:"),gen_button_message ($l,"icons/help.png") , $u); $row++;
558
 
559
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
560
        $scrolled_win->set_policy( "automatic", "automatic" );
561
        $scrolled_win->add_with_viewport($table);
562 25 alirezamon
 
563
        my $ok = def_image_button('icons/select.png','OK');
564 28 alirezamon
        my $mtable = def_table(10, 1, TRUE);
565
 
566
        $mtable->attach_defaults($scrolled_win,0,1,0,9);
567
        $mtable-> attach ($ok , 0, 1,  9, 10,'expand','shrink',2,2);
568 25 alirezamon
 
569 28 alirezamon
        $win->add ($mtable);
570
        $win->show_all();
571
 
572
 
573
 
574
 
575
 
576
 
577
 
578
 
579
 
580 25 alirezamon
 
581
 
582 28 alirezamon
 
583
 
584 25 alirezamon
        $ok->signal_connect("clicked"=> sub{
585
                #check if sof file has been selected
586
                my $s=$emulate->object_get_attribute("sample$n","sof_file");
587
                #check if injection ratios are valid
588
                my $r=$emulate->object_get_attribute("sample$n","ratios");
589
                if(defined $s && defined $r) {
590
                                $win->destroy;
591
                                set_gui_status($emulate,"ref",1);
592
                } else {
593
 
594
                        if(!defined $s){
595
                                 message_dialog("Please select sof file!")
596
                        } else {
597
                                 message_dialog("Please define valid injection ratio(s)!")
598
                        }
599
                }
600
        });
601 28 alirezamon
 
602 25 alirezamon
 
603 28 alirezamon
 
604
 
605
 
606
 
607
 
608
 
609 25 alirezamon
 
610
 
611
}
612
 
613
 
614
 
615
#####################
616
#               gen_widgets_column
617
###################      
618
 
619
sub gen_emulation_column {
620
        my ($emulate,$title, $row_num,$info)=@_;
621
        my $table=def_table($row_num,10,FALSE);
622
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
623
        $scrolled_win->set_policy( "automatic", "automatic" );
624
        $scrolled_win->add_with_viewport($table);
625
        my $row=0;
626
        #title  
627
        if(defined $title){
628
                my $title=gen_label_in_center($title);
629
                my $box=def_vbox(FALSE, 1);
630
                $box->pack_start( $title, FALSE, FALSE, 3);
631
                my $separator = Gtk2::HSeparator->new;
632
                $box->pack_start( $separator, FALSE, FALSE, 3);
633
                $table->attach_defaults ($box , 0, 10,  $row, $row+1); $row++;
634
        }
635
 
636
 
637
        my $lb=gen_label_in_left("Number of emulations");
638
        my $spin= gen_spin_object ($emulate,"emulate_num",undef,"1,100,1",1,'ref','1');
639
    $table->attach_defaults ($lb, 0, 2, $row, $row+1);
640
    $table->attach_defaults ($spin, 2, 4, $row, $row+1);$row++;
641
 
642
 
643
 
644
 
645
        my @positions=(0,1,2,3,6,7);
646
        my $col=0;
647
 
648
        my @title=(" NoC configuration", "Line's color", "Clear Graph","  ");
649
        foreach my $t (@title){
650
 
651
                $table->attach_defaults (gen_label_in_center($title[$col]), $positions[$col], $positions[$col+1], $row, $row+1);$col++;
652
        }
653
 
654
        my $traffics="Random,Transposed 1,Transposed 2,Tornado";
655
 
656
        $col=0;
657
        $row++;
658
        @positions=(0,1,2,3,4,5,6,7);
659
 
660
        my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
661
         if(!defined $sample_num){
662
                $sample_num=1;
663
                $emulate->object_add_attribute("emulate_num",undef,1);
664
         }
665
        my $i=0;
666
        for ($i=1;$i<=$sample_num; $i++){
667
                $col=0;
668
                my $sample="sample$i";
669
                my $n=$i;
670
                my $set=def_image_button("icons/setting.png");
671
                my $name=$emulate->object_get_attribute($sample,"line_name");
672
                my $l;
673
                if (defined $name){
674
                         $l=gen_label_in_left($name);
675
                } else {
676
                        $l=gen_label_in_center("Define NoC configuration");
677
                        $l->set_markup("<span  foreground= 'red' ><b>Define NoC configuration</b></span>");
678
                }
679
                my $box=def_pack_hbox(FALSE,0,(gen_label_in_left("$i- "),$l,$set));
680
                $table->attach ($box, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
681
                $set->signal_connect("clicked"=> sub{
682
                        get_noc_configuration($emulate,$n);
683
                });
684
 
685
 
686
 
687
                my $color_num=$emulate->object_get_attribute($sample,"color");
688
                if(!defined $color_num){
689
                        $color_num = $i+1;
690
                        $emulate->object_add_attribute($sample,"color",$color_num);
691
                }
692
                my $color=def_colored_button("    ",$color_num);
693
                $table->attach ($color, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
694
 
695
 
696
 
697
 
698
 
699
 
700
                $color->signal_connect("clicked"=> sub{
701
                        get_color_window($emulate,$sample,"color");
702
                });
703
 
704
                #clear line
705
                my $clear = def_image_button('icons/clear.png');
706
                $clear->signal_connect("clicked"=> sub{
707
                        $emulate->object_add_attribute ($sample,'result',undef);
708
                        set_gui_status($emulate,"ref",2);
709
                });
710
                $table->attach ($clear, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
711
                #run/pause
712
                my $run = def_image_button('icons/run.png','Run');
713
                $table->attach ($run, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
714
                $run->signal_connect("clicked"=> sub{
715
                        $emulate->object_add_attribute ($sample,"status","run");
716
                        #start the emulator if it is not running        
717
                        my $status= $emulate->object_get_attribute('status',undef);
718
                        if($status ne 'run'){
719
 
720
                                run_emulator($emulate,$info);
721
                                set_gui_status($emulate,"ref",2);
722
                        }
723
 
724
                });
725
 
726
                my $image = gen_noc_status_image($emulate,$i);
727
 
728
                $table->attach_defaults ($image, $positions[$col], $positions[$col+1], $row, $row+1);
729
 
730
 
731
                $row++;
732
 
733
        }
734
        while ( $row<15){
735
                $table->attach_defaults (gen_label_in_left(' '), 0, 1, $row, $row+1); $row++;
736
        }
737
 
738
 
739
 
740
 
741
        return $scrolled_win;
742
}
743
 
744
 
745
 
746
 
747
##########
748
#
749
##########
750
 
751
sub check_sample{
752
        my ($emulate,$i,$info)=@_;
753
        my $status=1;
754
        my $sof=$emulate->object_get_attribute ("sample$i","sof_file");
755
        # ckeck if sample have sof file
756
        if(!defined $sof){
757
                add_info($info, "Error: SoF file has not set for NoC$i!\n");
758
                $emulate->object_add_attribute ("sample$i","status","failed");
759
                $status=0;
760
        } else {
761
                # ckeck if sof file has info file 
762
                my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
763
                my $sof_info="$path$name.inf";
764
                if(!(-f $sof_info)){
765
                        add_info($info, "Could not find $name.inf file in $path. An information file is required for each sof file containig the device name and  NoC configuration. Press F4 for more help.\n");
766
                        $emulate->object_add_attribute ("sample$i","status","failed");
767
                        $status=0;
768
                }else { #add info
769 28 alirezamon
                        my $pp= do $sof_info ;
770
 
771
                        my $p=$pp->{'noc_param'};
772
 
773
 
774
 
775
 
776
 
777 25 alirezamon
                        $status=0 if $@;
778
                        message_dialog("Error reading: $@") if $@;
779
                        if ($status==1){
780
                                $emulate->object_add_attribute ("sample$i","noc_info",$p) ;
781
                                        #print"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n";
782
 
783
                        }
784
 
785
 
786
 
787
                }
788
        }
789
 
790
 
791
        return $status;
792
 
793
 
794
}
795
 
796
 
797
 
798
 
799
##########
800
#  run external commands
801
##########
802
 
803
 
804
 
805
 
806
 
807
sub run_cmd_in_back_ground
808
{
809
  my $command = shift;
810
 
811
 
812
 
813
 
814
 
815
 
816
  ### Start running the Background Job:
817
    my $proc = Proc::Background->new($command);
818
    my $PID = $proc->pid;
819
    my $start_time = $proc->start_time;
820
    my $alive = $proc->alive;
821
 
822
  ### While $alive is NOT '0', then keep checking till it is...
823
  #  *When $alive is '0', it has finished executing.
824
  while($alive ne 0)
825
  {
826
    $alive = $proc->alive;
827
 
828
    # This while loop will cause Gtk2 to conti processing events, if
829
    # there are events pending... *which there are...
830
    while (Gtk2->events_pending) {
831
      Gtk2->main_iteration;
832
    }
833
    Gtk2::Gdk->flush;
834
 
835
    usleep(1000);
836
  }
837
 
838
  my $end_time = $proc->end_time;
839
 # print "*Command Completed at $end_time, with PID = $PID\n\n";
840
 
841
  # Since the while loop has exited, the BG job has finished running:
842
  # so close the pop-up window...
843
 # $popup_window->hide;
844
 
845
  # Get the RETCODE from the Background Job using the 'wait' method
846
  my $retcode = $proc->wait;
847
  $retcode /= 256;
848
 
849
  print "\t*RETCODE == $retcode\n\n";
850
  Gtk2::Gdk->flush;
851
  ### Check if the RETCODE returned with an Error:
852
  if ($retcode ne 0) {
853
    print "Error: The Background Job ($command) returned with an Error...!\n";
854
    return 1;
855
  } else {
856
    #print "Success: The Background Job Completed Successfully...!\n";
857
    return 0;
858
  }
859
 
860
}
861
 
862
 
863
 
864
 
865
sub run_cmd_in_back_ground_get_stdout
866
{
867
        my $cmd=shift;
868
        my $exit;
869
        my ($stdout, $stderr);
870
        capture { $exit=run_cmd_in_back_ground($cmd) } \$stdout, \$stderr;
871
        return ($stdout,$exit,$stderr);
872
 
873
}
874
 
875
 
876
#############
877
#  images
878
##########
879
sub get_status_gif{
880
                my $emulate=shift;
881
                my $status= $emulate->object_get_attribute('status',undef);
882
                if($status eq 'ideal'){
883
                        return show_gif ("icons/ProNoC.png");
884
                } elsif ($status eq 'run') {
885
                        my($width,$hight)=max_win_size();
886
                        my $image=($width>=1600)? "icons/hamster_l.gif":
887
                                  ($width>=1200)? "icons/hamster_m.gif": "icons/hamster_s.gif";
888
 
889
                        return show_gif ($image);
890
                } elsif ($status eq 'programer_failed') {
891
                        return show_gif ("icons/Error.png");
892
                }
893
 
894
}
895
 
896
 
897
 
898
 
899
sub gen_noc_status_image {
900
        my ($emulate,$i)=@_;
901
        my   $status= $emulate->object_get_attribute ("sample$i","status");
902
         $status='' if(!defined  $status);
903
        my $image;
904
        my $vbox = Gtk2::HBox->new (TRUE,1);
905
        $image = Gtk2::Image->new_from_file ("icons/load.gif") if($status eq "run");
906
        $image = def_image("icons/button_ok.png") if($status eq "done");
907
        $image = def_image("icons/cancel.png") if($status eq "failed");
908
        #$image_file = "icons/load.gif" if($status eq "run");
909
 
910
        if (defined $image) {
911
                my $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
912
        my $frame = Gtk2::Frame->new;
913
                $frame->set_shadow_type ('in');
914
                # Animation
915
                $frame->add ($image);
916
                $align->add ($frame);
917
                $vbox->pack_start ($align, FALSE, FALSE, 0);
918
        }
919
        return $vbox;
920
 
921
}
922
 
923
 
924
############
925
#       run_emulator
926
###########
927
 
928
sub run_emulator {
929
        my ($emulate,$info)=@_;
930
        #return if(!check_samples($emulate,$info));
931
        $emulate->object_add_attribute('status',undef,'run');
932
        set_gui_status($emulate,"ref",1);
933
        show_info($info, "start emulation\n");
934
 
935
        #search for available usb blaster
936
        my $cmd = "jtagconfig";
937
        my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
938
        my @matches= ($stdout =~ /USB-Blaster.*/g);
939
        my $usb_blaster=$matches[0];
940
        if (!defined $usb_blaster){
941
                add_info($info, "jtagconfig could not find any USB blaster cable: $stdout \n");
942
                $emulate->object_add_attribute('status',undef,'programer_failed');
943
                set_gui_status($emulate,"ref",2);
944 28 alirezamon
                #/***/
945 25 alirezamon
                return;
946
        }else{
947
                add_info($info, "find $usb_blaster\n");
948
        }
949
        my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
950
        for (my $i=1; $i<=$sample_num; $i++){
951
                my $status=$emulate->object_get_attribute ("sample$i","status");
952
                next if($status ne "run");
953
                next if(!check_sample($emulate,$i,$info));
954
                my $r= $emulate->object_get_attribute("sample$i","ratios");
955
                my @ratios=@{check_inserted_ratios($r)};
956
                #$emulate->object_add_attribute ("sample$i","status","run");                    
957
                my $sof=$emulate->object_get_attribute ("sample$i","sof_file");
958
                add_info($info, "Programe FPGA device using $sof\n");
959
                my $Quartus_bin=  $ENV{QUARTUS_BIN};
960
 
961
 
962
                my $cmd = "$Quartus_bin/quartus_pgm -c \"$usb_blaster\" -m jtag -o \"p;$sof\"";
963 28 alirezamon
 
964 25 alirezamon
                #my $output = `$cmd 2>&1 1>/dev/null`;           # either with backticks
965 28 alirezamon
 
966
 
967
 
968
                #/***/
969 25 alirezamon
                my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
970
                if($exit){#programming FPGA board has failed
971
                        $emulate->object_add_attribute('status',undef,'programer_failed');
972
                        add_info($info, "$stdout\n");
973
                        $emulate->object_add_attribute ("sample$i","status","failed");
974
                        set_gui_status($emulate,"ref",2);
975
                        next;
976 28 alirezamon
                }
977
                #print "$stdout\n";
978
 
979 25 alirezamon
                # read noc configuration 
980
 
981
 
982 28 alirezamon
 
983
 
984 25 alirezamon
 
985 28 alirezamon
                foreach  my $ratio_in (@ratios){
986 25 alirezamon
 
987 28 alirezamon
                        add_info($info, "Configure packet generators for  injection ratio of $ratio_in \% \n");
988
                        next if(!programe_pck_gens($emulate,$i,$ratio_in,$info));
989
 
990
                        my $avg=read_pack_gen($emulate,$i,$info);
991
                        next if (!defined $avg);
992
                        my $ref=$emulate->object_get_attribute ("sample$i","result");
993
                        my %results;
994
                        %results= %{$ref} if(defined $ref);
995
                        #push(@results,$avg);
996
                        $results{$ratio_in}=$avg;
997
                        $emulate->object_add_attribute ("sample$i","result",\%results);
998
                        set_gui_status($emulate,"ref",2);
999 25 alirezamon
 
1000
                }
1001
                $emulate->object_add_attribute ("sample$i","status","done");
1002
 
1003
        }
1004
 
1005
        add_info($info, "End emulation!\n");
1006
        $emulate->object_add_attribute('status',undef,'ideal');
1007
        set_gui_status($emulate,"ref",1);
1008
}
1009
 
1010
 
1011
 
1012
 
1013
 
1014
 
1015
 
1016
 
1017
 
1018
 
1019
sub process_notebook_gen{
1020
                my ($emulate,$info)=@_;
1021
                my $notebook = Gtk2::Notebook->new;
1022
                $notebook->set_tab_pos ('left');
1023
                $notebook->set_scrollable(TRUE);
1024
                $notebook->can_focus(FALSE);
1025
                my $page1=gen_emulation_column($emulate,"NoC Configuration",10,$info);
1026
                $notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic ("  _Run emulator  "));
1027
 
1028
 
1029
                my $page2=get_noc_setting_gui ($emulate,$info);
1030
                my $pp=$notebook->append_page ($page2,Gtk2::Label->new_with_mnemonic ("  _Generate sof   "));
1031
 
1032
 
1033
 
1034
 
1035
                my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1036
                $scrolled_win->set_policy( "automatic", "automatic" );
1037
                $scrolled_win->add_with_viewport($notebook);
1038
                $scrolled_win->show_all;
1039
                my $page_num=$emulate->object_get_attribute ("process_notebook","currentpage");
1040
                $notebook->set_current_page ($page_num) if(defined $page_num);
1041
                $notebook->signal_connect( 'switch-page'=> sub{
1042
                        $emulate->object_add_attribute ("process_notebook","currentpage",$_[2]);        #save the new pagenumber
1043
 
1044
                });
1045
 
1046
                return $scrolled_win;
1047
 
1048
}
1049
 
1050
 
1051
sub get_noc_setting_gui {
1052 28 alirezamon
        my ($emulate,$info_text)=@_;
1053
        my $table=def_table(20,10,FALSE);#      my ($row,$col,$homogeneous)=@_;
1054
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1055
        $scrolled_win->set_policy( "automatic", "automatic" );
1056
        $scrolled_win->add_with_viewport($table);
1057
        my $row=noc_config ($emulate,$table);
1058 25 alirezamon
 
1059 28 alirezamon
        my($label,$param,$default,$content,$type,$info);
1060
        my @dirs = grep {-d} glob("../src_emulate/fpga/*");
1061
        my $fpgas;
1062
        foreach my $dir (@dirs) {
1063
                my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
1064
                $default=$name;
1065
                $fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
1066
 
1067
        }
1068
 
1069 25 alirezamon
 
1070 28 alirezamon
 
1071 25 alirezamon
 
1072 28 alirezamon
 
1073
 
1074
        my @fpgainfo = (
1075
        { label=>'FPGA board', param_name=>'FPGA_BOARD', type=>'Combo-box', default_val=>undef, content=>$fpgas, info=>undef, param_parent=>'fpga_param', ref_delay=> undef},
1076
        { label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'emulate1', content=>undef, info=>undef, param_parent=>'fpga_param', ref_delay=>undef},
1077
        { label=>"Project directory", param_name=>"SOF_DIR", type=>"DIR_path", default_val=>"$ENV{'PRONOC_WORK'}/emulate", content=>undef, info=>"Define the working directory for generating .sof file", param_parent=>'fpga_param',ref_delay=>undef },
1078
 
1079
);
1080
        foreach my $d (@fpgainfo) {
1081
        $row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
1082
}
1083
 
1084
 
1085 25 alirezamon
 
1086
 
1087
 
1088
 
1089
                my $generate = def_image_button('icons/gen.png','Generate');
1090
 
1091
 
1092
                $table->attach ($generate, 0,3, $row, $row+1,'expand','shrink',2,2);
1093
 
1094
                $generate->signal_connect ('clicked'=> sub{
1095
                        generate_sof_file($emulate,$info_text);
1096
 
1097
                });
1098
 
1099
 
1100
            return $scrolled_win;
1101
 
1102
}
1103
 
1104
 
1105
 
1106
 
1107
 
1108
 
1109
 
1110
sub generate_sof_file {
1111
        my ($emulate,$info)=@_;
1112
                print "start compilation\n";
1113
                my $fpga_board=  $emulate->object_get_attribute ('fpga_param',"FPGA_BOARD");
1114
                #create work directory
1115
                my $dir_name=$emulate->object_get_attribute ('fpga_param',"SOF_DIR");
1116 28 alirezamon
                $dir_name="$dir_name/$fpga_board";
1117 25 alirezamon
                my $save_name=$emulate->object_get_attribute ('fpga_param',"SAVE_NAME");
1118
                $save_name=$fpga_board if (!defined $save_name);
1119
                $dir_name= "$dir_name/$save_name";
1120
 
1121
                show_info($info, "generate working directory: $dir_name\n");
1122
 
1123
 
1124
                #copy all noc source codes
1125 28 alirezamon
                my @files = split(/\s*,\s*/,EMULATION_RTLS);
1126 25 alirezamon
 
1127
                my $dir = Cwd::getcwd();
1128
                my $project_dir   = abs_path("$dir/../../");
1129
                my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $dir_name/src/" );
1130 28 alirezamon
                copy_file_and_folders(\@files,$project_dir,"$dir_name/src/");
1131
 
1132
                foreach my $f(@files){
1133
                        my $n="$project_dir/$f";
1134
                        if (!(-f "$n") && !(-f "$f" ) && !(-d "$n") && !(-d "$f" )     ){
1135
                                add_info ($info, " WARNING: file/folder  \"$f\" ($n)  dose not exists \n");
1136
 
1137
                         }
1138
 
1139
 
1140
                }
1141 25 alirezamon
 
1142
 
1143 28 alirezamon
 
1144 25 alirezamon
 
1145 28 alirezamon
 
1146 25 alirezamon
                #copy fpga board files
1147
 
1148
                ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("cp -Rf \"$project_dir/mpsoc/src_emulate/fpga/$fpga_board\"/*    \"$dir_name/\"");
1149
                if($exit != 0 ){         print "$stdout\n";      message_dialog($stdout); return;}
1150
 
1151 28 alirezamon
                #generate parameters for emulator_top.v file
1152
                my ($localparam, $pass_param)=gen_noc_param_v( $emulate);
1153
                open(FILE,  ">$dir_name/src/noc_parameters.v") || die "Can not open: $!";
1154
                print FILE $localparam;
1155 25 alirezamon
                close(FILE) || die "Error closing file: $!";
1156 28 alirezamon
                open(FILE,  ">$dir_name/src/pass_parameters.v") || die "Can not open: $!";
1157
                print FILE $pass_param;
1158
                close(FILE) || die "Error closing file: $!";
1159 25 alirezamon
 
1160
 
1161
                #compile the code  
1162
                my $Quartus_bin=  $ENV{QUARTUS_BIN};
1163
                add_info($info, "Start Quartus compilation\n $stdout\n");
1164 28 alirezamon
                my @compilation_command =("cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_map --64bit $fpga_board --read_settings_files=on ",
1165
                                          "cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_fit --64bit $fpga_board --read_settings_files=on ",
1166
                                          "cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_asm --64bit $fpga_board --read_settings_files=on ",
1167
                                          "cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_sta --64bit $fpga_board ");
1168
 
1169
 
1170
 
1171
 
1172
 
1173
                foreach my $cmd (@compilation_command){
1174
                        ($stdout,$exit)=run_cmd_in_back_ground_get_stdout( $cmd);
1175
                        if($exit != 0){
1176
                                print "Quartus compilation failed !\n";
1177
                                add_info($info, "Quartus compilation failed !\n$cmd\n $stdout\n");
1178
                                return;
1179
                        }
1180 25 alirezamon
 
1181 28 alirezamon
                }
1182
 
1183
 
1184
 
1185 25 alirezamon
                        #save sof file
1186
                        my $sofdir="$ENV{PRONOC_WORK}/emulate/sof";
1187 28 alirezamon
                        mkpath("$sofdir/$fpga_board/",1,01777);
1188
                        open(FILE,  ">$sofdir/$fpga_board/$save_name.inf") || die "Can not open: $!";
1189 25 alirezamon
                        print FILE perl_file_header("$save_name.inf");
1190 28 alirezamon
                        my %pp;
1191
                        $pp{'noc_param'}= $emulate->{'noc_param'};
1192
                        $pp{'fpga_param'}= $emulate->{'fpga_param'};
1193
                        print FILE Data::Dumper->Dump([\%pp],["emulate_info"]);
1194 25 alirezamon
                        close(FILE) || die "Error closing file: $!";
1195 28 alirezamon
 
1196
 
1197
                        #find  $dir_name -name \*.sof -exec cp '{}' $sofdir/$fpga_board/$save_name.sof" 
1198
                        @files = File::Find::Rule->file()
1199
                            ->name( '*.sof' )
1200
                            ->in( "$dir_name" );
1201
                        copy($files[0],"$sofdir/$fpga_board/$save_name.sof") or do {
1202
                                my $err= "Error copy($files[0] , $sofdir/$fpga_board/$save_name.sof";
1203
                                print "$err\n";
1204
                                message_dialog($err);
1205
                                return;
1206
                        };
1207
                        message_dialog("sof file has been generated successfully");
1208 25 alirezamon
 
1209
 
1210
 
1211
}
1212
 
1213
##########
1214
#       save_emulation
1215
##########
1216
sub save_emulation {
1217
        my ($emulate)=@_;
1218
        # read emulation name
1219
        my $name=$emulate->object_get_attribute ("emulate_name",undef);
1220
        my $s= (!defined $name)? 0 : (length($name)==0)? 0 :1;
1221
        if ($s == 0){
1222
                message_dialog("Please set emulation name!");
1223
                return 0;
1224
        }
1225
        # Write object file
1226
        open(FILE,  ">lib/emulate/$name.EML") || die "Can not open: $!";
1227
        print FILE perl_file_header("$name.EML");
1228
        print FILE Data::Dumper->Dump([\%$emulate],[$name]);
1229
        close(FILE) || die "Error closing file: $!";
1230
        message_dialog("Emulation saved as lib/emulate/$name.EML!");
1231
        return 1;
1232
}
1233
 
1234
#############
1235
#       load_emulation
1236
############
1237
 
1238
sub load_emulation {
1239
        my ($emulate,$info)=@_;
1240
        my $file;
1241
        my $dialog = Gtk2::FileChooserDialog->new(
1242
                'Select a File', undef,
1243
                'open',
1244
                'gtk-cancel' => 'cancel',
1245
                'gtk-ok'     => 'ok',
1246
                );
1247
 
1248
        my $filter = Gtk2::FileFilter->new();
1249
        $filter->set_name("EML");
1250
        $filter->add_pattern("*.EML");
1251
        $dialog->add_filter ($filter);
1252
        my $dir = Cwd::getcwd();
1253
        $dialog->set_current_folder ("$dir/lib/emulate");
1254
 
1255
 
1256
        if ( "ok" eq $dialog->run ) {
1257
                $file = $dialog->get_filename;
1258
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1259
                if($suffix eq '.EML'){
1260
                        my $pp= eval { do $file };
1261
                        if ($@ || !defined $pp){
1262
                                add_info($info,"**Error reading  $file file: $@\n");
1263
                                 $dialog->destroy;
1264
                                return;
1265
                        }
1266
 
1267
                        clone_obj($emulate,$pp);
1268
                        #message_dialog("done!");                               
1269
                }
1270
     }
1271
     $dialog->destroy;
1272
}
1273
 
1274
############
1275
#    main
1276
############
1277
sub emulator_main{
1278
 
1279
        add_color_to_gd();
1280
        my $emulate= emulator->emulator_new();
1281
        set_gui_status($emulate,"ideal",0);
1282
        my $left_table = Gtk2::Table->new (25, 6, FALSE);
1283
        my $right_table = Gtk2::Table->new (25, 6, FALSE);
1284
 
1285
        my $main_table = Gtk2::Table->new (25, 12, FALSE);
1286
        my ($infobox,$info)= create_text();
1287
        my $refresh = Gtk2::Button->new_from_stock('ref');
1288
 
1289
 
1290
 
1291
 
1292
 
1293
        my $conf_box=process_notebook_gen($emulate,\$info);
1294
        my $chart   =gen_chart  ($emulate);
1295
 
1296
 
1297
 
1298
        $main_table->set_row_spacings (4);
1299
        $main_table->set_col_spacings (1);
1300
 
1301
        #my  $device_win=show_active_dev($soc,$soc,$infc,$soc_state,\$refresh,$info);
1302
 
1303
 
1304
        my $generate = def_image_button('icons/forward.png','Run all');
1305
        my $open = def_image_button('icons/browse.png','Load');
1306
 
1307
 
1308
 
1309
 
1310
        my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
1311
        $entry->signal_connect( 'changed'=> sub{
1312
                my $name=$entry->get_text();
1313
                $emulate->object_add_attribute ("emulate_name",undef,$name);
1314
        });
1315
        my $save = def_image_button('icons/save.png','Save');
1316
        $entrybox->pack_end($save,   FALSE, FALSE,0);
1317
 
1318
 
1319
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
1320
        my $image = get_status_gif($emulate);
1321
 
1322
 
1323
 
1324
 
1325
 
1326
        $left_table->attach_defaults ($conf_box , 0, 6, 0, 20);
1327
        $left_table->attach_defaults ($image , 0, 6, 20, 24);
1328
        $left_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
1329
        $left_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
1330
        $right_table->attach_defaults ($infobox  , 0, 6, 0,12);
1331
        $right_table->attach_defaults ($chart , 0, 6, 12, 24);
1332
        $right_table->attach ($generate, 4, 6, 24,25,'expand','shrink',2,2);
1333
        $main_table->attach_defaults ($left_table , 0, 6, 0, 25);
1334
        $main_table->attach_defaults ($right_table , 6, 12, 0, 25);
1335
 
1336
 
1337
 
1338
        #referesh the mpsoc generator 
1339
        $refresh-> signal_connect("clicked" => sub{
1340
                my $name=$emulate->object_get_attribute ("emulate_name",undef);
1341
                $entry->set_text($name) if(defined $name);
1342
 
1343
 
1344
                $conf_box->destroy();
1345
                $chart->destroy();
1346
                $image->destroy();
1347
                $image = get_status_gif($emulate);
1348
                $conf_box=process_notebook_gen($emulate,\$info);
1349
                $chart   =gen_chart  ($emulate);
1350
                $left_table->attach_defaults ($image , 0, 6, 20, 24);
1351
                $left_table->attach_defaults ($conf_box , 0, 6, 0, 12);
1352
                $right_table->attach_defaults ($chart , 0, 6, 12, 24);
1353
 
1354
                $conf_box->show_all();
1355
                $main_table->show_all();
1356
 
1357
 
1358
        });
1359
 
1360
 
1361
 
1362
        #check soc status every 0.5 second. referesh device table if there is any changes 
1363
        Glib::Timeout->add (100, sub{
1364
 
1365
                my ($state,$timeout)= get_gui_status($emulate);
1366
 
1367
                if ($timeout>0){
1368
                        $timeout--;
1369
                        set_gui_status($emulate,$state,$timeout);
1370
 
1371
                }
1372
                elsif( $state ne "ideal" ){
1373
                        $refresh->clicked;
1374
                        #my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
1375
                        #if(defined $saved_name) {$entry->set_text($saved_name);}
1376
                        set_gui_status($emulate,"ideal",0);
1377
 
1378
                }
1379
                return TRUE;
1380
 
1381
        } );
1382
 
1383
 
1384
        $generate-> signal_connect("clicked" => sub{
1385
                my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
1386
                for (my $i=1; $i<=$sample_num; $i++){
1387
                        $emulate->object_add_attribute ("sample$i","status","run");
1388
                }
1389
                run_emulator($emulate,\$info);
1390
                #set_gui_status($emulate,"ideal",2);
1391
 
1392
        });
1393
 
1394
#       $wb-> signal_connect("clicked" => sub{ 
1395
#               wb_address_setting($mpsoc);
1396
#       
1397
#       });
1398
 
1399
        $open-> signal_connect("clicked" => sub{
1400
 
1401
                load_emulation($emulate,\$info);
1402
                set_gui_status($emulate,"ref",5);
1403
 
1404
        });
1405
 
1406
        $save-> signal_connect("clicked" => sub{
1407
                save_emulation($emulate);
1408
                set_gui_status($emulate,"ref",5);
1409
 
1410
 
1411
        });
1412
 
1413
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
1414
                $sc_win->set_policy( "automatic", "automatic" );
1415
                $sc_win->add_with_viewport($main_table);
1416
 
1417
        return $sc_win;
1418
 
1419
 
1420
}
1421
 
1422
 
1423
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.