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 16

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

powered by: WebSVN 2.1.0

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