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/] [mpsoc_gen.pl] - Blame information for rev 54

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 alirezamon
#! /usr/bin/perl -w
2 48 alirezamon
use constant::boolean;
3 16 alirezamon
use strict;
4
use warnings;
5 43 alirezamon
use FindBin;
6
use lib $FindBin::Bin;
7 16 alirezamon
use mpsoc;
8
use soc;
9
use ip;
10
use interface;
11
use POSIX 'strtol';
12
use File::Path;
13
use File::Copy;
14
use Cwd 'abs_path';
15 48 alirezamon
use Glib::Event;
16
use Event; # any order
17 16 alirezamon
 
18
 
19
require "widget.pl";
20
require "mpsoc_verilog_gen.pl";
21 17 alirezamon
require "hdr_file_gen.pl";
22 25 alirezamon
require "readme_gen.pl";
23 28 alirezamon
require "soc_gen.pl";
24 48 alirezamon
require "topology.pl";
25 43 alirezamon
require "diagram.pl";
26 48 alirezamon
require "orcc.pl";
27 16 alirezamon
 
28
 
29
sub initial_default_param{
30 43 alirezamon
    my $mpsoc=shift;
31
    my @socs=$mpsoc->mpsoc_get_soc_list();
32
    foreach my $soc_name (@socs){
33
        my %param_value;
34
        my $top=$mpsoc->mpsoc_get_soc($soc_name);
35
        my @insts=$top->top_get_all_instances();
36
        my @exceptions=get_NI_instance_list($top);
37
        @insts=get_diff_array(\@insts,\@exceptions);
38
        foreach my $inst (@insts){
39
            my @params=$top->top_get_parameter_list($inst);
40
            foreach my $p (@params){
41
                my  ($default,$type,$content,$info,$global_param,$redefine)=$top->top_get_parameter($inst,$p);
42
                $param_value{$p}=$default;
43
            }
44
        }
45
        $top->top_add_default_soc_param(\%param_value);
46
    }
47
 
48 16 alirezamon
}
49
 
50
#############
51 43 alirezamon
#    get_soc_lists
52 16 alirezamon
############
53
 
54
sub get_soc_list {
55 48 alirezamon
    my ($mpsoc,$info)=@_;
56 43 alirezamon
    my $path=$mpsoc->object_get_attribute('setting','soc_path');
57
    $path =~ s/ /\\ /g;
58 48 alirezamon
    my @socs;
59 43 alirezamon
    my @files = glob "$path/*.SOC";
60
    for my $p (@files){
61
       my ($soc,$r,$err) = regen_object($p);
62
        # Read       
63
         if ($r){
64 48 alirezamon
            add_info($info,"**Error reading  $p file: $err\n");
65 43 alirezamon
                 next;
66
        }
67
        my $top=$soc->soc_get_top();
68
        if (defined $top){
69
            my @instance_list=$top->top_get_all_instances();
70
            #check if the soc has ni port
71
            foreach my $instanc(@instance_list){
72
                my $category=$top->top_get_def_of_instance($instanc,'category');
73
                if($category eq 'NoC')
74
                {
75
                    my $name=$soc->object_get_attribute('soc_name');
76 48 alirezamon
                    #get old tile parameter setting 
77
                    my $old_top = $mpsoc->mpsoc_get_soc($name);
78
                    copy_back_custom_soc_param($top,$old_top) if(defined $old_top);
79 43 alirezamon
                    $mpsoc->mpsoc_add_soc($name,$top);
80
                    #print" $name\n";
81
                }
82
            }
83
 
84
        }
85
    }# files
86
 
87
    # initial  default soc parameter
88
    initial_default_param($mpsoc);
89
    return $mpsoc->mpsoc_get_soc_list;
90 16 alirezamon
}
91 30 alirezamon
 
92 48 alirezamon
sub copy_back_custom_soc_param{
93
        my ($new,$old)=@_;
94
        my @tiles = $old->top_get_custom_tile_list();
95
        foreach my $tile (@tiles){
96
                my %l =$old->top_get_custom_soc_param($tile);
97
                $new->top_add_custom_soc_param (\%l,$tile);
98
        }
99
 
100
}
101 30 alirezamon
 
102
sub get_NI_instance_list {
103 43 alirezamon
    my $top=shift;
104
    my @nis;
105 48 alirezamon
    return if (!defined $top);
106 43 alirezamon
    my @instance_list=$top->top_get_all_instances();
107
    #check if the soc has ni port
108
    foreach my $instanc(@instance_list){
109
            my $category=$top->top_get_def_of_instance($instanc,'category');
110
             push(@nis,$instanc) if($category eq 'NoC') ;
111
    }
112
    return @nis;
113 30 alirezamon
}
114
 
115 16 alirezamon
####################
116
# get_conflict_decision
117
###########################
118
 
119
 
120
sub get_conflict_decision{
121 43 alirezamon
    my ($mpsoc,$name,$inserted,$conflicts,$msg)=@_;
122 48 alirezamon
    $msg="\tThe inserted tile number(s) have been mapped previously to \n\t\t\"$msg\".\n\tDo you want to remove the conflicted tiles number(s) in newly \n\tinserted range or remove them from the previous ones? ";
123 43 alirezamon
 
124
    my $wind=def_popwin_size(10,30,"warning",'percent');
125
    my $label= gen_label_in_left($msg);
126
    my $table=def_table(2,6,FALSE);
127
    $table->attach_defaults ($label , 0, 6, 0,1);
128
    $wind->add($table);
129 16 alirezamon
 
130 48 alirezamon
    my $b1= def_button("Remove Previous");
131
    my $b2= def_button("Remove Current");
132
    my $b3= def_button("Cancel");
133 43 alirezamon
 
134 48 alirezamon
    $table->attach ($b1 , 0, 1, 1,2,'fill','fill',2,2);
135
    $table->attach ($b2 , 3, 4, 1,2,'fill','fill',2,2);
136
    $table->attach ($b3 , 5, 6, 1,2,'fill','fill',2,2);
137 16 alirezamon
 
138 48 alirezamon
 
139 43 alirezamon
    $wind->show_all();
140
 
141
    $b1->signal_connect( "clicked"=> sub{ #Remove Previous
142
        my @socs=$mpsoc->mpsoc_get_soc_list();
143
        foreach my $p (@socs){
144
            if($p ne $name){
145
                my @taken_tiles=$mpsoc->mpsoc_get_soc_tiles_num($p);
146
                my @diff=get_diff_array(\@taken_tiles,$inserted);
147
                $mpsoc->mpsoc_add_soc_tiles_num($p,\@diff) if(scalar @diff  );
148
                $mpsoc->mpsoc_add_soc_tiles_num($p,undef) if(scalar @diff ==0 );
149
            }
150
        }
151
        $mpsoc->mpsoc_add_soc_tiles_num($name,$inserted) if(defined $inserted  );
152 48 alirezamon
        #set_gui_status($mpsoc,"ref",1);        
153
        $wind->destroy();
154
        get_soc_parameter_setting($mpsoc,$name, $inserted)if(defined $inserted  );
155 43 alirezamon
 
156
    });
157
 
158
    $b2->signal_connect( "clicked"=> sub{#Remove Current
159
        my @new= get_diff_array($inserted,$conflicts);
160
        $mpsoc->mpsoc_add_soc_tiles_num($name,\@new) if(scalar @new  );
161
        $mpsoc->mpsoc_add_soc_tiles_num($name,undef) if(scalar @new ==0 );
162 48 alirezamon
        #set_gui_status($mpsoc,"ref",1);        
163
        $wind->destroy();
164
        get_soc_parameter_setting($mpsoc,$name, \@new) if(scalar @new  );
165 43 alirezamon
 
166
    });
167
 
168
    $b3->signal_connect( "clicked"=> sub{
169
        $wind->destroy();
170
 
171 48 alirezamon
    });
172 43 alirezamon
}
173 16 alirezamon
 
174
 
175
#############
176 43 alirezamon
#    check_inserted_ip_nums
177 16 alirezamon
##########
178
sub check_inserted_ip_nums{
179 43 alirezamon
    my  ($mpsoc,$name,$str)=@_;
180
    my @all_num=();
181
    $str= remove_all_white_spaces ($str);
182
 
183
    if($str !~ /^[0-9.:,]+$/){ message_dialog ("The Ip numbers contains invalid character" ); return; }
184 48 alirezamon
    my @chunks=split(/\s*,\s*/,$str);
185 43 alirezamon
    foreach my $p (@chunks){
186
        my @range=split(':',$p);
187
        my $size= scalar @range;
188
        if($size==1){ # its a number
189 48 alirezamon
            if ( grep( /^$range[0]$/, @all_num ) ) { message_dialog ("Multiple definition for IP number $range[0]" ); return; }
190 43 alirezamon
            push(@all_num,$range[0]);
191
        }elsif($size ==2){# its a range
192
            my($min,$max)=@range;
193 48 alirezamon
            if($min>$max) {message_dialog ("invalid range: [$p]",'error' ); return;}
194 43 alirezamon
            for (my $i=$min; $i<=$max; $i++){
195 48 alirezamon
                if ( grep( /^$i$/, @all_num ) ) { message_dialog ("Multiple definition for IP number $i in $p" ); return; }
196 43 alirezamon
                push(@all_num,$i);
197
 
198
            }
199
 
200
        }else{message_dialog ("invalid range: [$p]" ); return; }
201
 
202
    }
203
    #check if range does not exceed the tile numbers
204 48 alirezamon
    my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($mpsoc);
205
    my $max_tile_num=$NE;
206 43 alirezamon
 
207
    my @f=sort { $a <=> $b }  @all_num;
208
    my @l;
209
    foreach my $num (@f){
210
        push(@l,$num) if($num<$max_tile_num);
211
 
212
    }
213
    @all_num=@l;
214
 
215
    #check if any ip number exists in the rest
216
    my $conflicts_msg;
217
    my @conflicts;
218
 
219
 
220
    my @socs=$mpsoc->mpsoc_get_soc_list();
221
    foreach my $p (@socs){
222
        if($p ne $name){
223
            my @taken_tiles=$mpsoc->mpsoc_get_soc_tiles_num($p);
224
            my @c=get_common_array(\@all_num,\@taken_tiles);
225
            if (scalar @c) {
226
                my $str=join(',', @c);
227
                $conflicts_msg = (defined $conflicts_msg)? "$conflicts_msg\n\t\t $str->$p" : "$str->$p";
228
                @conflicts= (defined $conflicts_msg)? (@conflicts,@c): @c;
229
            }
230
        }#if
231
    }
232
    if (defined $conflicts_msg) {
233 48 alirezamon
       get_conflict_decision($mpsoc,$name,\@all_num,\@conflicts,$conflicts_msg);
234
 
235 43 alirezamon
 
236
    }else {
237
        #save the entered ips
238 48 alirezamon
        if( scalar @all_num>0){
239
                $mpsoc->mpsoc_add_soc_tiles_num($name,\@all_num);
240
                return \@all_num;
241
        }
242
        else {
243
                $mpsoc->mpsoc_add_soc_tiles_num($name,undef);
244
                return undef;
245
        }
246
        #set_gui_status($mpsoc,"ref",1);
247 43 alirezamon
    }
248 48 alirezamon
    return undef;
249 16 alirezamon
}
250
 
251
 
252
#################
253
# get_soc_parameter_setting
254
################
255
 
256 48 alirezamon
 
257
 
258
 
259 16 alirezamon
sub get_soc_parameter_setting{
260 48 alirezamon
    my ($mpsoc,$soc_name,$tiles_ref)=@_;
261
    my @tiles = @{$tiles_ref} if defined ($tiles_ref);
262
    my $string = join (',',@tiles );
263
    my $window =  def_popwin_size(40,40,"Parameter setting for $soc_name mapped to tile( $string ) ",'percent');
264
    my $table = get_soc_parameter_setting_table($mpsoc,$soc_name,$window,$tiles_ref);
265
        $window->add($table);
266
        $window->show_all;
267
}
268
 
269
 
270
sub get_soc_parameter_setting_table{
271
    my ($mpsoc,$soc_name,$window,$tiles_ref)=@_;
272
    my @tiles;
273
    @tiles = @{$tiles_ref} if defined ($tiles_ref);
274
   # my $window =  def_popwin_size(40,40,"Parameter setting for $soc_name mapped to tile(@tiles) ",'percent');
275
    my $table = def_table(10, 7, FALSE);
276 43 alirezamon
 
277 48 alirezamon
    my $scrolled_win = add_widget_to_scrolled_win($table);
278 43 alirezamon
    my $row=0;
279 48 alirezamon
    my $column=0;
280 43 alirezamon
    my $top=$mpsoc->mpsoc_get_soc($soc_name);
281
 
282
    #read soc parameters
283 48 alirezamon
    my %param_value=(scalar @tiles ==1 ) ? $top->top_get_custom_soc_param($tiles[0])  : $top->top_get_default_soc_param();
284
    $mpsoc->object_add_attribute('current_tile_param',undef,\%param_value);
285
 
286 43 alirezamon
    my @insts=$top->top_get_all_instances();
287
    my @exceptions=get_NI_instance_list($top);
288
    @insts=get_diff_array(\@insts,\@exceptions);
289
    foreach my $inst (@insts){
290
        my @params=$top->top_get_parameter_list($inst);
291
        foreach my $p (@params){
292
            my  ($default,$type,$content,$info,$global_param,$redefine)=$top->top_get_parameter($inst,$p);
293 48 alirezamon
            my $show = ($type ne "Fixed");
294
                        $default= $param_value{$p} if(defined $param_value{$p});
295
                        ($row,$column)=add_param_widget($mpsoc,$p,$p, $default,$type,$content,$info, $table,$row,$column,$show,'current_tile_param',undef,undef,'vertical');
296
                }
297
 
298 43 alirezamon
 
299 48 alirezamon
  #          if ($type eq "Entry"){
300
  #              my $entry=gen_entry($param_value{$p});
301
  #              $table->attach_defaults ($entry, 3, 6, $row, $row+1);
302
  #              $entry-> signal_connect("changed" => sub{$param_value{$p}=$entry->get_text();});
303
  #          }
304
  #          elsif ($type eq "Combo-box"){
305
  #              my @combo_list=split(/\s*,\s*/,$content);
306
  #              my $pos=get_item_pos($param_value{$p}, @combo_list) if(defined $param_value{$p});
307
  #              my $combo=gen_combo(\@combo_list, $pos);
308
  #              $table->attach_defaults ($combo, 3, 6, $row, $row+1);
309
  #              $combo-> signal_connect("changed" => sub{$param_value{$p}=$combo->get_active_text();});
310
  #              
311
  #          }
312
  #          elsif     ($type eq "Spin-button"){ 
313
  #                my ($min,$max,$step)=split(/\s*,\s*/,$content);
314
  #                $param_value{$p}=~ s/\D//g;
315
  #                $min=~ s/\D//g;
316
  #                $max=~ s/\D//g;    
317
  #                $step=~ s/\D//g;
318
  #                my $spin=gen_spin($min,$max,$step);
319
  #                $spin->set_value($param_value{$p});
320
  #                $table->attach_defaults ($spin, 3, 4, $row, $row+1);
321
  #                $spin-> signal_connect("value_changed" => sub{$param_value{$p}=$spin->get_value_as_int();});
322
  #       
323
  #       # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
324
  #          }
325
  #          my $label =gen_label_in_center($p);
326
  #          $table->attach_defaults ($label, 0, 3, $row, $row+1);
327
  #          if (defined $info){
328
  #          my $info_button=def_image_button('icons/help.png');
329
  #          $table->attach_defaults ($info_button, 6, 7, $row, $row+1);    
330
  #          $info_button->signal_connect('clicked'=>sub{
331
  #              message_dialog($info);
332
  #              
333
  #          });
334
  #          
335
  #      }       
336
  #      $row++;
337
  #                      
338
  #      
339
  #      }
340 43 alirezamon
    }
341
 
342
    my $ok = def_image_button('icons/select.png','OK');
343
    my $okbox=def_hbox(TRUE,0);
344
    $okbox->pack_start($ok, FALSE, FALSE,0);
345
 
346
 
347
    my $mtable = def_table(10, 1, TRUE);
348 16 alirezamon
 
349 43 alirezamon
    $mtable->attach_defaults($scrolled_win,0,1,0,9);
350
    $mtable->attach_defaults($okbox,0,1,9,10);
351
 
352 48 alirezamon
 
353 43 alirezamon
 
354
    $ok-> signal_connect("clicked" => sub{
355 48 alirezamon
        $window->destroy if(defined $window);
356 43 alirezamon
        #save new values 
357 48 alirezamon
        my $ref=$mpsoc->object_get_attribute('current_tile_param');
358
                %param_value=%{$ref};
359
 
360
       # if(!defined $tile ) {
361
        #    $top->top_add_default_soc_param(\%param_value);
362
        #    $mpsoc->object_add_attribute('soc_param',"default",\%param_value);      
363
       # }
364
       # else {
365
        foreach my $tile (@tiles){
366 46 alirezamon
            $top->top_add_custom_soc_param(\%param_value,$tile);
367 48 alirezamon
            $mpsoc->object_add_attribute('soc_param',"custom_${soc_name}",\%param_value);
368 43 alirezamon
        }
369 48 alirezamon
        $mpsoc->object_add_attribute('current_tile_param',undef,undef);
370
        set_gui_status($mpsoc,"refresh_soc",1);
371
 
372 43 alirezamon
 
373 48 alirezamon
        });
374
    $mtable->show_all();
375
    return  $mtable;
376 16 alirezamon
}
377
 
378
################
379 43 alirezamon
#    tile_set_widget
380 16 alirezamon
################
381
 
382
sub tile_set_widget{
383 43 alirezamon
    my ($mpsoc,$soc_name,$num,$table,$show,$row)=@_;
384 48 alirezamon
    #my $label=gen_label_in_left($soc);
385 43 alirezamon
    my @all_num= $mpsoc->mpsoc_get_soc_tiles_num($soc_name);
386
    my $init=compress_nums(@all_num);
387
    my $entry;
388
    if (defined $init){$entry=gen_entry($init) ;}
389
    else              {$entry=gen_entry();}
390
    my $set= def_image_button('icons/right.png');
391
    my $remove= def_image_button('icons/cancel.png');
392
    #my $setting= def_image_button('icons/setting.png','setting');
393 48 alirezamon
 
394
 
395
    my $button = def_colored_button($soc_name,$num);
396 43 alirezamon
    $button->signal_connect("clicked"=> sub{
397 48 alirezamon
       # get_soc_parameter_setting($mpsoc,$soc_name,undef);        
398
    });
399 43 alirezamon
 
400
    $set->signal_connect("clicked"=> sub{
401
        my $data=$entry->get_text();
402 48 alirezamon
        my $r=check_inserted_ip_nums($mpsoc,$soc_name,$data);
403
        if(defined $r){
404
                my @all_num = @{$r};
405
                get_soc_parameter_setting($mpsoc,$soc_name,\@all_num);
406
        }
407 43 alirezamon
    });
408 48 alirezamon
 
409 43 alirezamon
    $remove->signal_connect("clicked"=> sub{
410
        $mpsoc->mpsoc_remove_soc($soc_name);
411
        set_gui_status($mpsoc,"ref",1);
412
    });
413 16 alirezamon
 
414 43 alirezamon
 
415 16 alirezamon
if($show){
416 43 alirezamon
    $table->attach ( $button, 0, 1, $row,$row+1,'fill','fill',2,2);
417
    $table->attach ( $remove, 1, 2, $row,$row+1,'fill','shrink',2,2);
418
    $table->attach ( $entry , 2, 3, $row,$row+1,'fill','shrink',2,2);
419
    $table->attach ( $set, 3, 4, $row,$row+1,'fill','shrink',2,2);
420
 
421 16 alirezamon
 
422 43 alirezamon
 
423
    $row++;
424
}
425
 
426
    return $row;
427
 
428
 
429
}
430 16 alirezamon
 
431
 
432
 
433
 
434
##################
435 43 alirezamon
#    defualt_tilles_setting
436 16 alirezamon
###################
437
 
438
sub defualt_tilles_setting {
439 43 alirezamon
    my ($mpsoc,$table,$show,$row,$info)=@_;
440
 
441
    #title    
442 48 alirezamon
    my $separator1 = gen_Hsep();
443
    my $separator2 = gen_Hsep();
444 43 alirezamon
    my $title2=gen_label_in_center("Tile Configuration");
445
    my $box1=def_vbox(FALSE, 1);
446
    $box1->pack_start( $separator1, FALSE, FALSE, 3);
447
    $box1->pack_start( $title2, FALSE, FALSE, 3);
448
    $box1->pack_start( $separator2, FALSE, FALSE, 3);
449
    if($show){$table->attach_defaults ($box1 ,0,4, $row,$row+1);$row++;}
450 48 alirezamon
 
451 43 alirezamon
 
452
    my $label = gen_label_in_left("Tiles path:");
453 48 alirezamon
    my $entry = gen_entry();
454 43 alirezamon
    my $browse= def_image_button("icons/browse.png");
455
    my $file= $mpsoc->object_get_attribute('setting','soc_path');
456
    if(defined $file){$entry->set_text($file);}
457
 
458
 
459 48 alirezamon
        $browse->signal_connect("clicked"=> sub{
460
                my $entry_ref=$_[1];
461
                my $file;
462
                my $dialog = gen_folder_dialog('Select tile directory');
463
                if ( "ok" eq $dialog->run ) {
464
                        $file = $dialog->get_filename;
465 43 alirezamon
            $$entry_ref->set_text($file);
466
            $mpsoc->object_add_attribute('setting','soc_path',$file);
467
            $mpsoc->mpsoc_remove_all_soc();
468
            set_gui_status($mpsoc,"ref",1);
469
            #check_input_file($file,$socgen,$info);
470
                    #print "file = $file\n";
471 48 alirezamon
                }
472
        $dialog->destroy;
473 16 alirezamon
 
474 43 alirezamon
    } , \$entry);
475 48 alirezamon
 
476 43 alirezamon
 
477
    $entry->signal_connect("activate"=>sub{
478
        my $file_name=$entry->get_text();
479
        $mpsoc->object_add_attribute('setting','soc_path',$file_name);
480
        $mpsoc->mpsoc_remove_all_soc();
481
        set_gui_status($mpsoc,"ref",1);
482
        #check_input_file($file_name,$socgen,$info);
483
    });
484
 
485
 
486
 
487
    if($show){
488
        my $tmp=gen_label_in_left(" ");
489
        $table->attach  ($label, 0, 1 , $row,$row+1,'fill','shrink',2,2);
490
        $table->attach ($tmp, 1, 2 , $row,$row+1,'fill','shrink',2,2);
491
        $table->attach ($entry, 2, 3 , $row,$row+1,'fill','shrink',2,2);
492
        $table->attach ($browse, 3, 4, $row,$row+1,'fill','shrink',2,2);
493
        $row++;
494
    }
495
 
496
 
497
 
498
    my @socs=$mpsoc->mpsoc_get_soc_list();
499
    if( scalar @socs == 0){
500
        @socs=get_soc_list($mpsoc,$info);
501
 
502
    }
503
    @socs=$mpsoc->mpsoc_get_soc_list();
504 46 alirezamon
 
505 43 alirezamon
 
506
 
507
    my $lab1=gen_label_in_center(' Tile name');
508
 
509
    my $lab2=gen_label_help('Define the tile numbers that each IP is mapped to.
510 16 alirezamon
you can add individual numbers or ranges as follow
511 48 alirezamon
    e.g. individual numbers: 5,6,7,8,9,10
512
    e.g. range: 5:10
513 43 alirezamon
    ', ' Tile numbers ');
514
    if($show){
515
        $table->attach_defaults ($lab1 ,0,1, $row,$row+1);
516
        $table->attach_defaults ($lab2 ,2,3, $row,$row+1);$row++;
517
    }
518
 
519
    my $soc_num=0;
520
    foreach my $soc_name (@socs){
521
        $row=tile_set_widget ($mpsoc,$soc_name,$soc_num,$table,$show,$row);
522
        $soc_num++;
523
 
524
    }
525
    return $row;
526
 
527 16 alirezamon
}
528
 
529
 
530
 
531
 
532
#######################
533
#   noc_config
534
######################
535
 
536 48 alirezamon
 
537
sub noc_topology_setting_gui {
538
        my ($mpsoc,$table,$txview,$row,$show_noc)=@_;
539
        my $coltmp=0;
540
        #  topology
541
        my  $label='Topology';
542
        my  $param='TOPOLOGY';
543
        my  $default='"MESH"';
544
        my  $content='"MESH","FMESH","TORUS","RING","LINE","FATTREE","TREE","STAR","CUSTOM"';
545
        my  $type='Combo-box';
546
        my  $info="NoC topology";
547
        ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',1);
548
 
549
    my $topology=$mpsoc->object_get_attribute('noc_param','TOPOLOGY');
550
 
551
        if($topology ne '"CUSTOM"' ){
552
    #topology T1 parameter
553
            $label=
554
                ($topology eq '"FATTREE"' || $topology eq '"TREE"')? 'K' :
555
                ($topology eq '"STAR"')? "Total Endpoint number" : 'Routers per row';
556
            $param= 'T1';
557
                $default= '2';
558
            $content=
559
            ($topology eq '"MESH"'  || $topology eq '"TORUS"') ? '2,16,1':
560
            ($topology eq '"FMESH"')? '1,16,1':
561
                ($topology eq '"FATTREE"' || $topology eq '"TREE"' )? '2,6,1':'2,64,1';
562
            $info= ($topology eq '"FATTREE"' || $topology eq '"TREE"' )? 'number of last level individual router`s endpoints.' :'Number of NoC routers in row (X dimension)';
563
            $type= 'Spin-button';
564
            ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',1);
565
 
566 43 alirezamon
 
567 48 alirezamon
    #Topology T2 parameter
568
    if($topology eq '"MESH"' || $topology eq '"FMESH"' || $topology eq '"TORUS"' || $topology eq '"FATTREE"' || $topology eq '"TREE"' ) {
569
        $label= ($topology eq '"FATTREE"' || $topology eq '"TREE"')?  'L' :'Routers per column';
570
        $param= 'T2';
571
        $default='2';
572
        $content=  ($topology eq '"FMESH"')? '1,16,1': '2,16,1';
573
        $info= ($topology eq '"FATTREE"' || $topology eq '"TREE"')? 'Fattree layer number (The height of FT)':'Number of NoC routers in column (Y dimension)';
574
        $type= 'Spin-button';
575
        ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',1);
576
    } else {
577
        $mpsoc->object_add_attribute('noc_param','T2',1);
578
    }
579
 
580
    #Topology T3 parameter
581
    if($topology eq '"MESH"' || $topology eq '"FMESH"' || $topology eq '"TORUS"' || $topology eq '"RING"' || $topology eq '"LINE"') {
582
        $label="Router's endpoint number";
583
                $param= 'T3';
584
        $default='1';
585
        $content='1,4,1';
586
        $info= "In $topology topology, each router can have up to 4 endpoint processing tile.";
587
        $type= 'Spin-button';
588
        ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',1);
589
    }
590
 
591
 
592
 
593
 
594
        }else{#its a custom Topology
595
                ($row,$coltmp)=config_custom_topology_gui($mpsoc,$table,$txview,$row);
596
        }
597
        return ($row,$coltmp);
598 16 alirezamon
 
599 48 alirezamon
}
600
 
601
 
602
 
603
sub noc_config{
604
    my ($mpsoc,$table,$txview)=@_;
605 43 alirezamon
 
606
    #title    
607
    my $row=0;
608
    my $title=gen_label_in_center("NoC Configuration");
609
    $table->attach ($title , 0, 4,  $row, $row+1,'expand','shrink',2,2); $row++;
610 48 alirezamon
        add_Hsep_to_table ($table,0,4,$row); $row++;
611
 
612 43 alirezamon
    my $label;
613
    my $param;
614
    my $default;
615
    my $type;
616
    my $content;
617
    my $info;
618
 
619
 
620
    #parameter start
621
    my $b1;
622
    my $show_noc=$mpsoc->object_get_attribute('setting','show_noc_setting');
623
    if(!defined $show_noc){
624
        $show_noc=1;
625
        $mpsoc->object_add_attribute('setting','show_noc_setting',$show_noc);
626
 
627
    }
628
    if($show_noc == 0){
629
        $b1= def_image_button("icons/down.png","NoC Parameters");
630
        $label=gen_label_in_center(' ');
631
        $table->attach  ( $label , 2, 3, $row,$row+1 ,'fill','shrink',2,2);
632
        $table->attach  ( $b1 , 0, 2, $row,$row+1,'fill','shrink',2,2);
633
        $row++;
634
    }
635
 
636
    my $coltmp=0;
637
 
638
    #Router type
639
    $label='Router Type';
640
    $param='ROUTER_TYPE';
641
    $default='"VC_BASED"';
642
    $content='"INPUT_QUEUED","VC_BASED"';
643
    $type='Combo-box';
644 22 alirezamon
    $info="    Input-queued: simple router with low performance and does not support fully adaptive routing.
645
    VC-based routers offer higher performance, fully adaptive routing  and traffic isolation for different packet classes.";
646 43 alirezamon
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_type',1);
647
    my $router_type=$mpsoc->object_get_attribute('noc_type',"ROUTER_TYPE");
648
 
649
 
650 48 alirezamon
    ($row,$coltmp) =noc_topology_setting_gui($mpsoc,$table,$txview,$row,$show_noc);
651
     my $topology=$mpsoc->object_get_attribute('noc_param','TOPOLOGY');
652
 
653 43 alirezamon
    #VC number per port
654
    if($router_type eq '"VC_BASED"'){
655
        my $v=$mpsoc->object_get_attribute('noc_param','V');
656
        if(defined $v){ $mpsoc->object_add_attribute('noc_param','V',2) if($v eq 1);}
657
        $label='VC number per port';
658
        $param='V';
659
        $default='2';
660
        $type='Spin-button';
661
        $content='2,16,1';
662 48 alirezamon
        $info='Number of Virtual chanel per each router port';
663 43 alirezamon
        ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',1);
664
    } else {
665
        $mpsoc->object_add_attribute('noc_param','V',1);
666
        $mpsoc->object_add_attribute('noc_param','C',0);
667
    }
668
 
669
    #buffer width per VC
670
    $label=($router_type eq '"VC_BASED"')? 'Buffer flits per VC': "Buffer flits";
671
    $param='B';
672 16 alirezamon
    $default='4';
673
    $content='2,256,1';
674
    $type='Spin-button';
675 43 alirezamon
    $info=($router_type eq '"VC_BASED"')?  'Buffer queue size per VC in flits' : 'Buffer queue size in flits';
676
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',undef);
677
 
678 48 alirezamon
 
679
    #Local port buffer width per VC
680
    $label=($router_type eq '"VC_BASED"')? 'Local port Buffer flits per VC': "Local Port Buffer flits";
681
    $param='LB';
682
    $default='4';
683
    $content='2,256,1';
684
    $type='Spin-button';
685
    $info = "The Local router ports buffer width (LB) is the width of the ports connected to the endpoints and can take different buffer sizes than other routers ports buffer width (B) connected to neighboring routers .It is valid only for MESH,FMESH, TORUS,LINE and RING topologies. In FMESH topology, this parameter does not affect the  width of extra endpoints connected to edge routers.";
686
 
687
    if ($topology eq '"MESH"' || $topology eq '"FMESH"' || $topology eq '"TORUS"' || $topology eq '"RING"' || $topology eq '"LINE"'){
688
                ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',undef);
689
    }else{
690
        $mpsoc->object_add_attribute('noc_param','LB','B');
691
    }
692
 
693
 
694
 
695
 
696 43 alirezamon
    #packet payload width
697
    $label='Payload width';
698
    $param='Fpay';
699
    $default='32';
700
    $content='32,256,32';
701
    $type='Spin-button';
702 16 alirezamon
    $info="The packet payload width in bits";
703 43 alirezamon
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info,$table,$row,undef,$show_noc,'noc_param',undef);
704 16 alirezamon
 
705 48 alirezamon
if($topology ne '"CUSTOM"' ){
706 43 alirezamon
    #routing algorithm
707
    $label='Routing Algorithm';
708
    $param="ROUTE_NAME";
709
    $type="Combo-box";
710
    if($router_type eq '"VC_BASED"'){
711 48 alirezamon
        $content=($topology eq '"MESH"' || $topology eq '"FMESH"')?  '"XY","WEST_FIRST","NORTH_LAST","NEGETIVE_FIRST","ODD_EVEN","DUATO"' :
712 43 alirezamon
                 ($topology eq '"TORUS"')? '"TRANC_XY","TRANC_WEST_FIRST","TRANC_NORTH_LAST","TRANC_NEGETIVE_FIRST","TRANC_DUATO"':
713
                 ($topology eq '"RING"')? '"TRANC_XY"' :
714
                 ($topology eq '"LINE"')?  '"XY"':
715
                 ($topology eq '"FATTREE"')? '"NCA_RND_UP","NCA_STRAIGHT_UP","NCA_DST_UP"':
716
                 ($topology eq '"TREE"')? '"NCA"' : '"UNKNOWN"';
717
    }else{
718 48 alirezamon
        $content=($topology eq '"MESH"' || $topology eq '"FMESH"')?  '"XY","WEST_FIRST","NORTH_LAST","NEGETIVE_FIRST","ODD_EVEN"' :
719 43 alirezamon
                 ($topology eq '"TORUS"')? '"TRANC_XY","TRANC_WEST_FIRST","TRANC_NORTH_LAST","TRANC_NEGETIVE_FIRST"':
720
                 ($topology eq '"RING"')? '"TRANC_XY"' :
721
                                 ($topology eq '"LINE"')?  '"XY"':
722
                 ($topology eq '"FATTREE"')? '"NCA_RND_UP","NCA_STRAIGHT_UP","NCA_DST_UP"' :
723
                                 ($topology eq '"TREE"')? '"NCA"' : '"UNKNOWN"';
724
 
725
    }
726 48 alirezamon
    $default=($topology eq '"MESH"' || $topology eq '"FMESH"' || $topology eq '"LINE"' )? '"XY"':
727 43 alirezamon
                 ($topology eq '"TORUS"'|| $topology eq '"RING"')?  '"TRANC_XY"' :
728
                 ($topology eq '"FATTREE"')? '"NCA_STRAIGHT_UP"' :
729
                 ($topology eq '"TREE"')? '"NCA"' : '"UNKNOWN"';
730
 
731
    my $info_mesh="Select the routing algorithm: XY(DoR) , partially adaptive (Turn models). Fully adaptive (Duato) ";
732 48 alirezamon
    my $info_fat="Nearest common ancestor (NCA) where the up port is selected randomly (RND), based on destination endpoint address (DST) or it is the top port that is located in front of the port which has received the packet (STRAIGHT) ";
733 43 alirezamon
 
734
    $info=($topology eq '"FATTREE"')? $info_fat :
735
          ($topology eq '"TREE"') ? "Nearest common ancestor": $info_mesh;
736 48 alirezamon
    my $show_routing =($topology eq '"STAR"' )? 0 : $show_noc;
737
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_routing,'noc_param',1);
738 16 alirezamon
 
739 48 alirezamon
}
740 16 alirezamon
 
741 48 alirezamon
        #PCK_TYPE
742
        $label='Packet type';
743
    $param='PCK_TYPE';
744
    $default='"MULTI_FLIT"';
745
    $content='"MULTI_FLIT","SINGLE_FLIT"';
746
    $type="Combo-box";
747
    $info="Define packet type: SINGLE_FLIT: all packets send to NoC are single-flit sized.
748
    Multi-flit: packets can be consists of one or several flits. A multi-flit packet can be
749
        a)single-flit sized : both headr and tail flag must be asserted for this flit,
750
        b)two-flit sized: a header flit and a tail flit, or
751
        c)more than 2 fits: start with a headr flit, continued with one or more body flits and end up with a tail flit
752
        For MULTI-FLIT packet you need to defin ethe minum size of a paket that can be injecte to the NoC.
753
    ";
754
 
755
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',1);
756
 
757
         my $pck_type=$mpsoc->object_get_attribute('noc_param','PCK_TYPE');
758
 
759
        if($pck_type eq '"MULTI_FLIT"'){
760 25 alirezamon
 
761 48 alirezamon
                #MIN_PCK_SIZE 
762
                # 2 //minimum packet size in flits. The minimum value is 1. 
763
                $label='Minimum packet size';
764
            $param='MIN_PCK_SIZE';
765
            $default='2';
766
            $content='1,65535,1';
767
            $type='Spin-button';
768
            $info="The minimum packet size in flits. In atomic VC re-allocation, it is just important to define if the single-flit sized packets are allowed to be injected to the NoC by defining this parameter value as one.  Setting any larger value than one results in the same architecture and the NoC works correctly even if it receives smaller packets size as while as they are not single flit -sized packets.  However, for non-atomic VC reallocation NoCs, you have to define the exact value as it defines the NoC control registers' internal buffers. The NoC may crash once it receives  packets having smaler size than the defined  minimum packet size.";
769
            ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',undef);
770
        }else{
771
                 $mpsoc->object_add_attribute('noc_param','MIN_PCK_SIZE',1);
772
        }
773 25 alirezamon
 
774 48 alirezamon
    # BYTE_EN
775
    $label='Byte Enable';
776
    $param='BYTE_EN';
777
    $default= 0;
778
    $info='0:disable, 1: enable. Add byte enable (BE) filed to header flit which shows the location of last valid byte in tail flit. It is needed once the send data unit is smaller than Fpay.';
779
    $content='0,1';
780
    $type="Combo-box";
781
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param');
782 43 alirezamon
 
783 54 alirezamon
 
784
 
785
 
786
 
787
    #CAST_TYPE
788
    $label='Casting Type';
789
    $param='CAST_TYPE';
790
    $default= '"UNICAST"';
791
    $info='Configure a NoC as Unicast, Multicast, or Broadcast NoC. In Unicast NoC, a packet can be sent to only one destination. In  Multicast, a single packet can have multiple target destination nodes, whereas,  Broadcast packets are sent to all other destination nodes. For Multicast and Broadcast NoC, only one copy of a packet must be injected into the source router. The routers in the path then fork the packets to different output ports when necessary. Multicast and Broadcast can be selected as FULL, where all destinations can be included in packet destination list, or as PARTIAL where a user-defined subset of nodes (defined with MCAST_ENDP_LIST parameter) can be targeted in destination lists. The other nodes not marked in MCAST_ENDP_LIST can only receive unicast packets. ';
792
    $content='"UNICAST","MULTICAST_PARTIAL","MULTICAST_FULL","BROADCAST_PARTIAL","BROADCAST_FULL"';
793
    $type="Combo-box";
794
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$show_noc,'noc_param',1);
795
 
796
 
797
    my $cast_type=$mpsoc->object_get_attribute('noc_param','CAST_TYPE');
798
    my ($NE, $NR, $RAw, $EAw, $Fw) = get_topology_info($mpsoc);
799
 
800
    my $cast = $mpsoc->object_get_attribute('noc_param',"MCAST_ENDP_LIST");
801
    if(!defined $cast){
802
            my $h=0;
803
            my $n="";
804
            for (my $i=0; $i<$NE; $i++){
805
                        $h+= (1<<$i%4);
806
                        if(($i+1) % 4==0){
807
                                $n="$h".$n if($h<10);
808
                                $n=chr($h-10+97).$n if($h>9);
809
                                $h=0;
810
                        }
811
                }
812
                $n="$h".$n if($h!=0);
813
                $n="'h".$n;
814
                $mpsoc->object_add_attribute('noc_param',"MCAST_ENDP_LIST",$n);
815
                $mpsoc->object_add_attribute_order('noc_param',"MCAST_ENDP_LIST");
816
        #       $mpsoc->object_add_attribute('noc_param',"MCAST_PRTLw",$NE);
817
        #       $mpsoc->object_add_attribute_order('noc_param',"MCAST_PRTLw");
818
                $cast=$n;
819 43 alirezamon
    }
820 54 alirezamon
 
821
    if($cast_type eq '"MULTICAST_PARTIAL"' || $cast_type eq '"BROADCAST_PARTIAL"') {
822
        #$table->attach  ( gen_label_help($info,"Muticast Node list"),0 , 2, $row,$row+1,'fill','shrink',2,2);    
823
        $info='MCAST_ENDP_LIST is a one-hot coded number where the asserted bit indicates that the corresponding destination ID can be targeted in multicast/broadcast packets. The corresponding destinations with zero bit can only receive unicast packets.';
824
 
825
        my $b1= def_image_button("icons/setting.png","Set");
826
        my $bb= def_pack_hbox(FALSE,0,gen_label_in_left("$cast"),$b1);
827
        my $label=gen_label_in_left("Muticast Node list");
828
        my $inf_bt= (defined $info)? gen_button_message ($info,"icons/help.png"):gen_label_in_left(" ");
829
                attach_widget_to_table ($table,$row,$label,$inf_bt,$bb,0);
830
 
831
 
832
       # $table->attach  ( $bb , 2, 3, $row,$row+1,'fill','shrink',2,2);
833
        $row++;
834
 
835
         $b1->signal_connect("clicked" => sub{
836
                set_multicast_list($mpsoc);
837
 
838
                 });
839 43 alirezamon
    }
840
 
841
 
842 54 alirezamon
 
843
    #advance parameter start
844
   # my $advc;
845
   # my $adv_set=$mpsoc->object_get_attribute('setting','show_adv_setting');
846
   #
847
   # if($adv_set == 0){    
848
   #     $advc= def_image_button("icons/down.png","Advance Parameters");
849
   #     $table->attach ( $advc , 0, 2, $row,$row+1,'fill','shrink',2,2);
850
   #     $row++;    
851
   # }
852
 
853
    my $adv_set= $show_noc;
854 48 alirezamon
    #SSA
855
    $label='SSA Enable';
856
    $param='SSA_EN';
857
    $default='"NO"';
858
    $content='"YES","NO"';
859
    $type='Combo-box';
860
    $info="Enable single cycle latency on packets traversing in the same direction using static straight allocator (SSA)";
861
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param',undef);
862
 
863
    #SMART
864
    $label='Max Straight Bypass';
865
    $param='SMART_MAX';
866
    $default='0';
867
    $content="0,1,2,3,4,5,6,7,8,9";
868
    $type='Combo-box';
869
    $info="If Max Straight Bypass (SMART_MAX) is defined as n>0 then packets are allowed to bypass Maximum of n routers in Straight direction in single cycle.";
870
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param',undef);
871
 
872
 
873
 
874 43 alirezamon
    #Fully and partially adaptive routing setting
875
    my $route=$mpsoc->object_get_attribute('noc_param',"ROUTE_NAME");
876
    $label="Congestion index";
877
    $param="CONGESTION_INDEX";
878
    $type="Spin-button";
879
    $content="0,12,1";
880
    $info="Congestion index determines how congestion information is collected from neighboring routers. Please refer to the usere manual for more information";
881
    $default=3;
882 48 alirezamon
    if($topology ne '"CUSTOM"' && $route ne '"XY"' && $route ne '"TRANC_XY"' ){
883 43 alirezamon
           ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param',undef);
884
    } else {
885
        ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,0,'noc_param',undef);
886
    }
887
 
888
    #Fully adaptive routing setting
889
    my $v=$mpsoc->object_get_attribute('noc_param',"V");
890
    $label="Select Escap VC";
891
    $param="ESCAP_VC_MASK";
892
    $type="Check-box";
893
    $content=$v;
894
    $default="$v\'b";
895
    for (my $i=1; $i<=$v-1; $i++){$default=  "${default}0";}
896
    $default=  "${default}1";
897
    $info="Select the escap VC for fully adaptive routing.";
898
    if( $route eq '"TRANC_DUATO"' or $route eq '"DUATO"'  ){
899
           ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set, 'noc_param',undef);
900
     }
901
    else{
902
         ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,0, 'noc_param',undef);
903
    }
904
 
905
    # VC reallocation type
906
    $label=($router_type eq '"VC_BASED"')? 'VC reallocation type': 'Queue reallocation type';
907
    $param='VC_REALLOCATION_TYPE';
908 38 alirezamon
    $info="VC reallocation type: If set as atomic only empty VCs can be allocated for new packets. Whereas, in non-atomic a non-empty VC which has received the last packet tail flit can accept a new  packet";
909
    $default='"NONATOMIC"';
910
    $content='"ATOMIC","NONATOMIC"';
911
    $type='Combo-box';
912 43 alirezamon
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param',undef);
913 16 alirezamon
 
914
 
915 43 alirezamon
    #vc/sw allocator type
916
    $label = 'VC/SW combination type';
917
    $param='COMBINATION_TYPE';
918 38 alirezamon
    $default='"COMB_NONSPEC"';
919
    $content='"BASELINE","COMB_SPEC1","COMB_SPEC2","COMB_NONSPEC"';
920
    $type='Combo-box';
921 48 alirezamon
    $info="The joint VC/ switch allocator type. using canonical combination is not recommended";
922 43 alirezamon
    if ($router_type eq '"VC_BASED"'){
923
        ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param',undef);
924
    } else{
925
         ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,0,'noc_param',undef);
926
    }
927 38 alirezamon
 
928 43 alirezamon
    # Crossbar mux type 
929
    $label='Crossbar mux type';
930
    $param='MUX_TYPE';
931
    $default='"BINARY"';
932
    $content='"ONE_HOT","BINARY"';
933
    $type='Combo-box';
934
    $info="Crossbar multiplexer type";
935
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param',undef);
936
 
937 38 alirezamon
    #class   
938 43 alirezamon
    if($router_type eq '"VC_BASED"'){
939
        $label='class number';
940
        $param='C';
941
        $default= 0;
942
        $info='Number of message classes. Each specific class can use different set of VC';
943
        $content='0,16,1';
944
        $type='Spin-button';
945
        ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param',5);
946
 
947 16 alirezamon
 
948 43 alirezamon
        my $class=$mpsoc->object_get_attribute('noc_param',"C");
949
        my $v=$mpsoc->object_get_attribute('noc_param',"V");
950
        $default= "$v\'b";
951
        for (my $i=1; $i<=$v; $i++){
952
            $default=  "${default}1";
953
        }
954
        #print "\$default=$default\n";
955
        for (my $i=0; $i<=$class-1; $i++){
956
 
957
             $label="Class $i Permitted VCs";
958
               $param="Cn_$i";
959
               $type="Check-box";
960
               $content=$v;
961
               $info="Select the permitted VCs which the message class $i can be sent via them.";
962
               ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'class_param',undef);
963
        }
964
 
965
    }#($router_type eq '"VC_BASED"')
966
 
967
 
968 16 alirezamon
 
969 43 alirezamon
    #simulation debuge enable     
970
    $label='Debug enable';
971
    $param='DEBUG_EN';
972 48 alirezamon
    $info= "Add extra Verilog code for debugging NoC for simulation";
973 43 alirezamon
    $default='0';
974
    $content='0,1';
975
    $type='Combo-box';
976
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param');
977 16 alirezamon
 
978 43 alirezamon
 
979
    #pipeline reg    
980
    $label="Add pipeline reg after crossbar";
981
    $param="ADD_PIPREG_AFTER_CROSSBAR";
982
    $type="Check-box";
983
    $content=1;
984
    $default="1\'b0";
985 48 alirezamon
    $info="If is enabled it adds a pipeline register at the output port of the router.";
986 43 alirezamon
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param');
987
 
988
 
989 48 alirezamon
    #MAX_SMART_NUM = 4 // 
990 43 alirezamon
    $label="Number of multiple router bypassing ";
991 48 alirezamon
    $param="MAX_SMART_NUM ";
992 43 alirezamon
    $type='Spin-button';
993
    $content='0,1,1';
994
    $default=0;
995
    $info="maximum number of routers which a packet can by pass during one clock cycle. Define it as zero will disable bypassing.";
996
    #($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param');
997
 
998
 
999
    #FIRST_ARBITER_EXT_P_EN
1000
    $label='Swich allocator first level
1001 42 alirezamon
arbiters external priority enable';
1002 43 alirezamon
    $param='FIRST_ARBITER_EXT_P_EN';
1003
    $default= 1;
1004
    $info='If set as 1 then the switch allocator\'s input (first) arbiters\' priority registers are enabled only when a request get both input and output arbiters\' grants';
1005
    $content='0,1';
1006
    $type="Combo-box";
1007
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info,$table,$row,undef,$adv_set,'noc_param');
1008
 
1009
 
1010
    #Arbiter type
1011
    $label='SW allocator arbitration type';
1012
    $param='SWA_ARBITER_TYPE';
1013
    $default='"RRA"';
1014
    $content='"RRA","WRRA"'; #,"WRRA_CLASSIC"';
1015
    $type='Combo-box';
1016 48 alirezamon
    $info="Switch allocator arbiter type:
1017 38 alirezamon
    RRA: Round robin arbiter. Only local fairness in a router.
1018
    WRRA: Weighted round robin arbiter. Results in global fairness in the NoC.
1019 48 alirezamon
          Switch allocation requests are grated according to their weight which increases due to contention";
1020 43 alirezamon
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param',1);
1021
 
1022
 
1023
 
1024 38 alirezamon
    my $arbiter=$mpsoc->object_get_attribute('noc_param',"SWA_ARBITER_TYPE");
1025
    my $wrra_show = ($arbiter ne  '"RRA"' && $adv_set == 1 )? 1 : 0;
1026 43 alirezamon
    # weight width
1027
    $label='Weight width';
1028
    $param='WEIGHTw';
1029
    $default='4';
1030
    $content='2,7,1';
1031
    $info= 'Maximum weight width';
1032
    $type= 'Spin-button';
1033
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$wrra_show,'noc_param',undef);
1034
 
1035 48 alirezamon
 
1036
 
1037
    $label='Self loop enable';
1038
    $param='SELF_LOOP_EN';
1039
    $default='"NO"';
1040
    $content='"NO","YES"';
1041
    $type='Combo-box';
1042
    $info="If the self loop is enabled, it allows a router input port sends packet to its own output port. Enabling it allows a tile to be able to sent packet to itself too.";
1043
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,$adv_set,'noc_param',1);
1044
 
1045
 
1046
 
1047 43 alirezamon
    #WRRA_CONFIG_INDEX
1048
    $label='Weight configuration index';
1049
    $param='WRRA_CONFIG_INDEX';
1050
    $default='0';
1051
    $content='0,7,1';
1052
    $info= 'WRRA_CONFIG_INDEX:
1053 16 alirezamon
 
1054 38 alirezamon
';
1055 43 alirezamon
    $type= 'Spin-button';
1056
    #($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$wrra_show,'noc_param',undef);  
1057 38 alirezamon
 
1058 43 alirezamon
 
1059 54 alirezamon
    if($show_noc == 1){
1060
        $b1= def_image_button("icons/up.png","NoC Parameters");
1061
        $table->attach  ( $b1 , 0, 2, $row,$row+1,'fill','shrink',2,2);
1062
        $row++;
1063 43 alirezamon
    }
1064 54 alirezamon
    $b1->signal_connect("clicked" => sub{
1065
        $show_noc=($show_noc==1)?0:1;
1066
        $mpsoc->object_add_attribute('setting','show_noc_setting',$show_noc);
1067 43 alirezamon
        set_gui_status($mpsoc,"ref",1);
1068
    });
1069
 
1070
 
1071 54 alirezamon
 
1072
 
1073
  #  if($adv_set == 1){    
1074
  #      $advc= def_image_button("icons/up.png","Advance Parameters");
1075
  #      $table->attach ( $advc , 0, 2, $row,$row+1,'fill','shrink',2,2);
1076
  #      $row++;
1077
  #  }
1078
  #  $advc->signal_connect("clicked" => sub{ 
1079
  #      $adv_set=($adv_set==1)?0:1;
1080
  #      $mpsoc->object_add_attribute('setting','show_adv_setting',$adv_set);
1081
   #     set_gui_status($mpsoc,"ref",1);
1082
  #  });
1083
 
1084
 
1085 43 alirezamon
    #other fixed parameters       
1086
 
1087
 
1088
    # AVC_ATOMIC_EN
1089
    $label='AVC_ATOMIC_EN';
1090
    $param='AVC_ATOMIC_EN';
1091
    $default= 0;
1092
    $info='AVC_ATOMIC_EN';
1093
    $content='0,1';
1094
    $type="Combo-box";
1095
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,0,'noc_param');
1096
 
1097
 
1098
    #ROUTE_SUBFUNC
1099
    #$label='ROUTE_SUBFUNC';
1100
    #$param='ROUTE_SUBFUNC';
1101
    #$default= '"XY"';
1102
    #$info='ROUTE_SUBFUNC'; 
1103
    #$content='"XY"';
1104
    #$type="Combo-box";
1105
    #($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,0,'noc_param');
1106
 
1107
    return $row;
1108 25 alirezamon
}
1109
 
1110
 
1111 54 alirezamon
 
1112
 
1113
sub set_multicast_list{
1114
        my($mpsoc)=@_;
1115
        my $window = def_popwin_size(50,40,"Select nodes invlove in multicasting ",'percent');
1116
        my $table= def_table(10,10,FALSE);
1117
        my $row=0;
1118
        my $col=0;
1119
 
1120
        my $init = $mpsoc->object_get_attribute('noc_param',"MCAST_ENDP_LIST");
1121
        $init =~ s/'h//g;
1122
        my @arr= reverse split (//, $init);
1123
 
1124
 
1125
        my $label = "Multicast Node list (hex fromat)";
1126
    my ($Ebox,$entry) = def_h_labeled_entry ($label);
1127
        $entry->set_sensitive (FALSE);
1128
 
1129
        my @sel_options= ("Select","All","None","2n","3n","4n","2n+1","3n+1","3n+2","4n+1","4n+2","4n+3");
1130
        my $combo= gen_combo(\@sel_options, 0);
1131
        $table->attach ($combo , 0, 1, $row,$row+1,'fill','shrink',2,2);
1132
        #get the number of endpoints
1133
        my ($NE, $NR, $RAw, $EAw, $Fw) = get_topology_info($mpsoc);
1134
        my @check;
1135
 
1136
 
1137
 
1138
        my $sel_val="Init";
1139
        for (my $i=0; $i<$NE; $i++){
1140
                if($i%10 == 0){  $row++;$col=0;}
1141
                my $box;
1142
                my $l=$NE -$i-1;
1143
 
1144
                my $char = $arr[$l/4];
1145
                $char=0 if (!defined $char);
1146
                my $hex = hex($char);
1147
                my $bit = ($hex >> ($l%4)) & 1;
1148
                ($box,$check[$l])=def_h_labeled_checkbutton("$l");
1149
                $table->attach ($box , $col, $col+1, $row,$row+1,'fill','shrink',2,2);
1150
                $col++;
1151
 
1152
                if($bit==1){
1153
                        $check[$l]->set_active(TRUE);
1154
                }
1155
 
1156
                $check[$l]-> signal_connect("toggled" => sub{
1157
                        get_multicast_val ($mpsoc,$entry,$NE,@check)if($sel_val eq "Select");
1158
                });
1159
        }
1160
        $row++;
1161
        $col=0;
1162
 
1163
        $sel_val="Select";
1164
        get_multicast_val ($mpsoc,$entry,$NE,@check);
1165
 
1166
        $combo-> signal_connect("changed" => sub{
1167
                $sel_val=$combo->get_active_text();
1168
                my $n=1;
1169
                my $r=0;
1170
                return if ($sel_val eq "Select");
1171
                if ($sel_val eq "None"){
1172
                        for (my $i=0; $i<$NE; $i++){$check[$i]->set_active(FALSE)};
1173
                        get_multicast_val ($mpsoc,$entry,$NE,@check);
1174
                        $combo->set_active(0);
1175
                        return;
1176
                }
1177
                ($n,$r)=sscanf("%dn+%d",$sel_val);
1178
                if(!defined $r){
1179
                        ($n,$r)=sscanf("%dn",$sel_val);
1180
                        $r=0;
1181
                        $n=1 if(!defined $n);
1182
                }
1183
 
1184
                for (my $i=0; $i<$NE; $i++){
1185
                        if($i % $n == $r){  $check[$i]->set_active(TRUE);}
1186
                }
1187
                $combo->set_active(0);
1188
                get_multicast_val ($mpsoc,$entry,$NE,@check);
1189
 
1190
         });
1191
 
1192
 
1193
 
1194
        $table->attach ($Ebox , 0, 10, $row,$row+1,'fill','shrink',2,2);$row++;
1195
 
1196
        my $main_table=def_table(10,10,FALSE);
1197
 
1198
        my $ok = def_image_button('icons/select.png','OK');
1199
        $main_table->attach_defaults ($table  , 0, 12, 0,11);
1200
    $main_table->attach ($ok,5, 6, 11,12,'shrink','shrink',0,0);
1201
 
1202
        $ok->signal_connect('clicked', sub {
1203
                my $s=get_multicast_val ($mpsoc,$entry,$NE,@check);
1204
                my $n=$entry->get_text( );
1205
                $mpsoc->object_add_attribute('noc_param',"MCAST_ENDP_LIST",$n);
1206
        #       $mpsoc->object_add_attribute('noc_param',"MCAST_PRTLw",$s);
1207
                set_gui_status($mpsoc,"ref",1);
1208
                $window->destroy;
1209
        });
1210
 
1211
 
1212
 
1213
 
1214
        my $scrolled_win = gen_scr_win_with_adjst($mpsoc,'gen_multicast');
1215
        add_widget_to_scrolled_win($main_table,$scrolled_win);
1216
        $window->add($scrolled_win);
1217
        $window->show_all();
1218
}
1219
 
1220
sub get_multicast_val {
1221
        my ($mpsoc,$entry,$NE,@check)=@_;
1222
        my $n="";
1223
        my $h=0;
1224
        my $s=0;
1225
        for (my $i=0; $i<$NE; $i++){
1226
                        if($check[$i]->get_active()){$h+= (1<<$i%4);$s++;}
1227
                if(($i+1) % 4==0){
1228
                        $n="$h".$n if($h<10);
1229
                        $n=chr($h-10+97).$n if($h>9);
1230
                        $h=0;
1231
                }
1232
        }
1233
 
1234
        $n="$h".$n if($NE%4!=0);
1235
        $n="'h".$n;
1236
        $entry->set_text("$n");
1237
        return $s;
1238
 
1239
}
1240 48 alirezamon
#############
1241
# config_custom_topology_gui
1242
############
1243
 
1244
sub config_custom_topology_gui{
1245
        my($mpsoc,$table,$txview,$row)=@_;
1246
 
1247
my $coltmp=0;
1248
#read param.obj file to load cutom topology info
1249
        my $dir =get_project_dir()."/mpsoc/rtl/src_topolgy";
1250
        my $file="$dir/param.obj";
1251
        unless (-f $file){
1252
                 add_colored_info($txview,"No Custom topology find in $dir. You can define a Custom Topology using ProNoC Topology maker.\n",'red');
1253
                 return;
1254
        }
1255
 
1256
        my %param;
1257
    my ($pp,$r,$err) = regen_object($file );
1258
    if ($r){
1259
         add_colored_info($txview,"Error: cannot open $file file: $err\n",'red');
1260
         return;
1261
    }
1262
 
1263
        %param=%{$pp};
1264
        my @topologies=sort keys %param;
1265
 
1266
        my $label='Topology_name';
1267
    my $param='CUSTOM_TOPOLOGY_NAME';
1268
    my $default=$topologies[0];
1269
    my $content= join(",", @topologies);
1270
    my $type='Combo-box';
1271
    my $info="Custom topology name";
1272
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,1,'noc_param',1);
1273
 
1274
    my $topology_name=$mpsoc->object_get_attribute('noc_param','CUSTOM_TOPOLOGY_NAME');
1275
 
1276
 
1277
        $label='Routing Algorithm';
1278
    $param="ROUTE_NAME";
1279
    $type="Combo-box";
1280
    $content=$param{$topology_name}{'ROUTE_NAME'};
1281
    my @rr=split(/\s*,\s*/,$content);
1282
    $default=$rr[0];
1283
    $info="Select the routing algorithm";
1284
    ($row,$coltmp)=add_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,undef,1,'noc_param',1);
1285
 
1286
        $mpsoc->object_add_attribute('noc_param','T1',$param{$topology_name}{'T1'});
1287
        $mpsoc->object_add_attribute('noc_param','T2',$param{$topology_name}{'T2'});
1288
        $mpsoc->object_add_attribute('noc_param','T3',$param{$topology_name}{'T3'});
1289
        $mpsoc->object_add_attribute('noc_connection','er_addr',$param{$topology_name}{'er_addr'});
1290
 
1291
 
1292
        return ($row,$coltmp);
1293
 
1294
}
1295
 
1296
 
1297
 
1298
 
1299 25 alirezamon
#######################
1300
#   get_config
1301
######################
1302
 
1303
sub get_config{
1304 43 alirezamon
    my ($mpsoc,$info)=@_;
1305
    my $table=def_table(20,10,FALSE);#    my ($row,$col,$homogeneous)=@_;
1306 48 alirezamon
 
1307 25 alirezamon
 
1308 43 alirezamon
    #noc_setting
1309 48 alirezamon
    my $row=noc_config ($mpsoc,$table,$info);
1310 43 alirezamon
 
1311
 
1312
    #tiles setting 
1313
    my $tile_set;
1314
    my $show=$mpsoc->object_get_attribute('setting','show_tile_setting');
1315
 
1316
    if($show == 0){
1317
        $tile_set= def_image_button("icons/down.png","Tiles setting");
1318
        $table->attach ( $tile_set , 0, 2, $row,$row+1,'fill','shrink',2,2);
1319
        $row++;
1320
 
1321
    }
1322
 
1323
    $row=defualt_tilles_setting($mpsoc,$table,$show,$row,$info);
1324
 
1325 16 alirezamon
 
1326 43 alirezamon
    #end tile setting
1327
    if($show == 1){
1328
        $tile_set= def_image_button("icons/up.png","Tiles setting");
1329
        $table->attach ( $tile_set , 0, 2, $row,$row+1,'fill','shrink',2,2);
1330
        $row++;
1331
    }
1332
    $tile_set->signal_connect("clicked" => sub{
1333
        $show=($show==1)?0:1;
1334
        $mpsoc->object_add_attribute('setting','show_tile_setting',$show);
1335
        set_gui_status($mpsoc,"ref",1);
1336 16 alirezamon
 
1337
 
1338 43 alirezamon
    });
1339 16 alirezamon
 
1340 48 alirezamon
    my $scrolled_win = gen_scr_win_with_adjst($mpsoc,'get_config_adj');
1341
        add_widget_to_scrolled_win($table,$scrolled_win);
1342
        return $scrolled_win;
1343 16 alirezamon
}
1344
 
1345
 
1346
#############
1347 43 alirezamon
#  gen_all_tiles
1348 16 alirezamon
###########
1349
 
1350 28 alirezamon
sub gen_all_tiles{
1351 43 alirezamon
    my ($mpsoc,$info, $hw_dir,$sw_dir)=@_;
1352
    my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($mpsoc);
1353
    my $mpsoc_name=$mpsoc->object_get_attribute('mpsoc_name');
1354
    my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name";
1355
    my @generated_tiles;
1356
    for (my $tile_num=0;$tile_num<$NE;$tile_num++){
1357
        #print "$tile_num\n";
1358
        my ($soc_name,$num)= $mpsoc->mpsoc_get_tile_soc_name($tile_num);
1359
        next if(!defined $soc_name);
1360
 
1361
 
1362
        my $path=$mpsoc->object_get_attribute('setting','soc_path');
1363
        $path=~ s/ /\\ /g;
1364
        my $p = "$path/$soc_name.SOC";
1365
            my ($soc,$r,$err) = regen_object($p);
1366
        if ($r){
1367 48 alirezamon
            show_info($info,"**Error reading  $p file: $err\n");
1368 43 alirezamon
            next;
1369
        }
1370
 
1371
        #update core id
1372
        $soc->object_add_attribute('global_param','CORE_ID',$tile_num);
1373
        #update NoC param
1374
        #my %nocparam = %{$mpsoc->object_get_attribute('noc_param',undef)};
1375
        my $nocparam =$mpsoc->object_get_attribute('noc_param',undef);
1376
        my $top=$mpsoc->mpsoc_get_soc($soc_name);
1377
        my @nis=get_NI_instance_list($top);
1378
        $soc->soc_add_instance_param($nis[0] ,$nocparam );
1379 48 alirezamon
        my %z;
1380
        foreach my $p (sort keys %{$nocparam}){
1381
                        $z{$p}="Parameter";
1382
                }
1383
                $soc->soc_add_instance_param_type($nis[0] ,\%z);
1384 43 alirezamon
        #foreach my $p ( sort keys %nocparam ) {
1385
 
1386
        #    print "$p = $nocparam{$p} \n";
1387
        #}
1388 29 alirezamon
 
1389 43 alirezamon
        my $sw_path     = "$sw_dir/tile$tile_num";
1390
        #print "$sw_path\n";
1391
        if( grep (/^$soc_name$/,@generated_tiles)){ # This soc is generated before only create the software file
1392 48 alirezamon
            generate_soc($soc,$info,$target_dir,$hw_dir,$sw_path,0,0,undef,1);
1393 43 alirezamon
        }else{
1394 48 alirezamon
            generate_soc($soc,$info,$target_dir,$hw_dir,$sw_path,0,1,"merge",1);
1395
            move ("$hw_dir/$soc_name.sv","$hw_dir/tiles/");
1396
            my @tmp= ("$hw_dir/tiles/$soc_name.sv");
1397 43 alirezamon
            add_to_project_file_list(\@tmp,"$hw_dir/tiles",$hw_dir);
1398
 
1399
        }
1400
    }#$tile_num
1401
 
1402
 
1403 16 alirezamon
}
1404
 
1405 28 alirezamon
 
1406 16 alirezamon
################
1407 43 alirezamon
#    generate_soc
1408 16 alirezamon
#################
1409
 
1410
sub generate_soc_files{
1411 43 alirezamon
    my ($mpsoc,$soc,$info)=@_;
1412
    my $mpsoc_name=$mpsoc->object_get_attribute('mpsoc_name');
1413
    my $soc_name=$soc->object_get_attribute('soc_name');
1414
 
1415
    # copy all files in project work directory
1416
    my $dir = Cwd::getcwd();
1417
    my $project_dir      = abs_path("$dir/../../");
1418
    #make target dir
1419
    my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name";
1420
    mkpath("$target_dir/src_verilog/lib/",1,0755);
1421
    mkpath("$target_dir/src_verilog/tiles/",1,0755);
1422
    mkpath("$target_dir/sw",1,0755);
1423 34 alirezamon
 
1424 48 alirezamon
    my ($file_v,$tmp)=soc_generate_verilog($soc,"$target_dir/sw",$info);
1425 43 alirezamon
 
1426
    # Write object file
1427
    open(FILE,  ">lib/soc/$soc_name.SOC") || die "Can not open: $!";
1428
    print FILE perl_file_header("$soc_name.SOC");
1429
    print FILE Data::Dumper->Dump([\%$soc],['soc']);
1430
    close(FILE) || die "Error closing file: $!";
1431
 
1432
    # Write verilog file
1433 48 alirezamon
    open(FILE,  ">lib/verilog/$soc_name.sv") || die "Can not open: $!";
1434 43 alirezamon
    print FILE $file_v;
1435
    close(FILE) || die "Error closing file: $!";
1436
 
1437 48 alirezamon
 
1438 43 alirezamon
 
1439 48 alirezamon
    #copy hdl codes in src_verilog         
1440 18 alirezamon
    my ($hdl_ref,$warnings)= get_all_files_list($soc,"hdl_files");
1441 48 alirezamon
    my ($sim_ref,$warnings2)= get_all_files_list($soc,"hdl_files_ticked");
1442
        #hdl_ref-sim_ref
1443
        my @n= get_diff_array($hdl_ref,$sim_ref);
1444
        $hdl_ref=\@n;
1445
 
1446
    foreach my $f(@{$hdl_ref}){
1447 43 alirezamon
        my $n="$project_dir$f";
1448
         if (-f "$n") {
1449
                 copy ("$n","$target_dir/src_verilog/lib");
1450
         }elsif(-f "$f" ){
1451 48 alirezamon
                 copy ("$f","$target_dir/src_verilog/lib");
1452
         }
1453 16 alirezamon
    }
1454 48 alirezamon
    show_colored_info($info,$warnings,'green')             if(defined $warnings);
1455 42 alirezamon
 
1456 48 alirezamon
 
1457
 
1458
        foreach my $f(@{$sim_ref}){
1459
         my $n="$project_dir$f";
1460
         if (-f "$n") {
1461
                 copy ("$n","$target_dir/src_sim");
1462
         }elsif(-f "$f" ){
1463
                 copy ("$f","$target_dir/src_sim");
1464
         }
1465
    }
1466
    show_colored_info($info,$warnings2,'green')             if(defined $warnings2);
1467
 
1468
 
1469 42 alirezamon
    #save project hdl file/folder list
1470
    my @new_file_ref;
1471 48 alirezamon
    foreach my $f(@{$hdl_ref}){
1472 43 alirezamon
            my ($name,$path,$suffix) = fileparse("$f",qr"\..[^.]*$");
1473
            push(@new_file_ref,"$target_dir/src_verilog/lib/$name$suffix");
1474
    }
1475 48 alirezamon
    foreach my $f(@{$sim_ref}){
1476
            my ($name,$path,$suffix) = fileparse("$f",qr"\..[^.]*$");
1477
            push(@new_file_ref,"$target_dir/src_sim/$name$suffix");
1478
    }
1479 42 alirezamon
    open(FILE,  ">$target_dir/src_verilog/file_list") || die "Can not open: $!";
1480 43 alirezamon
    print FILE Data::Dumper->Dump([\@new_file_ref],['files']);
1481
    close(FILE) || die "Error closing file: $!";
1482
 
1483
 
1484
 
1485
 
1486 48 alirezamon
        move ("$dir/lib/verilog/$soc_name.sv","$target_dir/src_verilog/tiles/");
1487
        copy_noc_files($project_dir,"$target_dir/src_verilog/lib");
1488 43 alirezamon
 
1489
 
1490 48 alirezamon
        # Write header file
1491
        generate_header_file($soc,$project_dir,$target_dir,$target_dir,$dir);
1492
        #use File::Copy::Recursive qw(dircopy);
1493
        #dircopy("$dir/../src_processor/aeMB/compiler","$target_dir/sw/") or die("$!\n");
1494
        my $msg="SoC \"$soc_name\" has been created successfully at $target_dir/ ";
1495
        return $msg;
1496 43 alirezamon
}
1497 16 alirezamon
 
1498 48 alirezamon
 
1499 34 alirezamon
sub generate_mpsoc_lib_file {
1500 43 alirezamon
    my ($mpsoc,$info) = @_;
1501 48 alirezamon
    my $tmp = $mpsoc;
1502 43 alirezamon
    my $name=$mpsoc->object_get_attribute('mpsoc_name');
1503 48 alirezamon
 
1504 43 alirezamon
    open(FILE,  ">lib/mpsoc/$name.MPSOC") || die "Can not open: $!";
1505
    print FILE perl_file_header("$name.MPSOC");
1506 48 alirezamon
    print FILE Data::Dumper->Dump([\%$tmp],['mpsoc']);
1507 43 alirezamon
    close(FILE) || die "Error closing file: $!";
1508 48 alirezamon
 
1509
    #get_soc_list($mpsoc,$info); 
1510 43 alirezamon
 
1511
}
1512 34 alirezamon
 
1513 48 alirezamon
sub check_mpsoc_name {
1514
        my ($name,$info)= @_;
1515
    my $error = check_verilog_identifier_syntax($name);
1516
    if ( defined $error ){
1517
        #message_dialog("The \"$name\" is given with an unacceptable formatting. The mpsoc name will be used as top level verilog module name so it must follow Verilog identifier declaration formatting:\n $error");
1518
        my $message = "The \"$name\" is given with an unacceptable formatting. The mpsoc name will be used as top level Verilog module name so it must follow Verilog identifier declaration formatting:\n $error";
1519
        add_colored_info($info, $message,'red' );
1520
        return 1;
1521
    }
1522
    my $size= (defined $name)? length($name) :0;
1523
    if ($size ==0) {
1524
        message_dialog("Please define the MPSoC name!");
1525
        return 1;
1526
    }
1527
        return 0;
1528
}
1529 34 alirezamon
 
1530 43 alirezamon
 
1531 16 alirezamon
################
1532 43 alirezamon
#    generate_mpsoc
1533 16 alirezamon
#################
1534
 
1535
sub generate_mpsoc{
1536 43 alirezamon
    my ($mpsoc,$info,$show_sucess_msg)=@_;
1537
    my $name=$mpsoc->object_get_attribute('mpsoc_name');
1538 48 alirezamon
    return 0 if (check_mpsoc_name($name,$info));
1539
 
1540 43 alirezamon
    # make target dir
1541
    my $dir = Cwd::getcwd();
1542
    my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$name";
1543
    my $hw_dir     = "$target_dir/src_verilog";
1544
    my $sw_dir     = "$target_dir/sw";
1545
 
1546
    # rmtree ($hw_dir);
1547
        mkpath("$hw_dir",1,01777);
1548
    mkpath("$hw_dir/lib/",1,0755);
1549
    mkpath("$hw_dir/tiles",1,0755);
1550
    mkpath("$sw_dir",1,0755);
1551 48 alirezamon
 
1552 43 alirezamon
    #remove old rtl files that were copied by ProNoC
1553
    my ($old_file_ref,$r,$err) = regen_object("$hw_dir/file_list");
1554
    if (defined $old_file_ref){
1555
        remove_file_and_folders($old_file_ref,$target_dir);
1556
    }
1557
    unlink "$hw_dir/file_list";
1558
 
1559
    #generate/copy all tiles HDL/SW codes
1560
    gen_all_tiles($mpsoc,$info, $hw_dir,$sw_dir );
1561
 
1562 48 alirezamon
    #copy clk setting hdl codes in src_verilog
1563
        my $project_dir   = abs_path("$dir/../../");
1564
    my $sc_soc =get_source_set_top($mpsoc,'mpsoc');
1565
        my ($file_ref,$warnings)= get_all_files_list($sc_soc,"hdl_files");
1566
        my ($sim_ref,$warnings2)= get_all_files_list($sc_soc,"hdl_files_ticked");
1567
        #file_ref-sim_ref
1568
        my @n= get_diff_array($file_ref,$sim_ref);
1569
        $file_ref=\@n;
1570
 
1571
        copy_file_and_folders($file_ref,$project_dir,"$hw_dir/lib");
1572
        show_colored_info($info,$warnings,'green')              if(defined $warnings);
1573
        add_to_project_file_list($file_ref,"$hw_dir/lib/",$hw_dir);
1574
 
1575
        copy_file_and_folders($sim_ref,$project_dir,"$hw_dir/../src_sim");
1576
        show_colored_info($info,$warnings2,'green')     if(defined $warnings2);
1577
        add_to_project_file_list($sim_ref,"$hw_dir/../src_sim",$hw_dir);
1578
 
1579
 
1580
 
1581 43 alirezamon
    #generate header file containig the tiles physical addresses
1582
    gen_tiles_physical_addrsses_header_file($mpsoc,"$sw_dir/phy_addr.h");
1583
 
1584
    #copy all NoC HDL files    
1585 48 alirezamon
    #my @files = glob( "$dir/../rtl/src_noc/*.v" );
1586
    #copy_file_and_folders(\@files,$project_dir,"$hw_dir/lib/");  
1587
    #add_to_project_file_list(\@files,"$hw_dir/lib/",$hw_dir);
1588
    my ($file_v,$top_v, $noc_param_v)=mpsoc_generate_verilog($mpsoc,$sw_dir,$info);
1589 43 alirezamon
 
1590 48 alirezamon
    #if Topology is custom copy custom topology files
1591
    my $topology=$mpsoc->object_get_attribute('noc_param','TOPOLOGY');
1592
        if ($topology eq '"CUSTOM"'){
1593
                my $Tname=$mpsoc->object_get_attribute('noc_param','CUSTOM_TOPOLOGY_NAME');
1594
                $Tname=~s/["]//gs;
1595
                my $dir1=  get_project_dir()."/mpsoc/rtl/src_topolgy/$Tname";
1596
                my $dir2=  get_project_dir()."/mpsoc/rtl/src_topolgy/common";
1597
                my @files = File::Find::Rule->file()
1598
                            ->name( '*.v','*.V')
1599
                            ->in( "$dir1" );
1600
                copy_file_and_folders (\@files,$project_dir,"$hw_dir/lib/");
1601
 
1602
                @files = File::Find::Rule->file()
1603
                            ->name( '*.v','*.V')
1604
                            ->in( "$dir2" );
1605
 
1606
                copy_file_and_folders (\@files,$project_dir,"$hw_dir/lib/");
1607
        }
1608
 
1609 43 alirezamon
 
1610
    # Write object file
1611
    generate_mpsoc_lib_file($mpsoc,$info);
1612 48 alirezamon
 
1613 43 alirezamon
    # Write verilog file
1614 48 alirezamon
    open(FILE,  ">$target_dir/src_verilog/$name.sv") || die "Can not open: $!";
1615 43 alirezamon
    print FILE $file_v;
1616
    close(FILE) || die "Error closing file: $!";
1617
 
1618
    my $l=autogen_warning().get_license_header("${name}_top.v");
1619 48 alirezamon
    open(FILE,  ">$target_dir/src_verilog/${name}_top.v") || die "Can not open: $!";
1620 43 alirezamon
    print FILE "$l\n$top_v";
1621 48 alirezamon
    close(FILE) || die "Error closing file: $!";
1622 43 alirezamon
 
1623 48 alirezamon
    gen_noc_localparam_v_file($mpsoc,"$target_dir/src_verilog/lib/src_noc");
1624
 
1625
 
1626 43 alirezamon
 
1627 28 alirezamon
 
1628 48 alirezamon
 
1629
 
1630
  #  $l=autogen_warning().get_license_header("${name}_mp.v");
1631
  #  open(FILE,  ">$target_dir/src_verilog/${name}_mp.v") || die "Can not open: $!";
1632
  #  print FILE "$l\n$mp_v";
1633
  #  close(FILE) || die "Error closing file: $!";
1634
 
1635
 
1636 28 alirezamon
    #generate makefile
1637
    open(FILE,  ">$sw_dir/Makefile") || die "Can not open: $!";
1638 43 alirezamon
    print FILE mpsoc_sw_make();
1639
    close(FILE) || die "Error closing file: $!";
1640
 
1641 48 alirezamon
    my $m_chain = $mpsoc->object_get_attribute('JTAG','M_CHAIN');
1642
 
1643 43 alirezamon
    #generate prog_mem
1644 28 alirezamon
    open(FILE,  ">$sw_dir/program.sh") || die "Can not open: $!";
1645 48 alirezamon
    print FILE mpsoc_mem_prog($m_chain);
1646 43 alirezamon
    close(FILE) || die "Error closing file: $!";
1647
 
1648 48 alirezamon
    my @ff= ("$target_dir/src_verilog/$name.sv","$target_dir/src_verilog/${name}_top.v");
1649
    add_to_project_file_list(\@ff,"$hw_dir/lib/",$hw_dir);
1650 45 alirezamon
 
1651
    #write perl_object_file
1652
        mkpath("$target_dir/perl_lib/",1,01777);
1653 48 alirezamon
        open(FILE,  ">$target_dir/perl_lib/$name.MPSOC") || die "Can not open: $!";
1654 45 alirezamon
        print FILE perl_file_header("$name.MPSOC");
1655 48 alirezamon
        print FILE Data::Dumper->Dump([\%$mpsoc],['mpsoc']);
1656 45 alirezamon
 
1657 48 alirezamon
    #regenerate linker var file
1658
    create_linker_var_file($mpsoc);
1659
 
1660
 
1661 42 alirezamon
    message_dialog("MPSoC \"$name\" has been created successfully at $target_dir/ " ) if($show_sucess_msg);
1662 48 alirezamon
        return 1;
1663 43 alirezamon
}
1664 16 alirezamon
 
1665 28 alirezamon
sub mpsoc_sw_make {
1666 48 alirezamon
     my $make="TOPTARGETS := all clean
1667
SUBDIRS := \$(wildcard */.)
1668
\$(TOPTARGETS): \$(SUBDIRS)
1669 43 alirezamon
\$(SUBDIRS):
1670 48 alirezamon
\t\$(MAKE) -C \$@ \$(MAKECMDGOALS)
1671 16 alirezamon
 
1672 48 alirezamon
.PHONY: \$(TOPTARGETS) \$(SUBDIRS)
1673 43 alirezamon
";
1674 48 alirezamon
        return $make;
1675 28 alirezamon
}
1676 16 alirezamon
 
1677
 
1678 28 alirezamon
sub mpsoc_mem_prog {
1679 48 alirezamon
    my $chain=shift;
1680
 
1681
     my $string="#!/bin/bash
1682 28 alirezamon
 
1683
 
1684 48 alirezamon
#JTAG_INTFC=\"\$PRONOC_WORK/toolchain/bin/JTAG_INTFC\"
1685 38 alirezamon
source ./jtag_intfc.sh
1686 28 alirezamon
 
1687 38 alirezamon
 
1688 28 alirezamon
#reset and disable cpus, then release the reset but keep the cpus disabled
1689
 
1690 48 alirezamon
\$JTAG_INTFC -t $chain  -n 127  -d  \"I:1,D:2:3,D:2:2,I:0\"
1691 28 alirezamon
 
1692
# jtag instruction
1693 43 alirezamon
#    0: bypass
1694
#    1: getting data
1695 28 alirezamon
# jtag data :
1696 43 alirezamon
#     bit 0 is reset
1697
#    bit 1 is disable
1698 28 alirezamon
# I:1  set jtag_enable  in active mode
1699
# D:2:3 load jtag_enable data register with 0x3 reset=1 disable=1
1700
# D:2:2 load jtag_enable data register with 0x2 reset=0 disable=1
1701
# I:0  set jtag_enable  in bypass mode
1702
 
1703
 
1704
 
1705
#programe the memory
1706 48 alirezamon
for i in \$(ls -d */); do
1707
    echo \"Enter \${i\%\%/}\"
1708
    cd \${i\%\%/}
1709 45 alirezamon
    bash write_memory.sh
1710 43 alirezamon
    cd ..
1711 28 alirezamon
done
1712
 
1713
#Enable the cpu
1714 48 alirezamon
\$JTAG_INTFC -t $chain -n 127  -d  \"I:1,D:2:0,I:0\"
1715 28 alirezamon
# I:1  set jtag_enable  in active mode
1716
# D:2:0 load jtag_enable data register with 0x0 reset=0 disable=0
1717
# I:0  set jtag_enable  in bypass mode
1718 48 alirezamon
";
1719
        return $string;
1720 28 alirezamon
}
1721
 
1722
 
1723 16 alirezamon
sub get_tile_LIST{
1724 48 alirezamon
    my ($mpsoc,$x,$y,$soc_num,$row,$table)=@_;
1725 43 alirezamon
    my $instance_name=$mpsoc->mpsoc_get_instance_info($soc_num);
1726
    if(!defined $instance_name){
1727
        $mpsoc->mpsoc_set_default_ip($soc_num);
1728
        $instance_name=$mpsoc->mpsoc_get_instance_info($soc_num);
1729
    }
1730 16 alirezamon
 
1731 43 alirezamon
    #ipname
1732
    my $col=0;
1733
    my $label=gen_label_in_left("IP_$soc_num($x,$y)");
1734
    $table->attach_defaults ( $label, $col, $col+1 , $row, $row+1);$col+=2;
1735
    #instance name
1736
    my $entry=gen_entry($instance_name);
1737
    $table->attach_defaults ( $entry, $col, $col+1 , $row, $row+1);$col+=2;
1738
    $entry->signal_connect( 'changed'=> sub{
1739
        my $new_instance=$entry->get_text();
1740
        $mpsoc->mpsoc_set_ip_inst_name($soc_num,$new_instance);
1741
        set_gui_status($mpsoc,"ref",20);
1742
        print "changed to  $new_instance\n ";
1743
    });
1744 16 alirezamon
 
1745 43 alirezamon
    #combo box
1746
    my @list=('A','B');
1747
    my $combo=gen_combo(\@list,0);
1748
    $table->attach_defaults ( $combo, $col, $col+1 , $row, $row+1);$col+=2;
1749
    #setting
1750
    my $setting= def_image_button("icons/setting.png","Browse");
1751
    $table->attach_defaults ( $setting, $col, $col+1 , $row, $row+1);$col+=2;
1752 16 alirezamon
}
1753
 
1754
sub get_tile{
1755 43 alirezamon
    my ($mpsoc,$tile)=@_;
1756
    my ($soc_name,$num)= $mpsoc->mpsoc_get_tile_soc_name($tile);
1757
    my $button;
1758
    my $topology=$mpsoc->object_get_attribute('noc_param','TOPOLOGY');
1759
 
1760
    if( defined $soc_name){
1761
        my $setting=$mpsoc->mpsoc_get_tile_param_setting($tile);
1762
        $button=($setting eq 'Custom')? def_colored_button("Tile $tile*\n$soc_name",$num) :    def_colored_button("Tile $tile\n$soc_name",$num) ;
1763
    }else {
1764
        $button =def_colored_button("Tile $tile\n",50) if(! defined $soc_name);
1765
    }
1766
 
1767
    $button->signal_connect("clicked" => sub{
1768 48 alirezamon
       get_tile_setting ($mpsoc,$tile);
1769
    });
1770
 
1771
    #$button->show_all;
1772
    return $button;
1773
}
1774
 
1775
sub define_empty_param_setting {
1776
        my ($mpsoc,$window)=@_;
1777
        my $ok = def_image_button('icons/select.png','OK');
1778
    my $okbox=def_hbox(TRUE,0);
1779
    $okbox->pack_start($ok, FALSE, FALSE,0);
1780
    $ok-> signal_connect("clicked" => sub{
1781
             set_gui_status($mpsoc,"refresh_soc",1);
1782
             $window->destroy;
1783
 
1784
     });
1785
     my $param_table = def_table(1, 1, TRUE);
1786
         $param_table->attach_defaults($okbox,0,1,3,4);
1787
         return $param_table;
1788
 
1789
 
1790
}
1791
 
1792
sub get_tile_setting {
1793
                my($mpsoc,$tile)=@_;
1794
                my $window = def_popwin_size(50,40,"Parameter setting for Tile $tile ",'percent');
1795
        my $table = def_table(6, 2, FALSE);
1796 43 alirezamon
 
1797 48 alirezamon
        my $scrolled_win = add_widget_to_scrolled_win($table);
1798 43 alirezamon
        my $row=0;
1799
        my ($soc_name,$g,$t)=$mpsoc->mpsoc_get_tile_soc_name($tile);
1800 48 alirezamon
 
1801 43 alirezamon
        my @socs=$mpsoc->mpsoc_get_soc_list();
1802
        my @list=(' ',@socs);
1803
        my $pos=(defined $soc_name)? get_scolar_pos($soc_name,@list): 0;
1804
        my $combo=gen_combo(\@list, $pos);
1805 48 alirezamon
        my $label=gen_label_in_left("  Processing tile name:");
1806
        $table->attach($label,0,2,$row,$row+1,'shrink','shrink',2,2);
1807
        $table->attach($combo,2,3,$row,$row+1,'shrink','shrink',2,2);$row++;
1808
                add_Hsep_to_table($table,0,3,$row);$row++;
1809
                $soc_name = ' ' if (!defined $soc_name);
1810
        my $param_table =  ($soc_name eq ' ')? define_empty_param_setting($mpsoc,$window) :
1811
                  get_soc_parameter_setting_table($mpsoc,$soc_name,$window,[$tile]);
1812
 
1813
        $table->attach_defaults($param_table,0,3,2,3);
1814
 
1815
 
1816
        $combo->signal_connect('changed'=>sub{
1817 43 alirezamon
            my $new_soc=$combo->get_active_text();
1818
            if ($new_soc eq ' '){
1819
                #unconnect tile
1820
                $mpsoc->mpsoc_set_tile_free($tile);
1821 48 alirezamon
                $param_table->destroy;
1822
                $param_table=  define_empty_param_setting($mpsoc,$window);
1823
                $table->attach_defaults($param_table,0,3,2,3);
1824
                $window->show_all;
1825 43 alirezamon
            }else {
1826
                $mpsoc->mpsoc_set_tile_soc_name($tile,$new_soc);
1827 48 alirezamon
                $param_table->destroy;
1828
                $param_table =  get_soc_parameter_setting_table($mpsoc,$new_soc,$window,[$tile]);
1829
                $table->attach_defaults($param_table,0,3,2,3);
1830
                $window->show_all;
1831 43 alirezamon
            }
1832
        });
1833 48 alirezamon
        $window->add($scrolled_win);
1834
        $window->show_all;
1835 16 alirezamon
}
1836
 
1837
 
1838
##########
1839 43 alirezamon
# gen_tiles
1840 16 alirezamon
#########
1841
sub gen_tiles{
1842 43 alirezamon
    my ($mpsoc)=@_;
1843
        my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($mpsoc);
1844
    my $table;
1845
    my $dim_y = floor(sqrt($NE));
1846 48 alirezamon
        $table=def_table($NE%8,$NE/8,FALSE);#    my ($row,$col,$homogeneous)=@_;
1847
        for (my $i=0; $i<$NE;$i++){
1848
                my $tile=get_tile($mpsoc,$i);
1849
                my $y= int($i/$dim_y);
1850
                my $x= $i % $dim_y;
1851
        $table->attach_defaults ($tile, $x, $x+1 , $y, $y+1);
1852
        }
1853
 
1854
        my $scrolled_win = gen_scr_win_with_adjst($mpsoc,'gen_tiles_adj');
1855
        add_widget_to_scrolled_win($table,$scrolled_win);
1856
        return $scrolled_win;
1857
}
1858 16 alirezamon
 
1859 48 alirezamon
 
1860
sub get_elf_file_addr_range {
1861
        my ($file,$tview)=@_;
1862
        #my $command=  "size  -A $file";
1863
        my $command=  "nm  $file";
1864
        #add_info($tview,"$command\n");
1865
        my      ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($command);
1866
        if(length $stderr>1){
1867
                add_colored_info($tview,"$stderr\n",'red');
1868
                add_colored_info($tview,"$command was not run successfully!\n",'red');
1869
                return ("Err","Err");
1870
        }
1871
        if($exit){
1872
                add_colored_info($tview,"$stdout\n",'red');
1873
                add_colored_info($tview,"$command was not run successfully!\n",'red');
1874
                return ("Err","Err");
1875
        }
1876
 
1877
        my @lines = split ("\n" ,$stdout);
1878
        my $max_addr=0;
1879
        my $sec_name;
1880
 
1881
        foreach my $p (@lines ){
1882
                $p =~ s/\s+/ /g; # remove extra spaces
1883
            $p =~ s/^\s+//; #ltrim
1884
                my ($addr,$type,$name)= sscanf("%x %s %s","$p");
1885
                if(defined $addr && defined $name){
1886
                        if($max_addr < $addr) {
1887
                                $max_addr = $addr;
1888
                                $sec_name = $name;
1889
                        }
1890
                }
1891
        }
1892
        return ($max_addr,$sec_name);
1893
}
1894
 
1895
 
1896
sub show_reqired_brams{
1897
        my ($self,$tview)=@_;
1898
        my $win=def_popwin_size (50,50,"BRAM info", 'percent');
1899
        my $sc_win = gen_scr_win_with_adjst($self,'liststore');
1900
        my $table= def_table(10,10,FALSE);
1901
        add_widget_to_scrolled_win($table,$sc_win);
1902
        my $row=0;
1903
        my $col=0;
1904 16 alirezamon
 
1905 48 alirezamon
        my  @clmns =('Tile#', 'Section located in Upper Bound Address (UBA) ','UBA in Bytes','UBA in Words','Minimum Memory Address Width');
1906
        my $target_dir;
1907
        my @data;
1908
 
1909
    my $mpsoc_name=$self->object_get_attribute('mpsoc_name');
1910
        if(defined $mpsoc_name){#it is an soc
1911
 
1912
                my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($self);
1913
 
1914
            $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name";
1915
 
1916
            for (my $tile_num=0;$tile_num<$NE;$tile_num++){
1917
                        my $ram_file     = "$target_dir/sw/tile$tile_num/image";
1918
                my ($size,$sec) = get_elf_file_addr_range($ram_file,$tview);
1919
                my %clmn;
1920
                $clmn{0}="tile$tile_num";
1921
                $clmn{1}= "$sec";
1922
                $clmn{2}="$size";
1923
                my $w=$size/4;
1924
                $clmn{3}="$w";
1925
                $clmn{4}=ceil(log($w)/log(2));
1926
                push(@data,\%clmn);
1927
 
1928
            }#$tile_num 
1929
        }
1930
        else
1931
        {
1932
                my $soc_name=$self->object_get_attribute('soc_name');
1933
                $target_dir  = "$ENV{'PRONOC_WORK'}/SOC/$soc_name";
1934
                my $ram_file     = "$target_dir/sw/image";
1935
            my ($size,$sec) = get_elf_file_addr_range($ram_file,$tview);
1936
            my %clmn;
1937
            $clmn{0}="$soc_name";
1938
            $clmn{1}= "$sec";
1939
            $clmn{2}="$size";
1940
            my $w=$size/4;
1941
            $clmn{3}="$w";
1942
            $clmn{4}=ceil(log($w)/log(2));
1943
            push(@data,\%clmn);
1944
        }
1945
 
1946
        my @clmn_type = (#'Glib::Boolean', # => G_TYPE_BOOLEAN
1947
                                    #'Glib::Uint',    # => G_TYPE_UINT
1948
                                    'Glib::String',  # => G_TYPE_STRING
1949
                                  'Glib::String',
1950
                                   'Glib::String',
1951
                                   'Glib::String',
1952
                                   'Glib::String'); # you get the idea
1953
 
1954
        my $list=       gen_list_store (\@data,\@clmn_type,\@clmns);
1955
        $table-> attach  ($list, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $row++;
1956
 
1957
        $win->add($sc_win);
1958
        $win->show_all();
1959 38 alirezamon
}
1960 16 alirezamon
 
1961 48 alirezamon
sub check_conflict {
1962
        my ($self,$tile_num,$label)=@_;
1963
 
1964
        my $r1 =$self->object_get_attribute("ROM$tile_num",'end');
1965
        my $r2 =$self->object_get_attribute("RAM$tile_num",'start');
1966
 
1967
        if(defined $r1 && defined $r2){
1968
                if(hex($r1)> hex($r2)){
1969
                        $label->set_markup("<span  foreground= 'red' ><b>RAM-ROM range Conflict</b></span>");
1970
 
1971
                }else {
1972
                        $label->set_label(" ");
1973
 
1974
                }
1975
        }else {
1976
                $label->set_label(" ");
1977
 
1978
        }
1979
}
1980 16 alirezamon
 
1981
 
1982 48 alirezamon
sub update_ram_rom_size {
1983
        my ($self,$tile_num,$name,$label,$start,$end,$conflict)=@_;
1984
        my $s = $start->get_value();
1985
        my $e = $end->get_value();
1986 38 alirezamon
 
1987 48 alirezamon
        $self->object_add_attribute($name.$tile_num,'start',$start->get_value());
1988
        $self->object_add_attribute($name.$tile_num,'end',$end->get_value());
1989
        if($e <= $s){
1990
                #$label->set_label("Invalid range" );
1991
                $label->set_markup("<span  foreground= 'red' ><b>Invalid range</b></span>");
1992
 
1993
        }else {
1994
                $label->set_label( metric_conversion($e - $s) . "B");
1995
 
1996
        }
1997
 
1998
        check_conflict($self,$tile_num,$conflict);
1999
 
2000
 
2001
 
2002
}
2003 38 alirezamon
 
2004 48 alirezamon
sub get_tile_peripheral_patameter {
2005
        my ($mpsoc,$tile_num,$peripheral,$param_name)=@_;
2006
        my ($soc_name,$n,$soc_num)=$mpsoc->mpsoc_get_tile_soc_name($tile_num);
2007
        if(defined $soc_name) {
2008
                my $top=$mpsoc->mpsoc_get_soc($soc_name);
2009
                my @insts=$top->top_get_all_instances();
2010
                foreach my $id (@insts){
2011
                        if ($id =~/$peripheral[0-9]/){
2012
                                my $name=$top->top_get_def_of_instance($id,'instance');
2013
 
2014
                                my  %params;
2015
                                my $setting=$mpsoc->mpsoc_get_tile_param_setting($tile_num);
2016
                                #if ($setting eq 'Custom'){
2017
                                        %params= $top->top_get_custom_soc_param($tile_num);
2018
                                #}else{
2019
                                #       %params=$top->top_get_default_soc_param();
2020
                                #}
2021
                                return $params{"${name}_$param_name"};
2022
                        }
2023
                }
2024
        }
2025
        return undef;
2026
 
2027
}
2028 38 alirezamon
 
2029 48 alirezamon
sub get_soc_peripheral_parameter {
2030
        my ($soc,$peripheral,$param_nam)=@_;
2031
        my @instances=$soc->soc_get_all_instances();
2032
        foreach my $id (@instances){
2033
                if ($id =~/$peripheral[0-9]/){
2034
                        return $soc->soc_get_module_param_value ($id,$param_nam) if (defined $param_nam);
2035
                }
2036
        }
2037
        return undef;
2038
}
2039
 
2040
 
2041
sub linker_initial_setting {
2042
        my ($self,$tview)=@_;
2043
        my $mpsoc_name=$self->object_get_attribute('mpsoc_name');
2044
    my $tnum;
2045
    my $target_dir;
2046
        if(defined $mpsoc_name){#it is an mpsoc
2047
 
2048
                my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($self);
2049
 
2050
            $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name";
2051
            for (my $tile_num=0;$tile_num<$NE;$tile_num++){
2052
 
2053
                my $v=get_tile_peripheral_patameter($self,$tile_num,"_ram","Aw");
2054
                $v = 13 if (!defined $v);
2055
                $self->object_add_attribute('MEM'.$tile_num,'width',$v);
2056
                $self->object_add_attribute('MEM'.$tile_num,'percent',75);
2057
 
2058
                my $s =(1 << ($v+2)) ;
2059
                        my $p = 75;
2060
 
2061
                        my $rom_start = 0;
2062
                        my $rom_end= int ( ($s*$p)/100);
2063
                        my $ram_start= int (($s*$p)/100);
2064
                        my $ram_end= $s;
2065
 
2066
                        $self->object_add_attribute('ROM'.$tile_num,'start',$rom_start);
2067
                        $self->object_add_attribute('ROM'.$tile_num,'end',$rom_end);
2068
                        $self->object_add_attribute('RAM'.$tile_num,'start',$ram_start);
2069
                        $self->object_add_attribute('RAM'.$tile_num,'end',$ram_end);
2070
 
2071
 
2072
            }
2073
 
2074
 
2075
        }
2076
        else
2077
        {
2078
                my $v=get_soc_peripheral_parameter ($self,"_ram","Aw");
2079
                $v = 13 if (!defined $v);
2080
                $self->object_add_attribute('MEM0','width',$v);
2081
                $self->object_add_attribute('MEM0','percent',75);
2082
                my $s =(1 << ($v+2)) ;
2083
                my $p = 75;
2084
 
2085
                my $rom_start = 0;
2086
                my $rom_end= int ( ($s*$p)/100);
2087
                my $ram_start= int (($s*$p)/100);
2088
                my $ram_end= $s;
2089
 
2090
                $self->object_add_attribute('ROM0','start',$rom_start);
2091
                $self->object_add_attribute('ROM0','end',$rom_end);
2092
                $self->object_add_attribute('RAM0','start',$ram_start);
2093
                $self->object_add_attribute('RAM0','end',$ram_end);
2094
        }
2095
 
2096
 
2097
}
2098
 
2099
 
2100
 
2101
sub linker_setting{
2102
        my ($self,$tview)=@_;
2103
        my $win=def_popwin_size (80,50,"BRAM info", 'percent');
2104
        my $sc_win = gen_scr_win_with_adjst($self,'liststore');
2105
        my $table= def_table(10,10,FALSE);
2106
 
2107
 
2108
        my $row=0;
2109
        my $col=0;
2110
 
2111
        $table-> attach  (gen_label_in_center("Tile"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col+=1;
2112
        $table-> attach  (gen_label_in_center("Memory Addr"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col+=1;
2113
        $table-> attach  (gen_label_in_center("ROM/(ROM+RAM)"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col+=1;
2114
 
2115
        $table-> attach  (gen_label_in_center("ROM index addr (hex)"), $col, $col+2,  $row, $row+1,'shrink','shrink',2,2); $col+=3;
2116
        $table-> attach  (gen_label_in_center("RAM index addr (hex)"), $col, $col+2,  $row, $row+1,'shrink','shrink',2,2); $col+=3;
2117
 
2118
 
2119
        $col=0;$row++;
2120
        $table-> attach  (gen_label_in_center("#"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2121
        $table-> attach  (gen_label_in_center("Width"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2122
        $table-> attach  (gen_label_in_center("(%)"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2123
 
2124
        $table-> attach  (gen_label_in_center("Beginning"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col+=1;
2125
        $table-> attach  (gen_label_in_center("End"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2126
        $table-> attach  (gen_label_in_center("Size"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2127
 
2128
        $table-> attach  (gen_label_in_center("Beginning"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col+=1;
2129
        $table-> attach  (gen_label_in_center("End"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2130
        $table-> attach  (gen_label_in_center("Size"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2131
 
2132
 
2133
        $col=0;$row++;
2134
 
2135
        my $target_dir;
2136
        my @data;
2137
 
2138
    my $mpsoc_name=$self->object_get_attribute('mpsoc_name');
2139
    my $tnum;
2140
        if(defined $mpsoc_name){#it is an mpsoc
2141
 
2142
                my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($self);
2143
                $tnum=$NE;
2144
            $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name";
2145
        }
2146
        else
2147
        {
2148
                my $soc_name=$self->object_get_attribute('soc_name');
2149
                $target_dir  = "$ENV{'PRONOC_WORK'}/SOC/$soc_name";
2150
                $tnum=1;
2151
        }
2152
        for (my $j=0;$j<$tnum;$j++){
2153
                        my $tile_num=$j;
2154
                        my $conflict =gen_label_in_center(" ") ;
2155
 
2156
                        $table-> attach  (gen_label_in_center("$tile_num"), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2);$col++;
2157
                        my $ram_width = gen_spin(2,64,1);
2158
                        my $width = $self->object_get_attribute('MEM'.$tile_num,'width');
2159
                        if(!defined $width){
2160
                                linker_initial_setting ($self,$tview);
2161
                                $width = $self->object_get_attribute('MEM'.$tile_num,'width');
2162
                        }
2163
                        $ram_width->set_value($width);
2164
                        my $size =gen_label_in_center(metric_conversion(1 << 15). "B") ;
2165
 
2166
 
2167
                        $table-> attach  (def_pack_hbox('FALSE',0,$ram_width,$size), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2168
 
2169
 
2170
 
2171
 
2172
                        my $percent = gen_spin_float(6.25,93.75,6.25,2);
2173
                        my $p=$self->object_get_attribute('MEM'.$tile_num,'percent');
2174
                        $percent->set_value($p);
2175
 
2176
                        my $enter= def_image_button("icons/enter.png");
2177
                        $table-> attach  (def_pack_hbox('FALSE',0,$percent,$enter), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2178
 
2179
                        my $rom_start_v =$self->object_get_attribute('ROM'.$tile_num,'start');
2180
                        my $rom_end_v = $self->object_get_attribute('ROM'.$tile_num,'end');
2181
                        my $ram_start_v = $self->object_get_attribute('RAM'.$tile_num,'start');
2182
                        my $ram_end_v = $self->object_get_attribute('RAM'.$tile_num,'end');
2183
 
2184
 
2185
 
2186
                        my $rom_start = HexSpin->new ( $rom_start_v, 0, 0xffffffff ,4);
2187
                        $rom_start->set_digits(8);
2188
                        $table-> attach  ($rom_start, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2189
 
2190
 
2191
 
2192
                        my $rom_end = HexSpin->new ( $rom_end_v, 0, 0xffffffff ,4);
2193
                        $rom_end->set_digits(8);
2194
                        $table-> attach  ($rom_end, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2195
 
2196
                        my $rom_size =gen_label_in_center(" ") ;
2197
                        $table-> attach  ($rom_size, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2198
                        update_ram_rom_size($self,$tile_num,'ROM',$rom_size,$rom_start,$rom_end,$conflict);
2199
                        $rom_start->signal_connect ( 'changed', sub {update_ram_rom_size($self,$tile_num,'ROM',$rom_size,$rom_start,$rom_end,$conflict);});
2200
                        $rom_end->signal_connect ( 'changed', sub {update_ram_rom_size($self,$tile_num,'ROM',$rom_size,$rom_start,$rom_end,$conflict);});
2201
 
2202
                        my $ram_start = HexSpin->new ( $ram_start_v, 0, 0xffffffff ,4);
2203
                        $ram_start->set_digits(8);
2204
                        $table-> attach  ($ram_start, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2205
 
2206
 
2207
                        my $ram_end = HexSpin->new ( $ram_end_v, 0, 0xffffffff ,4);
2208
                        $ram_end->set_digits(8);
2209
                        $table-> attach  ($ram_end, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2210
 
2211
                        my $ram_size =gen_label_in_center(" ") ;
2212
                        $table-> attach  ($ram_size, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2213
 
2214
 
2215
 
2216
 
2217
                        update_ram_rom_size($self,$tile_num,'RAM',$ram_size,$ram_start,$ram_end,$conflict);
2218
 
2219
                        $ram_start->signal_connect ( 'changed', sub {update_ram_rom_size($self,$tile_num,'RAM',$ram_size,$ram_start,$ram_end,$conflict);});
2220
                        $ram_end->signal_connect ( 'changed', sub {update_ram_rom_size($self,$tile_num,'RAM',$ram_size,$ram_start,$ram_end,$conflict);});
2221
 
2222
                    $ram_width->signal_connect("value_changed" => sub{
2223
                                my $w=$ram_width->get_value();
2224
                                $self->object_add_attribute('MEM'.$tile_num,'width',$w);
2225
                                $size->set_label (metric_conversion(1 << ($w+2)). "B") ;
2226
                                $size->show_all;
2227
                                $enter->clicked;
2228
                        });
2229
                    $percent->signal_connect("value_changed" => sub{
2230
                        $self->object_add_attribute('MEM'.$tile_num,'percent',$percent->get_value());
2231
                    });
2232
 
2233
                    $table-> attach  ($conflict, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
2234
 
2235
 
2236
 
2237
 
2238
                        $enter-> signal_connect ( 'clicked' , sub {
2239
                                my $w=$ram_width->get_value();
2240
                                my $s =(1 << ($w+2));
2241
                                my $p = $percent->get_value();
2242
 
2243
                                my $rom_start_v = 0;
2244
                                my $rom_end_v= int ( ($s*$p)/100);
2245
                                my $ram_start_v= int (($s*$p)/100);
2246
                                my $ram_end_v= $s;
2247
 
2248
                                $rom_start->set_value($rom_start_v);
2249
                                $rom_end->set_value($rom_end_v);
2250
                                $ram_start->set_value($ram_start_v);
2251
                                $ram_end->set_value($ram_end_v);
2252
                                update_ram_rom_size($self,$tile_num,'ROM',$rom_size,$rom_start,$rom_end,$conflict);
2253
                                update_ram_rom_size($self,$tile_num,'RAM',$ram_size,$ram_start,$ram_end,$conflict);
2254
 
2255
                        });
2256
 
2257
                        $col=0; $row++;
2258
 
2259
        }#$tile_num     
2260
 
2261
        my $main_table=def_table(10,10,FALSE);
2262
 
2263
        my $ok = def_image_button('icons/select.png','OK');
2264
        $main_table->attach_defaults ($table  , 0, 12, 0,11);
2265
    $main_table->attach ($ok,5, 6, 11,12,'shrink','shrink',0,0);
2266
 
2267
        $ok->signal_connect('clicked', sub {
2268
                for (my $t=0;$t<$tnum;$t++){
2269
                        my $r0 =$self->object_get_attribute("ROM$t",'start');
2270
                        my $r1 =$self->object_get_attribute("ROM$t",'end');
2271
                        my $r2 =$self->object_get_attribute("RAM$t",'start');
2272
                        my $r3 =$self->object_get_attribute("RAM$t",'end');
2273
                        if(hex($r1) <hex($r0)  || hex($r3) <hex($r2)   ){
2274
                                 message_dialog("Please fix tile $t invalid range !");
2275
                                 return ;
2276
 
2277
                        }
2278
 
2279
                        if(hex($r1) > hex($r2)  ){
2280
                                 message_dialog("Please fix tile $t conflict range !");
2281
                                 return ;
2282
 
2283
                        }
2284
 
2285
 
2286
 
2287
                }
2288
                create_linker_var_file($self);
2289
                $win->destroy();
2290
 
2291
 
2292
        });
2293
 
2294
 
2295
        add_widget_to_scrolled_win($main_table,$sc_win);
2296
        $win->add($sc_win);
2297
        $win->show_all();
2298
 
2299
}
2300
 
2301
 
2302
sub create_linker_var_file{
2303
        my ($self)=@_;
2304
        my $mpsoc_name=$self->object_get_attribute('mpsoc_name');
2305
    my $tnum;
2306
 
2307
    my $width = $self->object_get_attribute('MEM0','width');
2308
        if(!defined $width){
2309
        linker_initial_setting ($self);
2310
        }
2311
 
2312
        if(defined $mpsoc_name){#it is an mpsoc
2313
                my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($self);
2314
                $tnum=$NE;
2315
        }
2316
        else
2317
        {
2318
 
2319
                $tnum=1;
2320
        }
2321
 
2322
        for (my $t=0;$t<$tnum;$t++){
2323
                my $r0 =$self->object_get_attribute("ROM$t",'start');
2324
                my $r1 =$self->object_get_attribute("ROM$t",'end');
2325
                my $r2 =$self->object_get_attribute("RAM$t",'start');
2326
                my $r3 =$self->object_get_attribute("RAM$t",'end');
2327
 
2328
                my $file=sprintf("
2329
 
2330
MEMORY
2331
{
2332
        rom (rx)    : ORIGIN = 0x%x , LENGTH = 0x%x  /* %s B- Rom space  */
2333
        ram (wrx)   : ORIGIN = 0x%x , LENGTH = 0x%x  /* %s B- Ram space  */
2334
}
2335
 
2336
                        ",$r0,$r1 - $r0, metric_conversion($r1 - $r0),$r2,$r3- $r2,metric_conversion($r3 - $r2));
2337
 
2338
                if(defined $mpsoc_name){
2339
                        save_file ("$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name/sw/tile$t/linkvar.ld",$file) if(-d "$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name/sw/tile$t/");
2340
                }else{
2341
                        my $soc_name=$self->object_get_attribute('soc_name');
2342
                        my $p1="$ENV{'PRONOC_WORK'}/SOC/$soc_name/sw/";
2343
                        mkpath("$p1",1,0755) unless (-d "$p1");
2344
                        save_file ("$p1/linkvar.ld",$file)
2345
                }
2346
        }
2347
 
2348
}
2349
 
2350
 
2351 34 alirezamon
sub software_edit_mpsoc {
2352 43 alirezamon
    my $self=shift;
2353
    my $name=$self->object_get_attribute('mpsoc_name');
2354
    if (length($name)==0){
2355
        message_dialog("Please define the MPSoC name!");
2356
        return ;
2357
    }
2358
    my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$name";
2359
    my $sw     = "$target_dir/sw";
2360
 
2361 48 alirezamon
    my $orcc_page=select_orcc_generated_srcs($self);
2362
    my $orcc_lable=def_image_label('icons/orcc.png','Auto-generate Software using ORCC');
2363
    my @pages=($orcc_page);
2364
    my @pages_lables=($orcc_lable);
2365
    my ($app,$table,$tview) = software_main($sw,undef,\@pages,\@pages_lables);
2366 43 alirezamon
 
2367 48 alirezamon
        my $prog= def_image_button('icons/write.png','Program FPGA\'s BRAMs');
2368
    my $linker = def_image_button('icons/setting.png','LD Linker',FALSE,1);
2369
    my $make = def_image_button('icons/gen.png','_Compile',FALSE,1);
2370
    my $ram = def_image_button('icons/info.png',"Required BRAMs\' size",FALSE,1);
2371 43 alirezamon
 
2372 48 alirezamon
    $table->attach ($ram,0, 1, 1,2,'shrink','shrink',0,0);
2373
    $table->attach ($linker,4, 5, 1,2,'shrink','shrink',0,0);
2374 43 alirezamon
    $table->attach ($make,5, 6, 1,2,'shrink','shrink',0,0);
2375
    $table->attach ($prog,9, 10, 1,2,'shrink','shrink',0,0);
2376
 
2377 48 alirezamon
        $ram -> signal_connect("clicked" => sub{
2378
                show_reqired_brams($self,$tview);
2379
        });
2380
 
2381
          my $load;
2382
 
2383 43 alirezamon
    $make -> signal_connect("clicked" => sub{
2384 48 alirezamon
        $load->destroy   if(defined $load);
2385
        $load= show_gif("icons/load.gif");
2386 43 alirezamon
        $table->attach ($load,7, 8, 1,2,'shrink','shrink',0,0);
2387
        $load->show_all;
2388 48 alirezamon
        $app->ask_to_save_changes();
2389
        add_info($tview,' ');
2390
        unless (run_make_file($sw,$tview,'clean')){
2391
                $load->destroy;
2392
                $load=def_icon("icons/cancel.png");
2393
                $table->attach ($load,7, 8, 1,2,'shrink','shrink',0,0);
2394
                $load->show_all;
2395
                return;
2396
        };
2397
         unless (run_make_file($sw,$tview)){
2398
                $load->destroy;
2399
                $load=def_icon("icons/cancel.png");
2400
                $table->attach ($load,7, 8, 1,2,'shrink','shrink',0,0);
2401
                $load->show_all;
2402
                return;
2403
         }
2404
        $load->destroy;
2405
        $load=def_icon("icons/button_ok.png");
2406
        $table->attach ($load,7, 8, 1,2,'shrink','shrink',0,0);
2407
        $load->show_all;
2408
 
2409 16 alirezamon
 
2410 43 alirezamon
    });
2411
 
2412
    #Programe the board 
2413
    $prog-> signal_connect("clicked" => sub{
2414
        my $error = 0;
2415
        my $bash_file="$sw/program.sh";
2416
        my $jtag_intfc="$sw/jtag_intfc.sh";
2417
 
2418 48 alirezamon
        add_info($tview,"Program the board using quartus_pgm and $bash_file file\n");
2419 43 alirezamon
        #check if the programming file exists
2420
        unless (-f $bash_file) {
2421 48 alirezamon
            add_colored_info($tview,"\tThe $bash_file does not exists! \n", 'red');
2422 43 alirezamon
            $error=1;
2423
        }
2424
        #check if the jtag_intfc.sh file exists
2425
        unless (-f $jtag_intfc) {
2426 48 alirezamon
            add_colored_info($tview,"\tThe $jtag_intfc does not exists!. Press the compile button and select your FPGA board first to generate $jtag_intfc file\n", 'red');
2427 43 alirezamon
            $error=1;
2428
        }
2429
 
2430
        return if($error);
2431 45 alirezamon
        my $command = "cd $sw; bash program.sh";
2432 48 alirezamon
        add_info($tview,"$command\n");
2433 43 alirezamon
        my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($command);
2434
        if(length $stderr>1){
2435 48 alirezamon
            add_colored_info($tview,"$stderr\n",'red');
2436
            add_colored_info($tview,"Memory was not programmed successfully!\n",'red');
2437 43 alirezamon
        }else {
2438 16 alirezamon
 
2439 43 alirezamon
            if($exit){
2440 48 alirezamon
                add_colored_info($tview,"$stdout\n",'red');
2441
                add_colored_info($tview,"Memory was not programmed successfully!\n",'red');
2442 43 alirezamon
            }else{
2443 48 alirezamon
                add_info($tview,"$stdout\n");
2444
                add_colored_info($tview,"Memory is programmed successfully!\n",'blue');
2445 42 alirezamon
 
2446 43 alirezamon
            }
2447
 
2448
        }
2449
    });
2450 48 alirezamon
 
2451
 
2452
    $linker -> signal_connect("clicked" => sub{
2453
                linker_setting($self,$tview);
2454
        });
2455 42 alirezamon
 
2456 34 alirezamon
}
2457 16 alirezamon
 
2458
 
2459 34 alirezamon
 
2460 38 alirezamon
#############
2461 43 alirezamon
#    load_mpsoc
2462 38 alirezamon
#############
2463 34 alirezamon
 
2464 38 alirezamon
sub load_mpsoc{
2465 43 alirezamon
    my ($mpsoc,$info)=@_;
2466
    my $file;
2467 48 alirezamon
    my $dialog =  gen_file_dialog (undef, 'MPSOC');
2468
    my $dir = Cwd::getcwd();
2469 43 alirezamon
    $dialog->set_current_folder ("$dir/lib/mpsoc")    ;
2470
    my @newsocs=$mpsoc->mpsoc_get_soc_list();
2471 48 alirezamon
    add_info($info,'');
2472 43 alirezamon
    if ( "ok" eq $dialog->run ) {
2473
        $file = $dialog->get_filename;
2474
        my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
2475
        if($suffix eq '.MPSOC'){
2476
            my ($pp,$r,$err) = regen_object($file );
2477
            if ($r){
2478 48 alirezamon
                add_info($info,"**Error: cannot open $file file: $err\n");
2479
                $dialog->destroy;
2480 43 alirezamon
                return;
2481
            }
2482
 
2483 34 alirezamon
 
2484 43 alirezamon
            clone_obj($mpsoc,$pp);
2485
            #read save mpsoc socs
2486
            my @oldsocs=$mpsoc->mpsoc_get_soc_list();
2487 48 alirezamon
            #add existing SoCs and add them to mpsoc
2488 43 alirezamon
 
2489
            my $error;
2490
            #print "old: @oldsocs\n new @newsocs \n"; 
2491
            foreach my $p (@oldsocs) {
2492
                #print "$p\n";
2493
                my @num= $mpsoc->mpsoc_get_soc_tiles_num($p);
2494
                if (scalar @num && ( grep (/^$p$/,@newsocs)==0)){
2495 48 alirezamon
                    my $m="Processing tile $p that has been used for ties  @num but is not located in library anymore\n";
2496 43 alirezamon
                     $error = (defined $error ) ? "$error $m" : $m;
2497
                }
2498
                $mpsoc->mpsoc_remove_soc ($p) if (grep (/^$p$/,@newsocs)==0);
2499
 
2500 34 alirezamon
 
2501 43 alirezamon
            }
2502
            @newsocs=get_soc_list($mpsoc,$info); # add all existing socs
2503 48 alirezamon
            add_info($info,"**Error:  \n $error\n") if(defined $error);
2504 38 alirezamon
 
2505 43 alirezamon
            set_gui_status($mpsoc,"load_file",0);
2506
 
2507
        }
2508 38 alirezamon
     }
2509
     $dialog->destroy;
2510
}
2511
 
2512 48 alirezamon
#######
2513
#       CLK setting
2514
#######
2515
 
2516
sub clk_setting_win1{
2517
        my ($self,$info,$type)=@_;
2518
 
2519
        my $window = def_popwin_size(80,80,"CLK setting",'percent');
2520
 
2521
    my $next=def_image_button('icons/right.png','Next');
2522
        my $mtable = def_table(10, 1, FALSE);
2523
        #get the list of all tiles clk sources
2524
 
2525
        my @sources=('clk','reset');
2526
 
2527
        my $table = def_table(10, 7, FALSE);
2528
        my $notebook = gen_notebook();
2529
        $notebook->set_scrollable(TRUE);
2530
        #$notebook->can_focus(FALSE);
2531
        $notebook->set_tab_pos ('left');
2532
 
2533
 
2534
 
2535
        my($row,$column)=(0,0);
2536
 
2537
        my %all = ($type eq 'mpsoc') ? get_all_tiles_clk_sources_list($self): get_soc_clk_source_list($self) ;
2538
        foreach my $s (@sources){
2539
                 my $spin;
2540
                 ($row,$column,$spin)=  add_param_widget($self,"$s number","${s}_number", 1,'Spin-button',"1,1024,1","Define total number of ${s} input ports  mpsoc", $table,$row,$column,1,'SOURCE_SET',undef,undef,'horizontal');
2541
 
2542
                 my $w=get_source_assignment_win($self,$s,$all{$s},$type);
2543
                 my $box=def_hbox(FALSE,0);
2544
                 $box->pack_start($w, TRUE, TRUE, 0);
2545
                 $notebook->append_page ($box,gen_label_in_center ($s));
2546
                 $spin->signal_connect("value_changed" => sub{
2547
                        $self->object_add_attribute('SOURCE_SET',"REDEFINE_TOP",1);
2548
                        $w->destroy;
2549
                        $w=get_source_assignment_win($self,$s,$all{$s},$type);
2550
                        $box->pack_start($w, TRUE, TRUE, 0);
2551
                        $box->show_all;
2552
 
2553
                 });
2554
 
2555
        }
2556
 
2557
        $mtable->attach_defaults($table,0,1,0,1);
2558
        $mtable->attach_defaults( $notebook,0,1,1,20);
2559
        $mtable->attach($next,0,1,20,21,'expand','fill',2,2);
2560
        $window->add ($mtable);
2561
        $window->show_all();
2562
        $next-> signal_connect("clicked" => sub{
2563
                clk_setting_win2($self,$info,$type);
2564
                $window->destroy;
2565
 
2566
        });
2567
 
2568
}
2569
 
2570
 
2571
sub update_wave_form {
2572
        my ($period,$rise,$fall,$r_lab,$f_lab)=@_;
2573
        my $p =$period->get_value();
2574
        my $n =$rise->get_value();
2575
        my $v= ($p * $n)/100;
2576
        $r_lab->set_text("=$v ns");
2577
        $n =$fall->get_value();
2578
        $v= ($p * $n)/100;
2579
        $f_lab->set_text("=$v ns");
2580
}
2581
 
2582
sub get_source_assignment_win{
2583
        my ($mpsoc,$s,$ports_ref,$type)=@_;
2584
        my$row=0;
2585
        my $column=0;
2586
        my $num = $mpsoc->object_get_attribute('SOURCE_SET',"${s}_number");
2587
        my $table1 = def_table(20, 20, FALSE);
2588
        my $win1=add_widget_to_scrolled_win($table1);
2589
        my $win2;
2590
        my $v2;
2591
 
2592
        #if($s eq 'clk'){
2593
        #       my @labels=("clk name", 'Frequency MHz', 'Period ns', 'rise edge times ns', 'fall edge times ns');
2594
        #       foreach my $l (@labels){
2595
                        #  $table1->attach  (gen_label_in_center($l),$column,$column+1,$row,$row+1,'fill','shrink',2,2);$column+=5;
2596
        #       }
2597
                #$row++;
2598
                #$column=0;
2599
        #}
2600
 
2601
        #get source signal names        
2602
        my $loc =  'vertical';
2603
        for(my $n=0;$n<$num; $n++ ){
2604
                my $entry;
2605
                my $enter= def_image_button("icons/enter.png");
2606
                my $box=def_hbox(FALSE,0);
2607
                $box->pack_start( $enter, FALSE, FALSE, 0);
2608
 
2609
                ($row,$column,$entry)=  add_param_widget($mpsoc,"$n-","${s}_${n}_name", "${s}$n",'Entry',undef,undef, $table1,$row,$column,1,'SOURCE_SET',undef,undef,'horizontal');
2610
            $table1->attach  ($box,$column,$column+1,$row,$row+1,'fill','shrink',2,2);$column++;
2611
 
2612
                $enter->signal_connect ("clicked"  => sub{
2613
                        $mpsoc->object_add_attribute('SOURCE_SET',"REDEFINE_TOP",1);
2614
                        $win2->destroy;
2615
                        $win2= get_source_assignment_win2($mpsoc,$s,$ports_ref,$type);
2616
                        $v2-> pack2($win2, TRUE, TRUE);
2617
                        $v2->show_all;
2618
                });
2619
 
2620
 
2621
                if($s eq 'clk'){
2622
                        ($column,$row)=get_clk_constrain_widget($mpsoc,$table1,$column,$row, $s,$n);
2623
                }
2624
 
2625
 
2626
 
2627
           # if((($n+1) % 4)==0){
2628
                        $column=0;
2629
                        $row++;
2630
           #}             
2631
        }
2632
 
2633
        #source assigmnmet
2634
    $win2= get_source_assignment_win2($mpsoc,$s,$ports_ref,$type);
2635
        $v2=gen_vpaned($win1,.2,$win2);
2636
        return $v2;
2637
}
2638
 
2639
 
2640
sub get_clk_constrain_widget {
2641
        my ($self,$table,$column,$row, $s,$n)=@_;
2642
        $table->attach (gen_Vsep() , $column,$column+1,$row,$row+1,'fill','fill',2,2);$column+=1;
2643
        return ($column,$row);
2644
        my $frequency;
2645
        ($row,$column,$frequency)=  add_param_widget($self,"Frequency(MHz)","${s}_${n}_mhz", 100,'Spin-button',"1,1024,0.01",undef, $table,$row,$column,1,'SOURCE_SET',undef,undef,'horizontal');
2646
        $table->attach (gen_Vsep() , $column,$column+1,$row,$row+1,'fill','fill',2,2);$column+=1;
2647
        my $period;
2648
        ($row,$column,$period)=  add_param_widget($self,"Period(ns)","${s}_${n}_period", 10,'Spin-button',"0,1024,0.01",undef, $table,$row,$column,1,'SOURCE_SET',undef,undef,'horizontal');
2649
        $table->attach (gen_Vsep() , $column,$column+1,$row,$row+1,'fill','fill',2,2);$column+=1;
2650
        my $rise;
2651
        ($row,$column,$rise)=  add_param_widget($self,"rising edge(%)","${s}_${n}_rise", 0,'Spin-button',"0,100,0.1",undef, $table,$row,$column,1,'SOURCE_SET',undef,undef,'horizontal');
2652
        my $r_lab=gen_label_in_center('=0 ns');
2653
        $table->attach  ($r_lab,$column,$column+1,$row,$row+1,'fill','shrink',2,2);$column+=1;
2654
        $table->attach (gen_Vsep() , $column,$column+1,$row,$row+1,'fill','fill',2,2);$column+=1;
2655
        my $fall;
2656
        ($row,$column,$fall)=  add_param_widget($self,"falling edge(%)","${s}_${n}_fall", 50,'Spin-button',"0,100,0.1",undef, $table,$row,$column,1,'SOURCE_SET',undef,undef,'horizontal');
2657
        my $f_lab=gen_label_in_center('=5 ns');
2658
        $table->attach  ($f_lab,$column,$column+1,$row,$row+1,'fill','shrink',2,2);$column+=1;
2659
        update_wave_form($period,$rise,$fall,$r_lab,$f_lab);
2660
        $frequency-> signal_connect("value_changed" => sub{
2661
                my $fr =$frequency->get_value();
2662
                my $p = 1000/$fr;
2663
                $period->set_value($p);
2664
                update_wave_form($period,$rise,$fall,$r_lab,$f_lab);
2665
        });
2666
        $period-> signal_connect("value_changed" => sub{
2667
                my $p =$period->get_value();
2668
                my $fr = 1000/$p;
2669
                $frequency->set_value($fr);
2670
                update_wave_form($period,$rise,$fall,$r_lab,$f_lab);
2671
        });
2672
        $rise-> signal_connect("value_changed" => sub{
2673
                update_wave_form($period,$rise,$fall,$r_lab,$f_lab);
2674
        });
2675
        $fall-> signal_connect("value_changed" => sub{
2676
           update_wave_form($period,$rise,$fall,$r_lab,$f_lab);
2677
        });
2678
        return ($column,$row);
2679
}
2680
 
2681
 
2682
 
2683
sub get_source_assignment_win2{
2684
        my ($mpsoc,$s,$ports_ref,$type)=@_;
2685
        my $num = $mpsoc->object_get_attribute('SOURCE_SET',"${s}_number");
2686
        my $table2 = def_table(10, 7, FALSE);
2687
        my $win2=add_widget_to_scrolled_win($table2);
2688
        my %ports = %{$ports_ref} if(defined $ports_ref);
2689
 
2690
        my $contents;
2691
        for(my $n=0;$n<$num; $n++ ){
2692
                my $m=$mpsoc->object_get_attribute('SOURCE_SET',"${s}_${n}_name");
2693
                $contents=(defined $contents)? "$contents,$m":$m;
2694
        }
2695
        my $default=$mpsoc->object_get_attribute('SOURCE_SET',"${s}_0_name");
2696
        my $n=0;
2697
        my($row,$column)=(0,0);
2698
        if($type eq 'mpsoc' ) {
2699
                add_param_widget($mpsoc,"    NoC $s","NoC_${s}", $default,'Combo-box',$contents,undef, $table2,$row,$column,1,'SOURCE_SET_CONNECT',undef,undef,'horizontal');
2700
                ($row,$column)=(1,0);
2701
        }
2702
 
2703
        foreach my $p (sort keys %ports){
2704
                my @array=@{$ports{$p}};
2705
                foreach my $q (@array){
2706
                        my $param="${p}_$q";
2707
                        my $label="  ${p}_$q";
2708
                        ($row,$column)=  add_param_widget($mpsoc,$label,$param, $default,'Combo-box',$contents,undef, $table2,$row,$column,1,'SOURCE_SET_CONNECT',undef,undef,'horizontal');
2709
                        if((($n+1) % 4)==0){$column=0;$row++;}$n++;
2710
                }
2711
        }
2712
        return $win2;
2713
 
2714
}
2715
 
2716
 
2717
sub get_all_tiles_clk_sources_list{
2718
        my $mpsoc=shift;
2719
        my ($NE, $NR, $RAw, $EAw, $Fw)= get_topology_info ($mpsoc);
2720
    my %all_sources;
2721
        for (my $tile_num=0;$tile_num<$NE;$tile_num++){
2722
                my ($soc_name,$n,$soc_num)=$mpsoc->mpsoc_get_tile_soc_name($tile_num);
2723
                next if(!defined $soc_name);
2724
                my $top=$mpsoc->mpsoc_get_soc($soc_name);
2725
                my @intfcs=$top->top_get_intfc_list();
2726
 
2727
                my @sources=('clk','reset');
2728
 
2729
                foreach my $intfc (@intfcs){
2730
                        my($type,$name,$num)= split("[:\[ \\]]", $intfc);
2731
                        foreach my $s (@sources){
2732
                                if ($intfc =~ /plug:$s/){
2733
                                        my @ports=$top->top_get_intfc_ports_list($intfc);
2734
                                        $all_sources{$s}{"T$tile_num"}=\@ports;
2735
                                }
2736
                        }
2737
 
2738
                }
2739
        }
2740
                return  %all_sources;
2741
}
2742
 
2743
 
2744
 
2745
sub clk_setting_win2{
2746
        my ($self,$info,$type)=@_;
2747
 
2748
        my $window = def_popwin_size(70,70,"CLK setting",'percent');
2749
    my $table = def_table(10, 7, FALSE);
2750
    my $scrolled_win=add_widget_to_scrolled_win($table);
2751
    my $ok = def_image_button('icons/select.png','OK');
2752
    my $back = def_image_button('icons/left.png',undef);
2753
    my $diagram  = def_image_button('icons/diagram.png','Diagram');
2754
    my $ip = ip->lib_new ();
2755
    #print "get_top_ip(\$self,$type);\n";
2756
    my $mpsoc_ip=get_top_ip($self,$type);
2757
 
2758
        $ip->add_ip($mpsoc_ip);
2759
    my $soc =get_source_set_top($self,$type);
2760
    my $infc = interface->interface_new();
2761
 
2762
 
2763
    set_gui_status($soc,"ideal",0);
2764
    # A tree view for holding a library
2765
        my %tree_text;
2766
        my @categories= ('Source');
2767
    foreach my $p (@categories)
2768
    {
2769
                my @modules= $ip->get_modules($p);
2770
                $tree_text{$p}=\@modules;
2771
    }
2772
 
2773
        my $tree_box = create_tree ($soc,'IP list', $info,\%tree_text,\&tmp,\&add_module_to_mpsoc);
2774
    my  $device_win=show_active_dev($soc,$ip,$infc,$info);
2775
    my $h1=gen_hpaned($tree_box,.15,$device_win);
2776
    $table->attach_defaults ($h1,0, 10, 0, 10);
2777
 
2778
    my $event =Event->timer (after => 1, interval => 1, cb => sub {
2779
 
2780
my ($state,$timeout)= get_gui_status($soc);
2781
 
2782
 
2783
                if ($timeout>0){
2784
                    $timeout--;
2785
                    set_gui_status($soc,$state,$timeout);
2786
                }
2787
                elsif( $state ne "ideal" ){
2788
 
2789
                   #check if top is removed add it
2790
                                my @instances=$soc->soc_get_all_instances();
2791
                                my $redefine =1;
2792
                                foreach my $inst (@instances){
2793
                                        $redefine = 0 if ($inst eq 'TOP');
2794
                                }
2795
                                if($redefine == 1){
2796
                                        my $ip = ip->lib_new ();
2797
                                        #print "get_top_ip(\$self,$type);\n";
2798
                                my $mpsoc_ip=get_top_ip($self,$type);
2799
 
2800
                                        $ip->add_ip($mpsoc_ip);
2801
                                $soc ->object_add_attribute('SOURCE_SET',"IP",$mpsoc_ip);
2802
                                $self->object_add_attribute('SOURCE_SET',"REDEFINE_TOP",0);
2803
                                add_mpsoc_to_device($soc,$ip);
2804
                                $self->object_add_attribute('SOURCE_SET',"SOC",$soc);
2805
                                }
2806
 
2807
                    $device_win->destroy;
2808
 
2809
                    $device_win=show_active_dev($soc,$ip,$infc,$info);
2810
                    $h1 -> pack2($device_win, TRUE, TRUE);
2811
                                $h1 -> show_all;
2812
                    $table->show_all();
2813
                    $device_win->show_all();
2814
 
2815
                    $self->object_add_attribute('SOURCE_SET',"SOC",$soc);
2816
                    set_gui_status($soc,"ideal",0);
2817
 
2818
                }
2819
                return TRUE;
2820
 
2821
 
2822
 });
2823
 
2824
        my $mtable = def_table(10, 5, FALSE);
2825
        $mtable->attach_defaults($scrolled_win,0,5,0,9);
2826
        $mtable->attach($back,0,1,9,10,'expand','fill',2,2) if($type ne 'soc');
2827
        $mtable->attach($diagram,2,4,9,10,'expand','fill',2,2);
2828
        $mtable->attach($ok,4,5,9,10,'expand','fill',2,2);
2829
 
2830
        $window->add ($mtable);
2831
        $window->show_all();
2832
        $self->object_add_attribute('SOURCE_SET',"SOC",$soc);
2833
        $back-> signal_connect("clicked" => sub{
2834
                $self->object_add_attribute('SOURCE_SET',"SOC",$soc);
2835
                clk_setting_win1($self,$info,$type);
2836
                $window->destroy;
2837
                $event->cancel;
2838
        });
2839
 
2840
        $diagram-> signal_connect("clicked" => sub{
2841
                show_tile_diagram ($soc);
2842
        });
2843
 
2844
        $ok-> signal_connect("clicked" => sub{
2845
                set_gui_status($self,"ref",1);
2846
                $window->destroy;
2847
        $event->cancel;
2848
        });
2849
 
2850
 
2851
 
2852
 
2853
 
2854
 
2855
}
2856
 
2857
sub tmp{
2858
 
2859
}
2860
 
2861
sub add_module_to_mpsoc{
2862
        my ($soc,$category,$module,$info)=@_;
2863
        my $ip = ip->lib_new ();
2864
 
2865
        my ($instance_id,$id)= get_instance_id($soc,$category,$module);
2866
 
2867
        #add module instance
2868
        my $result=$soc->soc_add_instance($instance_id,$category,$module,$ip);
2869
 
2870
        if($result == 0){
2871
                my $info_text= "Failed to add \"$instance_id\" to SoC. $instance_id is already exist.";
2872
                show_info($info,$info_text);
2873
                return;
2874
        }
2875
        $soc->soc_add_instance_order($instance_id);
2876
        # Add IP version 
2877
        my $v=$ip->ip_get($category,$module,"version");
2878
        $v = 0 if(!defined $v);
2879
        #print "$v\n";
2880
        $soc->object_add_attribute($instance_id,"version",$v);
2881
        # Read default parameter from lib and add them to soc
2882
        my %param_default= $ip->get_param_default($category,$module);
2883
 
2884
        my $rr=$soc->soc_add_instance_param($instance_id,\%param_default);
2885
        if($rr == 0){
2886
                my $info_text= "Failed to add default parameter to \"$instance_id\".  $instance_id does not exist.";
2887
                show_info($info,$info_text);
2888
                return;
2889
        }
2890
        my @r=$ip->ip_get_param_order($category,$module);
2891
        $soc->soc_add_instance_param_order($instance_id,\@r);
2892
 
2893
        get_module_parameter($soc,$ip,$instance_id);
2894
        undef $ip;
2895
        set_gui_status($soc,"refresh_soc",0);
2896
}
2897
 
2898
 
2899
 
2900
 
2901
#$mpsoc,$top_ip,$sw_dir,$soc_name,$id,$soc_num,$txview
2902
sub get_top_ip{
2903
        my ($self,$type)=@_;
2904
 
2905
        my $mpsoc_ip=ip_gen->ip_gen_new();
2906
        $mpsoc_ip->ipgen_add("module_name",'TOP');
2907
        $mpsoc_ip->ipgen_add("ip_name",'TOP');
2908
        $mpsoc_ip->ipgen_add("category",'TOP');
2909
        $mpsoc_ip->ipgen_add('GUI_REMOVE_SET','DISABLE');
2910
        if($type eq 'mpsoc'){
2911
                my @sources=('clk','reset');
2912
                foreach my $s (@sources){
2913
                        my $num = $self->object_get_attribute('SOURCE_SET',"${s}_number");
2914
                        $num=1 if(!defined $num);
2915
                        $mpsoc_ip->ipgen_add_plug("$s",'num',$num);
2916
                        for (my $n=0; $n<$num; $n++ ){
2917
 
2918
                                my $name=$self->object_get_attribute('SOURCE_SET',"${s}_${n}_name");
2919
                                $mpsoc_ip->ipgen_set_plug_name($s,$n,$name);
2920
                                $mpsoc_ip->ipgen_add_port($name,undef,'input',"plug:${s}\[$n\]","${s}_i");
2921
 
2922
                        }
2923
                }
2924
        # add_mpsoc_ip_other_interfaces($mpsoc,$mpsoc_ip);      
2925
        }
2926
        else{
2927
                my %sources = get_soc_clk_source_list($self);
2928
                foreach my $s (sort keys %sources){
2929
                        my @ports = @{$sources{$s}} if (defined $sources{$s});
2930
                        my $num=scalar @ports;
2931
                        $mpsoc_ip->ipgen_add_plug("$s",'num',$num);
2932
                        my $n=0;
2933
                        foreach my $p (@ports){
2934
                                $mpsoc_ip->ipgen_set_plug_name($s,$n,$p);
2935
                                $mpsoc_ip->ipgen_add_port($p,undef,'input',"plug:${s}\[$n\]","${s}_i");
2936
                                $n++;
2937
                        }
2938
                }
2939
        }
2940
        return $mpsoc_ip;
2941
}
2942
 
2943
 
2944
sub add_mpsoc_ip_other_interfaces{
2945
        my ($mpsoc,$mpsoc_ip)=@_;
2946
my ($NE, $NR, $RAw, $EAw, $Fw)= get_topology_info ($mpsoc);
2947
    my $processors_en=0;
2948
    my %intfc_num;
2949
    my @parameters_order;
2950
        for (my $tile_num=0;$tile_num<$NE;$tile_num++){
2951
                        my ($soc_name,$n,$soc_num)=$mpsoc->mpsoc_get_tile_soc_name($tile_num);
2952
 
2953
 
2954
                        my $top=$mpsoc->mpsoc_get_soc($soc_name);
2955
                        my @nis=get_NI_instance_list($top);
2956
                        my @noc_param=$top->top_get_parameter_list($nis[0]);
2957
                        my $inst_name=$top->top_get_def_of_instance($nis[0],'instance');
2958
 
2959
                        #other parameters
2960
                        my %params=$top->top_get_default_soc_param();
2961
 
2962
                        my @intfcs=$top->top_get_intfc_list();
2963
 
2964
                        my $i=0;
2965
 
2966
                        my $dir = Cwd::getcwd();
2967
                        my $mpsoc_name=$mpsoc->object_get_attribute('mpsoc_name');
2968
                        my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name";
2969
                        my $soc_file="$target_dir/src_verilog/tiles/$soc_name.sv";
2970
 
2971
                        my $vdb =read_verilog_file($soc_file);
2972
 
2973
                        my %soc_localparam = $vdb->get_modules_parameters($soc_name);
2974
 
2975
 
2976
                        foreach my $intfc (@intfcs){
2977
 
2978
                                # Auto connected/not connected interface        
2979
                                if( $intfc eq 'socket:ni[0]' || ($intfc =~ /plug:clk\[/) ||  ( $intfc =~ /plug:reset\[/)|| ($intfc =~ /socket:RxD_sim\[/ )  || $intfc =~ /plug:enable\[/){
2980
                                        #do nothing
2981
                                }
2982
                                elsif( $intfc eq 'IO' ){
2983
                                        my @ports=$top->top_get_intfc_ports_list($intfc);
2984
                                        foreach my $p (@ports){
2985
                                                my ($io_port,$type,$new_range,$intfc_name,$intfc_port)= get_top_port_io_info($top,$p,$tile_num,\%params,\%soc_localparam);
2986
                                                $mpsoc_ip->ipgen_add_port($io_port,$new_range,$type,'IO','IO');
2987
 
2988
 
2989
                                        }
2990
 
2991
                                }
2992
 
2993
                                else {
2994
                                #other interface
2995
                                    my($if_type,$if_name,$if_num)= split("[:\[ \\]]", $intfc);
2996
                                    print "my($if_type,$if_name,$if_num)= split(, $intfc); \n";
2997
                                    my $num = (defined $intfc_num{"$if_type:$if_name"})? $intfc_num{"$if_type:$if_name"}+1:0;
2998
                                    $intfc_num{"$if_type:$if_name"}=$num;
2999
                                    $mpsoc_ip->ipgen_add_plug("$if_name",'num',$num) if ($if_type eq 'plug');
3000
                                    $mpsoc_ip->ipgen_add_soket("$if_name",'num',$num) if ($if_type eq 'socket');
3001
 
3002
                                        my @ports=$top->top_get_intfc_ports_list($intfc);
3003
                                        foreach my $p (@ports){
3004
                                                my ($io_port,$type,$new_range,$intfc_name,$intfc_port)= get_top_port_io_info($top,$p,$tile_num,\%params,\%soc_localparam);
3005
                                                $mpsoc_ip->ipgen_add_port($io_port,$new_range,$type,"$if_type:$if_name\[$num\]",$intfc_port);
3006
 
3007
                                        }
3008
                                }
3009
                        }
3010
 
3011
 
3012
                my $setting=$mpsoc->mpsoc_get_tile_param_setting($tile_num);
3013
                #if ($setting eq 'Custom'){
3014
                         %params= $top->top_get_custom_soc_param($tile_num);
3015
                #}else{
3016
                #        %params=$top->top_get_default_soc_param();
3017
                #}
3018
 
3019
                foreach my $p (sort keys %params){
3020
                        $params{$p}=add_instantc_name_to_parameters(\%params,"T$tile_num",$params{$p});
3021
                        $params{$p}=add_instantc_name_to_parameters(\%soc_localparam,"T$tile_num",$params{$p});
3022
                        my $pname="T${tile_num}_$p";
3023
                        $mpsoc_ip->     ipgen_add_parameter ($pname,$params{$p},'Fixed',undef,undef,'Localparam',1);
3024
                        push (@parameters_order,$pname);
3025
 
3026
                }
3027
                foreach my $p (sort keys %soc_localparam){
3028
                        $soc_localparam{$p}=add_instantc_name_to_parameters(\%params,"T$tile_num",$soc_localparam{$p});
3029
                        $soc_localparam{$p}=add_instantc_name_to_parameters(\%soc_localparam,"T$tile_num",$soc_localparam{$p});
3030
                        my $pname="T${tile_num}_$p";
3031
                        $mpsoc_ip->     ipgen_add_parameter ($pname,$soc_localparam{$p},'Fixed',undef,undef,'Localparam',0);
3032
                        push (@parameters_order,$pname);
3033
 
3034
                }
3035
 
3036
 
3037
 
3038
        }
3039
        #TODO get parameter order
3040
        $mpsoc_ip->ipgen_add("parameters_order",\@parameters_order);
3041
 
3042
}
3043
 
3044
sub get_source_set_top{
3045
        my ($self,$type)=@_;
3046
        my $soc =$self->object_get_attribute('SOURCE_SET',"SOC");
3047
    my $redefine =$self->object_get_attribute('SOURCE_SET',"REDEFINE_TOP");
3048
    $redefine=1 if(!defined $redefine);
3049
    if(!defined $soc){
3050
        $soc = soc->soc_new();
3051
        $soc->object_add_attribute('soc_name','TOP');
3052
        $redefine=1;
3053
    }
3054
    if($redefine==1){
3055
        my $ip = ip->lib_new ();
3056
        #print "get_top_ip(\$self,$type);\n";
3057
        my $mpsoc_ip=get_top_ip($self,$type);
3058
 
3059
                $ip->add_ip($mpsoc_ip);
3060
        $soc ->object_add_attribute('SOURCE_SET',"IP",$mpsoc_ip);
3061
        $self->object_add_attribute('SOURCE_SET',"REDEFINE_TOP",0);
3062
        add_mpsoc_to_device($soc,$ip);
3063
        $self->object_add_attribute('SOURCE_SET',"SOC",$soc);
3064
    }
3065
        return $soc;
3066
}
3067
 
3068
 
3069
sub add_mpsoc_to_device{
3070
        my ($soc,$ip)=@_;
3071
        my $category='TOP';
3072
        my $module='TOP';
3073
        my ($instance_id,$id) =('TOP',1);
3074
 
3075
        #my ($instance_id,$id)= get_instance_id($soc,$category,$module);
3076
 
3077
        remove_instance_from_soc($soc,$instance_id);
3078
 
3079
        #add module instanance
3080
        my $result=$soc->soc_add_instance($instance_id,$category,$module,$ip);
3081
 
3082
        if($result == 0){
3083
                my $info_text= "Failed to add \"$instance_id\" to SoC. $instance_id is already exist.";
3084
        #       show_info($info,$info_text); 
3085
                return;
3086
        }
3087
        $soc->soc_add_instance_order($instance_id);
3088
        # Add IP version 
3089
        my $v=$ip->ip_get($category,$module,"version");
3090
        $v = 0 if(!defined $v);
3091
        #print "$v\n";
3092
        $soc->object_add_attribute($instance_id,"version",$v);
3093
        # Read default parameter from lib and add them to soc
3094
        my %param_default= $ip->get_param_default($category,$module);
3095
 
3096
        my $rr=$soc->soc_add_instance_param($instance_id,\%param_default);
3097
        if($rr == 0){
3098
                my $info_text= "Failed to add default parameter to \"$instance_id\".  $instance_id does not exist.";
3099
        #       show_info($info,$info_text); 
3100
                return;
3101
        }
3102
        my @r=$ip->ip_get_param_order($category,$module);
3103
        $soc->soc_add_instance_param_order($instance_id,\@r);
3104
 
3105
        #get_module_parameter($soc,$ip,$instance_id);
3106
        undef $ip;
3107
        set_gui_status($soc,"refresh_soc",0);
3108
}
3109
 
3110
######
3111
# ctrl
3112
######
3113
 
3114
sub ctrl_box{
3115
        my ($mpsoc,$info)=@_;
3116
        my $table = def_table (1, 12, FALSE);
3117
        my $generate = def_image_button('icons/gen.png','_Generate RTL',FALSE,1);
3118
    my $open = def_image_button('icons/browse.png','_Load MPSoC',FALSE,1);
3119
    my $compile  = def_image_button('icons/gate.png','_Compile RTL',FALSE,1);
3120
    my $software = def_image_button('icons/binary.png','_Software',FALSE,1);
3121
    my $entry=gen_entry_object($mpsoc,'mpsoc_name',undef,undef,undef,undef);
3122
    my $entrybox=gen_label_info(" MPSoC name:",$entry);
3123
    my $save      = def_image_button('icons/save.png');
3124
    my $open_dir  = def_image_button('icons/open-folder.png');
3125
    set_tip($save, "Save current MPSoC configuration setting");
3126
        set_tip($open_dir, "Open target MPSoC folder");
3127
 
3128
        $entrybox->pack_start( $save, FALSE, FALSE, 0);
3129
        $entrybox->pack_start( $open_dir , FALSE, FALSE, 0);
3130
    my $diagram  = def_image_button('icons/diagram.png','Diagram');
3131
    my $clk=  def_image_button('icons/clk.png','CLK setting');
3132
 
3133
        my $row=0;
3134
    $table->attach ($open,$row, $row+2, 0,1,'expand','shrink',2,2);$row+=2;
3135
    $table->attach ($entrybox,$row, $row+2, 0,1,'expand','shrink',2,2);$row+=2;
3136
    $table->attach ($diagram, $row, $row+1, 0,1,'expand','shrink',2,2);$row++;
3137
    $table->attach ($clk, $row, $row+1, 0,1,'expand','shrink',2,2);$row++;
3138
    $table->attach ($generate, $row, $row+1, 0,1,'expand','shrink',2,2);$row++;
3139
    $table->attach ($software, $row, $row+1, 0,1,'expand','shrink',2,2);$row++;
3140
    $table->attach ($compile, $row, $row+1, 0,1,'expand','shrink',2,2);$row++;
3141
 
3142
        $generate-> signal_connect("clicked" => sub{
3143
        generate_mpsoc($mpsoc,$info,1);
3144
        set_gui_status($mpsoc,"refresh_soc",1);
3145
    });
3146
 
3147
    $save-> signal_connect("clicked" => sub{
3148
        my $name=$mpsoc->object_get_attribute('mpsoc_name');
3149
        return  if (check_mpsoc_name($name,$info));
3150
        generate_mpsoc_lib_file($mpsoc,$info);
3151
        message_dialog("MPSOC  \"$name\" is saved as lib/mpsoc/$name.MPSOC.");
3152
 
3153
    });
3154
 
3155
 
3156
    $open-> signal_connect("clicked" => sub{
3157
        set_gui_status($mpsoc,"ref",5);
3158
        load_mpsoc($mpsoc,$info);
3159
    });
3160
 
3161
 
3162
    $compile -> signal_connect("clicked" => sub{
3163
        $mpsoc->object_add_attribute('compile','compilers',"QuartusII,Vivado,Verilator,Modelsim");
3164
        my $name=$mpsoc->object_get_attribute('mpsoc_name');
3165
        $name="" if (!defined $name);
3166
        if (length($name)==0){
3167
            message_dialog("Please define the MPSoC name!");
3168
            return ;
3169
        }
3170
        my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$name";
3171
        my $top_file     = "$target_dir/src_verilog/${name}_top.v";
3172
        if (-f $top_file){
3173
                my $answer = yes_no_dialog ("Do you want to Regenearte the MPSoC RTL code too?");
3174
            generate_mpsoc($mpsoc,$info,0) if ($answer eq 'yes');
3175
            select_compiler($mpsoc,$name,$top_file,$target_dir);
3176
        } else {
3177
            message_dialog("Cannot find $top_file file. Please run RTL Generator first!");
3178
            return;
3179
        }
3180
    });
3181
 
3182
    $software -> signal_connect("clicked" => sub{
3183
        my $name=$mpsoc->object_get_attribute('mpsoc_name');
3184
        $name="" if (!defined $name);
3185
        if (length($name)==0){
3186
            message_dialog("Please define the MPSoC name!");
3187
            return ;
3188
        }
3189
        my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$name";
3190
        my $sw_folder = "$target_dir/sw";
3191
        unless (-d $sw_folder){
3192
                message_dialog("Cannot find $sw_folder. Please run RTL Generator first!");
3193
                return;
3194
        }
3195
        software_edit_mpsoc($mpsoc);
3196
 
3197
    });
3198
 
3199
    $diagram-> signal_connect("clicked" => sub{
3200
        show_topology_diagram ($mpsoc);
3201
    });
3202
 
3203
 
3204
        $clk-> signal_connect("clicked" => sub{
3205
                        clk_setting_win1($mpsoc,$info,'mpsoc');
3206
        });
3207
 
3208
        $open_dir-> signal_connect("clicked" => sub{
3209
                my $name=$mpsoc->object_get_attribute('mpsoc_name');
3210
        $name="" if (!defined $name);
3211
        if (length($name)==0){
3212
            message_dialog("Please define the MPSoC name!");
3213
            return ;
3214
        }
3215
        my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$name";
3216
                unless (-d $target_dir){
3217
                        message_dialog("Cannot find $target_dir.\n Please run RTL Generator first!",'error');
3218
                        return;
3219
                }
3220
                system "xdg-open   $target_dir";
3221
 
3222
        });
3223
 
3224
 
3225
        return $table;
3226
}
3227
 
3228 16 alirezamon
############
3229
#    main
3230
############
3231
sub mpsocgen_main{
3232 43 alirezamon
    my $infc = interface->interface_new();
3233
    my $soc = ip->lib_new ();
3234
    my $mpsoc= mpsoc->mpsoc_new();
3235 48 alirezamon
 
3236 43 alirezamon
    set_gui_status($mpsoc,"ideal",0);
3237 48 alirezamon
    my $main_table = def_table (25, 12, FALSE);
3238 43 alirezamon
 
3239 48 alirezamon
    # The box which holds the info, warning, error ...  messages
3240
    my ($infobox,$info)= create_txview();
3241 43 alirezamon
 
3242
    my $noc_conf_box=get_config ($mpsoc,$info);
3243
    my $noc_tiles=gen_tiles($mpsoc);
3244 48 alirezamon
 
3245 16 alirezamon
 
3246 43 alirezamon
    $main_table->set_row_spacings (4);
3247
    $main_table->set_col_spacings (1);
3248 48 alirezamon
    my $ctrl=ctrl_box($mpsoc,$info);
3249
    my $h1=gen_hpaned($noc_conf_box,.3,$noc_tiles);
3250 43 alirezamon
    my $v2=gen_vpaned($h1,.55,$infobox);
3251 48 alirezamon
        my $row=0;
3252 43 alirezamon
    $main_table->attach_defaults ($v2  , 0, 12, 0,24);
3253 48 alirezamon
    #$main_table->attach_defaults ($ctrl,0, 12, 24,25);
3254
    $main_table->attach ($ctrl,0, 12, 24,25, 'fill','fill',2,2);
3255 16 alirezamon
 
3256 48 alirezamon
    #check soc status every 0.5 second. refresh device table if there is any changes 
3257 43 alirezamon
    Glib::Timeout->add (100, sub{
3258
        my ($state,$timeout)= get_gui_status($mpsoc);
3259
        if ($timeout>0){
3260
            $timeout--;
3261
            set_gui_status($mpsoc,$state,$timeout);
3262
        }elsif ($state eq 'save_project'){
3263
            # Write object file
3264
            my $name=$mpsoc->object_get_attribute('mpsoc_name');
3265
            open(FILE,  ">lib/mpsoc/$name.MPSOC") || die "Can not open: $!";
3266
            print FILE perl_file_header("$name.MPSOC");
3267
            print FILE Data::Dumper->Dump([\%$mpsoc],[$name]);
3268 48 alirezamon
            close(FILE) || die "Error closing file: $!";
3269 43 alirezamon
            set_gui_status($mpsoc,"ideal",0);
3270
        }
3271
        elsif( $state ne "ideal" ){
3272
            $noc_conf_box->destroy();
3273
            $noc_conf_box=get_config ($mpsoc,$info);
3274
            $noc_tiles->destroy();
3275 48 alirezamon
            $noc_tiles=gen_tiles($mpsoc);
3276
            $h1 -> pack1($noc_conf_box, TRUE, TRUE);
3277
            $h1 -> pack2($noc_tiles, TRUE, TRUE);
3278 43 alirezamon
            $v2-> pack1($h1, TRUE, TRUE);
3279
            $h1->show_all;
3280 48 alirezamon
            $ctrl->destroy;
3281
            $ctrl=ctrl_box($mpsoc,$info);
3282
            $main_table->attach ($ctrl,0, 12, 24,25,'fill','fill',2,2);
3283 43 alirezamon
            $main_table->show_all();
3284 48 alirezamon
 
3285
 
3286 43 alirezamon
            set_gui_status($mpsoc,"ideal",0);
3287
 
3288
 
3289
        }
3290
        return TRUE;
3291
 
3292
    } );
3293
 
3294 48 alirezamon
    my $sc_win = add_widget_to_scrolled_win($main_table);
3295 34 alirezamon
 
3296 43 alirezamon
    return $sc_win;
3297 16 alirezamon
}
3298
 
3299
 

powered by: WebSVN 2.1.0

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