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 18

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

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

powered by: WebSVN 2.1.0

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