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