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 24

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 22 alirezamon
        set_state($soc_state,"refresh_soc",0);
106 16 alirezamon
}
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 24 alirezamon
                  $spin-> signal_connect("value_changed" => sub{ $new_param_value{$p}=$spin->get_value_as_int(); });
167 16 alirezamon
 
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 22 alirezamon
                set_state($soc_state,"refresh_soc",0);
231 16 alirezamon
                #$$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 22 alirezamon
                set_state($soc_state,"refresh_soc",0);
348 16 alirezamon
 
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 22 alirezamon
                set_state($soc_state,"refresh_soc",0);
367 16 alirezamon
 
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 22 alirezamon
 
638 16 alirezamon
                $dev_table->destroy;
639 22 alirezamon
                select(undef, undef, undef, 0.1); #wait 10 ms
640 16 alirezamon
                $dev_table = generate_dev_table($soc,$ip,$infc,$soc_state,$info);
641
                #$box->attach_defaults ($dev_table, 0, 1, 0, 1);#( $dev_table, FALSE, FALSE, 3);
642
                $scrolled_win->add_with_viewport($dev_table);
643
                $dev_table->show;
644
                $scrolled_win->show_all;
645
 
646
 
647
 
648
        });
649
        #$box->attach_defaults ($dev_table, 0, 1, 0, 1);#$box->pack_start( $dev_table, FALSE, FALSE, 3);
650
        #$box->show_all;
651
        return $scrolled_win;
652
 
653
 
654
 
655
}
656
 
657
 
658
 
659
 
660
 
661
sub row_activated_cb{
662
         my ($tree_view, $path, $column) = @_;
663
         my $model = $tree_view->get_model;
664
         my $iter = $model->get_iter ($path);
665
 
666
        #my ($selection, $ref) = @_;
667
        #my ($model,$textview)=@{$ref};
668
        #my $iter = $selection->get_selected;
669
        #return unless defined $iter;
670
        my ($category) = $model->get ($iter, DISPLAY_COLUMN);
671
        my ($module) = $model->get ($iter, CATRGORY_COLUMN);
672
 
673
 
674
 
675
        #if($module){print "$module   is selected via row activaton!\n"}
676
}
677
 
678
 
679
 
680
 
681
##############
682
#       create tree
683
##############
684
sub create_tree {
685
   my ($info,$ip,$soc,$soc_state)=@_;
686
   my $model = Gtk2::TreeStore->new ('Glib::String', 'Glib::String', 'Glib::Scalar', 'Glib::Boolean');
687
   my $tree_view = Gtk2::TreeView->new;
688
   $tree_view->set_model ($model);
689
   my $selection = $tree_view->get_selection;
690
 
691
   $selection->set_mode ('browse');
692
   $tree_view->set_size_request (200, -1);
693
 
694
   #
695
   # this code only supports 1 level of children. If we
696
   # want more we probably have to use a recursing function.
697
   #
698
 
699
 
700
   my @categories= $ip->ip_get_categories();
701
 
702
 
703
 
704
 
705
   foreach my $p (@categories)
706
   {
707
        my @modules= $ip->get_modules($p);
708
        #my @dev_entry=  @{$tree_entry{$p}};    
709
        my $iter = $model->append (undef);
710
        $model->set ($iter,
711
                   DISPLAY_COLUMN,    $p,
712
                   CATRGORY_COLUMN, $p || '',
713
                   MODULE_COLUMN,     0     || '',
714
                   ITALIC_COLUMN,   FALSE);
715
 
716
        next unless  @modules;
717
 
718
        foreach my $v ( @modules){
719
                 my $child_iter = $model->append ($iter);
720
                 my $entry= '';
721
 
722
                $model->set ($child_iter,
723
                        DISPLAY_COLUMN,    $v,
724
                        CATRGORY_COLUMN, $p|| '',
725
                        MODULE_COLUMN,     $v     || '',
726
                        ITALIC_COLUMN,   FALSE);
727
        }
728
 
729
 
730
 
731
   }
732
 
733
   my $cell = Gtk2::CellRendererText->new;
734
   $cell->set ('style' => 'italic');
735
   my $column = Gtk2::TreeViewColumn->new_with_attributes
736
                                        ("Double click to add the device",
737
                                        $cell,
738
                                        'text' => DISPLAY_COLUMN,
739
                                        'style_set' => ITALIC_COLUMN);
740
 
741
  $tree_view->append_column ($column);
742
  my @ll=($model,\$info);
743
#row selected
744
  $selection->signal_connect (changed =>sub {
745
        my ($selection, $ref) = @_;
746
        my ($model,$info)=@{$ref};
747
        my $iter = $selection->get_selected;
748
        return unless defined $iter;
749
 
750
        my ($category) = $model->get ($iter, CATRGORY_COLUMN);
751
        my ($module) = $model->get ($iter,MODULE_COLUMN );
752 24 alirezamon
        my $describ=$ip->ip_get($category,$module,"description");
753 16 alirezamon
        if($describ){
754
                #print "$entry describtion is: $describ \n";
755
                show_info($info,$describ);
756
 
757
        }
758
 
759
 
760
}, \@ll);
761
 
762
#  row_activated 
763
  $tree_view->signal_connect (row_activated => sub{
764
 
765
         my ($tree_view, $path, $column) = @_;
766
         my $model = $tree_view->get_model;
767
         my $iter = $model->get_iter ($path);
768
        my ($category) = $model->get ($iter, CATRGORY_COLUMN);
769
        my ($module) = $model->get ($iter,MODULE_COLUMN );
770
 
771
 
772
 
773
        if($module){
774
                #print "$module  is selected via row activaton!\n";
775
                add_module_to_soc($soc,$ip,$category,$module,\$info,$soc_state);
776
                set_state($soc_state,"refresh_soc",0);
777
        }
778
 
779
 
780
 
781
 
782
 
783
 
784
 
785
 
786
}, \@ll);
787
 
788
  #$tree_view->expand_all;
789
 
790
  my $scrolled_window = Gtk2::ScrolledWindow->new;
791
  $scrolled_window->set_policy ('automatic', 'automatic');
792
  $scrolled_window->set_shadow_type ('in');
793
  $scrolled_window->add($tree_view);
794
 
795
  my $hbox = Gtk2::HBox->new (TRUE, 0);
796
  $hbox->pack_start ( $scrolled_window, TRUE, TRUE, 0);
797
 
798
 
799
 
800
  return $hbox;
801
}
802
 
803
 
804
 
805 17 alirezamon
sub get_all_files_list {
806
        my ($soc,$list_name)=@_;
807 16 alirezamon
        my @instances=$soc->soc_get_all_instances();
808
        my $ip = ip->lib_new ();
809
        my @files;
810
        my $dir = Cwd::getcwd();
811
        my $warnings;
812
        #make target dir
813
        my $project_dir   = abs_path("$dir/../..");
814
 
815
        foreach my $id (@instances){
816
                my $module              =$soc->soc_get_module($id);
817
                my $module_name =$soc->soc_get_module_name($id);
818
                my $category    =$soc->soc_get_category($id);
819
                my $inst                =$soc->soc_get_instance_name($id);
820
 
821 24 alirezamon
                my @new=$ip->ip_get_list( $category,$module,$list_name);
822
                #print "@new\n";
823 16 alirezamon
                foreach my $f(@new){
824
                        my $n="$project_dir$f";
825 24 alirezamon
                         if (!(-f "$n") && !(-f "$f" ) && !(-d "$n") && !(-d "$f" )     ){
826 17 alirezamon
                                $warnings=(defined $warnings)? "$warnings WARNING: Can not find  \"$f\" which is required for \"$inst\" \n":"WARNING: Can not find  \"$f\"  which is required for \"$inst\"\n ";
827 16 alirezamon
 
828
                         }
829
 
830
 
831
                }
832
 
833
 
834
 
835
 
836
                @files=(@files,@new);
837
        }
838
        return \@files,$warnings;
839
}
840
 
841
################
842
#       generate_soc
843
#################
844
 
845
sub generate_soc{
846
        my ($soc,$info)=@_;
847
        my $name=$soc->soc_get_soc_name();
848
                if (length($name)>0){
849
                        my @tmp=split('_',$name);
850
                        if ( $tmp[-1] =~ /^[0-9]+$/ ){
851
                                message_dialog("The soc name must not end with '_number'!");
852
                                return 0;
853
                        }
854
 
855
                        my $file_v=soc_generate_verilog($soc);
856
 
857
                        # Write object file
858
                        open(FILE,  ">lib/soc/$name.SOC") || die "Can not open: $!";
859
                        print FILE Data::Dumper->Dump([\%$soc],[$name]);
860
                        close(FILE) || die "Error closing file: $!";
861
 
862
                        # Write verilog file
863
                        open(FILE,  ">lib/verilog/$name.v") || die "Can not open: $!";
864
                        print FILE $file_v;
865
                        close(FILE) || die "Error closing file: $!";
866
 
867
 
868
 
869
 
870
                        # copy all files in project work directory
871
                        my $dir = Cwd::getcwd();
872
                        #make target dir
873
                        my $project_dir   = abs_path("$dir/../../");
874
                        my $target_dir  = "$project_dir/mpsoc_work/SOC/$name";
875
                        mkpath("$target_dir/src_verilog/lib/",1,0755);
876
                        mkpath("$target_dir/sw",1,0755);
877
 
878
                #copy hdl codes in src_verilog
879
 
880 17 alirezamon
                my ($file_ref,$warnings)= get_all_files_list($soc,"hdl_files");
881 24 alirezamon
                copy_file_and_folders($file_ref,$project_dir,"$target_dir/src_verilog/lib");
882 16 alirezamon
 
883
                        show_info(\$info,$warnings)                     if(defined $warnings);
884
 
885
 
886
                #my @pathes=("$dir/../src_peripheral","$dir/../src_noc","$dir/../src_processor");
887
                #foreach my $p(@pathes){
888
                #       find(
889
                #               sub {
890
                #                       return unless ( -f $_ );
891
                #                       $_ =~ /\.v$/ && copy( $File::Find::name, "$target_dir/src_verilog/lib/" );
892
                #               },
893
                #       $p
894
                        #       );
895
                #}
896
 
897
 
898 18 alirezamon
                move ("$dir/lib/verilog/$name.v","$target_dir/src_verilog/");
899 16 alirezamon
 
900
 
901
 
902 24 alirezamon
                # Write system.h and generated file
903
                        generate_header_file($soc,$project_dir,$target_dir,$dir);
904
 
905 16 alirezamon
 
906 17 alirezamon
                # Write Software files
907
                        ($file_ref,$warnings)= get_all_files_list($soc,"sw_files");
908 24 alirezamon
                        copy_file_and_folders($file_ref,$project_dir,"$target_dir/sw");
909
 
910
                # Write Software gen files
911
                        ($file_ref,$warnings)= get_all_files_list($soc,"gen_sw_files");
912 17 alirezamon
                        foreach my $f(@{$file_ref}){
913 24 alirezamon
                                #print "$f\n";
914 17 alirezamon
 
915 24 alirezamon
 
916
                        }
917
 
918
 
919 23 alirezamon
                # Write main.c file if not exist
920
                my $n="$target_dir/sw/main.c";
921
                if (!(-f "$n")) {
922
                        # Write main.c
923
                        open(FILE,  ">$n") || die "Can not open: $!";
924
                        print FILE main_c_template($name);
925
                        close(FILE) || die "Error closing file: $!";
926 16 alirezamon
 
927 23 alirezamon
                }
928 16 alirezamon
 
929
 
930
 
931 17 alirezamon
 
932 16 alirezamon
                        message_dialog("SoC \"$name\" has been created successfully at $target_dir/ " );
933 17 alirezamon
                        exec($^X, $0, @ARGV);# reset ProNoC to apply changes
934 16 alirezamon
 
935
                }else {
936
                        message_dialog("Please define the SoC name!");
937
 
938
                }
939
 
940
return 1;
941
}
942
 
943
 
944 23 alirezamon
sub main_c_template{
945
        my $hdr=shift;
946
        my $text="
947
#include \"$hdr.h\"
948 16 alirezamon
 
949
 
950 23 alirezamon
// a simple delay function
951
void delay ( unsigned int num ){
952
 
953
        while (num>0){
954
                num--;
955
                asm volatile (\"nop\");
956
        }
957
        return;
958 16 alirezamon
 
959 23 alirezamon
}
960 16 alirezamon
 
961 23 alirezamon
int main(){
962
        while(1){
963
 
964
 
965 16 alirezamon
 
966 23 alirezamon
        }
967
 
968
return 0;
969
}
970
 
971
";
972
 
973
return $text;
974
 
975
 
976
}
977
 
978
 
979
 
980
 
981 16 alirezamon
sub get_wb_address      {
982
        my ($soc,$instance_id,$addr,$width)=@_;
983
        my ($base,$end);
984
        my @list= split (" ",$addr);
985
        $base= hex ($list[0]);
986
        $end= $base+(1 << $width)-1;
987
        #print "$addr:$base \& $end\n";
988
        my %taken_bases= $soc->soc_list_base_addreses($instance_id);
989
 
990
        my $conflict=0;
991
        do{
992
                $conflict=0;
993
                foreach my $taken_end (sort {$a<=>$b} keys %taken_bases){
994
                        my $taken_base=$taken_bases{$taken_end};
995
                        #print "taken:($taken_base,$taken_end)\n";
996
                        if (($base <= $taken_base && $end >= $taken_base ) || ($base <= $taken_end && $end >= $taken_end )){
997
                        #if (!(($base < $taken_base && $end < $taken_end ) || ($base > $taken_base && $end > $taken_end ))){
998
                                 $conflict=1;
999
                                 $base=$taken_end+1;
1000
                                 $end= $base+(1 << $width)-1;
1001
                                 last;
1002
 
1003
                        }
1004
                }
1005
 
1006
        }while($conflict==1 && $end<(1 << 32));
1007
        if($conflict==0){
1008
                #print"new ($base,$end);\n";
1009
                return ($base,$end);
1010
 
1011
        }
1012
 
1013
        return ;
1014
 
1015
}
1016
 
1017
 
1018
 
1019
 
1020
 
1021
 
1022
 
1023
 
1024
 
1025
##########
1026
#       wb address setting
1027
#########
1028
 
1029
sub wb_address_setting {
1030
        my $soc=shift;
1031
 
1032
 
1033
        my $window = def_popwin_size(1200,500,"Wishbone slave port address setting");
1034
        my $table = def_table(10, 6, TRUE);
1035
 
1036
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1037
        $scrolled_win->set_policy( "automatic", "automatic" );
1038
        $scrolled_win->add_with_viewport($table);
1039
        my $row=0;
1040
 
1041
        #title
1042
        $table->attach_defaults(gen_label_in_left  ("Instance name"),0,1,$row,$row+1);
1043
        $table->attach_defaults(gen_label_in_left  ("Interface name"),1,2,$row,$row+1);
1044
        $table->attach_defaults(gen_label_in_left  ("Bus name"),2,3,$row,$row+1);
1045
        $table->attach_defaults(gen_label_in_center("Base address"),3,4,$row,$row+1);
1046
        $table->attach_defaults(gen_label_in_center("End address"),4,5,$row,$row+1);
1047
        $table->attach_defaults(gen_label_in_center("Size (Bytes)"),5,6,$row,$row+1);
1048
 
1049
        my (@newbase,@newend,@connects);
1050
 
1051
        $row++;
1052
        my @all_instances=$soc->soc_get_all_instances();
1053
        foreach my $instance_id (@all_instances){
1054
                my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1055
                foreach my $plug (@plugs){
1056
                        my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1057
                        foreach my $num (@nums){
1058
                                my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1059
                                if((defined $connect_socket) && ($connect_socket eq 'wb_slave')){
1060
                                        my $number=$row-1;
1061
                                        $newbase[$number]=$base;
1062
                                        $newend[$number]=$end;
1063
                                        $connects[$number]=$connect_id;
1064
                                        $row++;
1065
                                }#if
1066
                        }#foreach my $num
1067
                }#foreach my $plug
1068
        }#foreach my $instance_id
1069
 
1070
        my @status_all;
1071
        $row=1;
1072
        foreach my $instance_id (@all_instances){
1073
                my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1074
                foreach my $plug (@plugs){
1075
                        my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1076
                        foreach my $num (@nums){
1077
                                my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1078
                                if((defined $connect_socket) && ($connect_socket eq 'wb_slave')){
1079
                                        my $instance_name=$soc->soc_get_instance_name($instance_id);
1080
                                        my $plug_name=(defined $name ) ? gen_label_in_left($name):
1081
                                                                                                         gen_label_in_left("$plug\[$num\]");
1082
 
1083
                                        my $connected_instance_name= $soc->soc_get_instance_name($connect_id);
1084
                                        my $number=$row-1;
1085
                                        my $label1= gen_label_in_left("$number: $instance_name");
1086
                                        my $label2= gen_label_in_left($connected_instance_name);
1087
                                        my $entry1= Gtk2::Entry->new_with_max_length (10);
1088
                                    $entry1->set_text(sprintf("0x%08x", $base));
1089
 
1090
                                        my $entry2= Gtk2::Entry->new_with_max_length (10);
1091
                                        $entry2->set_text(sprintf("0x%08x", $end));
1092
 
1093
                                        my ($box,$valid) =addr_box_gen(sprintf("0x%08x", $base), sprintf("0x%08x", $end),\@newbase,\@newend,\@connects,$number);
1094
                                        $status_all[$number]=$valid;
1095
 
1096
 
1097
                                        $table->attach_defaults($label1,0,1,$row,$row+1);
1098
                                        $table->attach_defaults($plug_name,1,2,$row,$row+1);
1099
                                        $table->attach_defaults($label2,2,3,$row,$row+1);
1100
                                        $table->attach_defaults($entry1,3,4,$row,$row+1);
1101
                                        $table->attach_defaults($entry2,4,5,$row,$row+1);
1102
 
1103
 
1104
                                        $table->attach_defaults($box,5,7,$row,$row+1);
1105
 
1106
 
1107
                                        $entry1->signal_connect('changed'=>sub{
1108
                                                my $base_in=$entry1->get_text();
1109
                                                if (length($base_in)<2){ $entry1->set_text('0x')};
1110
                                                my $end_in=$entry2->get_text();
1111
                                                my $valid;
1112
                                                $box->destroy;
1113
                                                ($box,$valid)=addr_box_gen($base_in, $end_in,\@newbase,\@newend,\@connects,$number);
1114
                                                $status_all[$number]=$valid;
1115
                                                $table->attach_defaults($box,5,7,$number+1,$number+2);
1116
                                                $table->show_all;
1117
 
1118
 
1119
                                        } );
1120
                                        $entry2->signal_connect('changed'=>sub{
1121
                                                my $base_in=$entry1->get_text();
1122
                                                my $end_in=$entry2->get_text();
1123
                                                if (length($end_in)<2){ $entry2->set_text('0x')};
1124
                                                my $valid;
1125
                                                $box->destroy;
1126
                                                ($box,$valid)=addr_box_gen($base_in, $end_in,\@newbase,\@newend,\@connects,$number);
1127
                                                $status_all[$number]=$valid;
1128
                                                $table->attach_defaults($box,5,7,$number+1,$number+2);
1129
                                                $table->show_all;
1130
                                        } );
1131
 
1132
 
1133
 
1134
                                        $row++;
1135
 
1136
 
1137
                                }#if
1138
                        }#foreach my $num
1139
                }#foreach my $plug
1140
        }#foreach my $instance_id
1141
 
1142
 
1143
        my $ok = def_image_button('icons/select.png','OK');
1144
        my $okbox=def_hbox(TRUE,0);
1145
        $okbox->pack_start($ok, FALSE, FALSE,0);
1146
 
1147
        my $refresh = def_image_button('icons/revert.png','Revert');
1148
        my $refbox=def_hbox(TRUE,0);
1149
        $refbox->pack_start($refresh, FALSE, FALSE,0);
1150
 
1151
        $refresh->signal_connect( 'clicked'=> sub {
1152
                $window->destroy;
1153
                wb_address_setting($soc);
1154
 
1155
 
1156
                });
1157
        $ok->signal_connect     ( 'clicked'=> sub {
1158
                my $st=1;
1159
                foreach my $valid (@status_all){
1160
                        if($valid==0){
1161
                                $st=0;
1162
 
1163
                        }
1164
                }
1165
 
1166
                if($st==1){
1167
                        $row=1;
1168
                        foreach my $instance_id (@all_instances){
1169
                        my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1170
                        foreach my $plug (@plugs){
1171
                                my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1172
                                foreach my $num (@nums){
1173
                                        my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1174
                                        if(defined $connect_socket && ($connect_socket eq 'wb_slave')){
1175
                                                my $number=$row-1;
1176
                                                $soc->soc_add_plug_base_addr($instance_id,$plug,$num,$newbase[$number],$newend[$number]);
1177
                                                $row++;
1178
                                        }#if
1179
                                }#foreach my $num
1180
                        }#foreach my $plug
1181
                }#foreach my $instance_id
1182
 
1183
 
1184
 
1185
 
1186
 
1187
                        $window->destroy;
1188
                }else{
1189
                        message_dialog("Invalid address !");
1190
 
1191
                }
1192
 
1193
 
1194
                });
1195
 
1196
 
1197
 
1198
        $row= ($row<9)? 9:$row;
1199
        $table->attach_defaults($refbox,2,3,$row,$row+1);
1200
        $table->attach_defaults($okbox,3,4,$row,$row+1);
1201
 
1202
        $window->add($scrolled_win);
1203
        $window->show_all;
1204
 
1205
 
1206
 
1207
}
1208
##############
1209
#       addr_box_gen
1210
##############
1211
 
1212
sub addr_box_gen{
1213
        my ($base_in, $end_in,$newbase_ref,$newend_ref,$connects_ref,$number)=@_;
1214
        my $box= def_hbox(TRUE,0);
1215
        my $label;
1216
        my $valid=1;
1217
        my $info;
1218
        if(is_hex($base_in) && is_hex($end_in)){
1219
                my $size=(hex ($end_in) >= hex ($base_in))? hex ($end_in) - hex ($base_in) +1 : 0;
1220 24 alirezamon
                my $size_text=  metric_conversion($size);
1221 16 alirezamon
                $label= gen_label_in_center($size_text);
1222
                $$newbase_ref[$number]=hex($base_in);
1223
                $$newend_ref[$number]=hex($end_in);
1224
                $info=check_entered_address($newbase_ref,$newend_ref,$connects_ref,$number);
1225
                if(defined      $info) {$valid=0;}
1226
 
1227
        }
1228
        else {
1229
                $label= gen_label_in_center("Invalid hex value!");
1230
                $info="Invalid hex value!";
1231
                $valid=0;
1232
        }
1233
 
1234
 
1235
        my $status=(defined $info)? gen_button_message ($info,'icons/warnning.png'):
1236
                                                                gen_button_message (undef,'icons/select.png');
1237
 
1238
        $box->pack_start($label,FALSE,FALSE,3);
1239
        $box->pack_start($status,FALSE,FALSE,3);
1240
        return ($box,$valid);
1241
 
1242
}
1243
 
1244
 
1245
 
1246
 
1247
###########
1248
#       get_parameter_final_value
1249
############
1250
sub get_parameter_final_value{
1251
        my ($soc,$id,$param)=@_;
1252
        #get ordered param
1253
        my @ordered_param=$soc->soc_get_instance_param_order($id);
1254
        my %sim_params;
1255
        foreach my $p (@ordered_param){
1256
                my $value=$soc->soc_get_module_param_value($id,$p);
1257
                foreach my $q (sort keys %sim_params){
1258
                        $value=replace_value($value,$q,$sim_params{$q}) if (defined $value);
1259
                }
1260
                $sim_params{$p}=$value;
1261
                #print "$sim_params{$p}=$value;\n";
1262
        }
1263
        return $sim_params{$param};
1264
}
1265
 
1266
 
1267
 
1268
 
1269
sub replace_value{
1270
        my ($string,$param,$value)=@_;
1271
 
1272
        my $new_string=$string;
1273
        #print "$new_range\n";
1274
        my $new_param= $value;
1275
        ($new_string=$new_string)=~ s/\b$param\b/$new_param/g;
1276
        return eval $new_string;
1277
 
1278
 
1279
}
1280
 
1281
 
1282
 
1283
 
1284
 
1285
 
1286
 
1287
 
1288
 
1289
 
1290
 
1291
 
1292
 
1293
sub check_entered_address{
1294
my      ($base_ref,$end_ref,$connect_ref,$number)=@_;
1295
my @bases=@{$base_ref};
1296
my @ends=@{$end_ref};
1297
my @connects=@{$connect_ref};
1298
 
1299
my $current_base=$bases[$number];
1300
my $current_end=$ends[$number];
1301
 
1302
if($current_base>  $current_end) {
1303
 
1304
return "Error: the given base address is bigger than the End address!";
1305
        }
1306
 
1307
my $size= scalar @bases;
1308
my $conflicts;
1309
foreach (my $i=0; $i<$size; $i++){
1310
        if($i != $number){ #if not same row
1311
                if      ($connects[$i] eq $connects[$number]) {#same bus
1312
                                my $ok=(($bases[$i]< $bases[$number] && $bases[$i] < $ends[$number])||($bases[$i]> $bases[$number] && $bases[$i] > $ends[$number]));
1313
                            if($ok==0) {
1314
                                        $conflicts=(defined $conflicts )? "$conflicts,$i": $i;
1315
                                }
1316
                }
1317
 
1318
 
1319
        }
1320
 
1321
 
1322
}
1323
if (defined $conflicts){ return " The given address range has conflict with rows:$conflicts"; }
1324
return;
1325
 
1326
 
1327
}
1328
 
1329
#############
1330
#       load_soc
1331
#############
1332
 
1333
sub load_soc{
1334
        my ($soc,$soc_state)=@_;
1335
        my $file;
1336
        my $dialog = Gtk2::FileChooserDialog->new(
1337
                'Select a File', undef,
1338
                'open',
1339
                'gtk-cancel' => 'cancel',
1340
                'gtk-ok'     => 'ok',
1341
                );
1342
 
1343
        my $filter = Gtk2::FileFilter->new();
1344
        $filter->set_name("SoC");
1345
        $filter->add_pattern("*.SOC");
1346
        $dialog->add_filter ($filter);
1347
        my $dir = Cwd::getcwd();
1348
        $dialog->set_current_folder ("$dir/lib/soc")    ;
1349
 
1350
 
1351
        if ( "ok" eq $dialog->run ) {
1352
                $file = $dialog->get_filename;
1353
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1354
                if($suffix eq '.SOC'){
1355
                        my $pp= eval { do $file };
1356
                        clone_obj($soc,$pp);
1357
                        set_state($soc_state,"load_file",0);
1358
                }
1359
     }
1360
     $dialog->destroy;
1361
 
1362
 
1363
 
1364
 
1365
 
1366
}
1367
 
1368
 
1369
 
1370
 
1371
 
1372
 
1373
 
1374
 
1375
 
1376
 
1377
 
1378
 
1379
 
1380
 
1381
 
1382
 
1383
 
1384
 
1385
 
1386
 
1387
 
1388
 
1389
############
1390
#    main
1391
############
1392
sub socgen_main{
1393
 
1394
        my $infc = interface->interface_new();
1395
        my $ip = ip->lib_new ();
1396
        my $soc = soc->soc_new();
1397
        #my $soc= eval { do 'lib/soc/soc.SOC' };
1398
 
1399
        my $soc_state=  def_state("ideal");
1400
        # main window
1401
        #my $window = def_win_size(1000,800,"Top");
1402
        #  The main table containg the lib tree, selected modules and info section 
1403
        my $main_table = Gtk2::Table->new (20, 12, FALSE);
1404
 
1405
        # The box which holds the info, warning, error ...  mesages
1406
        my ($infobox,$info)= create_text();
1407
 
1408
 
1409
        my $refresh_dev_win = Gtk2::Button->new_from_stock('ref');
1410
 
1411
        # A tree view for holding a library
1412
        my $tree_box = create_tree ($info,$ip,$soc,$soc_state);
1413
 
1414
 
1415
 
1416
        $main_table->set_row_spacings (4);
1417
        $main_table->set_col_spacings (1);
1418
 
1419
        my  $device_win=show_active_dev($soc,$ip,$infc,$soc_state,\$refresh_dev_win,$info);
1420
 
1421
 
1422
        my $generate = def_image_button('icons/gen.png','Generate');
1423
        my $genbox=def_hbox(TRUE,0);
1424
        $genbox->pack_start($generate,   FALSE, FALSE,0);
1425
 
1426
 
1427
 
1428
 
1429
 
1430
        my $wb = def_image_button('icons/setting.png','Wishbone address setting');
1431
        my $wbbox=def_hbox(TRUE,0);
1432
        $wbbox->pack_start($wb,   FALSE, FALSE,0);
1433
 
1434
        my $open = def_image_button('icons/browse.png','Load Tile');
1435
        my $openbox=def_hbox(TRUE,0);
1436
        $openbox->pack_start($open,   FALSE, FALSE,0);
1437
 
1438
 
1439
 
1440
        my ($entrybox,$entry) = def_h_labeled_entry('Tile name:');
1441
        $entry->signal_connect( 'changed'=> sub{
1442
                my $name=$entry->get_text();
1443
                $soc->soc_set_soc_name($name);
1444
        });
1445
 
1446
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
1447
        $main_table->attach_defaults ($tree_box , 0, 2, 0, 17);
1448
        $main_table->attach_defaults ($device_win , 2, 12, 0, 17);
1449
        $main_table->attach_defaults ($infobox  , 0, 12, 17,19);
1450
        $main_table->attach_defaults ($openbox,0, 3, 19,20);
1451
        $main_table->attach_defaults ($entrybox,3, 7, 19,20);
1452
        $main_table->attach_defaults ($wbbox, 7, 10, 19,20);
1453
        $main_table->attach_defaults ($genbox, 10, 12, 19,20);
1454
 
1455
 
1456
        #check soc status every 0.5 second. referesh device table if there is any changes 
1457
        Glib::Timeout->add (100, sub{
1458
 
1459
                my ($state,$timeout)= get_state($soc_state);
1460
 
1461
                if ($timeout>0){
1462
                        $timeout--;
1463
                        set_state($soc_state,$state,$timeout);
1464
                }
1465
                elsif( $state ne "ideal" ){
1466
                        $refresh_dev_win->clicked;
1467
                        my $saved_name=$soc->soc_get_soc_name();
1468
                        if(defined $saved_name) {$entry->set_text($saved_name);}
1469
                        set_state($soc_state,"ideal",0);
1470
 
1471
                }
1472
                return TRUE;
1473
 
1474
        } );
1475
 
1476
 
1477
        $generate-> signal_connect("clicked" => sub{
1478
                generate_soc($soc,$info);
1479
                $refresh_dev_win->clicked;
1480
 
1481
        });
1482
 
1483
        $wb-> signal_connect("clicked" => sub{
1484
                wb_address_setting($soc);
1485
 
1486
        });
1487
 
1488
        $open-> signal_connect("clicked" => sub{
1489
                load_soc($soc,$soc_state);
1490
 
1491
        });
1492
 
1493
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
1494
                $sc_win->set_policy( "automatic", "automatic" );
1495
                $sc_win->add_with_viewport($main_table);
1496
 
1497
        return $sc_win;
1498
        #return $main_table;
1499
 
1500
 
1501
}

powered by: WebSVN 2.1.0

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