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 42

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 38 alirezamon
require "graph.pl";
25 25 alirezamon
 
26
use List::MoreUtils qw(uniq);
27
 
28
 
29 28 alirezamon
# hardware parameters taken from noc_emulator.v
30
use constant PCK_CNTw =>30;  # packet counter width in bits (results in maximum of 2^30 = 1  G packets)
31
use constant PCK_SIZw =>14;  # packet size width in bits (results in maximum packet size of 2^14 = 16 K flit)
32
use constant MAXXw    =>4;   # maximum nodes in x dimention is 2^MAXXw equal to 16 nodes in x dimention
33
use constant MAXYw    =>4;   # 16 nodes in y dimention : hence max emulator size is 16X16
34
use constant MAXCw    =>4;   # 16 message classes  
35
use constant RATIOw   =>7;   # log2(100)
36 38 alirezamon
use constant RAM_Aw   =>7;
37
use constant RAM_RESERVED_ADDR_NUM=>8;
38
use constant MAX_PATTERN => ((2**RAM_Aw)-(RAM_RESERVED_ADDR_NUM));
39
use constant RAM_SIZE => (2**RAM_Aw);
40 25 alirezamon
 
41 28 alirezamon
 
42
#use constant MAX_PCK_NUM => (2**PCK_CNTw)-1;
43
use constant MAX_PCK_NUM => (2**PCK_CNTw)-1;
44
use constant MAX_PCK_SIZ => (2**PCK_SIZw)-1;
45 38 alirezamon
use constant MAX_SIM_CLKs=> 1000000000; # simulation end at if clock counter reach this number 
46 25 alirezamon
 
47 38 alirezamon
 
48
use constant MAX_RATIO => 1000;# 0->0 1->0.1 ...  1000->100
49
use constant EMULATION_RTLS => "/mpsoc/src_emulate/rtl/ , /mpsoc/src_peripheral/jtag/jtag_wb/ , /mpsoc/src_peripheral/ram/ , /mpsoc/src_noc/ ,";
50
use constant EMULATION_TOP => "/mpsoc/src_emulate/emulator_top.v";
51 25 alirezamon
 
52 28 alirezamon
 
53
 
54 25 alirezamon
sub check_inserted_ratios {
55
                my $str=shift;
56
                my @ratios;
57
 
58
            my @chunks=split(',',$str);
59
            foreach my $p (@chunks){
60
                        if($p !~ /^[0-9.:,]+$/){ message_dialog ("$p has invalid character(S)" ); return undef; }
61
                        my @range=split(':',$p);
62
                        my $size= scalar @range;
63
                        if($size==1){ # its a number
64
                                if ( $range[0] <= 0 || $range[0] >100  ) { message_dialog ("$range[0] is out of boundery (1:100)" ); return undef; }
65
                                push(@ratios,$range[0]);
66
                        }elsif($size ==3){# its a range
67
                                my($min,$max,$step)=@range;
68
                                if ( $min <= 0 || $min >100  ) { message_dialog ("$min in  $p is out of boundery (1:100)" ); return undef; }
69
                                if ( $max <= 0 || $max >100  ) { message_dialog ("$max in  $p is out of boundery (1:100)" ); return undef; }
70
                                for (my $i=$min; $i<=$max; $i=$i+$step){
71
                                                push(@ratios,$i);
72
                                }
73
 
74
                        }else{
75
                                 message_dialog ("$p has invalid format. The correct format for range is \$min:\$max:\$step" );
76
 
77 38 alirezamon
                        }
78 25 alirezamon
 
79
                }#foreach
80
                my @r=uniq(sort {$a<=>$b} @ratios);
81
                return \@r;
82
 
83
}
84
 
85
 
86
sub get_injection_ratios{
87
                my ($emulate,$atrebute1,$atrebute2)=@_;
88
                my $box = Gtk2::HBox->new( FALSE, 0 );
89
                my $init=$emulate->object_get_attribute($atrebute1,$atrebute2);
90
                my $entry=gen_entry($init);
91
                my $button=def_image_button("icons/right.png",'Check');
92
                $button->signal_connect("clicked" => sub {
93
                        my $text= $entry->get_text();
94
                        my $r=check_inserted_ratios($text);
95
                        if(defined      $r){
96
                                my $all=  join (',',@$r);
97
                                message_dialog ("$all" );
98
                        }
99
 
100
 
101
                });
102
                $entry->signal_connect ("changed" => sub {
103
                        my $text= $entry->get_text();
104
                        $emulate->object_add_attribute($atrebute1,$atrebute2,$text);
105
 
106
                });
107
                $box->pack_start( $entry, 1,1, 0);
108
                $box->pack_start( $button, 0, 1, 3);
109
                return  $box;
110
}
111
 
112
 
113
 
114
sub get_noc_configuration{
115 38 alirezamon
        my ($emulate,$mode,$sample,$set_win) =@_;
116
        if($mode eq "simulate") {get_simulator_noc_configuration(@_); return;}
117
        get_emulator_noc_configuration(@_);
118
}
119
 
120
sub get_sof_file_full_addr{
121
        my ($emulate,$sample)=@_;
122
        my $open_in     = $emulate->object_get_attribute($sample,"sof_path");
123
        my $board       = $emulate->object_get_attribute($sample,"FPGA_board");
124
        my $file        = $emulate->object_get_attribute($sample,"sof_file");
125
        return undef if(!defined ${open_in} || !defined ${board} || !defined $file );
126
        my $sof = "${open_in}/${board}/$file";
127
        #print "\n$sof\n";
128
        return $sof;
129
}
130
 
131
 
132
sub get_emulator_noc_configuration{
133
        my ($emulate,$mode,$sample,$set_win) =@_;
134 28 alirezamon
        my $table=def_table(10,2,FALSE);
135
        my $row=0;
136 25 alirezamon
 
137 32 alirezamon
        my $traffics="tornado,transposed 1,transposed 2,bit reverse,bit complement,random"; #TODO hot spot for emulator
138 38 alirezamon
 
139
        #search path    
140 32 alirezamon
        my $dir = Cwd::getcwd();
141 38 alirezamon
        my $open_in       = abs_path("$ENV{PRONOC_WORK}/emulate/sof");
142
        attach_widget_to_table ($table,$row,gen_label_in_left("Search Path:"),gen_button_message ("Select the the Path where the verilator simulation files are located. Different NoC verilated models can be generated using Generate NoC configuration tab.","icons/help.png"),
143
        get_dir_in_object ($emulate,$sample,"sof_path",undef,'ref_set_win',1,$open_in)); $row++;
144
        $open_in        = $emulate->object_get_attribute($sample,"sof_path");
145
 
146
 
147
 
148
        #select the board
149
        my($label,$param,$default,$content,$type,$info);
150
        my @dirs = grep {-d} glob("$open_in/*");
151
        my $fpgas;
152
        foreach my $dir (@dirs) {
153
                my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
154
                $default=$name;
155
                $fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
156
        }
157
 
158
        attach_widget_to_table ($table,$row,gen_label_in_left("Select FPGA board:"),gen_button_message ("Select the FPGA board. You can add your own FPGA board by adding its configuration file to mpsoc/boards directory","icons/help.png"),
159
        gen_combobox_object ($emulate,$sample, "FPGA_board", $fpgas, undef,'ref_set_win',1)); $row++;
160
 
161
 
162
        #select the sram object file
163
        my $board       = $emulate->object_get_attribute($sample,"FPGA_board");
164
        my @files;
165
        @files = glob "${open_in}/${board}/*" if(defined $board);
166
        my $sof_files="";
167
        foreach my $file (@files){
168
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
169
                $sof_files="$sof_files,$name" if($suffix eq '.sof');
170
        }
171
        attach_widget_to_table ($table,$row,gen_label_in_left("Sram Object File:"),gen_button_message ("Select the verilator simulation file. Different NoC simulators can be generated using Generate NoC configuration tab.","icons/help.png"),
172
        gen_combobox_object ($emulate,$sample, "sof_file", $sof_files, undef,undef,undef)); $row++;
173 28 alirezamon
 
174 32 alirezamon
 
175 38 alirezamon
 
176
        #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,"sof_file",'sof',$open_in)); $row++;
177
 
178 25 alirezamon
 
179 32 alirezamon
   my @emulateinfo = (
180 38 alirezamon
        { label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>$sample, content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>$sample, ref_delay=> undef},
181 28 alirezamon
 
182 38 alirezamon
        { label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>$sample, ref_delay=>undef},
183 28 alirezamon
 
184 38 alirezamon
{ 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, ref_delay=>undef},
185 28 alirezamon
 
186 38 alirezamon
        { label=>"Packet number limit per node:", 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, ref_delay=>undef},
187 28 alirezamon
 
188 38 alirezamon
{ 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, ref_delay=>undef},
189 28 alirezamon
 
190
 
191 32 alirezamon
);
192 28 alirezamon
 
193
 
194
 
195 32 alirezamon
        my @siminfo = (
196 38 alirezamon
        { label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>$sample, content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>$sample, ref_delay=> undef, new_status=>undef},
197 28 alirezamon
 
198 38 alirezamon
        { label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>$sample, ref_delay=>1, new_status=>'ref_set_win'},
199 32 alirezamon
 
200 38 alirezamon
        { 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, ref_delay=>undef},
201 32 alirezamon
 
202 38 alirezamon
        { label=>"Total packet number limit:", param_name=>'PCK_NUM_LIMIT', type=>'Spin-button', default_val=>200000, content=>"2,".MAX_PCK_NUM.",1", info=>"Simulation will stop when total numbr of sent packets by all nodes reaches packet number limit  or total simulation clock reach its limit", param_parent=>$sample, ref_delay=>undef, new_status=>undef},
203 32 alirezamon
 
204 38 alirezamon
        { label=>"Simulator clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>100000, 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, ref_delay=>undef,  new_status=>undef},
205 32 alirezamon
        );
206
 
207 38 alirezamon
 
208
my $hot_num=$emulate->object_get_attribute($sample,"HOTSPOT_NUM");
209
$hot_num=1 if(!defined $hot_num);
210
my $max= ($hot_num>0)? 100/$hot_num: 20;
211
 
212 32 alirezamon
my @hotspot_info=(
213
        { label=>'Hot Spot num:', param_name=>'HOTSPOT_NUM', type=>'Spin-button', default_val=>1,
214
          content=>"1,5,1", info=>"Number of hot spot nodes in the network",
215 38 alirezamon
          param_parent=>$sample, ref_delay=> 1, new_status=>'ref_set_win'},
216 32 alirezamon
        { label=>'Hot Spot traffic percentage:', param_name=>'HOTSPOT_PERCENTAGE', type=>'Spin-button', default_val=>1,
217 38 alirezamon
          content=>"1, $max,1", info=>"If it is set as n then each node sends n % of its traffic to each hotspot node",
218
          param_parent=>$sample, ref_delay=> undef, new_status=>undef},
219
 
220
        { label=>'Hot Spot nodes send enable:', param_name=>'HOTSPOT_SEND', type=>'Combo-box', default_val=>1,
221
          content=>"0,1", info=>"If it is set as 0 then hot spot nodes only recieves packet from other nodes and do not send packets to others",
222
          param_parent=>$sample, ref_delay=> undef, new_status=>undef},
223
 
224 32 alirezamon
 
225
        );
226
 
227 38 alirezamon
 
228 32 alirezamon
        my @info= ($mode eq "simulate")? @siminfo : @emulateinfo;
229
 
230
 
231
        foreach my $d ( @info) {
232
        $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}, $d->{new_status});
233
        }
234 38 alirezamon
        my $traffic=$emulate->object_get_attribute($sample,"traffic");
235 32 alirezamon
 
236
        if ($traffic eq 'hot spot'){
237
                foreach my $d ( @hotspot_info) {
238
                        $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}, $d->{new_status});
239
                }
240 38 alirezamon
                my $num=$emulate->object_get_attribute($sample,"HOTSPOT_NUM");
241 32 alirezamon
                for (my $i=0;$i<$num;$i++){
242
                        my $m=$i+1;
243
                        $row=noc_param_widget ($emulate, "Hotspot $m tile num:", "HOTSPOT_CORE_$m", 0, 'Spin-button', "0,256,1",
244 38 alirezamon
                         "Defne the tile number which is  hotspt. All other nodes will send [Hot Spot traffic percentage] of their traffic to this node ", $table,$row,1,$sample );
245
 
246 32 alirezamon
                }
247
 
248
        }
249 38 alirezamon
        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.
250
As an example defining 2,3,4:10:2 will result in (2,3,4,6,8,10) injection ratios." ;
251
        my $u=get_injection_ratios ($emulate,$sample,"ratios");
252 25 alirezamon
 
253 38 alirezamon
        attach_widget_to_table ($table,$row,gen_label_in_left("Injection ratios:"),gen_button_message ($l,"icons/help.png") , $u); $row++;
254 28 alirezamon
 
255
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
256
        $scrolled_win->set_policy( "automatic", "automatic" );
257
        $scrolled_win->add_with_viewport($table);
258 25 alirezamon
 
259
        my $ok = def_image_button('icons/select.png','OK');
260 28 alirezamon
        my $mtable = def_table(10, 1, TRUE);
261
 
262
        $mtable->attach_defaults($scrolled_win,0,1,0,9);
263
        $mtable-> attach ($ok , 0, 1,  9, 10,'expand','shrink',2,2);
264 25 alirezamon
 
265 32 alirezamon
        $set_win->add ($mtable);
266
        $set_win->show_all();
267 28 alirezamon
 
268 32 alirezamon
        $set_win ->signal_connect (destroy => sub{
269
 
270
                $emulate->object_add_attribute("active_setting",undef,undef);
271
        });
272 28 alirezamon
 
273 25 alirezamon
 
274
 
275
        $ok->signal_connect("clicked"=> sub{
276
                #check if sof file has been selected
277 38 alirezamon
                my $s=get_sof_file_full_addr($emulate,$sample);
278 25 alirezamon
                #check if injection ratios are valid
279 38 alirezamon
                my $r=$emulate->object_get_attribute($sample,"ratios");
280 25 alirezamon
                if(defined $s && defined $r) {
281 32 alirezamon
                                $set_win->destroy;
282
                                #$emulate->object_add_attribute("active_setting",undef,undef);
283 25 alirezamon
                                set_gui_status($emulate,"ref",1);
284
                } else {
285
 
286
                        if(!defined $s){
287 32 alirezamon
                                my $m=($mode eq 'simulate') ? "Please select NoC verilated file" : "Please select sof file!";
288
                                message_dialog($m);
289 25 alirezamon
                        } else {
290 32 alirezamon
                                 message_dialog("Please define valid injection ratio(s)!");
291 25 alirezamon
                        }
292
                }
293
        });
294 28 alirezamon
 
295 32 alirezamon
 
296 25 alirezamon
}
297
 
298
 
299
 
300
#####################
301
#               gen_widgets_column
302
###################      
303
 
304
sub gen_emulation_column {
305 38 alirezamon
        my ($emulate,$mode, $row_num,$info,@charts)=@_;
306 25 alirezamon
        my $table=def_table($row_num,10,FALSE);
307 38 alirezamon
 
308 34 alirezamon
        my $set_win=def_popwin_size(40,80,"NoC configuration setting",'percent');
309 38 alirezamon
        my $scrolled_win = gen_scr_win_with_adjst ($emulate,"emulation_column");
310 25 alirezamon
        $scrolled_win->add_with_viewport($table);
311
        my $row=0;
312 32 alirezamon
 
313 25 alirezamon
        #title  
314 32 alirezamon
        my $title_l =($mode eq "simulate" ) ? "NoC Simulator" : "NoC Emulator";
315
        my $title=gen_label_in_center($title_l);
316 38 alirezamon
        $table->attach ($title , 0, 10,  $row, $row+1,'expand','shrink',2,2); $row++;
317
        my $separator = Gtk2::HSeparator->new;
318
        $table->attach ($separator , 0, 10 , $row, $row+1,'fill','fill',2,2);    $row++;
319 25 alirezamon
 
320 32 alirezamon
 
321 38 alirezamon
        my @positions=(0,1,2,3,4,5,6);
322 25 alirezamon
        my $col=0;
323
 
324 38 alirezamon
        my @title=("Name", " Add/Remove "," Setting ", "Line\'s color", "Clear","Run");
325 25 alirezamon
        foreach my $t (@title){
326
 
327 38 alirezamon
                $table->attach (gen_label_in_center($title[$col]), $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
328 25 alirezamon
        }
329
 
330
        my $traffics="Random,Transposed 1,Transposed 2,Tornado";
331
 
332
        $col=0;
333
        $row++;
334
        @positions=(0,1,2,3,4,5,6,7);
335 38 alirezamon
 
336 25 alirezamon
 
337 38 alirezamon
        #my $i=0;
338 32 alirezamon
        my $active=$emulate->object_get_attribute("active_setting",undef);
339 38 alirezamon
        my @samples;
340
        @samples =$emulate->object_get_attribute_order("samples");
341
 
342
        foreach my $ss (@samples){
343
 
344 25 alirezamon
                $col=0;
345 38 alirezamon
                my $sample=$ss;
346
                #my $sample="sample$i";
347
                #my $n=$i;
348
 
349 25 alirezamon
                my $name=$emulate->object_get_attribute($sample,"line_name");
350
                my $l;
351 38 alirezamon
                my $s=($mode eq "simulate" ) ? 1 : get_sof_file_full_addr($emulate,$sample);
352 32 alirezamon
                #check if injection ratios are valid
353 38 alirezamon
                my $r=$emulate->object_get_attribute($sample,"ratios");
354
                if(defined $s  && defined $name){
355
                         $l=gen_label_in_center($name);
356 25 alirezamon
                } else {
357 32 alirezamon
                        $l=gen_label_in_left("Define NoC configuration");
358 25 alirezamon
                        $l->set_markup("<span  foreground= 'red' ><b>Define NoC configuration</b></span>");
359
                }
360 32 alirezamon
                #my $box=def_pack_hbox(FALSE,0,(gen_label_in_left("$i- "),$l,$set));
361 38 alirezamon
                $table->attach ($l, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
362 32 alirezamon
 
363 38 alirezamon
                #remove 
364
                my $remove=def_image_button("icons/cancel.png");
365
                $table->attach ($remove, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
366
                $remove->signal_connect("clicked"=> sub{
367
                        $emulate->object_delete_attribute_order("samples",$sample);
368
                        set_gui_status($emulate,"ref",2);
369
                });
370
 
371
                #setting
372
                my $set=def_image_button("icons/setting.png");
373
                $table->attach ($set, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
374
 
375 32 alirezamon
 
376
                if(defined $active){#The setting windows ask for refershing so open it again
377 38 alirezamon
                        get_noc_configuration($emulate,$mode,$sample,$set_win) if       ($active eq $sample);
378 32 alirezamon
                }
379
 
380
 
381
 
382 25 alirezamon
                $set->signal_connect("clicked"=> sub{
383 38 alirezamon
                        $emulate->object_add_attribute("active_setting",undef,$sample);
384
                        get_noc_configuration($emulate,$mode,$sample,$set_win);
385 25 alirezamon
                });
386
 
387
 
388
 
389
                my $color_num=$emulate->object_get_attribute($sample,"color");
390
                if(!defined $color_num){
391 38 alirezamon
                        $color_num = (scalar @samples) +1;
392 25 alirezamon
                        $emulate->object_add_attribute($sample,"color",$color_num);
393
                }
394
                my $color=def_colored_button("    ",$color_num);
395
                $table->attach ($color, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
396
 
397
 
398
 
399
                $color->signal_connect("clicked"=> sub{
400
                        get_color_window($emulate,$sample,"color");
401
                });
402
 
403
                #clear line
404
                my $clear = def_image_button('icons/clear.png');
405
                $clear->signal_connect("clicked"=> sub{
406 38 alirezamon
                        foreach my $chart (@charts){
407
                                $emulate->object_add_attribute ($sample,"$chart->{result_name}",undef);
408
 
409
                                #print "\$emulate->object_add_attribute ($sample,$chart->{result_name}_result,undef);";
410
 
411
                        }
412 25 alirezamon
                        set_gui_status($emulate,"ref",2);
413
                });
414
                $table->attach ($clear, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
415
                #run/pause
416 38 alirezamon
                my $run = def_image_button('icons/run.png',undef);
417 25 alirezamon
                $table->attach ($run, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
418
                $run->signal_connect("clicked"=> sub{
419
                        $emulate->object_add_attribute ($sample,"status","run");
420
                        #start the emulator if it is not running        
421
                        my $status= $emulate->object_get_attribute('status',undef);
422
                        if($status ne 'run'){
423
 
424 32 alirezamon
                                run_emulator($emulate,$info) if($mode eq 'emulate');
425
                                run_simulator($emulate,$info) if($mode eq 'simulate');
426 25 alirezamon
                                set_gui_status($emulate,"ref",2);
427
                        }
428
 
429
                });
430
 
431 38 alirezamon
                my $image = gen_noc_status_image($emulate,$sample);
432 25 alirezamon
 
433 38 alirezamon
                $table->attach ($image, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);
434 25 alirezamon
 
435
 
436
                $row++;
437
 
438
        }
439 38 alirezamon
        # add new simulation
440
        my $add=def_image_button("icons/plus.png", );
441
        $table->attach ($add, $positions[1], $positions[2], $row, $row+1,'expand','shrink',2,2);
442 25 alirezamon
 
443 38 alirezamon
        $add->signal_connect("clicked"=> sub{
444
                my $n=$emulate->object_get_attribute("id",undef);
445
                $n=0 if (!defined $n);
446
                my $sample="sample$n";
447
                $n++;
448
                $emulate->object_add_attribute("id",undef,$n);
449
                $emulate->object_add_attribute("active_setting",undef,$sample);
450
                #get_noc_configuration($emulate,$mode,$sample,$set_win);
451
                $emulate->object_add_attribute_order("samples",$sample);
452
                set_gui_status($emulate,"ref",1);
453
 
454
        });
455
 
456
 
457 32 alirezamon
        return ($scrolled_win,$set_win);
458 25 alirezamon
}
459
 
460
 
461
 
462
##########
463 38 alirezamon
# check_sample
464 25 alirezamon
##########
465
 
466
sub check_sample{
467 38 alirezamon
        my ($emulate,$sample,$info)=@_;
468 25 alirezamon
        my $status=1;
469 38 alirezamon
        my $sof=get_sof_file_full_addr($emulate,$sample);
470 36 alirezamon
 
471
 
472
 
473 25 alirezamon
        # ckeck if sample have sof file
474
        if(!defined $sof){
475 38 alirezamon
                #add_info($info, "Error: SoF file has not set for $sample!\n");
476
                add_colored_info($info, "Error: SoF file has not set for $sample!\n",'red');
477
                $emulate->object_add_attribute ($sample,"status","failed");
478 25 alirezamon
                $status=0;
479
        } else {
480
                # ckeck if sof file has info file 
481
                my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
482 36 alirezamon
                my $sof_info= "$path$name.inf";
483 38 alirezamon
 
484
        #       print "\n $sof \t $sof_info\n";
485
 
486 25 alirezamon
                if(!(-f $sof_info)){
487 38 alirezamon
                        add_colored_info($info, "Error: 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",'red');
488
                        $emulate->object_add_attribute ($sample,"status","failed");
489 25 alirezamon
                        $status=0;
490
                }else { #add info
491 28 alirezamon
                        my $pp= do $sof_info ;
492
 
493
                        my $p=$pp->{'noc_param'};
494
 
495 25 alirezamon
                        $status=0 if $@;
496
                        message_dialog("Error reading: $@") if $@;
497
                        if ($status==1){
498 38 alirezamon
                                $emulate->object_add_attribute ($sample,"noc_info",$p) ;
499
 
500 25 alirezamon
 
501 38 alirezamon
                        }
502 25 alirezamon
                }
503
        }
504
 
505
        return $status;
506
}
507
 
508
 
509
 
510
##########
511
#  run external commands
512
##########
513
 
514
sub run_cmd_in_back_ground
515
{
516
  my $command = shift;
517 38 alirezamon
  #print "\t$command\n";
518 25 alirezamon
 
519
  ### Start running the Background Job:
520
    my $proc = Proc::Background->new($command);
521
    my $PID = $proc->pid;
522
    my $start_time = $proc->start_time;
523
    my $alive = $proc->alive;
524
 
525
  ### While $alive is NOT '0', then keep checking till it is...
526
  #  *When $alive is '0', it has finished executing.
527
  while($alive ne 0)
528
  {
529
    $alive = $proc->alive;
530
 
531
    # This while loop will cause Gtk2 to conti processing events, if
532
    # there are events pending... *which there are...
533
    while (Gtk2->events_pending) {
534
      Gtk2->main_iteration;
535
    }
536
    Gtk2::Gdk->flush;
537
 
538
    usleep(1000);
539
  }
540
 
541
  my $end_time = $proc->end_time;
542
 # print "*Command Completed at $end_time, with PID = $PID\n\n";
543
 
544
  # Since the while loop has exited, the BG job has finished running:
545
  # so close the pop-up window...
546
 # $popup_window->hide;
547
 
548
  # Get the RETCODE from the Background Job using the 'wait' method
549
  my $retcode = $proc->wait;
550
  $retcode /= 256;
551
 
552
  print "\t*RETCODE == $retcode\n\n";
553
  Gtk2::Gdk->flush;
554
  ### Check if the RETCODE returned with an Error:
555
  if ($retcode ne 0) {
556
    print "Error: The Background Job ($command) returned with an Error...!\n";
557
    return 1;
558
  } else {
559
    #print "Success: The Background Job Completed Successfully...!\n";
560
    return 0;
561
  }
562
 
563
}
564
 
565
 
566
 
567
 
568
sub run_cmd_in_back_ground_get_stdout
569
{
570
        my $cmd=shift;
571
        my $exit;
572
        my ($stdout, $stderr);
573
        capture { $exit=run_cmd_in_back_ground($cmd) } \$stdout, \$stderr;
574
        return ($stdout,$exit,$stderr);
575
 
576
}
577
 
578
 
579
#############
580
#  images
581
##########
582
sub get_status_gif{
583
                my $emulate=shift;
584
                my $status= $emulate->object_get_attribute('status',undef);
585
                if($status eq 'ideal'){
586
                        return show_gif ("icons/ProNoC.png");
587
                } elsif ($status eq 'run') {
588
                        my($width,$hight)=max_win_size();
589
                        my $image=($width>=1600)? "icons/hamster_l.gif":
590
                                  ($width>=1200)? "icons/hamster_m.gif": "icons/hamster_s.gif";
591
 
592
                        return show_gif ($image);
593
                } elsif ($status eq 'programer_failed') {
594
                        return show_gif ("icons/Error.png");
595
                }
596
 
597
}
598
 
599
 
600
 
601
 
602
sub gen_noc_status_image {
603 38 alirezamon
        my ($emulate,$sample)=@_;
604
        my   $status= $emulate->object_get_attribute ($sample,"status");
605 25 alirezamon
         $status='' if(!defined  $status);
606
        my $image;
607
        my $vbox = Gtk2::HBox->new (TRUE,1);
608
        $image = Gtk2::Image->new_from_file ("icons/load.gif") if($status eq "run");
609 34 alirezamon
        $image = def_icon("icons/button_ok.png") if($status eq "done");
610 38 alirezamon
        $image = def_icon("icons/warnning.png") if($status eq "failed");
611 25 alirezamon
        #$image_file = "icons/load.gif" if($status eq "run");
612
 
613
        if (defined $image) {
614
                my $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
615
        my $frame = Gtk2::Frame->new;
616
                $frame->set_shadow_type ('in');
617
                # Animation
618
                $frame->add ($image);
619
                $align->add ($frame);
620
                $vbox->pack_start ($align, FALSE, FALSE, 0);
621
        }
622
        return $vbox;
623
 
624
}
625
 
626
 
627
############
628
#       run_emulator
629
###########
630
 
631
sub run_emulator {
632
        my ($emulate,$info)=@_;
633 38 alirezamon
        #my $graph_name="latency_ratio";
634 25 alirezamon
        #return if(!check_samples($emulate,$info));
635
        $emulate->object_add_attribute('status',undef,'run');
636
        set_gui_status($emulate,"ref",1);
637 38 alirezamon
        show_colored_info($info, "start emulation\n",'blue');
638 25 alirezamon
 
639 38 alirezamon
#       #search for available usb blaster
640
#       my $cmd = "jtagconfig";
641
#       my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
642
#       my @matches= ($stdout =~ /USB-Blaster.*/g);
643
#       my $usb_blaster=$matches[0];
644
#       if (!defined $usb_blaster){
645
#               add_info($info, "jtagconfig could not find any USB blaster cable: $stdout \n");
646
#               $emulate->object_add_attribute('status',undef,'programer_failed');
647
#               set_gui_status($emulate,"ref",2);
648
#               #/***/
649
#               return; 
650
#       }else{
651
#               add_info($info, "find $usb_blaster\n");
652
#       }
653
        my @samples =$emulate->object_get_attribute_order("samples");
654
        foreach my $sample (@samples){
655
                my $status=$emulate->object_get_attribute ($sample,"status");
656 25 alirezamon
                next if($status ne "run");
657 38 alirezamon
                next if(!check_sample($emulate,$sample,$info));
658
                my $r= $emulate->object_get_attribute($sample,"ratios");
659 25 alirezamon
                my @ratios=@{check_inserted_ratios($r)};
660
                #$emulate->object_add_attribute ("sample$i","status","run");                    
661 38 alirezamon
                my $sof=get_sof_file_full_addr($emulate,$sample);
662
                add_info($info, "Programe FPGA device using $sof.sof\n");
663
                my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
664
                my $programer="$path/program_device.sh";
665
                my $jtag_intfc="$path/jtag_intfc.sh";
666
                if((-f $programer)==0){
667
                        add_colored_info ($info, " Error: file  \"$programer\"  dose not exist. \n",'red');
668
                        $emulate->object_add_attribute('status',undef,'programer_failed');
669
                        $emulate->object_add_attribute ($sample,"status","failed");
670
                        set_gui_status($emulate,"ref",2);
671
                        last;
672
                }
673
                if((-f $jtag_intfc)==0){
674
                        add_colored_info ($info, " Error: file  \"$jtag_intfc\"  dose not exist. \n",'red');
675
                        $emulate->object_add_attribute('status',undef,'programer_failed');
676
                        $emulate->object_add_attribute ($sample,"status","failed");
677
                        set_gui_status($emulate,"ref",2);
678
                        last;
679
                }
680
                my $cmd =  "sh $programer $sof.sof";
681 36 alirezamon
 
682 38 alirezamon
 
683
                #my $Quartus_bin=  $ENV{QUARTUS_BIN};
684 25 alirezamon
 
685
 
686 38 alirezamon
                #my $cmd = "$Quartus_bin/quartus_pgm -c \"$usb_blaster\" -m jtag -o \"p;$sof\"";
687 28 alirezamon
 
688 25 alirezamon
                #my $output = `$cmd 2>&1 1>/dev/null`;           # either with backticks
689 28 alirezamon
 
690
                #/***/
691 25 alirezamon
                my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
692
                if($exit){#programming FPGA board has failed
693
                        $emulate->object_add_attribute('status',undef,'programer_failed');
694 38 alirezamon
                        add_colored_info($info, "$stdout\n",'red');
695
                        $emulate->object_add_attribute ($sample,"status","failed");
696 25 alirezamon
                        set_gui_status($emulate,"ref",2);
697
                        next;
698 28 alirezamon
                }
699
                #print "$stdout\n";
700
 
701 38 alirezamon
                # load noc configuration 
702 28 alirezamon
                foreach  my $ratio_in (@ratios){
703 25 alirezamon
 
704 28 alirezamon
                        add_info($info, "Configure packet generators for  injection ratio of $ratio_in \% \n");
705 38 alirezamon
                        if(!programe_pck_gens($emulate,$sample,$ratio_in,$info,$jtag_intfc)){
706
                                add_colored_info($info, "Error in programe_pck_gens function\n",'red');
707
                                next;
708
                        }
709 28 alirezamon
 
710 38 alirezamon
 
711
                        my $r=read_pack_gen($emulate,$sample,$info,$jtag_intfc,$ratio_in);
712
                            next if (!defined $r);
713
 
714
 
715
 
716 28 alirezamon
                        set_gui_status($emulate,"ref",2);
717 25 alirezamon
 
718
                }
719 38 alirezamon
                $emulate->object_add_attribute ($sample,"status","done");
720 25 alirezamon
 
721
        }
722
 
723 38 alirezamon
        add_colored_info($info, "End emulation!\n",'blue');
724 25 alirezamon
        $emulate->object_add_attribute('status',undef,'ideal');
725
        set_gui_status($emulate,"ref",1);
726
}
727
 
728
 
729
 
730
 
731
 
732
 
733 38 alirezamon
##############
734
#        process_notebook_gen
735
##############
736 25 alirezamon
 
737
 
738
sub process_notebook_gen{
739 38 alirezamon
                my ($emulate,$info,$mode,@charts)=@_;
740 25 alirezamon
                my $notebook = Gtk2::Notebook->new;
741
                $notebook->set_tab_pos ('left');
742
                $notebook->set_scrollable(TRUE);
743
                $notebook->can_focus(FALSE);
744 32 alirezamon
 
745 25 alirezamon
 
746 38 alirezamon
                my ($page1,$set_win)=gen_emulation_column($emulate, $mode,10,$info,@charts);
747 32 alirezamon
                $notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic ("  _Run emulator  ")) if($mode eq "emulate");
748
                $notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic ("  _Run simulator ")) if($mode eq "simulate");
749 25 alirezamon
 
750
 
751 32 alirezamon
                my $page2=get_noc_setting_gui ($emulate,$info,$mode);
752 38 alirezamon
                my $tt=($mode eq "emulate")? "  _Generate NoC \nEmulation Model" : "  _Generate NoC \nSimulation Model" ;
753
                $notebook->append_page ($page2,Gtk2::Label->new_with_mnemonic ($tt));
754 25 alirezamon
 
755 38 alirezamon
                #if($mode eq "simulate"){
756
                        #my $page3=gen_custom_traffic ($emulate,$info,$mode);
757
                        #$notebook->append_page ($page3,Gtk2::Label->new_with_mnemonic ("_Generate Custom\n Traffic Pattern"));
758
                #}              
759 25 alirezamon
 
760
                my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
761
                $scrolled_win->set_policy( "automatic", "automatic" );
762
                $scrolled_win->add_with_viewport($notebook);
763
                $scrolled_win->show_all;
764
                my $page_num=$emulate->object_get_attribute ("process_notebook","currentpage");
765
                $notebook->set_current_page ($page_num) if(defined $page_num);
766
                $notebook->signal_connect( 'switch-page'=> sub{
767
                        $emulate->object_add_attribute ("process_notebook","currentpage",$_[2]);        #save the new pagenumber
768
 
769
                });
770
 
771 32 alirezamon
                return ($scrolled_win,$set_win);
772 25 alirezamon
 
773
}
774
 
775
 
776
sub get_noc_setting_gui {
777 32 alirezamon
        my ($emulate,$info_text,$mode)=@_;
778 28 alirezamon
        my $table=def_table(20,10,FALSE);#      my ($row,$col,$homogeneous)=@_;
779 38 alirezamon
 
780
        my $scrolled_win = gen_scr_win_with_adjst ($emulate,"noc_setting_gui");
781 28 alirezamon
        $scrolled_win->add_with_viewport($table);
782
        my $row=noc_config ($emulate,$table);
783 25 alirezamon
 
784 28 alirezamon
        my($label,$param,$default,$content,$type,$info);
785 38 alirezamon
        my @dirs = grep {-d} glob("../boards/*");
786 28 alirezamon
        my $fpgas;
787
        foreach my $dir (@dirs) {
788
                my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
789
                $default=$name;
790 38 alirezamon
                $fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
791 28 alirezamon
        }
792
 
793 38 alirezamon
        my @fpgainfo;
794
        if($mode eq "emulate"){
795
                @fpgainfo = (
796
                { label=>'Pck. injector FIFO Width:', param_name=>'TIMSTMP_FIFO_NUM', type=>'Spin-button', default_val=>16, content=>"2,128,2", info=>"Packet injectors' timestamp FIFO width. In case a packet cannot be injected according to the desired injection ratio, the current system time is saved in a FIFO and then at injection time it will be read and attached to the packet. The larger FIFO width results in more accurate latency calculation at the cost of higher area overhead." , param_parent=>'fpga_param', ref_delay=> undef},
797
                { label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'emulate1', content=>undef, info=>undef, param_parent=>'fpga_param', ref_delay=>undef},
798
                { 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 },
799
                );
800
 
801
        }
802
        else {
803
                @fpgainfo = (
804
                { label=>'Pck. injector FIFO Width:', param_name=>'TIMSTMP_FIFO_NUM', type=>'Spin-button', default_val=>16, content=>"2,128,2", info=>"Packet injectors' timestamp FIFO width. In case a packet cannot be injected according to the desired injection ratio, the current system time is saved in a FIFO and then at injection time it will be read and attached to the packet. The larger FIFO width results in more accurate latency calculation." , param_parent=>'fpga_param', ref_delay=> undef},
805
                { label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'simulate1', content=>undef, info=>undef, param_parent=>'sim_param', ref_delay=>undef},
806
                { label=>"Project directory", param_name=>"BIN_DIR", type=>"DIR_path", default_val=>"$ENV{'PRONOC_WORK'}/simulate", content=>undef, info=>"Define the working directory for generating simulation executable binarry file", param_parent=>'sim_param',ref_delay=>undef },
807
                );
808
        }
809 25 alirezamon
 
810 38 alirezamon
        foreach my $d (@fpgainfo) {
811
                $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});
812
        }
813
 
814
        my $generate = def_image_button('icons/gen.png','Generate');
815
        $table->attach ($generate, 0,3, $row, $row+1,'expand','shrink',2,2);
816
 
817
    $generate->signal_connect ('clicked'=> sub{
818
                generate_sof_file($emulate,$info_text) if($mode eq "emulate");
819
                generate_sim_bin_file($emulate,$info_text) if($mode eq "simulate");
820
        });
821
 
822
        return $scrolled_win;
823
}
824 28 alirezamon
 
825 38 alirezamon
##########
826
#       generate_sof_file
827
##########
828 32 alirezamon
 
829
 
830 38 alirezamon
sub generate_sof_file {
831
        my ($self,$info)=@_;
832 32 alirezamon
 
833 38 alirezamon
        my $name=$self->object_get_attribute ('fpga_param',"SAVE_NAME");
834
        my $target_dir  = "$ENV{'PRONOC_WORK'}/emulate/$name";
835
        my $top         = "$target_dir/src_verilog/${name}_top.v";
836 32 alirezamon
 
837 38 alirezamon
 
838
        if (!defined $name){
839
                message_dialog("Please define the Save as filed!");
840
                return;
841
        }
842 32 alirezamon
 
843 38 alirezamon
        #copy all noc source codes
844
        my @files = split(/\s*,\s*/,EMULATION_RTLS);
845
        my $dir = Cwd::getcwd();
846
        my $project_dir   = abs_path("$dir/../../");
847
        my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $target_dir/src_verilog" );
848
        copy_file_and_folders(\@files,$project_dir,"$target_dir/src_verilog/lib/");
849 32 alirezamon
 
850
 
851 38 alirezamon
        #generate parameters for emulator_top.v file
852
        my ($localparam, $pass_param)=gen_noc_param_v( $self);
853
        open(FILE,  ">$target_dir/src_verilog/noc_parameters.v") || die "Can not open: $!";
854
        print FILE $localparam;
855
        close(FILE) || die "Error closing file: $!";
856
        open(FILE,  ">$target_dir/src_verilog/pass_parameters.v") || die "Can not open: $!";
857
        print FILE $pass_param;
858
        my $fifow=$self->object_get_attribute('fpga_param','TIMSTMP_FIFO_NUM');
859
        print FILE ",.TIMSTMP_FIFO_NUM($fifow)\n";
860
        close(FILE) || die "Error closing file: $!";
861
        open(FILE,  ">$top") || die "Can not open: $!";
862
        print FILE create_emulate_top($self,$name,$top);
863
        close(FILE) || die "Error closing file: $!";
864
        select_compiler($self,$name,$top,$target_dir,\&save_the_sof_file);
865
 
866
return;
867 28 alirezamon
}
868
 
869 38 alirezamon
sub create_emulate_top{
870
        my ($self,$name,$top)=@_;
871
        my $top_v= get_license_header("$top");
872 32 alirezamon
 
873 38 alirezamon
$top_v  ="$top_v
874 32 alirezamon
 
875 38 alirezamon
`timescale       1ns/1ps
876 32 alirezamon
 
877 38 alirezamon
module ${name}_top(
878
        output done_led,
879
        output noc_reset_led,
880
        output jtag_reset_led,
881
        input  reset,
882
        input  clk
883
);
884 32 alirezamon
 
885 25 alirezamon
 
886 38 alirezamon
        localparam
887
                STATISTIC_VJTAG_INDEX=124,
888
                PATTERN_VJTAG_INDEX=125,
889
                COUNTER_VJTAG_INDEX=126,
890
                DONE_RESET_VJTAG_INDEX=127;
891
 
892 25 alirezamon
 
893 38 alirezamon
        //NoC parameters will be defined by user
894
        `define NOC_PARAM
895
        `include \"noc_parameters.v\"
896
 
897
        wire  reset_noc, reset_injector, reset_noc_sync, reset_injector_sync, done;
898
        wire jtag_reset_injector, jtag_reset_noc;
899
        wire start_o;
900
        wire done_time_limit;
901
 
902
        assign done_led = done | done_time_limit;
903
        assign noc_reset_led= reset_noc;
904
        assign jtag_reset_led   = reset_injector;
905 25 alirezamon
 
906 38 alirezamon
 
907 25 alirezamon
 
908 38 alirezamon
        //  two reset sources which can be controled using jtag. One for reseting NoC another packet injectors
909
        jtag_source_probe #(
910
                .VJTAG_INDEX(DONE_RESET_VJTAG_INDEX),
911
                .Dw(2)  //source/probe width in bits
912
        )the_reset(
913
                .probe({done_time_limit,done}),
914
                .source({jtag_reset_injector,jtag_reset_noc})
915
        );
916 25 alirezamon
 
917
 
918 38 alirezamon
        assign  reset_noc               =       (jtag_reset_noc | reset);
919
        assign  reset_injector          =       (jtag_reset_injector | reset);
920 25 alirezamon
 
921 38 alirezamon
        altera_reset_synchronizer noc_rst_sync
922
        (
923
                .reset_in(reset_noc),
924
                .clk(clk),
925
                .reset_out(reset_noc_sync)
926
        );
927 25 alirezamon
 
928
 
929 38 alirezamon
        altera_reset_synchronizer inject_rst_sync
930
        (
931
                .reset_in(reset_injector),
932
                .clk(clk),
933
                .reset_out(reset_injector_sync)
934
        );
935
 
936
        //noc emulator
937
 
938
        noc_emulator #(
939
        .STATISTIC_VJTAG_INDEX(STATISTIC_VJTAG_INDEX),
940
        .PATTERN_VJTAG_INDEX(PATTERN_VJTAG_INDEX),
941
        `include \"pass_parameters.v\"
942
 
943
        )
944
        noc_emulate_top
945
        (
946
                .reset(reset_noc_sync),
947
                .jtag_ctrl_reset(reset_injector_sync),
948
                .clk(clk),
949
                .start_o(start_o),
950
                .done(done)
951
        );
952
 
953
 
954
 
955
        //clock counter
956
 
957
        function integer log2;
958
      input integer number; begin
959
         log2=(number <=1) ? 1: 0;
960
         while(2**log2<number) begin
961
            log2=log2+1;
962
         end
963
      end
964
    endfunction // log2
965
 
966
        localparam   MAX_SIM_CLKs  = 1_000_000_000;
967
        localparam   CLK_CNTw = log2(MAX_SIM_CLKs+1);
968
 
969
        reg     [CLK_CNTw-1             :   0] clk_counter;
970
        wire    [CLK_CNTw-1             :   0] clk_limit;
971
        reg start;
972
        always @(posedge clk or posedge reset_injector_sync) begin
973
                if(reset_injector_sync)begin
974
                        clk_counter <= {CLK_CNTw{1'b0}};
975
                        start<=1'b0;
976
                end else begin
977
                        if(start_o) start<=1'b1;
978
                        if(done==1'b0 && start ) clk_counter<=clk_counter +1'b1;
979
                end
980
        end
981
 
982
        jtag_source_probe #(
983
                .VJTAG_INDEX(COUNTER_VJTAG_INDEX),
984
                .Dw(CLK_CNTw)   //source/probe width in bits
985
        )the_clk_counter(
986
                .probe(clk_counter),
987
                .source(clk_limit)
988
        );
989
 
990
        assign done_time_limit = (clk_counter >= clk_limit);
991
endmodule
992
";
993
        return $top_v;
994
}
995 25 alirezamon
 
996 38 alirezamon
sub save_the_sof_file{
997 28 alirezamon
 
998 38 alirezamon
        my $self=shift;
999
        my $name=$self->object_get_attribute ('fpga_param',"SAVE_NAME");
1000
        my $sofdir="$ENV{PRONOC_WORK}/emulate/sof";
1001
        my $fpga_board=$self->object_get_attribute('compile','board');
1002
        my $target_dir  = "$ENV{'PRONOC_WORK'}/emulate/$name";
1003 28 alirezamon
 
1004 38 alirezamon
        mkpath("$sofdir/$fpga_board/",1,01777);
1005
        open(FILE,  ">$sofdir/$fpga_board/$name.inf") || die "Can not open: $!";
1006
        print FILE perl_file_header("$name.inf");
1007
        my %pp;
1008
        $pp{'noc_param'}= $self->{'noc_param'};
1009
        $pp{'fpga_param'}= $self->{'fpga_param'};
1010
        print FILE Data::Dumper->Dump([\%pp],["emulate_info"]);
1011
        close(FILE) || die "Error closing file: $!";
1012 28 alirezamon
 
1013
 
1014 38 alirezamon
        #find  $dir_name -name \*.sof -exec cp '{}' $sofdir/$fpga_board/$save_name.sof" 
1015
        my @files = File::Find::Rule->file()
1016
                 ->name( '*.sof' )
1017
                 ->in( "$target_dir" );
1018
        copy($files[0],"$sofdir/$fpga_board/$name.sof") or do {
1019
                my $err= "Error copy($files[0] , $sofdir/$fpga_board/$name.sof";
1020
                print "$err\n";
1021
                message_dialog($err);
1022
                return;
1023
        };
1024
        #copy the board's programming and jtag interface files
1025
 
1026
        my $board_name=$self->object_get_attribute('compile','board');
1027
        #copy board jtag_intfc.sh file 
1028
        copy("../boards/$board_name/jtag_intfc.sh","$sofdir/$fpga_board/jtag_intfc.sh");
1029
        #print "../boards/$board_name/jtag_intfc.sh","$sofdir/$fpga_board/jtag_intfc.sh\n";
1030
        #add argument run to jtag_interface file 
1031
        my $runarg='
1032 28 alirezamon
 
1033 38 alirezamon
if [ $# -ne 0 ]
1034
  then
1035
    $JTAG_INTFC $1
1036
fi
1037
';
1038
        append_text_to_file ("$sofdir/$fpga_board/jtag_intfc.sh",$runarg );
1039
 
1040
 
1041
 
1042 28 alirezamon
 
1043 38 alirezamon
        #copy board program_device.sh file 
1044
        copy("../boards/$board_name/program_device.sh","$sofdir/$fpga_board/program_device.sh");
1045
 
1046
 
1047 28 alirezamon
 
1048 38 alirezamon
        message_dialog("sof file has been generated successfully");
1049
}
1050 28 alirezamon
 
1051
 
1052 25 alirezamon
 
1053
##########
1054
#       save_emulation
1055
##########
1056
sub save_emulation {
1057
        my ($emulate)=@_;
1058
        # read emulation name
1059
        my $name=$emulate->object_get_attribute ("emulate_name",undef);
1060
        my $s= (!defined $name)? 0 : (length($name)==0)? 0 :1;
1061
        if ($s == 0){
1062
                message_dialog("Please set emulation name!");
1063
                return 0;
1064
        }
1065
        # Write object file
1066
        open(FILE,  ">lib/emulate/$name.EML") || die "Can not open: $!";
1067
        print FILE perl_file_header("$name.EML");
1068 38 alirezamon
        print FILE Data::Dumper->Dump([\%$emulate],["emulate"]);
1069 25 alirezamon
        close(FILE) || die "Error closing file: $!";
1070
        message_dialog("Emulation saved as lib/emulate/$name.EML!");
1071
        return 1;
1072
}
1073
 
1074
#############
1075
#       load_emulation
1076
############
1077
 
1078
sub load_emulation {
1079
        my ($emulate,$info)=@_;
1080
        my $file;
1081
        my $dialog = Gtk2::FileChooserDialog->new(
1082
                'Select a File', undef,
1083
                'open',
1084
                'gtk-cancel' => 'cancel',
1085
                'gtk-ok'     => 'ok',
1086
                );
1087
 
1088
        my $filter = Gtk2::FileFilter->new();
1089
        $filter->set_name("EML");
1090
        $filter->add_pattern("*.EML");
1091
        $dialog->add_filter ($filter);
1092
        my $dir = Cwd::getcwd();
1093
        $dialog->set_current_folder ("$dir/lib/emulate");
1094
 
1095
 
1096
        if ( "ok" eq $dialog->run ) {
1097
                $file = $dialog->get_filename;
1098
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1099
                if($suffix eq '.EML'){
1100
                        my $pp= eval { do $file };
1101
                        if ($@ || !defined $pp){
1102 38 alirezamon
                                add_colored_info($info,"**Error reading  $file file: $@\n",'red');
1103 25 alirezamon
                                 $dialog->destroy;
1104
                                return;
1105
                        }
1106
 
1107
                        clone_obj($emulate,$pp);
1108
                        #message_dialog("done!");                               
1109
                }
1110
     }
1111
     $dialog->destroy;
1112
}
1113
 
1114 38 alirezamon
 
1115
 
1116
sub update_result {
1117
        my ($self,$sample,$name,$x,$y,$z)=@_;
1118
        my $ref=$self->object_get_attribute ($sample,$name);
1119
        my %results;
1120
        %results= %{$ref} if(defined $ref);
1121
        if(!defined $z) {$results{$x}=$y;}
1122
        else {$results{$x}{$y}=$z;}
1123
        $self->object_add_attribute ($sample,$name,\%results);
1124
}
1125
 
1126
 
1127
sub capture_cores_data {
1128
        my ($data,$text)=@_;
1129
        my %result;
1130
        my @q =split  (/Core/,$text);
1131
        my $i=0;
1132
        foreach my $p (@q){
1133
                if ($i!=0){
1134
                        my @d = split (/[^0-9. ]/,$p);
1135
                        my $n=  $d[0];
1136
                        my $val = capture_number_after("$data",$p);
1137
                        $result{remove_all_white_spaces($n)}=remove_all_white_spaces($val);
1138
                }
1139
                $i++;
1140
        }
1141
        return %result;
1142
}
1143
 
1144
 
1145
 
1146
 
1147
 
1148 25 alirezamon
############
1149
#    main
1150
############
1151
sub emulator_main{
1152 38 alirezamon
 
1153 25 alirezamon
        add_color_to_gd();
1154
        my $emulate= emulator->emulator_new();
1155
        set_gui_status($emulate,"ideal",0);
1156 38 alirezamon
        $emulate->object_add_attribute('compile','compilers',"QuartusII");
1157 25 alirezamon
        my $left_table = Gtk2::Table->new (25, 6, FALSE);
1158
        my $right_table = Gtk2::Table->new (25, 6, FALSE);
1159
        my $main_table = Gtk2::Table->new (25, 12, FALSE);
1160 38 alirezamon
        my ($infobox,$info)= create_text();
1161
        add_colors_to_textview($info);
1162
 
1163
        my @pages =(
1164
                {page_name=>" Avg. throughput/latency", page_num=>0},
1165
                {page_name=>" Injected Packet ", page_num=>1},
1166
                {page_name=>" Worst-Case Delay ",page_num=>2},
1167
                {page_name=>" Executaion Time ",page_num=>3},
1168
        );
1169 25 alirezamon
 
1170 38 alirezamon
        my @charts = (
1171 42 alirezamon
                { type=>"2D_line", page_num=>0, graph_name=> "Latency", result_name => "latency_result", X_Title=> 'Desired Avg. Injected Load Per Router (flits/clock (%))', Y_Title=>'Avg. Latency (clock)', Z_Title=>undef, Y_Max=>100},
1172 38 alirezamon
                { type=>"2D_line", page_num=>0, graph_name=> "Throughput", result_name => "throughput_result", X_Title=> 'Desired Avg. Injected Load Per Router (flits/clock (%))', Y_Title=>'Avg. Throughput (flits/clock (%))', Z_Title=>undef},
1173
                { type=>"3D_bar",  page_num=>1, graph_name=> "Received", result_name => "packet_rsvd_result", X_Title=>'Core ID' , Y_Title=>'Received Packets Per Router', Z_Title=>undef},
1174
                { type=>"3D_bar",  page_num=>1, graph_name=> "Sent", result_name => "packet_sent_result", X_Title=>'Core ID' , Y_Title=>'Sent Packets Per Router', Z_Title=>undef},
1175
                { type=>"3D_bar",  page_num=>2, graph_name=> "Received", result_name => "worst_delay_rsvd_result",X_Title=>'Core ID' , Y_Title=>'Worst-Case Delay (clk)', Z_Title=>undef},
1176
                { type=>"2D_line", page_num=>3, graph_name=> "-", result_name => "exe_time_result",X_Title=>'Desired Avg. Injected Load Per Router (flits/clock (%))' , Y_Title=>'Total Emulation Time (clk)', Z_Title=>undef},
1177
        );
1178
 
1179
        my ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate", @charts);
1180
        my $chart   =gen_multiple_charts ($emulate,\@pages,\@charts);
1181 25 alirezamon
 
1182
        $main_table->set_row_spacings (4);
1183
        $main_table->set_col_spacings (1);
1184 38 alirezamon
 
1185 25 alirezamon
        my $generate = def_image_button('icons/forward.png','Run all');
1186
        my $open = def_image_button('icons/browse.png','Load');
1187 38 alirezamon
 
1188
        my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
1189 25 alirezamon
 
1190
        $entry->signal_connect( 'changed'=> sub{
1191
                my $name=$entry->get_text();
1192
                $emulate->object_add_attribute ("emulate_name",undef,$name);
1193
        });
1194
        my $save = def_image_button('icons/save.png','Save');
1195
        $entrybox->pack_end($save,   FALSE, FALSE,0);
1196 38 alirezamon
 
1197
        my $image = get_status_gif($emulate);
1198
        my $v1=gen_vpaned($conf_box,.45,$image);
1199
        my $v2=gen_vpaned($infobox,.2,$chart);
1200
        my $h1=gen_hpaned($v1,.4,$v2);
1201 25 alirezamon
 
1202
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
1203 38 alirezamon
        $main_table->attach_defaults ($h1  , 0, 12, 0,24);
1204
        $main_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
1205
        $main_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
1206
        $main_table->attach ($generate, 6, 9, 24,25,'expand','shrink',2,2);
1207 32 alirezamon
 
1208 25 alirezamon
        #check soc status every 0.5 second. referesh device table if there is any changes 
1209 38 alirezamon
        Glib::Timeout->add (100, sub{
1210 25 alirezamon
                my ($state,$timeout)= get_gui_status($emulate);
1211
 
1212
                if ($timeout>0){
1213
                        $timeout--;
1214
                        set_gui_status($emulate,$state,$timeout);
1215 38 alirezamon
                        return TRUE;
1216 25 alirezamon
                }
1217 38 alirezamon
                if($state eq "ideal"){
1218
                        return TRUE;
1219
 
1220
                }
1221 32 alirezamon
                elsif($state eq 'ref_set_win'){
1222
                        my $s=$emulate->object_get_attribute("active_setting",undef);
1223
                        $set_win->destroy();
1224 38 alirezamon
                        $emulate->object_add_attribute("active_setting",undef,$s);
1225 32 alirezamon
                }
1226 38 alirezamon
 
1227
                #refresh GUI
1228
                my $name=$emulate->object_get_attribute ("emulate_name",undef);
1229
                $entry->set_text($name) if(defined $name);
1230
                $conf_box->destroy();
1231
                $set_win->destroy();
1232
                $chart->destroy();
1233
                $image->destroy();
1234
                $image = get_status_gif($emulate);
1235
                ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate", @charts);
1236
                $chart   =gen_multiple_charts  ($emulate,\@pages,\@charts);
1237
                $v1 -> pack1($conf_box, TRUE, TRUE);
1238
                $v1 -> pack2($image, TRUE, TRUE);
1239
                $v2 -> pack2($chart, TRUE, TRUE);
1240
                $conf_box->show_all();
1241
                $main_table->show_all();
1242
                set_gui_status($emulate,"ideal",0);
1243
 
1244 25 alirezamon
                return TRUE;
1245
 
1246
        } );
1247
 
1248
 
1249
        $generate-> signal_connect("clicked" => sub{
1250 38 alirezamon
                my @samples =$emulate->object_get_attribute_order("samples");
1251
                foreach my $sample (@samples){
1252
                        $emulate->object_add_attribute ($sample,"status","run");
1253 25 alirezamon
                }
1254
                run_emulator($emulate,\$info);
1255
        });
1256
 
1257
 
1258
        $open-> signal_connect("clicked" => sub{
1259
                load_emulation($emulate,\$info);
1260
                set_gui_status($emulate,"ref",5);
1261
        });
1262
 
1263
        $save-> signal_connect("clicked" => sub{
1264
                save_emulation($emulate);
1265
                set_gui_status($emulate,"ref",5);
1266
        });
1267
 
1268
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
1269 38 alirezamon
        $sc_win->set_policy( "automatic", "automatic" );
1270
        $sc_win->add_with_viewport($main_table);
1271 25 alirezamon
 
1272
        return $sc_win;
1273
}
1274
 
1275
 
1276
 

powered by: WebSVN 2.1.0

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