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 34

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

powered by: WebSVN 2.1.0

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