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 28

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

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

powered by: WebSVN 2.1.0

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