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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 alirezamon
#! /usr/bin/perl -w
2
use Glib qw/TRUE FALSE/;
3
use strict;
4
use warnings;
5
use soc;
6
use ip;
7
use interface;
8
use POSIX 'strtol';
9
 
10
use File::Path;
11
use File::Find;
12
use File::Copy;
13 17 alirezamon
use File::Copy::Recursive qw(dircopy);
14 16 alirezamon
use Cwd 'abs_path';
15
 
16
 
17
use Gtk2;
18
use Gtk2::Pango;
19
 
20
 
21
 
22
# clean names for column numbers.
23
use constant DISPLAY_COLUMN    => 0;
24
use constant CATRGORY_COLUMN    => 1;
25
use constant MODULE_COLUMN     => 2;
26
use constant ITALIC_COLUMN   => 3;
27
use constant NUM_COLUMNS     => 4;
28
 
29
 
30
require "widget.pl";
31
require "verilog_gen.pl";
32 25 alirezamon
require "readme_gen.pl";
33 17 alirezamon
require "hdr_file_gen.pl";
34 16 alirezamon
 
35
 
36 17 alirezamon
 
37 16 alirezamon
 
38
 
39
sub is_hex {
40
    local $!;
41
    return ! (POSIX::strtol($_[0], 16))[1];
42
 }
43
 
44
###############
45
#   get_instance_id
46
# return an instance id which is the module name with a unique number 
47
#############
48
sub get_instance_id{
49
        my ($soc,$category,$module)=@_;
50
        my @id_list= $soc->soc_get_all_instances_of_module($category,$module);
51
        my $id=0;
52
        my $instance_id="$module$id";
53
        do {
54
                $instance_id = "$module$id";
55
                $id++;
56
        }while ((grep {$_ eq $instance_id} @id_list) ) ;
57
        #print "$instance_id\n";
58
        return ($instance_id,$id);
59
 
60
}
61
 
62
 
63
 
64
#################
65
#  add_module_to_soc
66
###############
67
sub add_module_to_soc{
68 25 alirezamon
        my ($soc,$ip,$category,$module,$info)=@_;
69 16 alirezamon
        my ($instance_id,$id)= get_instance_id($soc,$category,$module);
70
 
71
        #add module instanance
72
        my $result=$soc->soc_add_instance($instance_id,$category,$module,$ip);
73
 
74
        if($result == 0){
75
                my $info_text= "Failed to add \"$instance_id\" to SoC. $instance_id is already exist.";
76
                show_info($info,$info_text);
77
                return;
78
        }
79
        $soc->soc_add_instance_order($instance_id);
80
 
81 25 alirezamon
        # Read default parameter from lib and add them to soc
82 16 alirezamon
        my %param_default= $ip->get_param_default($category,$module);
83
 
84
        my $rr=$soc->soc_add_instance_param($instance_id,\%param_default);
85
        if($rr == 0){
86 25 alirezamon
                my $info_text= "Failed to add defualt parameter to \"$instance_id\".  $instance_id does not exist exist.";
87 16 alirezamon
                show_info($info,$info_text);
88
                return;
89
        }
90
        my @r=$ip->ip_get_param_order($category,$module);
91
        $soc->soc_add_instance_param_order($instance_id,\@r);
92
 
93 25 alirezamon
        get_module_parameter($soc,$ip,$instance_id);
94 16 alirezamon
 
95
 
96
 
97
}
98
################
99
#       remove_instance_from_soc
100
################
101
sub remove_instance_from_soc{
102 25 alirezamon
        my ($soc,$instance_id)=@_;
103 16 alirezamon
        $soc->soc_remove_instance($instance_id);
104
        $soc->soc_remove_from_instance_order($instance_id);
105 25 alirezamon
        set_gui_status($soc,"refresh_soc",0);
106 16 alirezamon
}
107
 
108
 
109
 
110
###############
111
#   get module_parameter
112
##############
113
 
114
sub get_module_parameter{
115 25 alirezamon
        my ($soc,$ip,$instance_id)=@_;
116 16 alirezamon
 
117
        #read module parameters from lib
118
        my $module=$soc->soc_get_module($instance_id);
119
        my $category=$soc->soc_get_category($instance_id);
120 25 alirezamon
        my @parameters=$ip->ip_get_param_order($category,$module);
121 16 alirezamon
        my $param_num = @parameters;
122
 
123
        #read soc parameters
124
        my %param_value= $soc->soc_get_module_param($instance_id);
125
        my %new_param_value=%param_value;
126
        #gui
127
        my $table_size = ($param_num<10) ? 10 : $param_num;
128 25 alirezamon
        my($width,$hight)=max_win_size();
129
        my $window =  def_popwin_size(.6*$width,.6*$hight, "Parameter setting for $module ");
130
        my $table = def_table($table_size, 7, FALSE);
131 16 alirezamon
 
132
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
133
        $scrolled_win->set_policy( "automatic", "automatic" );
134
        $scrolled_win->add_with_viewport($table);
135
        my $row=0;
136
 
137
        my $ok = def_image_button('icons/select.png','OK');
138 25 alirezamon
 
139
 
140
        $table->attach (gen_label_in_center("Parameter name"),0, 3, $row, $row+1,'expand','shrink',2,2);
141
        $table->attach (gen_label_in_center("Value"),3, 6, $row, $row+1,'expand','shrink',2,2);
142
        $table->attach (gen_label_in_center("Description"),6, 7, $row, $row+1,'expand','shrink',2,2);
143
        $row++;
144 16 alirezamon
        foreach my $p (@parameters){
145 25 alirezamon
                my ($default,$type,$content,$info)= $ip->ip_get_parameter($category,$module,$p);
146 16 alirezamon
 
147
                my $value=$param_value{$p};
148
 
149
                if ($type eq "Entry"){
150
                        my $entry=gen_entry($value);
151 25 alirezamon
                        $table->attach ($entry, 3, 6, $row, $row+1,'expand','shrink',2,2);
152 16 alirezamon
                        $entry-> signal_connect("changed" => sub{$new_param_value{$p}=$entry->get_text();});
153
                }
154
                elsif ($type eq "Combo-box"){
155
                        my @combo_list=split(",",$content);
156
                        my $pos=get_item_pos($value, @combo_list);
157
                        my $combo=gen_combo(\@combo_list, $pos);
158 25 alirezamon
                        $table->attach ($combo, 3, 6, $row, $row+1,'expand','shrink',2,2);
159 16 alirezamon
                        $combo-> signal_connect("changed" => sub{$new_param_value{$p}=$combo->get_active_text();});
160
 
161
                }
162
                elsif   ($type eq "Spin-button"){
163
                  my ($min,$max,$step)=split(",",$content);
164
                  $value=~ s/\D//g;
165
                  $min=~ s/\D//g;
166
                  $max=~ s/\D//g;
167
                  $step=~ s/\D//g;
168
                  my $spin=gen_spin($min,$max,$step);
169
                  $spin->set_value($value);
170 25 alirezamon
                  $table->attach ($spin, 3, 4, $row, $row+1,'expand','shrink',2,2);
171 24 alirezamon
                  $spin-> signal_connect("value_changed" => sub{ $new_param_value{$p}=$spin->get_value_as_int(); });
172 16 alirezamon
 
173
                 # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
174
                }
175
                if (defined $info && $type ne "Fixed"){
176
                        my $info_button=def_image_button('icons/help.png');
177 25 alirezamon
                        $table->attach ($info_button, 6, 7, $row, $row+1,'expand','shrink',2,2);
178 16 alirezamon
                        $info_button->signal_connect('clicked'=>sub{
179
                                message_dialog($info);
180
 
181
                        });
182
 
183
                }
184
                if ($type ne "Fixed"){
185
                        #print "$p:val:$value\n";
186
                        my $label =gen_label_in_center($p);
187 25 alirezamon
                        $table->attach ($label, 0, 3, $row, $row+1,'expand','shrink',2,2);
188 16 alirezamon
                        $row++;
189
                }
190
 
191 25 alirezamon
 
192 16 alirezamon
        }
193 25 alirezamon
        #if ($row== 0){
194
                        #my $label =gen_label_in_left("The $module IP does not have any adjatable parameter");
195
                #       $table->attach ($label, 0, 7, $row, $row+1,'expand','shrink',2,2);
196
 
197
        #}
198 16 alirezamon
 
199 25 alirezamon
        my $mtable = def_table(10, 1, FALSE);
200 16 alirezamon
 
201
        $mtable->attach_defaults($scrolled_win,0,1,0,9);
202 25 alirezamon
        $mtable->attach($ok,0,1,9,10,'expand','shrink',2,2);
203 16 alirezamon
 
204
        $window->add ($mtable);
205
        $window->show_all();
206
 
207
        $ok-> signal_connect("clicked" => sub{
208
                $window->destroy;
209
                #save new values 
210
                $soc->soc_add_instance_param($instance_id,\%new_param_value);
211
 
212
 
213
                #check if wishbone address bus is parameterizable regenerate the addresses again 
214
                my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
215
                foreach my $plug (@plugs){
216
                        if ($plug eq 'wb_slave'){
217
                                my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
218
                                foreach my $plug_num (@nums){
219
                                        my ($addr_connect,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$plug_num);
220
                                        if($connect_id ne 'IO' && $connect_id ne 'NC'){
221
                                                #print "$connect_id : soc_get_plug_addr ($instance_id,$plug,$plug_num)\n";
222
                                                #remove old wb addr
223
                                                $soc->soc_add_plug_base_addr($instance_id,$plug,$plug_num,undef,undef);
224
                                                #get base and address width
225
                                                my ($addr , $width)=$soc->soc_get_plug_addr ($instance_id,$plug,$plug_num);
226
                                                #check if width is a parameter
227
                                                my $val= get_parameter_final_value($soc,$instance_id,$width);
228
                                                $width= $val if(defined $val);
229
                                                #allocate new address in $connect_id
230
                                                my ($base,$end)=get_wb_address($soc,$connect_id,$addr,$width);
231
                                                if(defined $base){#save it
232
                                                        $soc->soc_add_plug_base_addr($instance_id,$plug,$plug_num,$base,$end);
233
                                                }
234
                                        }
235
                                }#plug_num
236
                        }#if
237
                }#plugs
238
 
239
 
240 25 alirezamon
                set_gui_status($soc,"refresh_soc",0);
241 16 alirezamon
                #$$refresh_soc->clicked;
242
 
243
                });
244
 
245
 
246
}
247
 
248
 
249
 
250
############
251
#  param_box
252
#
253
############
254
sub get_item_pos{#if not in return 0
255
                my ($item,@list)=@_;
256
                my $pos=0;
257
                foreach my $p (@list){
258
                                #print "$p eq $item\n";
259
                                if ($p eq $item){return $pos;}
260
                                $pos++;
261
                }
262
                return 0;
263
 
264
}
265
 
266
 sub param_box{
267
         my ($param, $default,$type,$content,$info, $value)=@_;
268
         my $box=def_hbox(TRUE,0);
269
         my $label =gen_label_in_left($param);
270
         $box->pack_start($label,FALSE,FALSE,3);
271
 
272
         if ($type eq "Entry"){
273
                my $entry=gen_entry($default);
274
                $box->pack_start($entry,FALSE,FALSE,3);
275
 
276
         }
277
         elsif ($type eq "Combo-box"){
278
                 my @combo_list=split(",",$content);
279
                 my $pos=get_item_pos($default, @combo_list);
280
                 my $combo=gen_combo(\@combo_list, $pos);
281
                 $box->pack_start($combo,FALSE,FALSE,3);
282
         }
283
         elsif  ($type eq "Spin-button"){
284
                  my ($min,$max,$step)=split(",",$content);
285
                  $default=~ s/\D//g;
286
                  $min=~ s/\D//g;
287
                  $max=~ s/\D//g;
288
                  $step=~ s/\D//g;
289
                  my $spin=gen_spin($min,$max,$step);
290
                  $box->pack_start($spin,FALSE,FALSE,3);
291
                 # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
292
         }
293
 
294
         return $box;
295
}
296
 
297
 
298
###############
299
#  get_mathced_socket_pos
300
###############
301
 
302
 
303
sub  get_mathced_socket_pos{
304
        my ($soc,$instance_id,$plug,$plug_num,@connettions)=@_;
305
        my ($id,$socket,$num)=$soc->soc_get_module_plug_conection($instance_id,$plug,$plug_num);
306
        my $pos=($id eq "IO")? 0: (scalar @connettions)-1;
307
        if($id ne "IO" && $id ne 'NC'){
308
                my $name= $soc->soc_get_instance_name($id);
309
                if (defined $name){
310
                        my $connect="$name\:$socket\[$num]";
311
                        if( grep {$_ eq $connect} @connettions){$pos = get_scolar_pos($connect,@connettions);}
312
                }
313
                else {
314
                        $soc->soc_add_instance_plug_conection($instance_id,$plug,$plug_num,"IO");
315
 
316
                }
317
        }
318
        return $pos;
319
}
320
 
321
 
322
##############
323
#       gen_dev_box
324
##############
325
 
326 25 alirezamon
sub gen_instance{
327
        #my ($soc,$ip,$infc,$instance_id,$info)=@_;
328
        my ($soc,$ip,$infc,$instance_id,$info,$table,$offset)=@_;
329 16 alirezamon
 
330
 
331
 
332
#       my $box= def_vbox (FALSE,0);
333
 
334
#       my $table = def_table(3,5,TRUE);
335
        my $data_in;
336
 
337
#column 1       
338
        #module name
339
        my $module=$soc->soc_get_module($instance_id);
340
        my $category=$soc->soc_get_category($instance_id);
341
        my $module_name_label=box_label(FALSE,0,$module);
342
        $table->attach_defaults ($module_name_label,0,1,$offset+0,$offset+1);
343
 
344
        #parameter setting button
345
        my $param_button = def_image_button('icons/setting.png','Setting');
346
        my $box1=def_hbox(FALSE,5);
347
        my $up=def_image_button("icons/up_sim.png");
348
        $box1->pack_start( $up, FALSE, FALSE, 3);
349
        $box1->pack_start($param_button,   FALSE, FALSE,3);
350
        $table->attach_defaults ($box1 ,0,1,$offset+1,$offset+2);
351
        $param_button->signal_connect (clicked => sub{
352 25 alirezamon
                get_module_parameter($soc,$ip,$instance_id);
353 16 alirezamon
 
354
        });
355
        $up->signal_connect (clicked => sub{
356
                $soc->soc_decrease_instance_order($instance_id);
357 25 alirezamon
                set_gui_status($soc,"refresh_soc",0);
358 16 alirezamon
 
359
        });
360
 
361
        #remove button
362
        #my ($box2,$cancel_button) = button_box("Remove");
363
        my $cancel_button=def_image_button('icons/cancel.png','Remove');
364
        my $box2=def_hbox(FALSE,5);
365
 
366
        my $dwn=def_image_button("icons/down_sim.png");
367
        $box2->pack_start( $dwn, FALSE, FALSE, 3);
368
        $box2->pack_start($cancel_button,   FALSE, FALSE,3);
369
        $table->attach_defaults ($box2,0,1,$offset+2,$offset+3);
370
        $cancel_button->signal_connect (clicked => sub{
371 25 alirezamon
                remove_instance_from_soc($soc,$instance_id);
372 16 alirezamon
 
373
        });
374
        $dwn->signal_connect (clicked => sub{
375
                $soc->soc_increase_instance_order($instance_id);
376 25 alirezamon
                set_gui_status($soc,"refresh_soc",0);
377 16 alirezamon
 
378
        });
379
 
380
 
381
        #instance name
382
        my $instance_name=$soc->soc_get_instance_name($instance_id);
383
        my $instance_label=gen_label_in_left("Instance name");
384
        my $instance_entry = gen_entry($instance_name);
385
 
386
 
387
 
388
        $table->attach_defaults ($instance_label,1,2,$offset+0,$offset+1);
389
        $table->attach_defaults ($instance_entry,1,2,$offset+1,$offset+2);
390
 
391
        $instance_entry->signal_connect (changed => sub{
392
                #print "changed\n";
393
                $instance_name=$instance_entry->get_text();
394
                #check if instance name exist in soc
395
                my @instance_names= $soc->soc_get_all_instance_name();
396
                if( grep {$_ eq $instance_name} @instance_names){
397
                        print "$instance_name exist\n";
398
                }
399
                else {
400
                #add instance name to soc
401
                        $soc->soc_set_instance_name($instance_id,$instance_name);
402
 
403 25 alirezamon
                        set_gui_status($soc,"refresh_soc",25);
404 16 alirezamon
 
405
                }
406
        });
407
 
408
 
409
 
410
        #interface_pluges
411
        my %plugs = $ip->get_module_plugs_value($category,$module);
412
 
413
        my $row=0;
414
        foreach my $plug (sort keys %plugs) {
415
 
416
                my $plug_num= $plugs{$plug};
417
                for (my $k=0;$k<$plug_num;$k++){
418
 
419
                        my @connettions=("IO");
420
                        my @connettions_name=("IO");
421
 
422
                        my ($connection_num,$matched_soket)= $infc->get_plug($plug);
423
 
424
 
425
 
426
                        my %connect_list= $soc->get_modules_have_this_socket($matched_soket);
427
                        foreach my $id(sort keys %connect_list ){
428
                                if($instance_id ne $id){ # assum its forbidden to connect the socket and plug of same ip to each other
429
                                        #generate soket list
430
                                        my $name=$soc->soc_get_instance_name($id);
431
                                        #check if its a number or parameter
432
                                        my $param=$connect_list{$id};
433
                                        my $value=$soc->soc_get_module_param_value($id,$param);
434
                                        my $array_name=0;
435
                                        if ( !length( $value || '' )) {
436
                                                $value=$param;
437
                                                $array_name=1;
438
 
439
 
440
                                        };
441
                                        for(my $i=0; $i<$value; $i++){
442
                                                my $s= "$name\:$matched_soket\[$i]";
443
                                                push (@connettions,$s);
444
 
445
                                                # show sockets with their connected plugs 
446
                                                my ($type_t,$value_t,$connection_num_t)=$soc->soc_get_socket_of_instance($id,$matched_soket);
447
 
448
                                                my $cc=find_connection($soc,$id,$matched_soket,$i);
449
                                                $cc= (!defined $cc )? '':
450
                                                         ($cc eq "$instance_id:$plug\[$k\]" || $connection_num_t eq 'multi connection')? '':  "->$cc";
451
 
452
                                                if($array_name eq 0){
453
                                                        my $n= $soc->soc_get_socket_name($id,$matched_soket, 0);
454
 
455
                                                        $n = (!defined $n)? $s:"$name\:$n\[$i]";
456
                                                        $n = "$n$cc";
457
                                                        push (@connettions_name,"$n");
458
 
459
                                                }else{
460
                                                        my $n= $soc->soc_get_socket_name($id,$matched_soket, $i);
461
 
462
                                                        $n = (!defined $n)? $s:"$name\:$n";
463
                                                        $n = "$n$cc";
464
                                                        push (@connettions_name,"$n");
465
 
466
                                                }
467
 
468
                                        }
469
 
470
                                }
471
 
472
 
473
                        }
474
                        push (@connettions,"NC");
475
                        push (@connettions_name,"NC");
476
 
477
                        #print "connection is $connect for $p\n";
478
                        #my @socket_list= $soc_get_sockets();
479
 
480
 
481
                        my $pos= get_mathced_socket_pos($soc,$instance_id,$plug,$k,@connettions);
482
 
483
                        #plug name
484
                        my $plug_name=  $soc->soc_get_plug_name($instance_id,$plug,$k);
485
                        if(! defined $plug_name ){$plug_name=($plug_num>1)?"$plug\[$k\]":$plug}
486
                        $plug_name="    $plug_name";
487
                        my($plug_box, $plug_combo)= def_h_labeled_combo_scaled($plug_name,\@connettions_name,$pos,1,2);
488
 
489
                        #if($row>2){$table->resize ($row, 2);}
490
                        $table->attach_defaults ($plug_box,2,5,$row+$offset,$row+$offset+1);$row=$row+1;
491
 
492
                        my $plug_num=$k;
493
                        my @ll=($soc,$instance_id,$plug,$info,$plug_num);
494
                        $plug_combo->signal_connect (changed => sub{
495
                                my $self=shift;
496
                                my $ref= shift;
497
                                my($soc,$instance_id,$plug,$info,$plug_num) = @{$ref};
498
                                my $connect_name=$plug_combo->get_active_text();
499
                                my $pos=get_item_pos($connect_name, @connettions_name);
500
                                my $connect=$connettions[$pos];
501
 
502
 
503
 
504
                                my($intance_name,$socket,$num)= split("[:\[ \\]]", $connect);
505
                                my $id=$intance_name;# default IO or NC
506
                                if(($intance_name ne 'IO') && ($intance_name ne 'NC')){
507
 
508
                                        $id=$soc->soc_get_instance_id($intance_name);
509
                                        my ($type,$value,$connection_num)=$soc->soc_get_socket_of_instance($id,$socket);
510
                                        #print "\$$connection_num=$connection_num\n";
511
                                        if($connection_num eq 'single connection'){# disconnect other plug from this soket
512
                                                my ($ref1,$ref2)= $soc->soc_get_modules_plug_connected_to_socket($id,$socket,$num);
513
                                                my %connected_plugs=%$ref1;
514
                                                my %connected_plug_nums=%$ref2;
515
                                                foreach my $p (sort keys %connected_plugs) {
516
                                                        #%pp{$instance_id}=$plug
517
                                                        $soc->soc_add_instance_plug_conection($p,$connected_plugs{$p},$connected_plug_nums{$p},'IO');
518
                                                        my $info_text="$id\:$socket\[$num\] support only single connection.  The previouse connection to $p:$connected_plugs{$p}\[$connected_plug_nums{$p}] has been removed.";
519
                                                        show_info(\$info, $info_text);
520
                                                }
521
 
522
                                        }
523
                                }
524
                                #print "$id \n $connect \n$num\n";
525
                                #my @rr=$soc->soc_get_all_plugs_of_an_instance($id);
526
 
527
 
528
 
529
 
530
                                $soc->soc_add_instance_plug_conection($instance_id,$plug,$plug_num,$id,$socket,$num);
531
 
532
                                #get address for wishbone slave port
533
                                if ($plug eq 'wb_slave'){
534
                                                #remove old wb addr
535
                                                $soc->soc_add_plug_base_addr($instance_id,$plug,$plug_num,undef,undef);
536
 
537
                                                #get base and address width
538
                                                my ($addr , $width)=$soc->soc_get_plug_addr ($instance_id,$plug,$plug_num);
539
 
540
                                                #check if width is a parameter
541
                                                my $val= get_parameter_final_value($soc,$instance_id,$width);
542
                                                #print "my $val= get_parameter_final_value($soc,$instance_id,$width);\n";
543
                                                $width= $val if(defined $val);
544
 
545
 
546
                                                #allocate new address in $id
547
                                                my ($base,$end)=get_wb_address($soc,$id,$addr,$width);
548
                                                if(defined $base){#save it
549
                                                        #print "($base,$end)\n";
550
                                                        $soc->soc_add_plug_base_addr($instance_id,$plug,$plug_num,$base,$end);
551
                                                }
552
 
553
 
554
                                                #$id
555
                                }
556
                                # "$name\:$connect\[$i]";
557
 
558
 
559
 
560 25 alirezamon
                                set_gui_status($soc,"refresh_soc",0);
561 16 alirezamon
                        },\@ll);
562
 
563
 
564
        }#for $plug_num
565
 
566
        }#foreach plug
567
 
568
 
569
 
570
 
571
 
572
 
573
 
574
 
575
        #$box->pack_start($table, FALSE, FALSE, 0);
576
        my $separator = Gtk2::HSeparator->new;
577
        #$box->pack_start($separator, FALSE, FALSE, 3);
578
        if($row<3) {$row=3;}
579
        $table->attach_defaults ($separator,0,5,$row+$offset,$row+$offset+1);$row=$row+1;
580
        return ($offset+$row);
581
}
582
 
583
 
584
sub find_connection{
585
        my ($soc,$id,$socket,$num)=@_;
586
        my ($ref1,$ref2)= $soc->soc_get_modules_plug_connected_to_socket($id,$socket,$num);
587
        my %connected_plugs=%$ref1;
588
        my %connected_plug_nums=%$ref2;
589
        my $c;
590
        foreach my $p (sort keys %connected_plugs) {
591
                                $c="$p:$connected_plugs{$p}\[$connected_plug_nums{$p}]" ;
592
                                #print "($instance_id,$plug,$plug_num);($p:$connected_plugs{$p}\[$connected_plug_nums{$p})\n";
593
        }
594
        return $c;
595
 
596
}
597
 
598
 
599
 
600
###############
601
#       generate_dev_table
602
############
603
sub generate_dev_table{
604 25 alirezamon
        my($soc,$ip,$infc,$info)=@_;
605 16 alirezamon
        #my $box= def_hbox (TRUE,0);
606
 
607
        my $table=def_table(3,25,FALSE);
608
        my $row=0;
609
        my @instance_list=$soc->soc_get_instance_order();
610
        if (scalar @instance_list ==0 ){
611
                @instance_list=$soc->soc_get_all_instances();
612
        }
613
        my $i=0;
614
 
615
        foreach my $instanc(@instance_list){
616 25 alirezamon
                $row=gen_instance($soc,$ip,$infc,$instanc,$info,$table,$row);
617 16 alirezamon
 
618
        }
619
        if($row<20){for ($i=$row; $i<20; $i++){
620
 
621
                my $temp=gen_label_in_center(" ");
622
                $table->attach_defaults ($temp, 0, 1 , $i, $i+1);
623
        }}
624
 
625
 
626
        #$box->pack_start( $scrolled_win, TRUE, TRUE, 3);
627
        return $table;
628
}
629
 
630
 
631
####################
632
#  show_active_dev
633
#
634
################ 
635
 
636
sub show_active_dev{
637 25 alirezamon
        my($soc,$ip,$infc,$refresh_ref,$info)=@_;
638 16 alirezamon
        my $box= def_table (1, 1, FALSE);
639 25 alirezamon
        my $dev_table = generate_dev_table($soc,$ip,$infc,$info);
640 16 alirezamon
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
641
        $scrolled_win->set_policy( "automatic", "automatic" );
642
        $scrolled_win->add_with_viewport($dev_table);
643
 
644
 
645
 
646
        $$refresh_ref-> signal_connect("clicked" => sub{
647 22 alirezamon
 
648 16 alirezamon
                $dev_table->destroy;
649 22 alirezamon
                select(undef, undef, undef, 0.1); #wait 10 ms
650 25 alirezamon
                $dev_table = generate_dev_table($soc,$ip,$infc,$info);
651 16 alirezamon
                #$box->attach_defaults ($dev_table, 0, 1, 0, 1);#( $dev_table, FALSE, FALSE, 3);
652
                $scrolled_win->add_with_viewport($dev_table);
653
                $dev_table->show;
654
                $scrolled_win->show_all;
655
 
656
 
657
 
658
        });
659
        #$box->attach_defaults ($dev_table, 0, 1, 0, 1);#$box->pack_start( $dev_table, FALSE, FALSE, 3);
660
        #$box->show_all;
661
        return $scrolled_win;
662
 
663
 
664
 
665
}
666
 
667
 
668
 
669
 
670
 
671
sub row_activated_cb{
672
         my ($tree_view, $path, $column) = @_;
673
         my $model = $tree_view->get_model;
674
         my $iter = $model->get_iter ($path);
675
 
676
        #my ($selection, $ref) = @_;
677
        #my ($model,$textview)=@{$ref};
678
        #my $iter = $selection->get_selected;
679
        #return unless defined $iter;
680
        my ($category) = $model->get ($iter, DISPLAY_COLUMN);
681
        my ($module) = $model->get ($iter, CATRGORY_COLUMN);
682
 
683
 
684
 
685
        #if($module){print "$module   is selected via row activaton!\n"}
686
}
687
 
688
 
689
 
690
 
691
##############
692
#       create tree
693
##############
694
sub create_tree {
695 25 alirezamon
   my ($info,$ip,$soc)=@_;
696 16 alirezamon
   my $model = Gtk2::TreeStore->new ('Glib::String', 'Glib::String', 'Glib::Scalar', 'Glib::Boolean');
697
   my $tree_view = Gtk2::TreeView->new;
698
   $tree_view->set_model ($model);
699
   my $selection = $tree_view->get_selection;
700
 
701
   $selection->set_mode ('browse');
702 25 alirezamon
   #$tree_view->set_size_request (200, -1);
703 16 alirezamon
 
704
   #
705
   # this code only supports 1 level of children. If we
706
   # want more we probably have to use a recursing function.
707
   #
708
 
709
 
710
   my @categories= $ip->ip_get_categories();
711
 
712
 
713
 
714
 
715
   foreach my $p (@categories)
716
   {
717
        my @modules= $ip->get_modules($p);
718
        #my @dev_entry=  @{$tree_entry{$p}};    
719
        my $iter = $model->append (undef);
720
        $model->set ($iter,
721
                   DISPLAY_COLUMN,    $p,
722
                   CATRGORY_COLUMN, $p || '',
723
                   MODULE_COLUMN,     0     || '',
724
                   ITALIC_COLUMN,   FALSE);
725
 
726
        next unless  @modules;
727
 
728
        foreach my $v ( @modules){
729
                 my $child_iter = $model->append ($iter);
730
                 my $entry= '';
731
 
732
                $model->set ($child_iter,
733
                        DISPLAY_COLUMN,    $v,
734
                        CATRGORY_COLUMN, $p|| '',
735
                        MODULE_COLUMN,     $v     || '',
736
                        ITALIC_COLUMN,   FALSE);
737
        }
738
 
739
 
740
 
741
   }
742
 
743
   my $cell = Gtk2::CellRendererText->new;
744
   $cell->set ('style' => 'italic');
745
   my $column = Gtk2::TreeViewColumn->new_with_attributes
746 25 alirezamon
                                        ("IP list",
747 16 alirezamon
                                        $cell,
748
                                        'text' => DISPLAY_COLUMN,
749
                                        'style_set' => ITALIC_COLUMN);
750
 
751
  $tree_view->append_column ($column);
752
  my @ll=($model,\$info);
753
#row selected
754
  $selection->signal_connect (changed =>sub {
755
        my ($selection, $ref) = @_;
756
        my ($model,$info)=@{$ref};
757
        my $iter = $selection->get_selected;
758
        return unless defined $iter;
759
 
760
        my ($category) = $model->get ($iter, CATRGORY_COLUMN);
761
        my ($module) = $model->get ($iter,MODULE_COLUMN );
762 24 alirezamon
        my $describ=$ip->ip_get($category,$module,"description");
763 16 alirezamon
        if($describ){
764
                #print "$entry describtion is: $describ \n";
765
                show_info($info,$describ);
766
 
767
        }
768
 
769
 
770
}, \@ll);
771
 
772
#  row_activated 
773
  $tree_view->signal_connect (row_activated => sub{
774
 
775
         my ($tree_view, $path, $column) = @_;
776
         my $model = $tree_view->get_model;
777
         my $iter = $model->get_iter ($path);
778
        my ($category) = $model->get ($iter, CATRGORY_COLUMN);
779
        my ($module) = $model->get ($iter,MODULE_COLUMN );
780
 
781
 
782
 
783
        if($module){
784
                #print "$module  is selected via row activaton!\n";
785 25 alirezamon
                add_module_to_soc($soc,$ip,$category,$module,\$info);
786
                set_gui_status($soc,"refresh_soc",0);
787 16 alirezamon
        }
788
 
789
 
790
 
791
 
792
 
793
 
794
 
795
 
796
}, \@ll);
797
 
798
  #$tree_view->expand_all;
799
 
800
  my $scrolled_window = Gtk2::ScrolledWindow->new;
801
  $scrolled_window->set_policy ('automatic', 'automatic');
802
  $scrolled_window->set_shadow_type ('in');
803
  $scrolled_window->add($tree_view);
804
 
805 25 alirezamon
  my $hbox = Gtk2::HBox->new (FALSE, 0);
806 16 alirezamon
  $hbox->pack_start ( $scrolled_window, TRUE, TRUE, 0);
807
 
808
 
809
 
810
  return $hbox;
811
}
812
 
813
 
814
 
815 17 alirezamon
sub get_all_files_list {
816
        my ($soc,$list_name)=@_;
817 16 alirezamon
        my @instances=$soc->soc_get_all_instances();
818
        my $ip = ip->lib_new ();
819
        my @files;
820
        my $dir = Cwd::getcwd();
821
        my $warnings;
822
        #make target dir
823
        my $project_dir   = abs_path("$dir/../..");
824
 
825
        foreach my $id (@instances){
826
                my $module              =$soc->soc_get_module($id);
827
                my $module_name =$soc->soc_get_module_name($id);
828
                my $category    =$soc->soc_get_category($id);
829
                my $inst                =$soc->soc_get_instance_name($id);
830
 
831 24 alirezamon
                my @new=$ip->ip_get_list( $category,$module,$list_name);
832
                #print "@new\n";
833 16 alirezamon
                foreach my $f(@new){
834
                        my $n="$project_dir$f";
835 24 alirezamon
                         if (!(-f "$n") && !(-f "$f" ) && !(-d "$n") && !(-d "$f" )     ){
836 17 alirezamon
                                $warnings=(defined $warnings)? "$warnings WARNING: Can not find  \"$f\" which is required for \"$inst\" \n":"WARNING: Can not find  \"$f\"  which is required for \"$inst\"\n ";
837 16 alirezamon
 
838
                         }
839
 
840
 
841
                }
842
 
843
 
844
 
845
 
846
                @files=(@files,@new);
847
        }
848
        return \@files,$warnings;
849
}
850
 
851
################
852
#       generate_soc
853
#################
854
 
855
sub generate_soc{
856
        my ($soc,$info)=@_;
857 25 alirezamon
        my $name=$soc->object_get_attribute('soc_name');
858 16 alirezamon
                if (length($name)>0){
859
                        my @tmp=split('_',$name);
860
                        if ( $tmp[-1] =~ /^[0-9]+$/ ){
861
                                message_dialog("The soc name must not end with '_number'!");
862
                                return 0;
863
                        }
864
 
865 25 alirezamon
                        my ($file_v,$top_v,$readme)=soc_generate_verilog($soc);
866 16 alirezamon
 
867
                        # Write object file
868
                        open(FILE,  ">lib/soc/$name.SOC") || die "Can not open: $!";
869 25 alirezamon
                        print FILE perl_file_header("$name.SOC");
870 16 alirezamon
                        print FILE Data::Dumper->Dump([\%$soc],[$name]);
871
                        close(FILE) || die "Error closing file: $!";
872
 
873
                        # Write verilog file
874
                        open(FILE,  ">lib/verilog/$name.v") || die "Can not open: $!";
875
                        print FILE $file_v;
876
                        close(FILE) || die "Error closing file: $!";
877
 
878 25 alirezamon
                        # Write Top module file
879
                        my $l=autogen_warning().get_license_header("${name}_top.v");
880
                        open(FILE,  ">lib/verilog/${name}_top.v") || die "Can not open: $!";
881
                        print FILE "$l\n$top_v";
882
                        close(FILE) || die "Error closing file: $!";
883
 
884 16 alirezamon
 
885 25 alirezamon
                        # Write readme file
886
                        open(FILE,  ">lib/verilog/README") || die "Can not open: $!";
887
                        print FILE $readme;
888
                        close(FILE) || die "Error closing file: $!";
889 16 alirezamon
 
890
                        # copy all files in project work directory
891
                        my $dir = Cwd::getcwd();
892
                        #make target dir
893
                        my $project_dir   = abs_path("$dir/../../");
894
                        my $target_dir  = "$project_dir/mpsoc_work/SOC/$name";
895 25 alirezamon
                        mkpath("$target_dir/src_verilog/lib/",1,01777);
896
                        mkpath("$target_dir/sw",1,01777);
897 16 alirezamon
 
898
                #copy hdl codes in src_verilog
899
 
900 17 alirezamon
                my ($file_ref,$warnings)= get_all_files_list($soc,"hdl_files");
901 25 alirezamon
 
902
                    copy_file_and_folders($file_ref,$project_dir,"$target_dir/src_verilog/lib");
903 16 alirezamon
 
904
                        show_info(\$info,$warnings)                     if(defined $warnings);
905
 
906
 
907 25 alirezamon
                #copy jtag control files 
908
                my @jtags=(("/mpsoc/src_peripheral/jtag/jtag_wb"),("jtag"));
909
                copy_file_and_folders(\@jtags,$project_dir,"$target_dir/src_verilog/lib");
910
 
911 16 alirezamon
                #my @pathes=("$dir/../src_peripheral","$dir/../src_noc","$dir/../src_processor");
912
                #foreach my $p(@pathes){
913
                #       find(
914
                #               sub {
915
                #                       return unless ( -f $_ );
916
                #                       $_ =~ /\.v$/ && copy( $File::Find::name, "$target_dir/src_verilog/lib/" );
917
                #               },
918
                #       $p
919
                        #       );
920
                #}
921
 
922
 
923 25 alirezamon
                move ("$dir/lib/verilog/$name.v","$target_dir/src_verilog/");
924
                move ("$dir/lib/verilog/${name}_top.v","$target_dir/src_verilog/");
925
                move ("$dir/lib/verilog/README" ,"$target_dir/sw/");
926
                # Copy Software files
927
                        ($file_ref,$warnings)= get_all_files_list($soc,"sw_files");
928
                        copy_file_and_folders($file_ref,$project_dir,"$target_dir/sw");
929 16 alirezamon
 
930 25 alirezamon
                # Write system.h and Software gen files
931 24 alirezamon
                        generate_header_file($soc,$project_dir,$target_dir,$dir);
932
 
933 16 alirezamon
 
934 25 alirezamon
 
935 24 alirezamon
 
936
 
937 23 alirezamon
                # Write main.c file if not exist
938
                my $n="$target_dir/sw/main.c";
939
                if (!(-f "$n")) {
940
                        # Write main.c
941
                        open(FILE,  ">$n") || die "Can not open: $!";
942
                        print FILE main_c_template($name);
943
                        close(FILE) || die "Error closing file: $!";
944 16 alirezamon
 
945 23 alirezamon
                }
946 16 alirezamon
 
947
 
948
 
949 17 alirezamon
 
950 16 alirezamon
                        message_dialog("SoC \"$name\" has been created successfully at $target_dir/ " );
951 17 alirezamon
                        exec($^X, $0, @ARGV);# reset ProNoC to apply changes
952 16 alirezamon
 
953
                }else {
954
                        message_dialog("Please define the SoC name!");
955
 
956
                }
957
 
958
return 1;
959
}
960
 
961
 
962 23 alirezamon
sub main_c_template{
963
        my $hdr=shift;
964
        my $text="
965
#include \"$hdr.h\"
966 16 alirezamon
 
967
 
968 23 alirezamon
// a simple delay function
969
void delay ( unsigned int num ){
970
 
971
        while (num>0){
972
                num--;
973 25 alirezamon
                nop(); // asm volatile (\"nop\");
974 23 alirezamon
        }
975
        return;
976 16 alirezamon
 
977 23 alirezamon
}
978 16 alirezamon
 
979 23 alirezamon
int main(){
980
        while(1){
981
 
982
 
983 16 alirezamon
 
984 23 alirezamon
        }
985
 
986
return 0;
987
}
988
 
989
";
990
 
991
return $text;
992
 
993
 
994
}
995
 
996
 
997
 
998
 
999 16 alirezamon
sub get_wb_address      {
1000
        my ($soc,$instance_id,$addr,$width)=@_;
1001
        my ($base,$end);
1002
        my @list= split (" ",$addr);
1003
        $base= hex ($list[0]);
1004
        $end= $base+(1 << $width)-1;
1005
        #print "$addr:$base \& $end\n";
1006
        my %taken_bases= $soc->soc_list_base_addreses($instance_id);
1007
 
1008
        my $conflict=0;
1009
        do{
1010
                $conflict=0;
1011
                foreach my $taken_end (sort {$a<=>$b} keys %taken_bases){
1012
                        my $taken_base=$taken_bases{$taken_end};
1013
                        #print "taken:($taken_base,$taken_end)\n";
1014
                        if (($base <= $taken_base && $end >= $taken_base ) || ($base <= $taken_end && $end >= $taken_end )){
1015
                        #if (!(($base < $taken_base && $end < $taken_end ) || ($base > $taken_base && $end > $taken_end ))){
1016
                                 $conflict=1;
1017
                                 $base=$taken_end+1;
1018
                                 $end= $base+(1 << $width)-1;
1019
                                 last;
1020
 
1021
                        }
1022
                }
1023
 
1024
        }while($conflict==1 && $end<(1 << 32));
1025
        if($conflict==0){
1026
                #print"new ($base,$end);\n";
1027
                return ($base,$end);
1028
 
1029
        }
1030
 
1031
        return ;
1032
 
1033
}
1034
 
1035
 
1036
 
1037
 
1038
 
1039
 
1040
 
1041
 
1042
 
1043
##########
1044
#       wb address setting
1045
#########
1046
 
1047
sub wb_address_setting {
1048
        my $soc=shift;
1049
 
1050
 
1051
        my $window = def_popwin_size(1200,500,"Wishbone slave port address setting");
1052 25 alirezamon
        my $table = def_table(10, 6, FALSE);
1053 16 alirezamon
 
1054
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1055
        $scrolled_win->set_policy( "automatic", "automatic" );
1056
        $scrolled_win->add_with_viewport($table);
1057
        my $row=0;
1058
 
1059
        #title
1060 25 alirezamon
        $table->attach(gen_label_in_left  ("Instance name"),0,1,$row,$row+1,'expand','shrink',2,2);
1061
        $table->attach(gen_label_in_left  ("Interface name"),1,2,$row,$row+1,'expand','shrink',2,2);
1062
        $table->attach(gen_label_in_left  ("Bus name"),2,3,$row,$row+1,'expand','shrink',2,2);
1063
        $table->attach(gen_label_in_center("Base address"),3,4,$row,$row+1,'expand','shrink',2,2);
1064
        $table->attach(gen_label_in_center("End address"),4,5,$row,$row+1,'expand','shrink',2,2);
1065
        $table->attach(gen_label_in_center("Size (Bytes)"),5,6,$row,$row+1,'expand','shrink',2,2);
1066 16 alirezamon
 
1067
        my (@newbase,@newend,@connects);
1068
 
1069
        $row++;
1070
        my @all_instances=$soc->soc_get_all_instances();
1071
        foreach my $instance_id (@all_instances){
1072
                my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1073
                foreach my $plug (@plugs){
1074
                        my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1075
                        foreach my $num (@nums){
1076
                                my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1077
                                if((defined $connect_socket) && ($connect_socket eq 'wb_slave')){
1078
                                        my $number=$row-1;
1079
                                        $newbase[$number]=$base;
1080
                                        $newend[$number]=$end;
1081
                                        $connects[$number]=$connect_id;
1082
                                        $row++;
1083
                                }#if
1084
                        }#foreach my $num
1085
                }#foreach my $plug
1086
        }#foreach my $instance_id
1087
 
1088
        my @status_all;
1089
        $row=1;
1090
        foreach my $instance_id (@all_instances){
1091
                my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1092
                foreach my $plug (@plugs){
1093
                        my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1094
                        foreach my $num (@nums){
1095
                                my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1096
                                if((defined $connect_socket) && ($connect_socket eq 'wb_slave')){
1097
                                        my $instance_name=$soc->soc_get_instance_name($instance_id);
1098
                                        my $plug_name=(defined $name ) ? gen_label_in_left($name):
1099
                                                                                                         gen_label_in_left("$plug\[$num\]");
1100
 
1101
                                        my $connected_instance_name= $soc->soc_get_instance_name($connect_id);
1102
                                        my $number=$row-1;
1103
                                        my $label1= gen_label_in_left("$number: $instance_name");
1104
                                        my $label2= gen_label_in_left($connected_instance_name);
1105
                                        my $entry1= Gtk2::Entry->new_with_max_length (10);
1106
                                    $entry1->set_text(sprintf("0x%08x", $base));
1107
 
1108
                                        my $entry2= Gtk2::Entry->new_with_max_length (10);
1109
                                        $entry2->set_text(sprintf("0x%08x", $end));
1110
 
1111
                                        my ($box,$valid) =addr_box_gen(sprintf("0x%08x", $base), sprintf("0x%08x", $end),\@newbase,\@newend,\@connects,$number);
1112
                                        $status_all[$number]=$valid;
1113
 
1114
 
1115 25 alirezamon
                                        $table->attach($label1,0,1,$row,$row+1,'expand','shrink',2,2);
1116
                                        $table->attach($plug_name,1,2,$row,$row+1,'expand','shrink',2,2);
1117
                                        $table->attach($label2,2,3,$row,$row+1,'expand','shrink',2,2);
1118
                                        $table->attach($entry1,3,4,$row,$row+1,'expand','shrink',2,2);
1119
                                        $table->attach($entry2,4,5,$row,$row+1,'expand','shrink',2,2);
1120 16 alirezamon
 
1121
 
1122 25 alirezamon
                                        $table->attach($box,5,7,$row,$row+1,'expand','shrink',2,2);
1123 16 alirezamon
 
1124
 
1125
                                        $entry1->signal_connect('changed'=>sub{
1126
                                                my $base_in=$entry1->get_text();
1127
                                                if (length($base_in)<2){ $entry1->set_text('0x')};
1128
                                                my $end_in=$entry2->get_text();
1129
                                                my $valid;
1130
                                                $box->destroy;
1131
                                                ($box,$valid)=addr_box_gen($base_in, $end_in,\@newbase,\@newend,\@connects,$number);
1132
                                                $status_all[$number]=$valid;
1133 25 alirezamon
                                                $table->attach($box,5,7,$number+1,$number+2,'expand','shrink',2,2);
1134 16 alirezamon
                                                $table->show_all;
1135
 
1136
 
1137
                                        } );
1138
                                        $entry2->signal_connect('changed'=>sub{
1139
                                                my $base_in=$entry1->get_text();
1140
                                                my $end_in=$entry2->get_text();
1141
                                                if (length($end_in)<2){ $entry2->set_text('0x')};
1142
                                                my $valid;
1143
                                                $box->destroy;
1144
                                                ($box,$valid)=addr_box_gen($base_in, $end_in,\@newbase,\@newend,\@connects,$number);
1145
                                                $status_all[$number]=$valid;
1146 25 alirezamon
                                                $table->attach($box,5,7,$number+1,$number+2,'expand','shrink',2,2);
1147 16 alirezamon
                                                $table->show_all;
1148
                                        } );
1149
 
1150
 
1151
 
1152
                                        $row++;
1153
 
1154
 
1155
                                }#if
1156
                        }#foreach my $num
1157
                }#foreach my $plug
1158
        }#foreach my $instance_id
1159
 
1160
 
1161
        my $ok = def_image_button('icons/select.png','OK');
1162
 
1163 25 alirezamon
 
1164
 
1165 16 alirezamon
        my $refresh = def_image_button('icons/revert.png','Revert');
1166
        my $refbox=def_hbox(TRUE,0);
1167
        $refbox->pack_start($refresh, FALSE, FALSE,0);
1168
 
1169
        $refresh->signal_connect( 'clicked'=> sub {
1170
                $window->destroy;
1171
                wb_address_setting($soc);
1172
 
1173
 
1174
                });
1175
        $ok->signal_connect     ( 'clicked'=> sub {
1176
                my $st=1;
1177
                foreach my $valid (@status_all){
1178
                        if($valid==0){
1179
                                $st=0;
1180
 
1181
                        }
1182
                }
1183
 
1184
                if($st==1){
1185
                        $row=1;
1186
                        foreach my $instance_id (@all_instances){
1187
                        my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1188
                        foreach my $plug (@plugs){
1189
                                my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1190
                                foreach my $num (@nums){
1191
                                        my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1192
                                        if(defined $connect_socket && ($connect_socket eq 'wb_slave')){
1193
                                                my $number=$row-1;
1194
                                                $soc->soc_add_plug_base_addr($instance_id,$plug,$num,$newbase[$number],$newend[$number]);
1195
                                                $row++;
1196
                                        }#if
1197
                                }#foreach my $num
1198
                        }#foreach my $plug
1199
                }#foreach my $instance_id
1200
 
1201
 
1202
 
1203
 
1204
 
1205
                        $window->destroy;
1206
                }else{
1207
                        message_dialog("Invalid address !");
1208
 
1209
                }
1210
 
1211
 
1212
                });
1213
 
1214
 
1215
 
1216
 
1217 25 alirezamon
        $table->attach ($refbox,2,3,$row,$row+1,'expand','shrink',2,2);
1218
        $table->attach ($ok,3,4,$row,$row+1,'expand','shrink',2,2);
1219
 
1220 16 alirezamon
        $window->add($scrolled_win);
1221
        $window->show_all;
1222
 
1223
 
1224
 
1225
}
1226
##############
1227
#       addr_box_gen
1228
##############
1229
 
1230
sub addr_box_gen{
1231
        my ($base_in, $end_in,$newbase_ref,$newend_ref,$connects_ref,$number)=@_;
1232
        my $box= def_hbox(TRUE,0);
1233
        my $label;
1234
        my $valid=1;
1235
        my $info;
1236
        if(is_hex($base_in) && is_hex($end_in)){
1237
                my $size=(hex ($end_in) >= hex ($base_in))? hex ($end_in) - hex ($base_in) +1 : 0;
1238 24 alirezamon
                my $size_text=  metric_conversion($size);
1239 16 alirezamon
                $label= gen_label_in_center($size_text);
1240
                $$newbase_ref[$number]=hex($base_in);
1241
                $$newend_ref[$number]=hex($end_in);
1242
                $info=check_entered_address($newbase_ref,$newend_ref,$connects_ref,$number);
1243
                if(defined      $info) {$valid=0;}
1244
 
1245
        }
1246
        else {
1247
                $label= gen_label_in_center("Invalid hex value!");
1248
                $info="Invalid hex value!";
1249
                $valid=0;
1250
        }
1251
 
1252
 
1253
        my $status=(defined $info)? gen_button_message ($info,'icons/warnning.png'):
1254
                                                                gen_button_message (undef,'icons/select.png');
1255
 
1256
        $box->pack_start($label,FALSE,FALSE,3);
1257
        $box->pack_start($status,FALSE,FALSE,3);
1258
        return ($box,$valid);
1259
 
1260
}
1261
 
1262
 
1263
 
1264
 
1265
###########
1266
#       get_parameter_final_value
1267
############
1268
sub get_parameter_final_value{
1269
        my ($soc,$id,$param)=@_;
1270
        #get ordered param
1271
        my @ordered_param=$soc->soc_get_instance_param_order($id);
1272
        my %sim_params;
1273
        foreach my $p (@ordered_param){
1274
                my $value=$soc->soc_get_module_param_value($id,$p);
1275
                foreach my $q (sort keys %sim_params){
1276
                        $value=replace_value($value,$q,$sim_params{$q}) if (defined $value);
1277
                }
1278
                $sim_params{$p}=$value;
1279
                #print "$sim_params{$p}=$value;\n";
1280
        }
1281
        return $sim_params{$param};
1282
}
1283
 
1284
 
1285
 
1286
 
1287
sub replace_value{
1288
        my ($string,$param,$value)=@_;
1289
 
1290
        my $new_string=$string;
1291
        #print "$new_range\n";
1292
        my $new_param= $value;
1293
        ($new_string=$new_string)=~ s/\b$param\b/$new_param/g;
1294
        return eval $new_string;
1295
 
1296
 
1297
}
1298
 
1299
 
1300
 
1301
 
1302
 
1303
 
1304
 
1305
 
1306
 
1307
 
1308
 
1309
 
1310
 
1311
sub check_entered_address{
1312
my      ($base_ref,$end_ref,$connect_ref,$number)=@_;
1313
my @bases=@{$base_ref};
1314
my @ends=@{$end_ref};
1315
my @connects=@{$connect_ref};
1316
 
1317
my $current_base=$bases[$number];
1318
my $current_end=$ends[$number];
1319
 
1320
if($current_base>  $current_end) {
1321
 
1322
return "Error: the given base address is bigger than the End address!";
1323
        }
1324
 
1325
my $size= scalar @bases;
1326
my $conflicts;
1327
foreach (my $i=0; $i<$size; $i++){
1328
        if($i != $number){ #if not same row
1329
                if      ($connects[$i] eq $connects[$number]) {#same bus
1330
                                my $ok=(($bases[$i]< $bases[$number] && $bases[$i] < $ends[$number])||($bases[$i]> $bases[$number] && $bases[$i] > $ends[$number]));
1331
                            if($ok==0) {
1332
                                        $conflicts=(defined $conflicts )? "$conflicts,$i": $i;
1333
                                }
1334
                }
1335
 
1336
 
1337
        }
1338
 
1339
 
1340
}
1341
if (defined $conflicts){ return " The given address range has conflict with rows:$conflicts"; }
1342
return;
1343
 
1344
 
1345
}
1346
 
1347
#############
1348
#       load_soc
1349
#############
1350
 
1351
sub load_soc{
1352 25 alirezamon
        my ($soc,$info)=@_;
1353 16 alirezamon
        my $file;
1354
        my $dialog = Gtk2::FileChooserDialog->new(
1355
                'Select a File', undef,
1356
                'open',
1357
                'gtk-cancel' => 'cancel',
1358
                'gtk-ok'     => 'ok',
1359
                );
1360
 
1361
        my $filter = Gtk2::FileFilter->new();
1362
        $filter->set_name("SoC");
1363
        $filter->add_pattern("*.SOC");
1364
        $dialog->add_filter ($filter);
1365
        my $dir = Cwd::getcwd();
1366
        $dialog->set_current_folder ("$dir/lib/soc")    ;
1367
 
1368
 
1369
        if ( "ok" eq $dialog->run ) {
1370
                $file = $dialog->get_filename;
1371
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1372
                if($suffix eq '.SOC'){
1373
                        my $pp= eval { do $file };
1374 25 alirezamon
                        if ($@ || !defined $pp){
1375
                                show_info(\$info,"**Error reading  $file file: $@\n");
1376
                                 $dialog->destroy;
1377
                                return;
1378
                        }
1379 16 alirezamon
                        clone_obj($soc,$pp);
1380 25 alirezamon
                        set_gui_status($soc,"load_file",0);
1381 16 alirezamon
                }
1382
     }
1383
     $dialog->destroy;
1384
 
1385
 
1386
 
1387
 
1388
 
1389
}
1390
 
1391
 
1392
 
1393
 
1394
 
1395
 
1396
 
1397
 
1398
 
1399
 
1400
 
1401
 
1402
 
1403
 
1404
 
1405
 
1406
 
1407
 
1408
 
1409
 
1410
 
1411
 
1412
############
1413
#    main
1414
############
1415
sub socgen_main{
1416
 
1417
        my $infc = interface->interface_new();
1418
        my $ip = ip->lib_new ();
1419
        my $soc = soc->soc_new();
1420 25 alirezamon
        set_gui_status($soc,"ideal",0);
1421 16 alirezamon
        #my $soc= eval { do 'lib/soc/soc.SOC' };
1422
 
1423 25 alirezamon
 
1424 16 alirezamon
        # main window
1425
        #my $window = def_win_size(1000,800,"Top");
1426
        #  The main table containg the lib tree, selected modules and info section 
1427
        my $main_table = Gtk2::Table->new (20, 12, FALSE);
1428
 
1429
        # The box which holds the info, warning, error ...  mesages
1430
        my ($infobox,$info)= create_text();
1431
 
1432
 
1433
        my $refresh_dev_win = Gtk2::Button->new_from_stock('ref');
1434
 
1435
        # A tree view for holding a library
1436 25 alirezamon
        my $tree_box = create_tree ($info,$ip,$soc);
1437 16 alirezamon
 
1438
 
1439
 
1440
        $main_table->set_row_spacings (4);
1441
        $main_table->set_col_spacings (1);
1442
 
1443 25 alirezamon
        my  $device_win=show_active_dev($soc,$ip,$infc,\$refresh_dev_win,$info);
1444 16 alirezamon
 
1445
 
1446
        my $generate = def_image_button('icons/gen.png','Generate');
1447 25 alirezamon
 
1448 16 alirezamon
 
1449
 
1450
 
1451
 
1452
 
1453
        my $wb = def_image_button('icons/setting.png','Wishbone address setting');
1454
 
1455 25 alirezamon
 
1456
 
1457 16 alirezamon
        my $open = def_image_button('icons/browse.png','Load Tile');
1458
 
1459
 
1460 25 alirezamon
        my $entry=gen_entry_object($soc,'soc_name',undef,undef,undef,undef);
1461
        my $entrybox=labele_widget_info(" Tile name:",$entry);
1462 16 alirezamon
 
1463
 
1464
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
1465
        $main_table->attach_defaults ($tree_box , 0, 2, 0, 17);
1466
        $main_table->attach_defaults ($device_win , 2, 12, 0, 17);
1467
        $main_table->attach_defaults ($infobox  , 0, 12, 17,19);
1468 25 alirezamon
        $main_table->attach ($open,0, 3, 19,20,'expand','shrink',2,2);
1469 16 alirezamon
        $main_table->attach_defaults ($entrybox,3, 7, 19,20);
1470 25 alirezamon
        $main_table->attach ($wb, 7, 10, 19,20,'expand','shrink',2,2);
1471
        $main_table->attach ($generate, 10, 12, 19,20,'expand','shrink',2,2);
1472 16 alirezamon
 
1473
 
1474
        #check soc status every 0.5 second. referesh device table if there is any changes 
1475
        Glib::Timeout->add (100, sub{
1476 25 alirezamon
                my ($state,$timeout)= get_gui_status($soc);
1477
 
1478 16 alirezamon
                if ($timeout>0){
1479
                        $timeout--;
1480 25 alirezamon
                        set_gui_status($soc,$state,$timeout);
1481
 
1482 16 alirezamon
                }
1483
                elsif( $state ne "ideal" ){
1484
                        $refresh_dev_win->clicked;
1485 25 alirezamon
                        my $saved_name=$soc->object_get_attribute('soc_name',undef);
1486 16 alirezamon
                        if(defined $saved_name) {$entry->set_text($saved_name);}
1487 25 alirezamon
                        set_gui_status($soc,"ideal",0);
1488 16 alirezamon
                }
1489
                return TRUE;
1490
 
1491
        } );
1492
 
1493
 
1494
        $generate-> signal_connect("clicked" => sub{
1495
                generate_soc($soc,$info);
1496
                $refresh_dev_win->clicked;
1497
 
1498
        });
1499
 
1500
        $wb-> signal_connect("clicked" => sub{
1501
                wb_address_setting($soc);
1502
 
1503
        });
1504
 
1505
        $open-> signal_connect("clicked" => sub{
1506 25 alirezamon
                load_soc($soc,$info);
1507 16 alirezamon
 
1508
        });
1509
 
1510
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
1511
                $sc_win->set_policy( "automatic", "automatic" );
1512
                $sc_win->add_with_viewport($main_table);
1513
 
1514
        return $sc_win;
1515
        #return $main_table;
1516
 
1517
 
1518
}

powered by: WebSVN 2.1.0

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