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 44

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

powered by: WebSVN 2.1.0

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