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 43

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 38 alirezamon
        my @positions=(0,1,2,3,4,5,6);
329 25 alirezamon
        my $col=0;
330
 
331 38 alirezamon
        my @title=("Name", " Add/Remove "," Setting ", "Line\'s color", "Clear","Run");
332 25 alirezamon
        foreach my $t (@title){
333
 
334 38 alirezamon
                $table->attach (gen_label_in_center($title[$col]), $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
335 25 alirezamon
        }
336
 
337
        my $traffics="Random,Transposed 1,Transposed 2,Tornado";
338
 
339
        $col=0;
340
        $row++;
341
        @positions=(0,1,2,3,4,5,6,7);
342 38 alirezamon
 
343 25 alirezamon
 
344 38 alirezamon
        #my $i=0;
345 32 alirezamon
        my $active=$emulate->object_get_attribute("active_setting",undef);
346 38 alirezamon
        my @samples;
347
        @samples =$emulate->object_get_attribute_order("samples");
348
 
349
        foreach my $ss (@samples){
350
 
351 25 alirezamon
                $col=0;
352 38 alirezamon
                my $sample=$ss;
353
                #my $sample="sample$i";
354
                #my $n=$i;
355
 
356 25 alirezamon
                my $name=$emulate->object_get_attribute($sample,"line_name");
357
                my $l;
358 38 alirezamon
                my $s=($mode eq "simulate" ) ? 1 : get_sof_file_full_addr($emulate,$sample);
359 32 alirezamon
                #check if injection ratios are valid
360 38 alirezamon
                my $r=$emulate->object_get_attribute($sample,"ratios");
361
                if(defined $s  && defined $name){
362
                         $l=gen_label_in_center($name);
363 43 alirezamon
                         $l=def_image_button('icons/diagram.png',$name);
364
                         $l-> signal_connect("clicked" => sub{
365
                                my $st = ($mode eq "simulate" )?  check_sim_sample($emulate,$sample,$info)   : check_sample($emulate,$sample,$info);
366
                                return if $st==0;
367
                                my ($topology, $T1, $T2, $T3, $V, $Fpay) = get_sample_emulation_param($emulate,$sample);
368
                                $emulate->object_add_attribute('noc_param','T1',$T1);
369
                                $emulate->object_add_attribute('noc_param','T2',$T2);
370
                                $emulate->object_add_attribute('noc_param','T3',$T3);
371
                                $emulate->object_add_attribute('noc_param','TOPOLOGY',$topology);
372
                        show_topology_diagram ($emulate);
373
                 });
374
 
375 25 alirezamon
                } else {
376 32 alirezamon
                        $l=gen_label_in_left("Define NoC configuration");
377 25 alirezamon
                        $l->set_markup("<span  foreground= 'red' ><b>Define NoC configuration</b></span>");
378
                }
379 32 alirezamon
                #my $box=def_pack_hbox(FALSE,0,(gen_label_in_left("$i- "),$l,$set));
380 38 alirezamon
                $table->attach ($l, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
381 32 alirezamon
 
382 38 alirezamon
                #remove 
383
                my $remove=def_image_button("icons/cancel.png");
384
                $table->attach ($remove, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
385
                $remove->signal_connect("clicked"=> sub{
386
                        $emulate->object_delete_attribute_order("samples",$sample);
387
                        set_gui_status($emulate,"ref",2);
388
                });
389
 
390
                #setting
391
                my $set=def_image_button("icons/setting.png");
392
                $table->attach ($set, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
393
 
394 32 alirezamon
 
395
                if(defined $active){#The setting windows ask for refershing so open it again
396 38 alirezamon
                        get_noc_configuration($emulate,$mode,$sample,$set_win) if       ($active eq $sample);
397 32 alirezamon
                }
398
 
399
 
400
 
401 25 alirezamon
                $set->signal_connect("clicked"=> sub{
402 38 alirezamon
                        $emulate->object_add_attribute("active_setting",undef,$sample);
403
                        get_noc_configuration($emulate,$mode,$sample,$set_win);
404 25 alirezamon
                });
405
 
406
 
407
 
408
                my $color_num=$emulate->object_get_attribute($sample,"color");
409
                if(!defined $color_num){
410 38 alirezamon
                        $color_num = (scalar @samples) +1;
411 25 alirezamon
                        $emulate->object_add_attribute($sample,"color",$color_num);
412
                }
413
                my $color=def_colored_button("    ",$color_num);
414
                $table->attach ($color, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
415
 
416
 
417
 
418
                $color->signal_connect("clicked"=> sub{
419
                        get_color_window($emulate,$sample,"color");
420
                });
421
 
422
                #clear line
423
                my $clear = def_image_button('icons/clear.png');
424
                $clear->signal_connect("clicked"=> sub{
425 38 alirezamon
                        foreach my $chart (@charts){
426
                                $emulate->object_add_attribute ($sample,"$chart->{result_name}",undef);
427
 
428
                                #print "\$emulate->object_add_attribute ($sample,$chart->{result_name}_result,undef);";
429
 
430
                        }
431 25 alirezamon
                        set_gui_status($emulate,"ref",2);
432
                });
433
                $table->attach ($clear, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
434
                #run/pause
435 38 alirezamon
                my $run = def_image_button('icons/run.png',undef);
436 25 alirezamon
                $table->attach ($run, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
437
                $run->signal_connect("clicked"=> sub{
438
                        $emulate->object_add_attribute ($sample,"status","run");
439
                        #start the emulator if it is not running        
440
                        my $status= $emulate->object_get_attribute('status',undef);
441
                        if($status ne 'run'){
442
 
443 32 alirezamon
                                run_emulator($emulate,$info) if($mode eq 'emulate');
444
                                run_simulator($emulate,$info) if($mode eq 'simulate');
445 25 alirezamon
                                set_gui_status($emulate,"ref",2);
446
                        }
447
 
448
                });
449
 
450 38 alirezamon
                my $image = gen_noc_status_image($emulate,$sample);
451 25 alirezamon
 
452 38 alirezamon
                $table->attach ($image, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);
453 25 alirezamon
 
454
 
455
                $row++;
456
 
457
        }
458 38 alirezamon
        # add new simulation
459
        my $add=def_image_button("icons/plus.png", );
460
        $table->attach ($add, $positions[1], $positions[2], $row, $row+1,'expand','shrink',2,2);
461 25 alirezamon
 
462 38 alirezamon
        $add->signal_connect("clicked"=> sub{
463
                my $n=$emulate->object_get_attribute("id",undef);
464
                $n=0 if (!defined $n);
465
                my $sample="sample$n";
466
                $n++;
467
                $emulate->object_add_attribute("id",undef,$n);
468
                $emulate->object_add_attribute("active_setting",undef,$sample);
469
                #get_noc_configuration($emulate,$mode,$sample,$set_win);
470
                $emulate->object_add_attribute_order("samples",$sample);
471
                set_gui_status($emulate,"ref",1);
472
 
473
        });
474
 
475
 
476 32 alirezamon
        return ($scrolled_win,$set_win);
477 25 alirezamon
}
478
 
479
 
480
 
481
##########
482 38 alirezamon
# check_sample
483 25 alirezamon
##########
484
 
485
sub check_sample{
486 38 alirezamon
        my ($emulate,$sample,$info)=@_;
487 25 alirezamon
        my $status=1;
488 38 alirezamon
        my $sof=get_sof_file_full_addr($emulate,$sample);
489 36 alirezamon
 
490
 
491
 
492 25 alirezamon
        # ckeck if sample have sof file
493
        if(!defined $sof){
494 38 alirezamon
                #add_info($info, "Error: SoF file has not set for $sample!\n");
495
                add_colored_info($info, "Error: SoF file has not set for $sample!\n",'red');
496
                $emulate->object_add_attribute ($sample,"status","failed");
497 25 alirezamon
                $status=0;
498
        } else {
499
                # ckeck if sof file has info file 
500
                my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
501 36 alirezamon
                my $sof_info= "$path$name.inf";
502 38 alirezamon
 
503
        #       print "\n $sof \t $sof_info\n";
504
 
505 25 alirezamon
                if(!(-f $sof_info)){
506 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');
507 38 alirezamon
                        $emulate->object_add_attribute ($sample,"status","failed");
508 25 alirezamon
                        $status=0;
509
                }else { #add info
510 28 alirezamon
                        my $pp= do $sof_info ;
511
 
512
                        my $p=$pp->{'noc_param'};
513
 
514 25 alirezamon
                        $status=0 if $@;
515
                        message_dialog("Error reading: $@") if $@;
516
                        if ($status==1){
517 38 alirezamon
                                $emulate->object_add_attribute ($sample,"noc_info",$p) ;
518
 
519 25 alirezamon
 
520 38 alirezamon
                        }
521 25 alirezamon
                }
522
        }
523
 
524
        return $status;
525
}
526
 
527
 
528
 
529
##########
530
#  run external commands
531
##########
532
 
533
sub run_cmd_in_back_ground
534
{
535
  my $command = shift;
536 38 alirezamon
  #print "\t$command\n";
537 25 alirezamon
 
538
  ### Start running the Background Job:
539
    my $proc = Proc::Background->new($command);
540
    my $PID = $proc->pid;
541
    my $start_time = $proc->start_time;
542
    my $alive = $proc->alive;
543
 
544
  ### While $alive is NOT '0', then keep checking till it is...
545
  #  *When $alive is '0', it has finished executing.
546
  while($alive ne 0)
547
  {
548
    $alive = $proc->alive;
549
 
550
    # This while loop will cause Gtk2 to conti processing events, if
551
    # there are events pending... *which there are...
552
    while (Gtk2->events_pending) {
553
      Gtk2->main_iteration;
554
    }
555
    Gtk2::Gdk->flush;
556
 
557
    usleep(1000);
558
  }
559
 
560
  my $end_time = $proc->end_time;
561
 # print "*Command Completed at $end_time, with PID = $PID\n\n";
562
 
563
  # Since the while loop has exited, the BG job has finished running:
564
  # so close the pop-up window...
565
 # $popup_window->hide;
566
 
567
  # Get the RETCODE from the Background Job using the 'wait' method
568
  my $retcode = $proc->wait;
569
  $retcode /= 256;
570
 
571
  print "\t*RETCODE == $retcode\n\n";
572
  Gtk2::Gdk->flush;
573
  ### Check if the RETCODE returned with an Error:
574
  if ($retcode ne 0) {
575
    print "Error: The Background Job ($command) returned with an Error...!\n";
576
    return 1;
577
  } else {
578
    #print "Success: The Background Job Completed Successfully...!\n";
579
    return 0;
580
  }
581
 
582
}
583
 
584
 
585
 
586
 
587
sub run_cmd_in_back_ground_get_stdout
588
{
589
        my $cmd=shift;
590
        my $exit;
591
        my ($stdout, $stderr);
592
        capture { $exit=run_cmd_in_back_ground($cmd) } \$stdout, \$stderr;
593
        return ($stdout,$exit,$stderr);
594
 
595
}
596
 
597
 
598
#############
599
#  images
600
##########
601
sub get_status_gif{
602
                my $emulate=shift;
603
                my $status= $emulate->object_get_attribute('status',undef);
604
                if($status eq 'ideal'){
605
                        return show_gif ("icons/ProNoC.png");
606
                } elsif ($status eq 'run') {
607
                        my($width,$hight)=max_win_size();
608
                        my $image=($width>=1600)? "icons/hamster_l.gif":
609
                                  ($width>=1200)? "icons/hamster_m.gif": "icons/hamster_s.gif";
610
 
611
                        return show_gif ($image);
612
                } elsif ($status eq 'programer_failed') {
613
                        return show_gif ("icons/Error.png");
614
                }
615
 
616
}
617
 
618
 
619
 
620
 
621
sub gen_noc_status_image {
622 38 alirezamon
        my ($emulate,$sample)=@_;
623
        my   $status= $emulate->object_get_attribute ($sample,"status");
624 25 alirezamon
         $status='' if(!defined  $status);
625
        my $image;
626
        my $vbox = Gtk2::HBox->new (TRUE,1);
627
        $image = Gtk2::Image->new_from_file ("icons/load.gif") if($status eq "run");
628 34 alirezamon
        $image = def_icon("icons/button_ok.png") if($status eq "done");
629 43 alirezamon
        $image = def_icon("icons/warning.png") if($status eq "failed");
630 25 alirezamon
        #$image_file = "icons/load.gif" if($status eq "run");
631
 
632
        if (defined $image) {
633
                my $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
634
        my $frame = Gtk2::Frame->new;
635
                $frame->set_shadow_type ('in');
636
                # Animation
637
                $frame->add ($image);
638
                $align->add ($frame);
639
                $vbox->pack_start ($align, FALSE, FALSE, 0);
640
        }
641
        return $vbox;
642
 
643
}
644
 
645
 
646
############
647
#       run_emulator
648
###########
649
 
650
sub run_emulator {
651
        my ($emulate,$info)=@_;
652 38 alirezamon
        #my $graph_name="latency_ratio";
653 25 alirezamon
        #return if(!check_samples($emulate,$info));
654
        $emulate->object_add_attribute('status',undef,'run');
655
        set_gui_status($emulate,"ref",1);
656 38 alirezamon
        show_colored_info($info, "start emulation\n",'blue');
657 25 alirezamon
 
658 38 alirezamon
#       #search for available usb blaster
659
#       my $cmd = "jtagconfig";
660
#       my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
661
#       my @matches= ($stdout =~ /USB-Blaster.*/g);
662
#       my $usb_blaster=$matches[0];
663
#       if (!defined $usb_blaster){
664
#               add_info($info, "jtagconfig could not find any USB blaster cable: $stdout \n");
665
#               $emulate->object_add_attribute('status',undef,'programer_failed');
666
#               set_gui_status($emulate,"ref",2);
667
#               #/***/
668
#               return; 
669
#       }else{
670
#               add_info($info, "find $usb_blaster\n");
671
#       }
672
        my @samples =$emulate->object_get_attribute_order("samples");
673
        foreach my $sample (@samples){
674
                my $status=$emulate->object_get_attribute ($sample,"status");
675 25 alirezamon
                next if($status ne "run");
676 38 alirezamon
                next if(!check_sample($emulate,$sample,$info));
677
                my $r= $emulate->object_get_attribute($sample,"ratios");
678 25 alirezamon
                my @ratios=@{check_inserted_ratios($r)};
679
                #$emulate->object_add_attribute ("sample$i","status","run");                    
680 38 alirezamon
                my $sof=get_sof_file_full_addr($emulate,$sample);
681
                add_info($info, "Programe FPGA device using $sof.sof\n");
682
                my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
683
                my $programer="$path/program_device.sh";
684
                my $jtag_intfc="$path/jtag_intfc.sh";
685
                if((-f $programer)==0){
686
                        add_colored_info ($info, " Error: file  \"$programer\"  dose not exist. \n",'red');
687
                        $emulate->object_add_attribute('status',undef,'programer_failed');
688
                        $emulate->object_add_attribute ($sample,"status","failed");
689
                        set_gui_status($emulate,"ref",2);
690
                        last;
691
                }
692
                if((-f $jtag_intfc)==0){
693
                        add_colored_info ($info, " Error: file  \"$jtag_intfc\"  dose not exist. \n",'red');
694
                        $emulate->object_add_attribute('status',undef,'programer_failed');
695
                        $emulate->object_add_attribute ($sample,"status","failed");
696
                        set_gui_status($emulate,"ref",2);
697
                        last;
698
                }
699
                my $cmd =  "sh $programer $sof.sof";
700 36 alirezamon
 
701 38 alirezamon
 
702
                #my $Quartus_bin=  $ENV{QUARTUS_BIN};
703 25 alirezamon
 
704
 
705 38 alirezamon
                #my $cmd = "$Quartus_bin/quartus_pgm -c \"$usb_blaster\" -m jtag -o \"p;$sof\"";
706 28 alirezamon
 
707 25 alirezamon
                #my $output = `$cmd 2>&1 1>/dev/null`;           # either with backticks
708 28 alirezamon
 
709
                #/***/
710 25 alirezamon
                my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
711
                if($exit){#programming FPGA board has failed
712
                        $emulate->object_add_attribute('status',undef,'programer_failed');
713 38 alirezamon
                        add_colored_info($info, "$stdout\n",'red');
714
                        $emulate->object_add_attribute ($sample,"status","failed");
715 25 alirezamon
                        set_gui_status($emulate,"ref",2);
716
                        next;
717 28 alirezamon
                }
718
                #print "$stdout\n";
719
 
720 38 alirezamon
                # load noc configuration 
721 28 alirezamon
                foreach  my $ratio_in (@ratios){
722 25 alirezamon
 
723 28 alirezamon
                        add_info($info, "Configure packet generators for  injection ratio of $ratio_in \% \n");
724 38 alirezamon
                        if(!programe_pck_gens($emulate,$sample,$ratio_in,$info,$jtag_intfc)){
725
                                add_colored_info($info, "Error in programe_pck_gens function\n",'red');
726
                                next;
727
                        }
728 28 alirezamon
 
729 38 alirezamon
 
730
                        my $r=read_pack_gen($emulate,$sample,$info,$jtag_intfc,$ratio_in);
731
                            next if (!defined $r);
732
 
733
 
734
 
735 28 alirezamon
                        set_gui_status($emulate,"ref",2);
736 25 alirezamon
 
737
                }
738 38 alirezamon
                $emulate->object_add_attribute ($sample,"status","done");
739 25 alirezamon
 
740
        }
741
 
742 38 alirezamon
        add_colored_info($info, "End emulation!\n",'blue');
743 25 alirezamon
        $emulate->object_add_attribute('status',undef,'ideal');
744
        set_gui_status($emulate,"ref",1);
745
}
746
 
747
 
748
 
749
 
750
 
751
 
752 38 alirezamon
##############
753
#        process_notebook_gen
754
##############
755 25 alirezamon
 
756
 
757
sub process_notebook_gen{
758 38 alirezamon
                my ($emulate,$info,$mode,@charts)=@_;
759 25 alirezamon
                my $notebook = Gtk2::Notebook->new;
760
                $notebook->set_tab_pos ('left');
761
                $notebook->set_scrollable(TRUE);
762
                $notebook->can_focus(FALSE);
763 32 alirezamon
 
764 25 alirezamon
 
765 38 alirezamon
                my ($page1,$set_win)=gen_emulation_column($emulate, $mode,10,$info,@charts);
766 32 alirezamon
                $notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic ("  _Run emulator  ")) if($mode eq "emulate");
767
                $notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic ("  _Run simulator ")) if($mode eq "simulate");
768 25 alirezamon
 
769
 
770 32 alirezamon
                my $page2=get_noc_setting_gui ($emulate,$info,$mode);
771 38 alirezamon
                my $tt=($mode eq "emulate")? "  _Generate NoC \nEmulation Model" : "  _Generate NoC \nSimulation Model" ;
772
                $notebook->append_page ($page2,Gtk2::Label->new_with_mnemonic ($tt));
773 25 alirezamon
 
774 38 alirezamon
                #if($mode eq "simulate"){
775
                        #my $page3=gen_custom_traffic ($emulate,$info,$mode);
776
                        #$notebook->append_page ($page3,Gtk2::Label->new_with_mnemonic ("_Generate Custom\n Traffic Pattern"));
777
                #}              
778 25 alirezamon
 
779
                my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
780
                $scrolled_win->set_policy( "automatic", "automatic" );
781
                $scrolled_win->add_with_viewport($notebook);
782
                $scrolled_win->show_all;
783
                my $page_num=$emulate->object_get_attribute ("process_notebook","currentpage");
784
                $notebook->set_current_page ($page_num) if(defined $page_num);
785
                $notebook->signal_connect( 'switch-page'=> sub{
786
                        $emulate->object_add_attribute ("process_notebook","currentpage",$_[2]);        #save the new pagenumber
787
 
788
                });
789
 
790 32 alirezamon
                return ($scrolled_win,$set_win);
791 25 alirezamon
 
792
}
793
 
794
 
795
sub get_noc_setting_gui {
796 32 alirezamon
        my ($emulate,$info_text,$mode)=@_;
797 28 alirezamon
        my $table=def_table(20,10,FALSE);#      my ($row,$col,$homogeneous)=@_;
798 38 alirezamon
 
799
        my $scrolled_win = gen_scr_win_with_adjst ($emulate,"noc_setting_gui");
800 28 alirezamon
        $scrolled_win->add_with_viewport($table);
801
        my $row=noc_config ($emulate,$table);
802 25 alirezamon
 
803 28 alirezamon
        my($label,$param,$default,$content,$type,$info);
804 38 alirezamon
        my @dirs = grep {-d} glob("../boards/*");
805 28 alirezamon
        my $fpgas;
806
        foreach my $dir (@dirs) {
807
                my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
808
                $default=$name;
809 38 alirezamon
                $fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
810 28 alirezamon
        }
811
 
812 38 alirezamon
        my @fpgainfo;
813
        if($mode eq "emulate"){
814
                @fpgainfo = (
815
                { 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},
816
                { label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'emulate1', content=>undef, info=>undef, param_parent=>'fpga_param', ref_delay=>undef},
817
                { 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 },
818
                );
819
 
820
        }
821
        else {
822
                @fpgainfo = (
823
                { 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},
824
                { label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'simulate1', content=>undef, info=>undef, param_parent=>'sim_param', ref_delay=>undef},
825
                { 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 },
826
                );
827
        }
828 25 alirezamon
 
829 43 alirezamon
        my $coltmp=0;
830
        foreach my $d (@fpgainfo) {
831
                ($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});
832 38 alirezamon
        }
833
 
834 43 alirezamon
        my $generate = def_image_button('icons/gen.png','Gener_ate',FALSE,1);
835
        my $diagram  = def_image_button('icons/diagram.png','Diagram');
836
        $table->attach ($generate, 0,2, $row, $row+1,'expand','shrink',2,2);
837
        $table->attach ($diagram, 2,4, $row, $row+1,'expand','shrink',2,2);
838
    $diagram-> signal_connect("clicked" => sub{
839
        show_topology_diagram ($emulate);
840
    });
841 38 alirezamon
    $generate->signal_connect ('clicked'=> sub{
842
                generate_sof_file($emulate,$info_text) if($mode eq "emulate");
843
                generate_sim_bin_file($emulate,$info_text) if($mode eq "simulate");
844 43 alirezamon
 
845 38 alirezamon
        });
846
 
847
        return $scrolled_win;
848
}
849 28 alirezamon
 
850 38 alirezamon
##########
851
#       generate_sof_file
852
##########
853 32 alirezamon
 
854
 
855 38 alirezamon
sub generate_sof_file {
856 43 alirezamon
        my ($self,$info)=@_;
857 38 alirezamon
        my $name=$self->object_get_attribute ('fpga_param',"SAVE_NAME");
858
        my $target_dir  = "$ENV{'PRONOC_WORK'}/emulate/$name";
859
        my $top         = "$target_dir/src_verilog/${name}_top.v";
860
 
861
        if (!defined $name){
862
                message_dialog("Please define the Save as filed!");
863
                return;
864
        }
865 32 alirezamon
 
866 38 alirezamon
        #copy all noc source codes
867
        my @files = split(/\s*,\s*/,EMULATION_RTLS);
868
        my $dir = Cwd::getcwd();
869
        my $project_dir   = abs_path("$dir/../../");
870
        my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $target_dir/src_verilog" );
871
        copy_file_and_folders(\@files,$project_dir,"$target_dir/src_verilog/lib/");
872 32 alirezamon
 
873
 
874 38 alirezamon
        #generate parameters for emulator_top.v file
875
        my ($localparam, $pass_param)=gen_noc_param_v( $self);
876
        open(FILE,  ">$target_dir/src_verilog/noc_parameters.v") || die "Can not open: $!";
877
        print FILE $localparam;
878
        close(FILE) || die "Error closing file: $!";
879
        open(FILE,  ">$target_dir/src_verilog/pass_parameters.v") || die "Can not open: $!";
880
        print FILE $pass_param;
881
        my $fifow=$self->object_get_attribute('fpga_param','TIMSTMP_FIFO_NUM');
882
        print FILE ",.TIMSTMP_FIFO_NUM($fifow)\n";
883
        close(FILE) || die "Error closing file: $!";
884
        open(FILE,  ">$top") || die "Can not open: $!";
885
        print FILE create_emulate_top($self,$name,$top);
886
        close(FILE) || die "Error closing file: $!";
887
        select_compiler($self,$name,$top,$target_dir,\&save_the_sof_file);
888
 
889
return;
890 28 alirezamon
}
891
 
892 38 alirezamon
sub create_emulate_top{
893
        my ($self,$name,$top)=@_;
894
        my $top_v= get_license_header("$top");
895 32 alirezamon
 
896 38 alirezamon
$top_v  ="$top_v
897 32 alirezamon
 
898 38 alirezamon
`timescale       1ns/1ps
899 32 alirezamon
 
900 38 alirezamon
module ${name}_top(
901
        output done_led,
902
        output noc_reset_led,
903
        output jtag_reset_led,
904
        input  reset,
905
        input  clk
906
);
907 32 alirezamon
 
908 25 alirezamon
 
909 38 alirezamon
        localparam
910
                STATISTIC_VJTAG_INDEX=124,
911
                PATTERN_VJTAG_INDEX=125,
912
                COUNTER_VJTAG_INDEX=126,
913
                DONE_RESET_VJTAG_INDEX=127;
914
 
915 25 alirezamon
 
916 38 alirezamon
        //NoC parameters will be defined by user
917
        `define NOC_PARAM
918
        `include \"noc_parameters.v\"
919
 
920
        wire  reset_noc, reset_injector, reset_noc_sync, reset_injector_sync, done;
921
        wire jtag_reset_injector, jtag_reset_noc;
922
        wire start_o;
923
        wire done_time_limit;
924
 
925
        assign done_led = done | done_time_limit;
926
        assign noc_reset_led= reset_noc;
927
        assign jtag_reset_led   = reset_injector;
928 25 alirezamon
 
929 38 alirezamon
 
930 25 alirezamon
 
931 38 alirezamon
        //  two reset sources which can be controled using jtag. One for reseting NoC another packet injectors
932
        jtag_source_probe #(
933
                .VJTAG_INDEX(DONE_RESET_VJTAG_INDEX),
934
                .Dw(2)  //source/probe width in bits
935
        )the_reset(
936
                .probe({done_time_limit,done}),
937
                .source({jtag_reset_injector,jtag_reset_noc})
938
        );
939 25 alirezamon
 
940
 
941 38 alirezamon
        assign  reset_noc               =       (jtag_reset_noc | reset);
942
        assign  reset_injector          =       (jtag_reset_injector | reset);
943 25 alirezamon
 
944 38 alirezamon
        altera_reset_synchronizer noc_rst_sync
945
        (
946
                .reset_in(reset_noc),
947
                .clk(clk),
948
                .reset_out(reset_noc_sync)
949
        );
950 25 alirezamon
 
951
 
952 38 alirezamon
        altera_reset_synchronizer inject_rst_sync
953
        (
954
                .reset_in(reset_injector),
955
                .clk(clk),
956
                .reset_out(reset_injector_sync)
957
        );
958
 
959
        //noc emulator
960
 
961
        noc_emulator #(
962
        .STATISTIC_VJTAG_INDEX(STATISTIC_VJTAG_INDEX),
963
        .PATTERN_VJTAG_INDEX(PATTERN_VJTAG_INDEX),
964
        `include \"pass_parameters.v\"
965
 
966
        )
967
        noc_emulate_top
968
        (
969
                .reset(reset_noc_sync),
970
                .jtag_ctrl_reset(reset_injector_sync),
971
                .clk(clk),
972
                .start_o(start_o),
973
                .done(done)
974
        );
975
 
976
 
977
 
978
        //clock counter
979
 
980
        function integer log2;
981
      input integer number; begin
982
         log2=(number <=1) ? 1: 0;
983
         while(2**log2<number) begin
984
            log2=log2+1;
985
         end
986
      end
987
    endfunction // log2
988
 
989
        localparam   MAX_SIM_CLKs  = 1_000_000_000;
990
        localparam   CLK_CNTw = log2(MAX_SIM_CLKs+1);
991
 
992
        reg     [CLK_CNTw-1             :   0] clk_counter;
993
        wire    [CLK_CNTw-1             :   0] clk_limit;
994
        reg start;
995
        always @(posedge clk or posedge reset_injector_sync) begin
996
                if(reset_injector_sync)begin
997
                        clk_counter <= {CLK_CNTw{1'b0}};
998
                        start<=1'b0;
999
                end else begin
1000
                        if(start_o) start<=1'b1;
1001
                        if(done==1'b0 && start ) clk_counter<=clk_counter +1'b1;
1002
                end
1003
        end
1004
 
1005
        jtag_source_probe #(
1006
                .VJTAG_INDEX(COUNTER_VJTAG_INDEX),
1007
                .Dw(CLK_CNTw)   //source/probe width in bits
1008
        )the_clk_counter(
1009
                .probe(clk_counter),
1010
                .source(clk_limit)
1011
        );
1012
 
1013
        assign done_time_limit = (clk_counter >= clk_limit);
1014
endmodule
1015
";
1016
        return $top_v;
1017
}
1018 25 alirezamon
 
1019 38 alirezamon
sub save_the_sof_file{
1020 28 alirezamon
 
1021 38 alirezamon
        my $self=shift;
1022
        my $name=$self->object_get_attribute ('fpga_param',"SAVE_NAME");
1023
        my $sofdir="$ENV{PRONOC_WORK}/emulate/sof";
1024
        my $fpga_board=$self->object_get_attribute('compile','board');
1025
        my $target_dir  = "$ENV{'PRONOC_WORK'}/emulate/$name";
1026 28 alirezamon
 
1027 38 alirezamon
        mkpath("$sofdir/$fpga_board/",1,01777);
1028
        open(FILE,  ">$sofdir/$fpga_board/$name.inf") || die "Can not open: $!";
1029
        print FILE perl_file_header("$name.inf");
1030
        my %pp;
1031
        $pp{'noc_param'}= $self->{'noc_param'};
1032
        $pp{'fpga_param'}= $self->{'fpga_param'};
1033
        print FILE Data::Dumper->Dump([\%pp],["emulate_info"]);
1034
        close(FILE) || die "Error closing file: $!";
1035 28 alirezamon
 
1036
 
1037 38 alirezamon
        #find  $dir_name -name \*.sof -exec cp '{}' $sofdir/$fpga_board/$save_name.sof" 
1038
        my @files = File::Find::Rule->file()
1039
                 ->name( '*.sof' )
1040
                 ->in( "$target_dir" );
1041
        copy($files[0],"$sofdir/$fpga_board/$name.sof") or do {
1042
                my $err= "Error copy($files[0] , $sofdir/$fpga_board/$name.sof";
1043
                print "$err\n";
1044
                message_dialog($err);
1045
                return;
1046
        };
1047
        #copy the board's programming and jtag interface files
1048
 
1049
        my $board_name=$self->object_get_attribute('compile','board');
1050
        #copy board jtag_intfc.sh file 
1051
        copy("../boards/$board_name/jtag_intfc.sh","$sofdir/$fpga_board/jtag_intfc.sh");
1052
        #print "../boards/$board_name/jtag_intfc.sh","$sofdir/$fpga_board/jtag_intfc.sh\n";
1053
        #add argument run to jtag_interface file 
1054
        my $runarg='
1055 28 alirezamon
 
1056 38 alirezamon
if [ $# -ne 0 ]
1057
  then
1058
    $JTAG_INTFC $1
1059
fi
1060
';
1061
        append_text_to_file ("$sofdir/$fpga_board/jtag_intfc.sh",$runarg );
1062
 
1063
 
1064
 
1065 28 alirezamon
 
1066 38 alirezamon
        #copy board program_device.sh file 
1067
        copy("../boards/$board_name/program_device.sh","$sofdir/$fpga_board/program_device.sh");
1068
 
1069
 
1070 28 alirezamon
 
1071 38 alirezamon
        message_dialog("sof file has been generated successfully");
1072
}
1073 28 alirezamon
 
1074
 
1075 25 alirezamon
 
1076
##########
1077
#       save_emulation
1078
##########
1079
sub save_emulation {
1080
        my ($emulate)=@_;
1081
        # read emulation name
1082
        my $name=$emulate->object_get_attribute ("emulate_name",undef);
1083
        my $s= (!defined $name)? 0 : (length($name)==0)? 0 :1;
1084
        if ($s == 0){
1085
                message_dialog("Please set emulation name!");
1086
                return 0;
1087
        }
1088
        # Write object file
1089
        open(FILE,  ">lib/emulate/$name.EML") || die "Can not open: $!";
1090
        print FILE perl_file_header("$name.EML");
1091 38 alirezamon
        print FILE Data::Dumper->Dump([\%$emulate],["emulate"]);
1092 25 alirezamon
        close(FILE) || die "Error closing file: $!";
1093
        message_dialog("Emulation saved as lib/emulate/$name.EML!");
1094
        return 1;
1095
}
1096
 
1097
#############
1098
#       load_emulation
1099
############
1100
 
1101
sub load_emulation {
1102
        my ($emulate,$info)=@_;
1103
        my $file;
1104
        my $dialog = Gtk2::FileChooserDialog->new(
1105
                'Select a File', undef,
1106
                'open',
1107
                'gtk-cancel' => 'cancel',
1108
                'gtk-ok'     => 'ok',
1109
                );
1110
 
1111
        my $filter = Gtk2::FileFilter->new();
1112
        $filter->set_name("EML");
1113
        $filter->add_pattern("*.EML");
1114
        $dialog->add_filter ($filter);
1115
        my $dir = Cwd::getcwd();
1116
        $dialog->set_current_folder ("$dir/lib/emulate");
1117
 
1118
 
1119
        if ( "ok" eq $dialog->run ) {
1120
                $file = $dialog->get_filename;
1121
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1122
                if($suffix eq '.EML'){
1123 43 alirezamon
 
1124
                        my ($pp,$r,$err) = regen_object($file);
1125
                        if ($r ){
1126
                                add_colored_info($info,"**Error reading  $file file: $err\n",'red');
1127 25 alirezamon
                                 $dialog->destroy;
1128
                                return;
1129
                        }
1130
 
1131
                        clone_obj($emulate,$pp);
1132
                        #message_dialog("done!");                               
1133
                }
1134
     }
1135
     $dialog->destroy;
1136
}
1137
 
1138 38 alirezamon
 
1139
 
1140
sub update_result {
1141
        my ($self,$sample,$name,$x,$y,$z)=@_;
1142
        my $ref=$self->object_get_attribute ($sample,$name);
1143
        my %results;
1144
        %results= %{$ref} if(defined $ref);
1145
        if(!defined $z) {$results{$x}=$y;}
1146
        else {$results{$x}{$y}=$z;}
1147
        $self->object_add_attribute ($sample,$name,\%results);
1148
}
1149
 
1150
 
1151
sub capture_cores_data {
1152
        my ($data,$text)=@_;
1153
        my %result;
1154
        my @q =split  (/Core/,$text);
1155
        my $i=0;
1156
        foreach my $p (@q){
1157
                if ($i!=0){
1158
                        my @d = split (/[^0-9. ]/,$p);
1159
                        my $n=  $d[0];
1160
                        my $val = capture_number_after("$data",$p);
1161
                        $result{remove_all_white_spaces($n)}=remove_all_white_spaces($val);
1162
                }
1163
                $i++;
1164
        }
1165
        return %result;
1166
}
1167
 
1168 43 alirezamon
sub gen_sim_parameter_h {
1169
        my ($param_h,$includ_h,$ne,$nr,$router_p,$fifow)=@_;
1170
 
1171
        $param_h =~ s/\d\'b/ /g;
1172
        my $text=  "
1173
#ifndef     INCLUDE_PARAM
1174
        #define   INCLUDE_PARAM \n \n
1175 38 alirezamon
 
1176 43 alirezamon
        $param_h
1177
 
1178
        #define NE  $ne
1179
        #define NR  $nr
1180
        #define ROUTER_P_NUM $router_p
1181
 
1182
        //simulation parameter
1183
        #define MAX_RATIO   ".MAX_RATIO."
1184
        #define AVG_LATENCY_METRIC \"HEAD_2_TAIL\"
1185
        #define TIMSTMP_FIFO_NUM   $fifow
1186
 
1187
        $includ_h
1188
\n \n \#endif" ;
1189
        return $text;
1190
}
1191 38 alirezamon
 
1192 43 alirezamon
sub gen_vrouter_param_v {
1193
        my ($simulate,$src_verilog_dr)=@_;
1194
        # generate NoC parameter file
1195
        my ($noc_param,$pass_param)=gen_noc_param_v($simulate);
1196
        open(FILE,  ">$src_verilog_dr/parameter.v") || die "Can not open: $!";
1197
        my $fifow=$simulate->object_get_attribute('fpga_param','TIMSTMP_FIFO_NUM');
1198 38 alirezamon
 
1199
 
1200 43 alirezamon
 
1201
        print FILE  " \`ifdef     INCLUDE_PARAM \n \n
1202
        $noc_param
1203
 
1204
        //simulation parameter
1205
        localparam MAX_RATIO = ".MAX_RATIO.";
1206
        localparam MAX_PCK_NUM = ".MAX_SIM_CLKs.";
1207
        localparam MAX_PCK_SIZ = ".MAX_PCK_SIZ.";
1208
        localparam MAX_SIM_CLKs=  ".MAX_SIM_CLKs.";
1209
        localparam TIMSTMP_FIFO_NUM = $fifow;
1210
\n \n \`endif" ;
1211
        close FILE;
1212
}
1213
 
1214
 
1215 25 alirezamon
############
1216
#    main
1217
############
1218
sub emulator_main{
1219 38 alirezamon
 
1220 25 alirezamon
        add_color_to_gd();
1221
        my $emulate= emulator->emulator_new();
1222
        set_gui_status($emulate,"ideal",0);
1223 38 alirezamon
        $emulate->object_add_attribute('compile','compilers',"QuartusII");
1224 25 alirezamon
        my $left_table = Gtk2::Table->new (25, 6, FALSE);
1225
        my $right_table = Gtk2::Table->new (25, 6, FALSE);
1226
        my $main_table = Gtk2::Table->new (25, 12, FALSE);
1227 38 alirezamon
        my ($infobox,$info)= create_text();
1228 43 alirezamon
 
1229 38 alirezamon
 
1230
        my @pages =(
1231
                {page_name=>" Avg. throughput/latency", page_num=>0},
1232
                {page_name=>" Injected Packet ", page_num=>1},
1233
                {page_name=>" Worst-Case Delay ",page_num=>2},
1234
                {page_name=>" Executaion Time ",page_num=>3},
1235
        );
1236 25 alirezamon
 
1237 38 alirezamon
        my @charts = (
1238 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},
1239 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},
1240
                { 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},
1241
                { 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},
1242
                { 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},
1243
                { 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},
1244
        );
1245
 
1246
        my ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate", @charts);
1247
        my $chart   =gen_multiple_charts ($emulate,\@pages,\@charts);
1248 25 alirezamon
 
1249
        $main_table->set_row_spacings (4);
1250
        $main_table->set_col_spacings (1);
1251 38 alirezamon
 
1252 25 alirezamon
        my $generate = def_image_button('icons/forward.png','Run all');
1253
        my $open = def_image_button('icons/browse.png','Load');
1254 43 alirezamon
        my $diagram  = def_image_button('icons/diagram.png','Diagram');
1255 38 alirezamon
 
1256
        my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
1257 25 alirezamon
 
1258
        $entry->signal_connect( 'changed'=> sub{
1259
                my $name=$entry->get_text();
1260
                $emulate->object_add_attribute ("emulate_name",undef,$name);
1261
        });
1262
        my $save = def_image_button('icons/save.png','Save');
1263
        $entrybox->pack_end($save,   FALSE, FALSE,0);
1264 38 alirezamon
 
1265
        my $image = get_status_gif($emulate);
1266
        my $v1=gen_vpaned($conf_box,.45,$image);
1267
        my $v2=gen_vpaned($infobox,.2,$chart);
1268
        my $h1=gen_hpaned($v1,.4,$v2);
1269 25 alirezamon
 
1270
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
1271 38 alirezamon
        $main_table->attach_defaults ($h1  , 0, 12, 0,24);
1272 43 alirezamon
        $main_table->attach ($open,0, 2, 24,25,'expand','shrink',2,2);
1273
#       $main_table->attach ($diagram, 2, 4, 24,25,'expand','shrink',2,2);
1274
        $main_table->attach ($entrybox,4, 7, 24,25,'expand','shrink',2,2);
1275
        $main_table->attach ($generate, 7, 9, 24,25,'expand','shrink',2,2);
1276 32 alirezamon
 
1277 25 alirezamon
        #check soc status every 0.5 second. referesh device table if there is any changes 
1278 38 alirezamon
        Glib::Timeout->add (100, sub{
1279 25 alirezamon
                my ($state,$timeout)= get_gui_status($emulate);
1280
 
1281
                if ($timeout>0){
1282
                        $timeout--;
1283
                        set_gui_status($emulate,$state,$timeout);
1284 38 alirezamon
                        return TRUE;
1285 25 alirezamon
                }
1286 38 alirezamon
                if($state eq "ideal"){
1287
                        return TRUE;
1288
 
1289
                }
1290 32 alirezamon
                elsif($state eq 'ref_set_win'){
1291
                        my $s=$emulate->object_get_attribute("active_setting",undef);
1292
                        $set_win->destroy();
1293 38 alirezamon
                        $emulate->object_add_attribute("active_setting",undef,$s);
1294 32 alirezamon
                }
1295 38 alirezamon
 
1296
                #refresh GUI
1297
                my $name=$emulate->object_get_attribute ("emulate_name",undef);
1298
                $entry->set_text($name) if(defined $name);
1299
                $conf_box->destroy();
1300
                $set_win->destroy();
1301
                $chart->destroy();
1302
                $image->destroy();
1303
                $image = get_status_gif($emulate);
1304
                ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate", @charts);
1305
                $chart   =gen_multiple_charts  ($emulate,\@pages,\@charts);
1306
                $v1 -> pack1($conf_box, TRUE, TRUE);
1307
                $v1 -> pack2($image, TRUE, TRUE);
1308
                $v2 -> pack2($chart, TRUE, TRUE);
1309
                $conf_box->show_all();
1310
                $main_table->show_all();
1311
                set_gui_status($emulate,"ideal",0);
1312
 
1313 25 alirezamon
                return TRUE;
1314
 
1315
        } );
1316 43 alirezamon
 
1317
         $diagram-> signal_connect("clicked" => sub{
1318
        show_topology_diagram ($emulate);
1319
    });
1320 25 alirezamon
 
1321
        $generate-> signal_connect("clicked" => sub{
1322 38 alirezamon
                my @samples =$emulate->object_get_attribute_order("samples");
1323
                foreach my $sample (@samples){
1324
                        $emulate->object_add_attribute ($sample,"status","run");
1325 25 alirezamon
                }
1326
                run_emulator($emulate,\$info);
1327
        });
1328
 
1329
 
1330
        $open-> signal_connect("clicked" => sub{
1331
                load_emulation($emulate,\$info);
1332
                set_gui_status($emulate,"ref",5);
1333
        });
1334
 
1335
        $save-> signal_connect("clicked" => sub{
1336
                save_emulation($emulate);
1337
                set_gui_status($emulate,"ref",5);
1338
        });
1339
 
1340
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
1341 38 alirezamon
        $sc_win->set_policy( "automatic", "automatic" );
1342
        $sc_win->add_with_viewport($main_table);
1343 25 alirezamon
 
1344
        return $sc_win;
1345
}
1346
 
1347
 
1348
 

powered by: WebSVN 2.1.0

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