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 23

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
                  $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 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
        my $describ=$ip->get_describtion($category,$module);
753
        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 17 alirezamon
                my @new=$ip->ip_get_files( $category,$module,$list_name);
822 16 alirezamon
                foreach my $f(@new){
823
                        my $n="$project_dir$f";
824 17 alirezamon
                         if (!(-f "$n") && !(-f "$f" ) ){
825
                                $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 ";
826 16 alirezamon
 
827
                         }
828
 
829
 
830
                }
831
 
832
 
833
 
834
 
835
                @files=(@files,@new);
836
        }
837
        return \@files,$warnings;
838
}
839
 
840
################
841
#       generate_soc
842
#################
843
 
844
sub generate_soc{
845
        my ($soc,$info)=@_;
846
        my $name=$soc->soc_get_soc_name();
847
                if (length($name)>0){
848
                        my @tmp=split('_',$name);
849
                        if ( $tmp[-1] =~ /^[0-9]+$/ ){
850
                                message_dialog("The soc name must not end with '_number'!");
851
                                return 0;
852
                        }
853
 
854
                        my $file_v=soc_generate_verilog($soc);
855
 
856
                        # Write object file
857
                        open(FILE,  ">lib/soc/$name.SOC") || die "Can not open: $!";
858
                        print FILE Data::Dumper->Dump([\%$soc],[$name]);
859
                        close(FILE) || die "Error closing file: $!";
860
 
861
                        # Write verilog file
862
                        open(FILE,  ">lib/verilog/$name.v") || die "Can not open: $!";
863
                        print FILE $file_v;
864
                        close(FILE) || die "Error closing file: $!";
865
 
866
 
867
 
868
 
869
                        # copy all files in project work directory
870
                        my $dir = Cwd::getcwd();
871
                        #make target dir
872
                        my $project_dir   = abs_path("$dir/../../");
873
                        my $target_dir  = "$project_dir/mpsoc_work/SOC/$name";
874
                        mkpath("$target_dir/src_verilog/lib/",1,0755);
875
                        mkpath("$target_dir/sw",1,0755);
876
 
877
                #copy hdl codes in src_verilog
878
 
879 17 alirezamon
                my ($file_ref,$warnings)= get_all_files_list($soc,"hdl_files");
880
                foreach my $f(@{$file_ref}){
881 16 alirezamon
                        my $n="$project_dir$f";
882
                         if (-f "$n") {
883
                                copy ("$n","$target_dir/src_verilog/lib");
884
                         }elsif(-f "$f" ){
885
                                copy ("$f","$target_dir/src_verilog/lib");
886
 
887
                         }
888
 
889
 
890
                }
891
                        show_info(\$info,$warnings)                     if(defined $warnings);
892
 
893
 
894
                #my @pathes=("$dir/../src_peripheral","$dir/../src_noc","$dir/../src_processor");
895
                #foreach my $p(@pathes){
896
                #       find(
897
                #               sub {
898
                #                       return unless ( -f $_ );
899
                #                       $_ =~ /\.v$/ && copy( $File::Find::name, "$target_dir/src_verilog/lib/" );
900
                #               },
901
                #       $p
902
                        #       );
903
                #}
904
 
905
 
906 18 alirezamon
                move ("$dir/lib/verilog/$name.v","$target_dir/src_verilog/");
907 16 alirezamon
 
908
 
909
 
910 17 alirezamon
                # Write header files
911
                        my $file_h=generate_header_file($soc);
912 16 alirezamon
                        open(FILE,  ">lib/verilog/$name.h") || die "Can not open: $!";
913
                        print FILE $file_h;
914
                        close(FILE) || die "Error closing file: $!";
915 18 alirezamon
                        move ("$dir/lib/verilog/$name.h","$target_dir/sw/");
916 16 alirezamon
 
917 17 alirezamon
                # Write Software files
918
                        ($file_ref,$warnings)= get_all_files_list($soc,"sw_files");
919
 
920
                        foreach my $f(@{$file_ref}){
921
                                my $name= basename($f);
922
 
923
                        my $n="$project_dir$f";
924
                         if (-f "$n") { #copy file
925
                                copy ("$n","$target_dir/sw");
926
                         }elsif(-f "$f" ){
927
                                copy ("$f","$target_dir/sw");
928
 
929
                         }elsif (-d "$n") {#copy folder
930
                                dircopy ("$n","$target_dir/sw/$name");
931
                         }elsif(-d "$f" ){
932
                                dircopy ("$f","$target_dir/sw/$name");
933
 
934
                         }
935
 
936
 
937
                }
938 23 alirezamon
                # Write main.c file if not exist
939
                my $n="$target_dir/sw/main.c";
940
                if (!(-f "$n")) {
941
                        # Write main.c
942
                        open(FILE,  ">$n") || die "Can not open: $!";
943
                        print FILE main_c_template($name);
944
                        close(FILE) || die "Error closing file: $!";
945 16 alirezamon
 
946 23 alirezamon
                }
947 16 alirezamon
 
948
 
949
 
950 17 alirezamon
 
951 16 alirezamon
                        message_dialog("SoC \"$name\" has been created successfully at $target_dir/ " );
952 17 alirezamon
                        exec($^X, $0, @ARGV);# reset ProNoC to apply changes
953 16 alirezamon
 
954
                }else {
955
                        message_dialog("Please define the SoC name!");
956
 
957
                }
958
 
959
return 1;
960
}
961
 
962
 
963 23 alirezamon
sub main_c_template{
964
        my $hdr=shift;
965
        my $text="
966
#include \"$hdr.h\"
967 16 alirezamon
 
968
 
969 23 alirezamon
// a simple delay function
970
void delay ( unsigned int num ){
971
 
972
        while (num>0){
973
                num--;
974
                asm volatile (\"nop\");
975
        }
976
        return;
977 16 alirezamon
 
978 23 alirezamon
}
979 16 alirezamon
 
980 23 alirezamon
int main(){
981
        while(1){
982
 
983
 
984 16 alirezamon
 
985 23 alirezamon
        }
986
 
987
return 0;
988
}
989
 
990
";
991
 
992
return $text;
993
 
994
 
995
}
996
 
997
 
998
 
999
 
1000 16 alirezamon
sub get_wb_address      {
1001
        my ($soc,$instance_id,$addr,$width)=@_;
1002
        my ($base,$end);
1003
        my @list= split (" ",$addr);
1004
        $base= hex ($list[0]);
1005
        $end= $base+(1 << $width)-1;
1006
        #print "$addr:$base \& $end\n";
1007
        my %taken_bases= $soc->soc_list_base_addreses($instance_id);
1008
 
1009
        my $conflict=0;
1010
        do{
1011
                $conflict=0;
1012
                foreach my $taken_end (sort {$a<=>$b} keys %taken_bases){
1013
                        my $taken_base=$taken_bases{$taken_end};
1014
                        #print "taken:($taken_base,$taken_end)\n";
1015
                        if (($base <= $taken_base && $end >= $taken_base ) || ($base <= $taken_end && $end >= $taken_end )){
1016
                        #if (!(($base < $taken_base && $end < $taken_end ) || ($base > $taken_base && $end > $taken_end ))){
1017
                                 $conflict=1;
1018
                                 $base=$taken_end+1;
1019
                                 $end= $base+(1 << $width)-1;
1020
                                 last;
1021
 
1022
                        }
1023
                }
1024
 
1025
        }while($conflict==1 && $end<(1 << 32));
1026
        if($conflict==0){
1027
                #print"new ($base,$end);\n";
1028
                return ($base,$end);
1029
 
1030
        }
1031
 
1032
        return ;
1033
 
1034
}
1035
 
1036
 
1037
 
1038
 
1039
 
1040
 
1041
 
1042
 
1043
 
1044
##########
1045
#       wb address setting
1046
#########
1047
 
1048
sub wb_address_setting {
1049
        my $soc=shift;
1050
 
1051
 
1052
        my $window = def_popwin_size(1200,500,"Wishbone slave port address setting");
1053
        my $table = def_table(10, 6, TRUE);
1054
 
1055
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1056
        $scrolled_win->set_policy( "automatic", "automatic" );
1057
        $scrolled_win->add_with_viewport($table);
1058
        my $row=0;
1059
 
1060
        #title
1061
        $table->attach_defaults(gen_label_in_left  ("Instance name"),0,1,$row,$row+1);
1062
        $table->attach_defaults(gen_label_in_left  ("Interface name"),1,2,$row,$row+1);
1063
        $table->attach_defaults(gen_label_in_left  ("Bus name"),2,3,$row,$row+1);
1064
        $table->attach_defaults(gen_label_in_center("Base address"),3,4,$row,$row+1);
1065
        $table->attach_defaults(gen_label_in_center("End address"),4,5,$row,$row+1);
1066
        $table->attach_defaults(gen_label_in_center("Size (Bytes)"),5,6,$row,$row+1);
1067
 
1068
        my (@newbase,@newend,@connects);
1069
 
1070
        $row++;
1071
        my @all_instances=$soc->soc_get_all_instances();
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 $number=$row-1;
1080
                                        $newbase[$number]=$base;
1081
                                        $newend[$number]=$end;
1082
                                        $connects[$number]=$connect_id;
1083
                                        $row++;
1084
                                }#if
1085
                        }#foreach my $num
1086
                }#foreach my $plug
1087
        }#foreach my $instance_id
1088
 
1089
        my @status_all;
1090
        $row=1;
1091
        foreach my $instance_id (@all_instances){
1092
                my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1093
                foreach my $plug (@plugs){
1094
                        my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1095
                        foreach my $num (@nums){
1096
                                my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1097
                                if((defined $connect_socket) && ($connect_socket eq 'wb_slave')){
1098
                                        my $instance_name=$soc->soc_get_instance_name($instance_id);
1099
                                        my $plug_name=(defined $name ) ? gen_label_in_left($name):
1100
                                                                                                         gen_label_in_left("$plug\[$num\]");
1101
 
1102
                                        my $connected_instance_name= $soc->soc_get_instance_name($connect_id);
1103
                                        my $number=$row-1;
1104
                                        my $label1= gen_label_in_left("$number: $instance_name");
1105
                                        my $label2= gen_label_in_left($connected_instance_name);
1106
                                        my $entry1= Gtk2::Entry->new_with_max_length (10);
1107
                                    $entry1->set_text(sprintf("0x%08x", $base));
1108
 
1109
                                        my $entry2= Gtk2::Entry->new_with_max_length (10);
1110
                                        $entry2->set_text(sprintf("0x%08x", $end));
1111
 
1112
                                        my ($box,$valid) =addr_box_gen(sprintf("0x%08x", $base), sprintf("0x%08x", $end),\@newbase,\@newend,\@connects,$number);
1113
                                        $status_all[$number]=$valid;
1114
 
1115
 
1116
                                        $table->attach_defaults($label1,0,1,$row,$row+1);
1117
                                        $table->attach_defaults($plug_name,1,2,$row,$row+1);
1118
                                        $table->attach_defaults($label2,2,3,$row,$row+1);
1119
                                        $table->attach_defaults($entry1,3,4,$row,$row+1);
1120
                                        $table->attach_defaults($entry2,4,5,$row,$row+1);
1121
 
1122
 
1123
                                        $table->attach_defaults($box,5,7,$row,$row+1);
1124
 
1125
 
1126
                                        $entry1->signal_connect('changed'=>sub{
1127
                                                my $base_in=$entry1->get_text();
1128
                                                if (length($base_in)<2){ $entry1->set_text('0x')};
1129
                                                my $end_in=$entry2->get_text();
1130
                                                my $valid;
1131
                                                $box->destroy;
1132
                                                ($box,$valid)=addr_box_gen($base_in, $end_in,\@newbase,\@newend,\@connects,$number);
1133
                                                $status_all[$number]=$valid;
1134
                                                $table->attach_defaults($box,5,7,$number+1,$number+2);
1135
                                                $table->show_all;
1136
 
1137
 
1138
                                        } );
1139
                                        $entry2->signal_connect('changed'=>sub{
1140
                                                my $base_in=$entry1->get_text();
1141
                                                my $end_in=$entry2->get_text();
1142
                                                if (length($end_in)<2){ $entry2->set_text('0x')};
1143
                                                my $valid;
1144
                                                $box->destroy;
1145
                                                ($box,$valid)=addr_box_gen($base_in, $end_in,\@newbase,\@newend,\@connects,$number);
1146
                                                $status_all[$number]=$valid;
1147
                                                $table->attach_defaults($box,5,7,$number+1,$number+2);
1148
                                                $table->show_all;
1149
                                        } );
1150
 
1151
 
1152
 
1153
                                        $row++;
1154
 
1155
 
1156
                                }#if
1157
                        }#foreach my $num
1158
                }#foreach my $plug
1159
        }#foreach my $instance_id
1160
 
1161
 
1162
        my $ok = def_image_button('icons/select.png','OK');
1163
        my $okbox=def_hbox(TRUE,0);
1164
        $okbox->pack_start($ok, FALSE, FALSE,0);
1165
 
1166
        my $refresh = def_image_button('icons/revert.png','Revert');
1167
        my $refbox=def_hbox(TRUE,0);
1168
        $refbox->pack_start($refresh, FALSE, FALSE,0);
1169
 
1170
        $refresh->signal_connect( 'clicked'=> sub {
1171
                $window->destroy;
1172
                wb_address_setting($soc);
1173
 
1174
 
1175
                });
1176
        $ok->signal_connect     ( 'clicked'=> sub {
1177
                my $st=1;
1178
                foreach my $valid (@status_all){
1179
                        if($valid==0){
1180
                                $st=0;
1181
 
1182
                        }
1183
                }
1184
 
1185
                if($st==1){
1186
                        $row=1;
1187
                        foreach my $instance_id (@all_instances){
1188
                        my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1189
                        foreach my $plug (@plugs){
1190
                                my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1191
                                foreach my $num (@nums){
1192
                                        my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1193
                                        if(defined $connect_socket && ($connect_socket eq 'wb_slave')){
1194
                                                my $number=$row-1;
1195
                                                $soc->soc_add_plug_base_addr($instance_id,$plug,$num,$newbase[$number],$newend[$number]);
1196
                                                $row++;
1197
                                        }#if
1198
                                }#foreach my $num
1199
                        }#foreach my $plug
1200
                }#foreach my $instance_id
1201
 
1202
 
1203
 
1204
 
1205
 
1206
                        $window->destroy;
1207
                }else{
1208
                        message_dialog("Invalid address !");
1209
 
1210
                }
1211
 
1212
 
1213
                });
1214
 
1215
 
1216
 
1217
        $row= ($row<9)? 9:$row;
1218
        $table->attach_defaults($refbox,2,3,$row,$row+1);
1219
        $table->attach_defaults($okbox,3,4,$row,$row+1);
1220
 
1221
        $window->add($scrolled_win);
1222
        $window->show_all;
1223
 
1224
 
1225
 
1226
}
1227
##############
1228
#       addr_box_gen
1229
##############
1230
 
1231
sub addr_box_gen{
1232
        my ($base_in, $end_in,$newbase_ref,$newend_ref,$connects_ref,$number)=@_;
1233
        my $box= def_hbox(TRUE,0);
1234
        my $label;
1235
        my $valid=1;
1236
        my $info;
1237
        if(is_hex($base_in) && is_hex($end_in)){
1238
                my $size=(hex ($end_in) >= hex ($base_in))? hex ($end_in) - hex ($base_in) +1 : 0;
1239
                my $size_text=  $size==0  ? 'Error':
1240
                                                $size<(1 << 10)? $size:
1241
                                                $size<(1 << 20)? join (' ', ($size>>10,"K")) :
1242
                                                $size<(1 << 30)? join (' ', ($size>>20,"M")) :
1243
                                                                           join (' ', ($size>>30,"G")) ;
1244
                $label= gen_label_in_center($size_text);
1245
                $$newbase_ref[$number]=hex($base_in);
1246
                $$newend_ref[$number]=hex($end_in);
1247
                $info=check_entered_address($newbase_ref,$newend_ref,$connects_ref,$number);
1248
                if(defined      $info) {$valid=0;}
1249
 
1250
        }
1251
        else {
1252
                $label= gen_label_in_center("Invalid hex value!");
1253
                $info="Invalid hex value!";
1254
                $valid=0;
1255
        }
1256
 
1257
 
1258
        my $status=(defined $info)? gen_button_message ($info,'icons/warnning.png'):
1259
                                                                gen_button_message (undef,'icons/select.png');
1260
 
1261
        $box->pack_start($label,FALSE,FALSE,3);
1262
        $box->pack_start($status,FALSE,FALSE,3);
1263
        return ($box,$valid);
1264
 
1265
}
1266
 
1267
 
1268
 
1269
 
1270
###########
1271
#       get_parameter_final_value
1272
############
1273
sub get_parameter_final_value{
1274
        my ($soc,$id,$param)=@_;
1275
        #get ordered param
1276
        my @ordered_param=$soc->soc_get_instance_param_order($id);
1277
        my %sim_params;
1278
        foreach my $p (@ordered_param){
1279
                my $value=$soc->soc_get_module_param_value($id,$p);
1280
                foreach my $q (sort keys %sim_params){
1281
                        $value=replace_value($value,$q,$sim_params{$q}) if (defined $value);
1282
                }
1283
                $sim_params{$p}=$value;
1284
                #print "$sim_params{$p}=$value;\n";
1285
        }
1286
        return $sim_params{$param};
1287
}
1288
 
1289
 
1290
 
1291
 
1292
sub replace_value{
1293
        my ($string,$param,$value)=@_;
1294
 
1295
        my $new_string=$string;
1296
        #print "$new_range\n";
1297
        my $new_param= $value;
1298
        ($new_string=$new_string)=~ s/\b$param\b/$new_param/g;
1299
        return eval $new_string;
1300
 
1301
 
1302
}
1303
 
1304
 
1305
 
1306
 
1307
 
1308
 
1309
 
1310
 
1311
 
1312
 
1313
 
1314
 
1315
 
1316
sub check_entered_address{
1317
my      ($base_ref,$end_ref,$connect_ref,$number)=@_;
1318
my @bases=@{$base_ref};
1319
my @ends=@{$end_ref};
1320
my @connects=@{$connect_ref};
1321
 
1322
my $current_base=$bases[$number];
1323
my $current_end=$ends[$number];
1324
 
1325
if($current_base>  $current_end) {
1326
 
1327
return "Error: the given base address is bigger than the End address!";
1328
        }
1329
 
1330
my $size= scalar @bases;
1331
my $conflicts;
1332
foreach (my $i=0; $i<$size; $i++){
1333
        if($i != $number){ #if not same row
1334
                if      ($connects[$i] eq $connects[$number]) {#same bus
1335
                                my $ok=(($bases[$i]< $bases[$number] && $bases[$i] < $ends[$number])||($bases[$i]> $bases[$number] && $bases[$i] > $ends[$number]));
1336
                            if($ok==0) {
1337
                                        $conflicts=(defined $conflicts )? "$conflicts,$i": $i;
1338
                                }
1339
                }
1340
 
1341
 
1342
        }
1343
 
1344
 
1345
}
1346
if (defined $conflicts){ return " The given address range has conflict with rows:$conflicts"; }
1347
return;
1348
 
1349
 
1350
}
1351
 
1352
#############
1353
#       load_soc
1354
#############
1355
 
1356
sub load_soc{
1357
        my ($soc,$soc_state)=@_;
1358
        my $file;
1359
        my $dialog = Gtk2::FileChooserDialog->new(
1360
                'Select a File', undef,
1361
                'open',
1362
                'gtk-cancel' => 'cancel',
1363
                'gtk-ok'     => 'ok',
1364
                );
1365
 
1366
        my $filter = Gtk2::FileFilter->new();
1367
        $filter->set_name("SoC");
1368
        $filter->add_pattern("*.SOC");
1369
        $dialog->add_filter ($filter);
1370
        my $dir = Cwd::getcwd();
1371
        $dialog->set_current_folder ("$dir/lib/soc")    ;
1372
 
1373
 
1374
        if ( "ok" eq $dialog->run ) {
1375
                $file = $dialog->get_filename;
1376
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1377
                if($suffix eq '.SOC'){
1378
                        my $pp= eval { do $file };
1379
                        clone_obj($soc,$pp);
1380
                        set_state($soc_state,"load_file",0);
1381
                }
1382
     }
1383
     $dialog->destroy;
1384
 
1385
 
1386
 
1387
 
1388
 
1389
}
1390
 
1391
 
1392
 
1393
 
1394
 
1395
 
1396
 
1397
 
1398
 
1399
 
1400
 
1401
 
1402
 
1403
 
1404
 
1405
 
1406
 
1407
 
1408
 
1409
 
1410
 
1411
 
1412
############
1413
#    main
1414
############
1415
sub socgen_main{
1416
 
1417
        my $infc = interface->interface_new();
1418
        my $ip = ip->lib_new ();
1419
        my $soc = soc->soc_new();
1420
        #my $soc= eval { do 'lib/soc/soc.SOC' };
1421
 
1422
        my $soc_state=  def_state("ideal");
1423
        # main window
1424
        #my $window = def_win_size(1000,800,"Top");
1425
        #  The main table containg the lib tree, selected modules and info section 
1426
        my $main_table = Gtk2::Table->new (20, 12, FALSE);
1427
 
1428
        # The box which holds the info, warning, error ...  mesages
1429
        my ($infobox,$info)= create_text();
1430
 
1431
 
1432
        my $refresh_dev_win = Gtk2::Button->new_from_stock('ref');
1433
 
1434
        # A tree view for holding a library
1435
        my $tree_box = create_tree ($info,$ip,$soc,$soc_state);
1436
 
1437
 
1438
 
1439
        $main_table->set_row_spacings (4);
1440
        $main_table->set_col_spacings (1);
1441
 
1442
        my  $device_win=show_active_dev($soc,$ip,$infc,$soc_state,\$refresh_dev_win,$info);
1443
 
1444
 
1445
        my $generate = def_image_button('icons/gen.png','Generate');
1446
        my $genbox=def_hbox(TRUE,0);
1447
        $genbox->pack_start($generate,   FALSE, FALSE,0);
1448
 
1449
 
1450
 
1451
 
1452
 
1453
        my $wb = def_image_button('icons/setting.png','Wishbone address setting');
1454
        my $wbbox=def_hbox(TRUE,0);
1455
        $wbbox->pack_start($wb,   FALSE, FALSE,0);
1456
 
1457
        my $open = def_image_button('icons/browse.png','Load Tile');
1458
        my $openbox=def_hbox(TRUE,0);
1459
        $openbox->pack_start($open,   FALSE, FALSE,0);
1460
 
1461
 
1462
 
1463
        my ($entrybox,$entry) = def_h_labeled_entry('Tile name:');
1464
        $entry->signal_connect( 'changed'=> sub{
1465
                my $name=$entry->get_text();
1466
                $soc->soc_set_soc_name($name);
1467
        });
1468
 
1469
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
1470
        $main_table->attach_defaults ($tree_box , 0, 2, 0, 17);
1471
        $main_table->attach_defaults ($device_win , 2, 12, 0, 17);
1472
        $main_table->attach_defaults ($infobox  , 0, 12, 17,19);
1473
        $main_table->attach_defaults ($openbox,0, 3, 19,20);
1474
        $main_table->attach_defaults ($entrybox,3, 7, 19,20);
1475
        $main_table->attach_defaults ($wbbox, 7, 10, 19,20);
1476
        $main_table->attach_defaults ($genbox, 10, 12, 19,20);
1477
 
1478
 
1479
        #check soc status every 0.5 second. referesh device table if there is any changes 
1480
        Glib::Timeout->add (100, sub{
1481
 
1482
                my ($state,$timeout)= get_state($soc_state);
1483
 
1484
                if ($timeout>0){
1485
                        $timeout--;
1486
                        set_state($soc_state,$state,$timeout);
1487
                }
1488
                elsif( $state ne "ideal" ){
1489
                        $refresh_dev_win->clicked;
1490
                        my $saved_name=$soc->soc_get_soc_name();
1491
                        if(defined $saved_name) {$entry->set_text($saved_name);}
1492
                        set_state($soc_state,"ideal",0);
1493
 
1494
                }
1495
                return TRUE;
1496
 
1497
        } );
1498
 
1499
 
1500
        $generate-> signal_connect("clicked" => sub{
1501
                generate_soc($soc,$info);
1502
                $refresh_dev_win->clicked;
1503
 
1504
        });
1505
 
1506
        $wb-> signal_connect("clicked" => sub{
1507
                wb_address_setting($soc);
1508
 
1509
        });
1510
 
1511
        $open-> signal_connect("clicked" => sub{
1512
                load_soc($soc,$soc_state);
1513
 
1514
        });
1515
 
1516
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
1517
                $sc_win->set_policy( "automatic", "automatic" );
1518
                $sc_win->add_with_viewport($main_table);
1519
 
1520
        return $sc_win;
1521
        #return $main_table;
1522
 
1523
 
1524
}

powered by: WebSVN 2.1.0

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