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 42

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 34 alirezamon
 
23 16 alirezamon
# clean names for column numbers.
24
use constant DISPLAY_COLUMN    => 0;
25
use constant CATRGORY_COLUMN    => 1;
26
use constant MODULE_COLUMN     => 2;
27
use constant ITALIC_COLUMN   => 3;
28
use constant NUM_COLUMNS     => 4;
29
 
30
 
31
require "widget.pl";
32
require "verilog_gen.pl";
33 25 alirezamon
require "readme_gen.pl";
34 17 alirezamon
require "hdr_file_gen.pl";
35 34 alirezamon
require "diagram.pl";
36
require "compile.pl";
37
require  "software_editor.pl";
38 16 alirezamon
 
39
 
40
 
41
sub is_hex {
42
    local $!;
43
    return ! (POSIX::strtol($_[0], 16))[1];
44
 }
45
 
46
###############
47
#   get_instance_id
48
# return an instance id which is the module name with a unique number 
49
#############
50
sub get_instance_id{
51
        my ($soc,$category,$module)=@_;
52
        my @id_list= $soc->soc_get_all_instances_of_module($category,$module);
53
        my $id=0;
54
        my $instance_id="$module$id";
55
        do {
56
                $instance_id = "$module$id";
57
                $id++;
58
        }while ((grep {$_ eq $instance_id} @id_list) ) ;
59
        #print "$instance_id\n";
60
        return ($instance_id,$id);
61
 
62
}
63
 
64
 
65
 
66
#################
67
#  add_module_to_soc
68
###############
69
sub add_module_to_soc{
70 25 alirezamon
        my ($soc,$ip,$category,$module,$info)=@_;
71 16 alirezamon
        my ($instance_id,$id)= get_instance_id($soc,$category,$module);
72
 
73
        #add module instanance
74
        my $result=$soc->soc_add_instance($instance_id,$category,$module,$ip);
75
 
76
        if($result == 0){
77
                my $info_text= "Failed to add \"$instance_id\" to SoC. $instance_id is already exist.";
78
                show_info($info,$info_text);
79
                return;
80
        }
81
        $soc->soc_add_instance_order($instance_id);
82 34 alirezamon
        # Add IP version 
83
        my $v=$ip->ip_get($category,$module,"version");
84
        $v = 0 if(!defined $v);
85
        #print "$v\n";
86
        $soc->object_add_attribute($instance_id,"version",$v);
87 25 alirezamon
        # Read default parameter from lib and add them to soc
88 16 alirezamon
        my %param_default= $ip->get_param_default($category,$module);
89
 
90
        my $rr=$soc->soc_add_instance_param($instance_id,\%param_default);
91
        if($rr == 0){
92 25 alirezamon
                my $info_text= "Failed to add defualt parameter to \"$instance_id\".  $instance_id does not exist exist.";
93 16 alirezamon
                show_info($info,$info_text);
94
                return;
95
        }
96
        my @r=$ip->ip_get_param_order($category,$module);
97
        $soc->soc_add_instance_param_order($instance_id,\@r);
98
 
99 25 alirezamon
        get_module_parameter($soc,$ip,$instance_id);
100 16 alirezamon
 
101
 
102
 
103
}
104
################
105
#       remove_instance_from_soc
106
################
107
sub remove_instance_from_soc{
108 25 alirezamon
        my ($soc,$instance_id)=@_;
109 16 alirezamon
        $soc->soc_remove_instance($instance_id);
110
        $soc->soc_remove_from_instance_order($instance_id);
111 25 alirezamon
        set_gui_status($soc,"refresh_soc",0);
112 16 alirezamon
}
113
 
114
 
115
 
116
###############
117
#   get module_parameter
118
##############
119
 
120
sub get_module_parameter{
121 25 alirezamon
        my ($soc,$ip,$instance_id)=@_;
122 16 alirezamon
 
123
        #read module parameters from lib
124
        my $module=$soc->soc_get_module($instance_id);
125
        my $category=$soc->soc_get_category($instance_id);
126 25 alirezamon
        my @parameters=$ip->ip_get_param_order($category,$module);
127 16 alirezamon
        my $param_num = @parameters;
128
 
129
        #read soc parameters
130
        my %param_value= $soc->soc_get_module_param($instance_id);
131
        my %new_param_value=%param_value;
132
        #gui
133
        my $table_size = ($param_num<10) ? 10 : $param_num;
134 34 alirezamon
        my $window =  def_popwin_size(60,60, "Parameter setting for $module ",'percent');
135 25 alirezamon
        my $table = def_table($table_size, 7, FALSE);
136 16 alirezamon
 
137
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
138
        $scrolled_win->set_policy( "automatic", "automatic" );
139
        $scrolled_win->add_with_viewport($table);
140
        my $row=0;
141
 
142
        my $ok = def_image_button('icons/select.png','OK');
143 25 alirezamon
 
144 34 alirezamon
        my $at0= 'expand';
145
        my $at1= 'shrink';
146 25 alirezamon
 
147 34 alirezamon
        $table->attach (gen_label_in_left("Parameter name"),0, 3, $row, $row+1,$at0,$at1,2,2);
148
        $table->attach (gen_label_in_left("Value"),3, 6, $row, $row+1,$at0,$at1,2,2);
149
        $table->attach (gen_label_in_left("Description"),6, 7, $row, $row+1,$at0,$at1,2,2);
150 25 alirezamon
        $row++;
151 16 alirezamon
        foreach my $p (@parameters){
152 25 alirezamon
                my ($default,$type,$content,$info)= $ip->ip_get_parameter($category,$module,$p);
153 16 alirezamon
 
154
                my $value=$param_value{$p};
155 38 alirezamon
                #$value = $default if (!defined $value && defined $default);
156
                #print "$value\n";
157 34 alirezamon
                if ($type eq "File_Entry"){
158
                        my $entry=gen_entry($value);
159
                        my $brows=get_file_name(undef,undef,$entry,undef,undef,undef,undef,undef);
160
                        my $box=def_hbox(TRUE,0);
161
                        $box->pack_start($entry,FALSE,FALSE,3);
162
                        $box->pack_start($brows,FALSE,FALSE,3);
163
                        $table->attach ($box, 3, 6, $row, $row+1,$at0,$at1,2,2);
164
                        $entry-> signal_connect("changed" => sub{$new_param_value{$p}=$entry->get_text();});
165
                }
166 16 alirezamon
 
167 34 alirezamon
                elsif ($type eq "Entry"){
168 16 alirezamon
                        my $entry=gen_entry($value);
169 34 alirezamon
                        $table->attach ($entry, 3, 6, $row, $row+1,$at0,$at1,2,2);
170 16 alirezamon
                        $entry-> signal_connect("changed" => sub{$new_param_value{$p}=$entry->get_text();});
171
                }
172
                elsif ($type eq "Combo-box"){
173
                        my @combo_list=split(",",$content);
174
                        my $pos=get_item_pos($value, @combo_list);
175
                        my $combo=gen_combo(\@combo_list, $pos);
176 34 alirezamon
                        $table->attach ($combo, 3, 6, $row, $row+1,$at0,$at1,2,2);
177 16 alirezamon
                        $combo-> signal_connect("changed" => sub{$new_param_value{$p}=$combo->get_active_text();});
178
 
179
                }
180
                elsif   ($type eq "Spin-button"){
181
                  my ($min,$max,$step)=split(",",$content);
182
                  $value=~ s/\D//g;
183
                  $min=~ s/\D//g;
184
                  $max=~ s/\D//g;
185
                  $step=~ s/\D//g;
186
                  my $spin=gen_spin($min,$max,$step);
187 28 alirezamon
                  if(defined $value) {$spin->set_value($value);}
188
                  else {$spin->set_value($min);}
189 34 alirezamon
                  $table->attach ($spin, 3, 4, $row, $row+1,$at0,$at1,2,2);
190 24 alirezamon
                  $spin-> signal_connect("value_changed" => sub{ $new_param_value{$p}=$spin->get_value_as_int(); });
191 16 alirezamon
 
192
                 # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
193
                }
194
                if (defined $info && $type ne "Fixed"){
195
                        my $info_button=def_image_button('icons/help.png');
196 34 alirezamon
                        $table->attach ($info_button, 6, 7, $row, $row+1,$at0,$at1,2,2);
197 16 alirezamon
                        $info_button->signal_connect('clicked'=>sub{
198
                                message_dialog($info);
199
 
200
                        });
201
 
202
                }
203
                if ($type ne "Fixed"){
204
                        #print "$p:val:$value\n";
205 34 alirezamon
                        my $label =gen_label_in_left($p);
206
                        $table->attach ($label, 0, 3, $row, $row+1,$at0,$at1,2,2);
207 16 alirezamon
                        $row++;
208
                }
209
 
210 25 alirezamon
 
211 16 alirezamon
        }
212 25 alirezamon
        #if ($row== 0){
213
                        #my $label =gen_label_in_left("The $module IP does not have any adjatable parameter");
214 34 alirezamon
                #       $table->attach ($label, 0, 7, $row, $row+1,$at0,'shrink',2,2);
215 25 alirezamon
 
216
        #}
217 16 alirezamon
 
218 34 alirezamon
 
219
 
220 25 alirezamon
        my $mtable = def_table(10, 1, FALSE);
221 16 alirezamon
 
222
        $mtable->attach_defaults($scrolled_win,0,1,0,9);
223 34 alirezamon
        $mtable->attach($ok,0,1,9,10,'expand','fill',2,2);
224 16 alirezamon
 
225
        $window->add ($mtable);
226
        $window->show_all();
227
 
228
        $ok-> signal_connect("clicked" => sub{
229
                $window->destroy;
230
                #save new values 
231
                $soc->soc_add_instance_param($instance_id,\%new_param_value);
232
 
233
 
234
                #check if wishbone address bus is parameterizable regenerate the addresses again 
235
                my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
236
                foreach my $plug (@plugs){
237
                        if ($plug eq 'wb_slave'){
238
                                my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
239
                                foreach my $plug_num (@nums){
240
                                        my ($addr_connect,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$plug_num);
241
                                        if($connect_id ne 'IO' && $connect_id ne 'NC'){
242
                                                #print "$connect_id : soc_get_plug_addr ($instance_id,$plug,$plug_num)\n";
243
                                                #remove old wb addr
244
                                                $soc->soc_add_plug_base_addr($instance_id,$plug,$plug_num,undef,undef);
245
                                                #get base and address width
246
                                                my ($addr , $width)=$soc->soc_get_plug_addr ($instance_id,$plug,$plug_num);
247
                                                #check if width is a parameter
248
                                                my $val= get_parameter_final_value($soc,$instance_id,$width);
249
                                                $width= $val if(defined $val);
250
                                                #allocate new address in $connect_id
251
                                                my ($base,$end)=get_wb_address($soc,$connect_id,$addr,$width);
252
                                                if(defined $base){#save it
253
                                                        $soc->soc_add_plug_base_addr($instance_id,$plug,$plug_num,$base,$end);
254
                                                }
255
                                        }
256
                                }#plug_num
257
                        }#if
258
                }#plugs
259
 
260
 
261 25 alirezamon
                set_gui_status($soc,"refresh_soc",0);
262 16 alirezamon
                #$$refresh_soc->clicked;
263
 
264
                });
265
 
266
 
267
}
268
 
269
 
270
 
271
############
272
#  param_box
273
#
274
############
275
sub get_item_pos{#if not in return 0
276
                my ($item,@list)=@_;
277
                my $pos=0;
278
                foreach my $p (@list){
279
                                #print "$p eq $item\n";
280
                                if ($p eq $item){return $pos;}
281
                                $pos++;
282
                }
283
                return 0;
284
 
285
}
286
 
287
 sub param_box{
288
         my ($param, $default,$type,$content,$info, $value)=@_;
289
         my $box=def_hbox(TRUE,0);
290
         my $label =gen_label_in_left($param);
291
         $box->pack_start($label,FALSE,FALSE,3);
292
 
293
         if ($type eq "Entry"){
294
                my $entry=gen_entry($default);
295
                $box->pack_start($entry,FALSE,FALSE,3);
296
 
297
         }
298
         elsif ($type eq "Combo-box"){
299
                 my @combo_list=split(",",$content);
300
                 my $pos=get_item_pos($default, @combo_list);
301
                 my $combo=gen_combo(\@combo_list, $pos);
302
                 $box->pack_start($combo,FALSE,FALSE,3);
303
         }
304
         elsif  ($type eq "Spin-button"){
305
                  my ($min,$max,$step)=split(",",$content);
306
                  $default=~ s/\D//g;
307
                  $min=~ s/\D//g;
308
                  $max=~ s/\D//g;
309
                  $step=~ s/\D//g;
310
                  my $spin=gen_spin($min,$max,$step);
311
                  $box->pack_start($spin,FALSE,FALSE,3);
312
                 # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
313
         }
314
 
315
         return $box;
316
}
317
 
318
 
319
###############
320
#  get_mathced_socket_pos
321
###############
322
 
323
 
324
sub  get_mathced_socket_pos{
325
        my ($soc,$instance_id,$plug,$plug_num,@connettions)=@_;
326
        my ($id,$socket,$num)=$soc->soc_get_module_plug_conection($instance_id,$plug,$plug_num);
327
        my $pos=($id eq "IO")? 0: (scalar @connettions)-1;
328
        if($id ne "IO" && $id ne 'NC'){
329
                my $name= $soc->soc_get_instance_name($id);
330
                if (defined $name){
331
                        my $connect="$name\:$socket\[$num]";
332
                        if( grep {$_ eq $connect} @connettions){$pos = get_scolar_pos($connect,@connettions);}
333
                }
334
                else {
335
                        $soc->soc_add_instance_plug_conection($instance_id,$plug,$plug_num,"IO");
336
 
337
                }
338
        }
339
        return $pos;
340
}
341
 
342
 
343
##############
344
#       gen_dev_box
345
##############
346
 
347 25 alirezamon
sub gen_instance{
348
        #my ($soc,$ip,$infc,$instance_id,$info)=@_;
349
        my ($soc,$ip,$infc,$instance_id,$info,$table,$offset)=@_;
350 16 alirezamon
 
351
 
352
 
353
#       my $box= def_vbox (FALSE,0);
354
 
355
#       my $table = def_table(3,5,TRUE);
356
        my $data_in;
357
 
358
#column 1       
359
        #module name
360
        my $module=$soc->soc_get_module($instance_id);
361
        my $category=$soc->soc_get_category($instance_id);
362
        my $module_name_label=box_label(FALSE,0,$module);
363 34 alirezamon
        my $box0=def_hbox(FALSE,5);
364
        $box0->pack_start( $module_name_label, FALSE, FALSE, 3);
365
 
366
        #module pdf
367
        my $pdf=$soc->soc_get_description_pdf($instance_id);
368
        if(defined $pdf){
369
                my $b=def_image_button('icons/evince-icon.png');
370
                $box0->pack_start( $b, FALSE, FALSE, 3);
371
                $b->signal_connect ("clicked"  => sub{
372
                        my $dir = Cwd::getcwd();
373
                        my $project_dir   = abs_path("$dir/../../"); #mpsoc directory address
374
                        #print "path ${project_dir}$pdf\n";
375
                        if (-f "${project_dir}$pdf"){
376
                                system qq (xdg-open ${project_dir}$pdf);
377
                        }elsif (-f "$pdf"){
378
                                system qq (xdg-open $pdf);
379
                        }else{
380
                                message_dialog("Error! $pdf or ${project_dir}$pdf did not find!\n");
381
                        }
382
 
383
                });
384
 
385
        }
386
        $table->attach  ($box0,0,1,$offset+0,$offset+1,'expand','shrink',2,2);
387
 
388 16 alirezamon
        #parameter setting button
389
        my $param_button = def_image_button('icons/setting.png','Setting');
390
        my $box1=def_hbox(FALSE,5);
391
        my $up=def_image_button("icons/up_sim.png");
392
        $box1->pack_start( $up, FALSE, FALSE, 3);
393
        $box1->pack_start($param_button,   FALSE, FALSE,3);
394 34 alirezamon
        $table->attach  ($box1 ,0,1,$offset+1,$offset+2,'expand','shrink',2,2);
395 16 alirezamon
        $param_button->signal_connect (clicked => sub{
396 25 alirezamon
                get_module_parameter($soc,$ip,$instance_id);
397 16 alirezamon
 
398
        });
399
        $up->signal_connect (clicked => sub{
400
                $soc->soc_decrease_instance_order($instance_id);
401 25 alirezamon
                set_gui_status($soc,"refresh_soc",0);
402 16 alirezamon
 
403
        });
404
 
405
        #remove button
406
        #my ($box2,$cancel_button) = button_box("Remove");
407
        my $cancel_button=def_image_button('icons/cancel.png','Remove');
408
        my $box2=def_hbox(FALSE,5);
409
 
410
        my $dwn=def_image_button("icons/down_sim.png");
411
        $box2->pack_start( $dwn, FALSE, FALSE, 3);
412
        $box2->pack_start($cancel_button,   FALSE, FALSE,3);
413 34 alirezamon
        $table->attach  ($box2,0,1,$offset+2,$offset+3,'expand','shrink',2,2);
414 16 alirezamon
        $cancel_button->signal_connect (clicked => sub{
415 25 alirezamon
                remove_instance_from_soc($soc,$instance_id);
416 16 alirezamon
 
417
        });
418
        $dwn->signal_connect (clicked => sub{
419
                $soc->soc_increase_instance_order($instance_id);
420 25 alirezamon
                set_gui_status($soc,"refresh_soc",0);
421 16 alirezamon
 
422
        });
423 34 alirezamon
 
424 16 alirezamon
 
425
 
426
        #instance name
427
        my $instance_name=$soc->soc_get_instance_name($instance_id);
428 34 alirezamon
        my $instance_label=gen_label_in_left(" Instance name");
429 16 alirezamon
        my $instance_entry = gen_entry($instance_name);
430
 
431
 
432
 
433 34 alirezamon
        $table->attach  ($instance_label,1,2,$offset+0,$offset+1,'expand','shrink',2,2);
434
        #$table->attach_defaults ($instance_entry,1,2,$offset+1,$offset+2);
435
 
436
 
437
        my $enter= def_image_button("icons/enter.png");
438 16 alirezamon
 
439 34 alirezamon
        my $box=def_pack_hbox(FALSE,0,$instance_entry );
440
        $table->attach  ($box,1,2,$offset+1,$offset+2,'expand','shrink',2,2);
441
 
442
        my ($old_v,$new_v)=  get_old_new_ip_version ($soc,$ip,$instance_id);
443
        if($old_v != $new_v){
444
                my $warn=def_image_button("icons/warnning.png");
445
                $table->attach  ($warn,1,2,$offset+2,$offset+3,'expand','shrink',2,2);  #$box2->pack_start($warn, FALSE, FALSE, 3);  
446
                $warn->signal_connect (clicked => sub{
447
                        message_dialog("Warning: ${module}'s version (V.$old_v) missmatches with the one exsiting in librray (V.$new_v). The generated system may not work correctly.  Please remove and then add $module again to update it with current version")
448
 
449
                });
450
 
451
 
452
        }
453
 
454
 
455
        $instance_entry->signal_connect ("activate"  => sub{
456 16 alirezamon
                #print "changed\n";
457 34 alirezamon
                my $new_name=$instance_entry->get_text();
458 16 alirezamon
                #check if instance name exist in soc
459 34 alirezamon
                set_gui_status($soc,"refresh_soc",1) if($instance_name eq $new_name );
460 16 alirezamon
                my @instance_names= $soc->soc_get_all_instance_name();
461 34 alirezamon
                if( grep {$_ eq $new_name} @instance_names){
462
                        print "$new_name exist\n";
463 16 alirezamon
                }
464
                else {
465
                #add instance name to soc
466 34 alirezamon
                        $soc->soc_set_instance_name($instance_id,$new_name);
467 16 alirezamon
 
468 34 alirezamon
                        set_gui_status($soc,"refresh_soc",1);
469 16 alirezamon
 
470
                }
471
        });
472 34 alirezamon
        my $change=0;
473
        $instance_entry->signal_connect ("changed"  => sub{
474
                if($change ==0){
475
                        $box->pack_start( $enter, FALSE, FALSE, 0);
476
                        $box->show_all;
477
                        $change=1;
478
                }
479
 
480
        });
481 16 alirezamon
 
482 34 alirezamon
        $enter->signal_connect ("clicked"  => sub{
483
                my $new_name=$instance_entry->get_text();
484
                #check if instance name exist in soc
485
                set_gui_status($soc,"refresh_soc",1) if($instance_name eq $new_name );
486
                my @instance_names= $soc->soc_get_all_instance_name();
487
                if( grep {$_ eq $new_name} @instance_names){
488
                        print "$new_name exist\n";
489
                }
490
                else {
491
                #add instance name to soc
492
                        $soc->soc_set_instance_name($instance_id,$new_name);
493
 
494
                        set_gui_status($soc,"refresh_soc",1);
495
 
496
                }
497
 
498
 
499
        });
500
 
501
 
502 16 alirezamon
 
503
        #interface_pluges
504
        my %plugs = $ip->get_module_plugs_value($category,$module);
505
 
506
        my $row=0;
507
        foreach my $plug (sort keys %plugs) {
508
 
509
                my $plug_num= $plugs{$plug};
510
                for (my $k=0;$k<$plug_num;$k++){
511
 
512
                        my @connettions=("IO");
513
                        my @connettions_name=("IO");
514
 
515
                        my ($connection_num,$matched_soket)= $infc->get_plug($plug);
516
 
517
 
518
 
519
                        my %connect_list= $soc->get_modules_have_this_socket($matched_soket);
520
                        foreach my $id(sort keys %connect_list ){
521
                                if($instance_id ne $id){ # assum its forbidden to connect the socket and plug of same ip to each other
522
                                        #generate soket list
523
                                        my $name=$soc->soc_get_instance_name($id);
524
                                        #check if its a number or parameter
525
                                        my $param=$connect_list{$id};
526
                                        my $value=$soc->soc_get_module_param_value($id,$param);
527
                                        my $array_name=0;
528
                                        if ( !length( $value || '' )) {
529
                                                $value=$param;
530
                                                $array_name=1;
531
 
532
 
533
                                        };
534
                                        for(my $i=0; $i<$value; $i++){
535
                                                my $s= "$name\:$matched_soket\[$i]";
536
                                                push (@connettions,$s);
537
 
538
                                                # show sockets with their connected plugs 
539
                                                my ($type_t,$value_t,$connection_num_t)=$soc->soc_get_socket_of_instance($id,$matched_soket);
540
 
541
                                                my $cc=find_connection($soc,$id,$matched_soket,$i);
542
                                                $cc= (!defined $cc )? '':
543
                                                         ($cc eq "$instance_id:$plug\[$k\]" || $connection_num_t eq 'multi connection')? '':  "->$cc";
544
 
545
                                                if($array_name eq 0){
546
                                                        my $n= $soc->soc_get_socket_name($id,$matched_soket, 0);
547
 
548
                                                        $n = (!defined $n)? $s:"$name\:$n\[$i]";
549
                                                        $n = "$n$cc";
550
                                                        push (@connettions_name,"$n");
551
 
552
                                                }else{
553
                                                        my $n= $soc->soc_get_socket_name($id,$matched_soket, $i);
554
 
555
                                                        $n = (!defined $n)? $s:"$name\:$n";
556
                                                        $n = "$n$cc";
557
                                                        push (@connettions_name,"$n");
558
 
559
                                                }
560
 
561
                                        }
562
 
563
                                }
564
 
565
 
566
                        }
567
                        push (@connettions,"NC");
568
                        push (@connettions_name,"NC");
569
 
570
                        #print "connection is $connect for $p\n";
571
                        #my @socket_list= $soc_get_sockets();
572
 
573
 
574
                        my $pos= get_mathced_socket_pos($soc,$instance_id,$plug,$k,@connettions);
575
 
576
                        #plug name
577
                        my $plug_name=  $soc->soc_get_plug_name($instance_id,$plug,$k);
578
                        if(! defined $plug_name ){$plug_name=($plug_num>1)?"$plug\[$k\]":$plug}
579 34 alirezamon
                        $plug_name="  $plug_name  ";
580 16 alirezamon
                        my($plug_box, $plug_combo)= def_h_labeled_combo_scaled($plug_name,\@connettions_name,$pos,1,2);
581
 
582
                        #if($row>2){$table->resize ($row, 2);}
583 34 alirezamon
                        $table->attach ($plug_box,2,5,$row+$offset,$row+$offset+1,'fill','fill',2,2);   $row++;
584 16 alirezamon
 
585
                        my $plug_num=$k;
586
                        my @ll=($soc,$instance_id,$plug,$info,$plug_num);
587
                        $plug_combo->signal_connect (changed => sub{
588
                                my $self=shift;
589
                                my $ref= shift;
590
                                my($soc,$instance_id,$plug,$info,$plug_num) = @{$ref};
591
                                my $connect_name=$plug_combo->get_active_text();
592
                                my $pos=get_item_pos($connect_name, @connettions_name);
593
                                my $connect=$connettions[$pos];
594
 
595
 
596
 
597
                                my($intance_name,$socket,$num)= split("[:\[ \\]]", $connect);
598
                                my $id=$intance_name;# default IO or NC
599
                                if(($intance_name ne 'IO') && ($intance_name ne 'NC')){
600
 
601
                                        $id=$soc->soc_get_instance_id($intance_name);
602
                                        my ($type,$value,$connection_num)=$soc->soc_get_socket_of_instance($id,$socket);
603
                                        #print "\$$connection_num=$connection_num\n";
604
                                        if($connection_num eq 'single connection'){# disconnect other plug from this soket
605
                                                my ($ref1,$ref2)= $soc->soc_get_modules_plug_connected_to_socket($id,$socket,$num);
606
                                                my %connected_plugs=%$ref1;
607
                                                my %connected_plug_nums=%$ref2;
608
                                                foreach my $p (sort keys %connected_plugs) {
609
                                                        #%pp{$instance_id}=$plug
610
                                                        $soc->soc_add_instance_plug_conection($p,$connected_plugs{$p},$connected_plug_nums{$p},'IO');
611
                                                        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.";
612
                                                        show_info(\$info, $info_text);
613
                                                }
614
 
615
                                        }
616
                                }
617
                                #print "$id \n $connect \n$num\n";
618
                                #my @rr=$soc->soc_get_all_plugs_of_an_instance($id);
619
 
620
 
621
 
622
 
623
                                $soc->soc_add_instance_plug_conection($instance_id,$plug,$plug_num,$id,$socket,$num);
624
 
625
                                #get address for wishbone slave port
626
                                if ($plug eq 'wb_slave'){
627
                                                #remove old wb addr
628
                                                $soc->soc_add_plug_base_addr($instance_id,$plug,$plug_num,undef,undef);
629
 
630
                                                #get base and address width
631
                                                my ($addr , $width)=$soc->soc_get_plug_addr ($instance_id,$plug,$plug_num);
632
 
633
                                                #check if width is a parameter
634
                                                my $val= get_parameter_final_value($soc,$instance_id,$width);
635
                                                #print "my $val= get_parameter_final_value($soc,$instance_id,$width);\n";
636
                                                $width= $val if(defined $val);
637
 
638
 
639
                                                #allocate new address in $id
640
                                                my ($base,$end)=get_wb_address($soc,$id,$addr,$width);
641
                                                if(defined $base){#save it
642
                                                        #print "($base,$end)\n";
643
                                                        $soc->soc_add_plug_base_addr($instance_id,$plug,$plug_num,$base,$end);
644
                                                }
645
 
646
 
647
                                                #$id
648
                                }
649
                                # "$name\:$connect\[$i]";
650
 
651
 
652
 
653 25 alirezamon
                                set_gui_status($soc,"refresh_soc",0);
654 16 alirezamon
                        },\@ll);
655
 
656
 
657
        }#for $plug_num
658
 
659
        }#foreach plug
660
 
661
 
662
 
663
 
664
 
665
 
666
 
667
 
668
        #$box->pack_start($table, FALSE, FALSE, 0);
669
        my $separator = Gtk2::HSeparator->new;
670
        #$box->pack_start($separator, FALSE, FALSE, 3);
671
        if($row<3) {$row=3;}
672 34 alirezamon
        $table->attach ($separator,0,5,$row+$offset,$row+$offset+1,'fill','fill',2,2);   $row++;
673 16 alirezamon
        return ($offset+$row);
674
}
675
 
676
 
677
sub find_connection{
678
        my ($soc,$id,$socket,$num)=@_;
679
        my ($ref1,$ref2)= $soc->soc_get_modules_plug_connected_to_socket($id,$socket,$num);
680
        my %connected_plugs=%$ref1;
681
        my %connected_plug_nums=%$ref2;
682
        my $c;
683
        foreach my $p (sort keys %connected_plugs) {
684
                                $c="$p:$connected_plugs{$p}\[$connected_plug_nums{$p}]" ;
685
                                #print "($instance_id,$plug,$plug_num);($p:$connected_plugs{$p}\[$connected_plug_nums{$p})\n";
686
        }
687
        return $c;
688
 
689
}
690
 
691
 
692
 
693
###############
694
#       generate_dev_table
695
############
696
sub generate_dev_table{
697 25 alirezamon
        my($soc,$ip,$infc,$info)=@_;
698 16 alirezamon
        #my $box= def_hbox (TRUE,0);
699
 
700
        my $table=def_table(3,25,FALSE);
701
        my $row=0;
702
        my @instance_list=$soc->soc_get_instance_order();
703
        if (scalar @instance_list ==0 ){
704
                @instance_list=$soc->soc_get_all_instances();
705
        }
706
        my $i=0;
707
 
708
        foreach my $instanc(@instance_list){
709 25 alirezamon
                $row=gen_instance($soc,$ip,$infc,$instanc,$info,$table,$row);
710 16 alirezamon
 
711
        }
712
        if($row<20){for ($i=$row; $i<20; $i++){
713
 
714 34 alirezamon
                #my $temp=gen_label_in_center(" ");
715
                #$table->attach_defaults ($temp, 0, 1 , $i, $i+1);
716 16 alirezamon
        }}
717
 
718
 
719
        #$box->pack_start( $scrolled_win, TRUE, TRUE, 3);
720
        return $table;
721
}
722
 
723
 
724
####################
725
#  show_active_dev
726
#
727
################ 
728
 
729
sub show_active_dev{
730 25 alirezamon
        my($soc,$ip,$infc,$refresh_ref,$info)=@_;
731 16 alirezamon
        my $box= def_table (1, 1, FALSE);
732 25 alirezamon
        my $dev_table = generate_dev_table($soc,$ip,$infc,$info);
733 16 alirezamon
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
734
        $scrolled_win->set_policy( "automatic", "automatic" );
735
        $scrolled_win->add_with_viewport($dev_table);
736
 
737
 
738
 
739
        $$refresh_ref-> signal_connect("clicked" => sub{
740 22 alirezamon
 
741 16 alirezamon
                $dev_table->destroy;
742 22 alirezamon
                select(undef, undef, undef, 0.1); #wait 10 ms
743 25 alirezamon
                $dev_table = generate_dev_table($soc,$ip,$infc,$info);
744 16 alirezamon
                #$box->attach_defaults ($dev_table, 0, 1, 0, 1);#( $dev_table, FALSE, FALSE, 3);
745
                $scrolled_win->add_with_viewport($dev_table);
746
                $dev_table->show;
747
                $scrolled_win->show_all;
748
 
749
 
750
 
751
        });
752
        #$box->attach_defaults ($dev_table, 0, 1, 0, 1);#$box->pack_start( $dev_table, FALSE, FALSE, 3);
753
        #$box->show_all;
754
        return $scrolled_win;
755
 
756
 
757
 
758
}
759
 
760
 
761
 
762
 
763
 
764
sub row_activated_cb{
765
         my ($tree_view, $path, $column) = @_;
766
         my $model = $tree_view->get_model;
767
         my $iter = $model->get_iter ($path);
768
 
769
        #my ($selection, $ref) = @_;
770
        #my ($model,$textview)=@{$ref};
771
        #my $iter = $selection->get_selected;
772
        #return unless defined $iter;
773
        my ($category) = $model->get ($iter, DISPLAY_COLUMN);
774
        my ($module) = $model->get ($iter, CATRGORY_COLUMN);
775
 
776
 
777
 
778
        #if($module){print "$module   is selected via row activaton!\n"}
779
}
780
 
781
 
782
 
783
 
784
##############
785
#       create tree
786
##############
787
sub create_tree {
788 25 alirezamon
   my ($info,$ip,$soc)=@_;
789 16 alirezamon
   my $model = Gtk2::TreeStore->new ('Glib::String', 'Glib::String', 'Glib::Scalar', 'Glib::Boolean');
790
   my $tree_view = Gtk2::TreeView->new;
791
   $tree_view->set_model ($model);
792
   my $selection = $tree_view->get_selection;
793
 
794
   $selection->set_mode ('browse');
795 25 alirezamon
   #$tree_view->set_size_request (200, -1);
796 16 alirezamon
 
797
   #
798
   # this code only supports 1 level of children. If we
799
   # want more we probably have to use a recursing function.
800
   #
801
 
802
 
803
   my @categories= $ip->ip_get_categories();
804
 
805
 
806
 
807
 
808
   foreach my $p (@categories)
809
   {
810
        my @modules= $ip->get_modules($p);
811
        #my @dev_entry=  @{$tree_entry{$p}};    
812
        my $iter = $model->append (undef);
813
        $model->set ($iter,
814
                   DISPLAY_COLUMN,    $p,
815
                   CATRGORY_COLUMN, $p || '',
816
                   MODULE_COLUMN,     0     || '',
817
                   ITALIC_COLUMN,   FALSE);
818
 
819
        next unless  @modules;
820
 
821
        foreach my $v ( @modules){
822
                 my $child_iter = $model->append ($iter);
823
                 my $entry= '';
824
 
825
                $model->set ($child_iter,
826
                        DISPLAY_COLUMN,    $v,
827
                        CATRGORY_COLUMN, $p|| '',
828
                        MODULE_COLUMN,     $v     || '',
829
                        ITALIC_COLUMN,   FALSE);
830
        }
831
 
832
 
833
 
834
   }
835
 
836
   my $cell = Gtk2::CellRendererText->new;
837
   $cell->set ('style' => 'italic');
838
   my $column = Gtk2::TreeViewColumn->new_with_attributes
839 25 alirezamon
                                        ("IP list",
840 16 alirezamon
                                        $cell,
841
                                        'text' => DISPLAY_COLUMN,
842
                                        'style_set' => ITALIC_COLUMN);
843
 
844
  $tree_view->append_column ($column);
845
  my @ll=($model,\$info);
846
#row selected
847
  $selection->signal_connect (changed =>sub {
848
        my ($selection, $ref) = @_;
849
        my ($model,$info)=@{$ref};
850
        my $iter = $selection->get_selected;
851
        return unless defined $iter;
852
 
853
        my ($category) = $model->get ($iter, CATRGORY_COLUMN);
854
        my ($module) = $model->get ($iter,MODULE_COLUMN );
855 24 alirezamon
        my $describ=$ip->ip_get($category,$module,"description");
856 16 alirezamon
        if($describ){
857
                #print "$entry describtion is: $describ \n";
858
                show_info($info,$describ);
859
 
860
        }
861
 
862
 
863
}, \@ll);
864
 
865
#  row_activated 
866
  $tree_view->signal_connect (row_activated => sub{
867
 
868
         my ($tree_view, $path, $column) = @_;
869
         my $model = $tree_view->get_model;
870
         my $iter = $model->get_iter ($path);
871
        my ($category) = $model->get ($iter, CATRGORY_COLUMN);
872
        my ($module) = $model->get ($iter,MODULE_COLUMN );
873
 
874
 
875
 
876
        if($module){
877
                #print "$module  is selected via row activaton!\n";
878 25 alirezamon
                add_module_to_soc($soc,$ip,$category,$module,\$info);
879
                set_gui_status($soc,"refresh_soc",0);
880 16 alirezamon
        }
881
 
882
 
883
 
884
 
885
 
886
 
887
 
888
 
889
}, \@ll);
890
 
891
  #$tree_view->expand_all;
892
 
893
  my $scrolled_window = Gtk2::ScrolledWindow->new;
894
  $scrolled_window->set_policy ('automatic', 'automatic');
895
  $scrolled_window->set_shadow_type ('in');
896
  $scrolled_window->add($tree_view);
897
 
898 25 alirezamon
  my $hbox = Gtk2::HBox->new (FALSE, 0);
899 16 alirezamon
  $hbox->pack_start ( $scrolled_window, TRUE, TRUE, 0);
900
 
901
 
902
 
903
  return $hbox;
904
}
905
 
906
 
907
 
908 17 alirezamon
sub get_all_files_list {
909
        my ($soc,$list_name)=@_;
910 16 alirezamon
        my @instances=$soc->soc_get_all_instances();
911
        my $ip = ip->lib_new ();
912
        my @files;
913
        my $dir = Cwd::getcwd();
914
        my $warnings;
915
        #make target dir
916
        my $project_dir   = abs_path("$dir/../..");
917
 
918
        foreach my $id (@instances){
919
                my $module              =$soc->soc_get_module($id);
920
                my $module_name =$soc->soc_get_module_name($id);
921
                my $category    =$soc->soc_get_category($id);
922
                my $inst                =$soc->soc_get_instance_name($id);
923
 
924 24 alirezamon
                my @new=$ip->ip_get_list( $category,$module,$list_name);
925
                #print "@new\n";
926 16 alirezamon
                foreach my $f(@new){
927
                        my $n="$project_dir$f";
928 24 alirezamon
                         if (!(-f "$n") && !(-f "$f" ) && !(-d "$n") && !(-d "$f" )     ){
929 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 ";
930 16 alirezamon
 
931
                         }
932
 
933
 
934
                }
935
 
936
 
937
 
938
 
939
                @files=(@files,@new);
940
        }
941
        return \@files,$warnings;
942
}
943
 
944 42 alirezamon
 
945
sub add_to_project_file_list{
946
                my ($files_ref,$files_path,$list_path )=@_;
947
                        my @new_file_ref;
948
                        foreach my $f(@{$files_ref}){
949
                                my ($name,$path,$suffix) = fileparse("$f",qr"\..[^.]*$");
950
                                push(@new_file_ref,"$files_path/$name$suffix");
951
                        }
952
                        my $old_file_ref= eval { do "$list_path/file_list" };
953
                        if (defined $old_file_ref){
954
                                foreach my $f(@{$old_file_ref}){
955
                                        unless ( grep( /^$f$/, @new_file_ref ) ){
956
                                                push(@new_file_ref,$f);
957
                                        }
958
 
959
                                }
960
                        }
961
                        open(FILE,  ">$list_path/file_list") || die "Can not open: $!";
962
                        print FILE Data::Dumper->Dump([\@new_file_ref],['files']);
963
                        close(FILE) || die "Error closing file: $!";
964
}
965
 
966
 
967
 
968 16 alirezamon
################
969
#       generate_soc
970
#################
971
 
972
sub generate_soc{
973 28 alirezamon
        my ($soc,$info,$target_dir,$hw_path,$sw_path,$gen_top,$gen_hw_lib)=@_;
974
                my $name=$soc->object_get_attribute('soc_name');
975
 
976
 
977 34 alirezamon
                my ($file_v,$top_v,$readme,$prog)=soc_generate_verilog($soc,$sw_path);
978 16 alirezamon
 
979 28 alirezamon
                # Write object file
980
                open(FILE,  ">lib/soc/$name.SOC") || die "Can not open: $!";
981
                print FILE perl_file_header("$name.SOC");
982
                print FILE Data::Dumper->Dump([\%$soc],['soc']);
983
                close(FILE) || die "Error closing file: $!";
984 16 alirezamon
 
985 28 alirezamon
                # Write verilog file
986 34 alirezamon
                my $h=autogen_warning().get_license_header("${name}.v")."\n`timescale 1ns / 1ps\n";
987 28 alirezamon
                open(FILE,  ">lib/verilog/$name.v") || die "Can not open: $!";
988 34 alirezamon
                print FILE $h.$file_v;
989 28 alirezamon
                close(FILE) || die "Error closing file: $!";
990 16 alirezamon
 
991 28 alirezamon
                # Write Top module file
992
                if($gen_top){
993 34 alirezamon
                        my $l=autogen_warning().get_license_header("${name}_top.v")."\n`timescale 1ns / 1ps\n";
994 25 alirezamon
                        open(FILE,  ">lib/verilog/${name}_top.v") || die "Can not open: $!";
995
                        print FILE "$l\n$top_v";
996
                        close(FILE) || die "Error closing file: $!";
997 28 alirezamon
                }
998
 
999
                # Write readme file
1000
                open(FILE,  ">lib/verilog/README") || die "Can not open: $!";
1001
                print FILE $readme;
1002
                close(FILE) || die "Error closing file: $!";
1003 25 alirezamon
 
1004 28 alirezamon
 
1005
                # Write memory prog file
1006
                open(FILE,  ">lib/verilog/write_memory.sh") || die "Can not open: $!";
1007
                print FILE $prog;
1008
                close(FILE) || die "Error closing file: $!";
1009 38 alirezamon
 
1010
                #generate prog_mem
1011 42 alirezamon
                open(FILE,  ">lib/verilog/program.sh") || die "Can not open: $!";
1012 38 alirezamon
                print FILE soc_mem_prog();
1013
                close(FILE) || die "Error closing file: $!";
1014
 
1015
 
1016 28 alirezamon
 
1017
                my $dir = Cwd::getcwd();
1018
                my $project_dir   = abs_path("$dir/../../");
1019
                if($gen_hw_lib){
1020
 
1021
                        #make target dir
1022
                        my $hw_lib="$hw_path/lib";
1023
                        mkpath("$hw_lib/",1,01777);
1024
                        mkpath("$sw_path/",1,01777);
1025 42 alirezamon
 
1026
                        #remove old rtl files that were copied by ProNoC
1027
                        my $old_file_ref= eval { do "$hw_path/file_list" };
1028
                        if (defined $old_file_ref){
1029
                                remove_file_and_folders($old_file_ref,$target_dir);
1030
                        }
1031 28 alirezamon
 
1032 42 alirezamon
                        #copy hdl codes in src_verilog                  
1033
                        my ($file_ref,$warnings)= get_all_files_list($soc,"hdl_files");
1034 28 alirezamon
                        copy_file_and_folders($file_ref,$project_dir,$hw_lib);
1035 42 alirezamon
                        show_info(\$info,$warnings)                     if(defined $warnings);
1036
                        add_to_project_file_list($file_ref,$hw_lib,$hw_path);
1037
 
1038 16 alirezamon
 
1039
 
1040 28 alirezamon
                        #copy jtag control files 
1041
                        my @jtags=(("/mpsoc/src_peripheral/jtag/jtag_wb"),("jtag"));
1042 42 alirezamon
                        copy_file_and_folders(\@jtags,$project_dir,$hw_lib);
1043
                        add_to_project_file_list(\@jtags,$hw_lib,$hw_path);
1044
 
1045 28 alirezamon
                        move ("$dir/lib/verilog/$name.v","$hw_path/");
1046
                        move ("$dir/lib/verilog/${name}_top.v","$hw_path/");
1047
                        move ("$dir/lib/verilog/README" ,"$sw_path/");
1048
                        move ("$dir/lib/verilog/write_memory.sh" ,"$sw_path/");
1049 38 alirezamon
                        move ("$dir/lib/verilog/program.sh" ,"$sw_path/");
1050 28 alirezamon
                }
1051
 
1052 42 alirezamon
                #remove old software files that were copied by ProNoC
1053
                my $old_file_ref= eval { do "$sw_path/file_list" };
1054
                if (defined $old_file_ref){
1055
                        remove_file_and_folders($old_file_ref,$project_dir);
1056
                }
1057
 
1058 28 alirezamon
                # Copy Software files
1059
                my ($file_ref,$warnings)= get_all_files_list($soc,"sw_files");
1060
                copy_file_and_folders($file_ref,$project_dir,$sw_path);
1061 42 alirezamon
 
1062
 
1063
                my @new_file_ref;
1064
                foreach my $f(@{$file_ref}){
1065
                        my ($name,$path,$suffix) = fileparse("$f",qr"\..[^.]*$");
1066
                        push(@new_file_ref,"$sw_path/$name$suffix");
1067
                }
1068
 
1069
                push(@new_file_ref,"$sw_path/$name.h");
1070
        open(FILE,  ">$sw_path/file_list") || die "Can not open: $!";
1071
                print FILE Data::Dumper->Dump([\@new_file_ref],['files']);
1072
                close(FILE) || die "Error closing file: $!";
1073
 
1074
 
1075 28 alirezamon
                # Write system.h and Software gen files
1076 38 alirezamon
                generate_header_file($soc,$project_dir,$sw_path,$hw_path,$dir);
1077 24 alirezamon
 
1078 16 alirezamon
 
1079 25 alirezamon
 
1080 24 alirezamon
 
1081
 
1082 23 alirezamon
                # Write main.c file if not exist
1083 28 alirezamon
                my $n="$sw_path/main.c";
1084 23 alirezamon
                if (!(-f "$n")) {
1085
                        # Write main.c
1086
                        open(FILE,  ">$n") || die "Can not open: $!";
1087
                        print FILE main_c_template($name);
1088
                        close(FILE) || die "Error closing file: $!";
1089 16 alirezamon
 
1090 23 alirezamon
                }
1091 16 alirezamon
 
1092
 
1093
 
1094 17 alirezamon
 
1095 16 alirezamon
 
1096 28 alirezamon
 
1097 16 alirezamon
}
1098
 
1099
 
1100 23 alirezamon
sub main_c_template{
1101
        my $hdr=shift;
1102
        my $text="
1103
#include \"$hdr.h\"
1104 16 alirezamon
 
1105
 
1106 23 alirezamon
// a simple delay function
1107
void delay ( unsigned int num ){
1108
 
1109
        while (num>0){
1110
                num--;
1111 25 alirezamon
                nop(); // asm volatile (\"nop\");
1112 23 alirezamon
        }
1113
        return;
1114 16 alirezamon
 
1115 23 alirezamon
}
1116 16 alirezamon
 
1117 23 alirezamon
int main(){
1118
        while(1){
1119
 
1120
 
1121 16 alirezamon
 
1122 23 alirezamon
        }
1123
 
1124
return 0;
1125
}
1126
 
1127
";
1128
 
1129
return $text;
1130
 
1131
 
1132
}
1133
 
1134
 
1135
 
1136
 
1137 16 alirezamon
sub get_wb_address      {
1138
        my ($soc,$instance_id,$addr,$width)=@_;
1139
        my ($base,$end);
1140
        my @list= split (" ",$addr);
1141
        $base= hex ($list[0]);
1142
        $end= $base+(1 << $width)-1;
1143
        #print "$addr:$base \& $end\n";
1144
        my %taken_bases= $soc->soc_list_base_addreses($instance_id);
1145
 
1146
        my $conflict=0;
1147
        do{
1148
                $conflict=0;
1149
                foreach my $taken_end (sort {$a<=>$b} keys %taken_bases){
1150
                        my $taken_base=$taken_bases{$taken_end};
1151
                        #print "taken:($taken_base,$taken_end)\n";
1152
                        if (($base <= $taken_base && $end >= $taken_base ) || ($base <= $taken_end && $end >= $taken_end )){
1153
                        #if (!(($base < $taken_base && $end < $taken_end ) || ($base > $taken_base && $end > $taken_end ))){
1154
                                 $conflict=1;
1155
                                 $base=$taken_end+1;
1156
                                 $end= $base+(1 << $width)-1;
1157
                                 last;
1158
 
1159
                        }
1160
                }
1161
 
1162
        }while($conflict==1 && $end<(1 << 32));
1163
        if($conflict==0){
1164
                #print"new ($base,$end);\n";
1165
                return ($base,$end);
1166
 
1167
        }
1168
 
1169
        return ;
1170
 
1171
}
1172
 
1173
 
1174
 
1175 42 alirezamon
#############
1176
#  set_unset_infc
1177
#############
1178 16 alirezamon
 
1179 42 alirezamon
sub set_unset_infc{
1180
        my $soc =shift;
1181
        my $window = def_popwin_size(40,60,"Unconnected Socket Interfaces",'percent');
1182
        my $table = def_table(10,4, FALSE);
1183
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1184
        $scrolled_win->set_policy( "automatic", "automatic" );
1185
        $scrolled_win->add_with_viewport($table);
1186
        my $row=0;
1187
        my $column=0;
1188
 
1189
        my $ip = ip->lib_new ();
1190
        my @instances=$soc->soc_get_all_instances();
1191
        foreach my $id (@instances){
1192
                my $module      =$soc->soc_get_module($id);
1193
                my $module_name =$soc->soc_get_module_name($id);
1194
                my $category    =$soc->soc_get_category($id);
1195
                my $inst        = $soc->soc_get_instance_name($id);
1196
                my @ports=$ip->ip_list_ports($category,$module);
1197
                foreach my $port (@ports){
1198
                        my ($type,$range,$intfc_name,$i_port)=$ip->ip_get_port($category,$module,$port);
1199
                        my($i_type,$i_name,$i_num) =split("[:\[ \\]]", $intfc_name);
1200
                        if($i_type eq 'socket' && $i_name ne'wb_addr_map' ){
1201
                                my ($ref1,$ref2)= $soc->soc_get_modules_plug_connected_to_socket($id,$i_name,$i_num);
1202
                                my %connected_plugs=%$ref1;
1203
                                my %connected_plug_nums=%$ref2;
1204
                                if(!%connected_plugs ){
1205
                                        my  ($s_type,$s_value,$s_connection_num)=$soc->soc_get_socket_of_instance($id,$i_name);
1206
                                        my $v=$soc->soc_get_module_param_value($id,$s_value);
1207
                                        if ( length( $v || '' ) || $category eq 'NoC' ){ }
1208
                                        else {
1209
                                                ($row,$column)=add_param_widget ($soc,"$inst->$port","$inst-$port", 'IO','Combo-box',"IO,NC",undef, $table,$row,$column,1,"Unset-intfc",undef,undef,"vertical");
1210
                                                if($column == 0){
1211
                                                        $column = 4;
1212
 
1213
                                                        $row= $row-1;
1214
                                                }else{
1215
                                                        $column =  0;
1216
 
1217
 
1218
 
1219
                                                }
1220
 
1221
                                        }
1222
 
1223
                                }
1224
                        }
1225
                }
1226
        }
1227
 
1228
        my $box1=def_hbox(FALSE, 1);
1229
        $box1->pack_start( Gtk2::VSeparator->new, FALSE, FALSE, 3);
1230
        $table->attach($box1,3,4,0,$row+1,'expand','fill',2,2);
1231
        my $ok = def_image_button('icons/select.png','OK');
1232
        $ok->signal_connect     ( 'clicked'=> sub {
1233
                $window->destroy;
1234
        });
1235
 
1236
        my $mtable = def_table(10, 1, FALSE);
1237
        $mtable->attach_defaults($scrolled_win,0,1,0,9);
1238
        $mtable->attach($ok,0,1,9,10,'expand','fill',2,2);
1239
        $window->add ($mtable);
1240
        $window->show_all;
1241
 
1242
 
1243
}
1244 16 alirezamon
 
1245
 
1246
 
1247
 
1248
 
1249
##########
1250
#       wb address setting
1251
#########
1252
 
1253
sub wb_address_setting {
1254
        my $soc=shift;
1255
 
1256
 
1257 34 alirezamon
        my $window = def_popwin_size(80,50,"Wishbone slave port address setting",'percent');
1258 25 alirezamon
        my $table = def_table(10, 6, FALSE);
1259 16 alirezamon
 
1260
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1261
        $scrolled_win->set_policy( "automatic", "automatic" );
1262
        $scrolled_win->add_with_viewport($table);
1263
        my $row=0;
1264
 
1265
        #title
1266 25 alirezamon
        $table->attach(gen_label_in_left  ("Instance name"),0,1,$row,$row+1,'expand','shrink',2,2);
1267
        $table->attach(gen_label_in_left  ("Interface name"),1,2,$row,$row+1,'expand','shrink',2,2);
1268
        $table->attach(gen_label_in_left  ("Bus name"),2,3,$row,$row+1,'expand','shrink',2,2);
1269
        $table->attach(gen_label_in_center("Base address"),3,4,$row,$row+1,'expand','shrink',2,2);
1270
        $table->attach(gen_label_in_center("End address"),4,5,$row,$row+1,'expand','shrink',2,2);
1271
        $table->attach(gen_label_in_center("Size (Bytes)"),5,6,$row,$row+1,'expand','shrink',2,2);
1272 16 alirezamon
 
1273
        my (@newbase,@newend,@connects);
1274
 
1275
        $row++;
1276
        my @all_instances=$soc->soc_get_all_instances();
1277
        foreach my $instance_id (@all_instances){
1278
                my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1279
                foreach my $plug (@plugs){
1280
                        my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1281
                        foreach my $num (@nums){
1282
                                my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1283
                                if((defined $connect_socket) && ($connect_socket eq 'wb_slave')){
1284
                                        my $number=$row-1;
1285
                                        $newbase[$number]=$base;
1286
                                        $newend[$number]=$end;
1287
                                        $connects[$number]=$connect_id;
1288
                                        $row++;
1289
                                }#if
1290
                        }#foreach my $num
1291
                }#foreach my $plug
1292
        }#foreach my $instance_id
1293
 
1294
        my @status_all;
1295
        $row=1;
1296
        foreach my $instance_id (@all_instances){
1297
                my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1298
                foreach my $plug (@plugs){
1299
                        my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1300
                        foreach my $num (@nums){
1301
                                my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1302
                                if((defined $connect_socket) && ($connect_socket eq 'wb_slave')){
1303
                                        my $instance_name=$soc->soc_get_instance_name($instance_id);
1304
                                        my $plug_name=(defined $name ) ? gen_label_in_left($name):
1305
                                                                                                         gen_label_in_left("$plug\[$num\]");
1306
 
1307
                                        my $connected_instance_name= $soc->soc_get_instance_name($connect_id);
1308
                                        my $number=$row-1;
1309
                                        my $label1= gen_label_in_left("$number: $instance_name");
1310
                                        my $label2= gen_label_in_left($connected_instance_name);
1311
                                        my $entry1= Gtk2::Entry->new_with_max_length (10);
1312
                                    $entry1->set_text(sprintf("0x%08x", $base));
1313
 
1314
                                        my $entry2= Gtk2::Entry->new_with_max_length (10);
1315
                                        $entry2->set_text(sprintf("0x%08x", $end));
1316
 
1317
                                        my ($box,$valid) =addr_box_gen(sprintf("0x%08x", $base), sprintf("0x%08x", $end),\@newbase,\@newend,\@connects,$number);
1318
                                        $status_all[$number]=$valid;
1319
 
1320
 
1321 25 alirezamon
                                        $table->attach($label1,0,1,$row,$row+1,'expand','shrink',2,2);
1322
                                        $table->attach($plug_name,1,2,$row,$row+1,'expand','shrink',2,2);
1323
                                        $table->attach($label2,2,3,$row,$row+1,'expand','shrink',2,2);
1324
                                        $table->attach($entry1,3,4,$row,$row+1,'expand','shrink',2,2);
1325
                                        $table->attach($entry2,4,5,$row,$row+1,'expand','shrink',2,2);
1326 16 alirezamon
 
1327
 
1328 25 alirezamon
                                        $table->attach($box,5,7,$row,$row+1,'expand','shrink',2,2);
1329 16 alirezamon
 
1330
 
1331
                                        $entry1->signal_connect('changed'=>sub{
1332
                                                my $base_in=$entry1->get_text();
1333
                                                if (length($base_in)<2){ $entry1->set_text('0x')};
1334
                                                my $end_in=$entry2->get_text();
1335
                                                my $valid;
1336
                                                $box->destroy;
1337
                                                ($box,$valid)=addr_box_gen($base_in, $end_in,\@newbase,\@newend,\@connects,$number);
1338
                                                $status_all[$number]=$valid;
1339 25 alirezamon
                                                $table->attach($box,5,7,$number+1,$number+2,'expand','shrink',2,2);
1340 16 alirezamon
                                                $table->show_all;
1341
 
1342
 
1343
                                        } );
1344
                                        $entry2->signal_connect('changed'=>sub{
1345
                                                my $base_in=$entry1->get_text();
1346
                                                my $end_in=$entry2->get_text();
1347
                                                if (length($end_in)<2){ $entry2->set_text('0x')};
1348
                                                my $valid;
1349
                                                $box->destroy;
1350
                                                ($box,$valid)=addr_box_gen($base_in, $end_in,\@newbase,\@newend,\@connects,$number);
1351
                                                $status_all[$number]=$valid;
1352 25 alirezamon
                                                $table->attach($box,5,7,$number+1,$number+2,'expand','shrink',2,2);
1353 16 alirezamon
                                                $table->show_all;
1354
                                        } );
1355
 
1356
 
1357
 
1358
                                        $row++;
1359
 
1360
 
1361
                                }#if
1362
                        }#foreach my $num
1363
                }#foreach my $plug
1364
        }#foreach my $instance_id
1365
 
1366
 
1367
        my $ok = def_image_button('icons/select.png','OK');
1368
 
1369 25 alirezamon
 
1370
 
1371 16 alirezamon
        my $refresh = def_image_button('icons/revert.png','Revert');
1372
        my $refbox=def_hbox(TRUE,0);
1373
        $refbox->pack_start($refresh, FALSE, FALSE,0);
1374
 
1375
        $refresh->signal_connect( 'clicked'=> sub {
1376
                $window->destroy;
1377
                wb_address_setting($soc);
1378
 
1379
 
1380
                });
1381
        $ok->signal_connect     ( 'clicked'=> sub {
1382
                my $st=1;
1383
                foreach my $valid (@status_all){
1384
                        if($valid==0){
1385
                                $st=0;
1386
 
1387
                        }
1388
                }
1389
 
1390
                if($st==1){
1391
                        $row=1;
1392
                        foreach my $instance_id (@all_instances){
1393
                        my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
1394
                        foreach my $plug (@plugs){
1395
                                my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
1396
                                foreach my $num (@nums){
1397
                                        my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
1398
                                        if(defined $connect_socket && ($connect_socket eq 'wb_slave')){
1399
                                                my $number=$row-1;
1400
                                                $soc->soc_add_plug_base_addr($instance_id,$plug,$num,$newbase[$number],$newend[$number]);
1401
                                                $row++;
1402
                                        }#if
1403
                                }#foreach my $num
1404
                        }#foreach my $plug
1405
                }#foreach my $instance_id
1406
 
1407
 
1408
 
1409
 
1410
 
1411
                        $window->destroy;
1412
                }else{
1413 42 alirezamon
                        message_dialog("Invalid address!");
1414 16 alirezamon
 
1415
                }
1416
 
1417
 
1418
                });
1419
 
1420
 
1421 42 alirezamon
        my $mtable = def_table(10, 2, FALSE);
1422
        $mtable->attach_defaults($scrolled_win,0,2,0,9);
1423
        $mtable->attach ($refbox,0,1,9,10,'expand','shrink',2,2);
1424
        $mtable->attach($ok,1,2,9,10,'expand','fill',2,2);
1425
        $window->add ($mtable);
1426 16 alirezamon
        $window->show_all;
1427 42 alirezamon
 
1428 16 alirezamon
 
1429
 
1430
 
1431
}
1432
##############
1433
#       addr_box_gen
1434
##############
1435
 
1436
sub addr_box_gen{
1437
        my ($base_in, $end_in,$newbase_ref,$newend_ref,$connects_ref,$number)=@_;
1438
        my $box= def_hbox(TRUE,0);
1439
        my $label;
1440
        my $valid=1;
1441
        my $info;
1442
        if(is_hex($base_in) && is_hex($end_in)){
1443
                my $size=(hex ($end_in) >= hex ($base_in))? hex ($end_in) - hex ($base_in) +1 : 0;
1444 24 alirezamon
                my $size_text=  metric_conversion($size);
1445 16 alirezamon
                $label= gen_label_in_center($size_text);
1446
                $$newbase_ref[$number]=hex($base_in);
1447
                $$newend_ref[$number]=hex($end_in);
1448
                $info=check_entered_address($newbase_ref,$newend_ref,$connects_ref,$number);
1449
                if(defined      $info) {$valid=0;}
1450
 
1451
        }
1452
        else {
1453
                $label= gen_label_in_center("Invalid hex value!");
1454
                $info="Invalid hex value!";
1455
                $valid=0;
1456
        }
1457
 
1458
 
1459
        my $status=(defined $info)? gen_button_message ($info,'icons/warnning.png'):
1460
                                                                gen_button_message (undef,'icons/select.png');
1461
 
1462
        $box->pack_start($label,FALSE,FALSE,3);
1463
        $box->pack_start($status,FALSE,FALSE,3);
1464
        return ($box,$valid);
1465
 
1466
}
1467
 
1468
 
1469
 
1470
 
1471
###########
1472
#       get_parameter_final_value
1473
############
1474
sub get_parameter_final_value{
1475
        my ($soc,$id,$param)=@_;
1476
        #get ordered param
1477
        my @ordered_param=$soc->soc_get_instance_param_order($id);
1478
        my %sim_params;
1479
        foreach my $p (@ordered_param){
1480
                my $value=$soc->soc_get_module_param_value($id,$p);
1481
                foreach my $q (sort keys %sim_params){
1482
                        $value=replace_value($value,$q,$sim_params{$q}) if (defined $value);
1483
                }
1484
                $sim_params{$p}=$value;
1485
                #print "$sim_params{$p}=$value;\n";
1486
        }
1487
        return $sim_params{$param};
1488
}
1489
 
1490
 
1491
 
1492
 
1493
sub replace_value{
1494
        my ($string,$param,$value)=@_;
1495
 
1496
        my $new_string=$string;
1497
        #print "$new_range\n";
1498
        my $new_param= $value;
1499
        ($new_string=$new_string)=~ s/\b$param\b/$new_param/g;
1500
        return eval $new_string;
1501
 
1502
 
1503
}
1504
 
1505
 
1506
 
1507
 
1508
 
1509
 
1510
 
1511
 
1512
 
1513
 
1514
 
1515
 
1516
 
1517
sub check_entered_address{
1518
my      ($base_ref,$end_ref,$connect_ref,$number)=@_;
1519
my @bases=@{$base_ref};
1520
my @ends=@{$end_ref};
1521
my @connects=@{$connect_ref};
1522
 
1523
my $current_base=$bases[$number];
1524
my $current_end=$ends[$number];
1525
 
1526
if($current_base>  $current_end) {
1527
 
1528
return "Error: the given base address is bigger than the End address!";
1529
        }
1530
 
1531
my $size= scalar @bases;
1532
my $conflicts;
1533
foreach (my $i=0; $i<$size; $i++){
1534
        if($i != $number){ #if not same row
1535
                if      ($connects[$i] eq $connects[$number]) {#same bus
1536
                                my $ok=(($bases[$i]< $bases[$number] && $bases[$i] < $ends[$number])||($bases[$i]> $bases[$number] && $bases[$i] > $ends[$number]));
1537
                            if($ok==0) {
1538
                                        $conflicts=(defined $conflicts )? "$conflicts,$i": $i;
1539
                                }
1540
                }
1541
 
1542
 
1543
        }
1544
 
1545
 
1546
}
1547
if (defined $conflicts){ return " The given address range has conflict with rows:$conflicts"; }
1548
return;
1549
 
1550
 
1551
}
1552
 
1553
#############
1554
#       load_soc
1555
#############
1556
 
1557
sub load_soc{
1558 34 alirezamon
        my ($soc,$info,$ip)=@_;
1559 16 alirezamon
        my $file;
1560
        my $dialog = Gtk2::FileChooserDialog->new(
1561
                'Select a File', undef,
1562
                'open',
1563
                'gtk-cancel' => 'cancel',
1564
                'gtk-ok'     => 'ok',
1565
                );
1566
 
1567
        my $filter = Gtk2::FileFilter->new();
1568
        $filter->set_name("SoC");
1569
        $filter->add_pattern("*.SOC");
1570
        $dialog->add_filter ($filter);
1571
        my $dir = Cwd::getcwd();
1572
        $dialog->set_current_folder ("$dir/lib/soc")    ;
1573
 
1574
 
1575
        if ( "ok" eq $dialog->run ) {
1576
                $file = $dialog->get_filename;
1577
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1578
                if($suffix eq '.SOC'){
1579
                        my $pp= eval { do $file };
1580 25 alirezamon
                        if ($@ || !defined $pp){
1581
                                show_info(\$info,"**Error reading  $file file: $@\n");
1582
                                 $dialog->destroy;
1583
                                return;
1584
                        }
1585 16 alirezamon
                        clone_obj($soc,$pp);
1586 34 alirezamon
                        check_instances_version($soc,$ip);
1587 25 alirezamon
                        set_gui_status($soc,"load_file",0);
1588 16 alirezamon
                }
1589
     }
1590
     $dialog->destroy;
1591
 
1592 34 alirezamon
 
1593 16 alirezamon
 
1594
 
1595
 
1596
}
1597
 
1598
 
1599 34 alirezamon
sub check_instances_version{
1600
        my ($soc,$ip)=@_;
1601 16 alirezamon
 
1602 34 alirezamon
 #check if the IP's version didnt increases 
1603
    my @all_instances=$soc->soc_get_all_instances();
1604
    foreach my $instance_id (@all_instances){
1605
        my ($old_v,$new_v)=  get_old_new_ip_version ($soc,$ip,$instance_id);
1606
        my $differences='';
1607
        $differences="$differences \t The $instance_id version (V.$old_v) missmatches with the one exsiting in the library (V.$new_v).\n " if($old_v != $new_v);
1608
 
1609
 
1610
        message_dialog("Warning: The generated system may not work correctly: \n $differences Please remove and then add the aforementioned instance(s) to update them with current version(s)") if(length($differences)>1);
1611 16 alirezamon
 
1612 34 alirezamon
    }
1613 16 alirezamon
 
1614
 
1615 34 alirezamon
}
1616 16 alirezamon
 
1617 34 alirezamon
sub get_old_new_ip_version{
1618
        my ($soc,$ip,$instance_id)=@_;
1619
        my $old_v=$soc->object_get_attribute($instance_id,"version",undef);
1620
        $old_v=0 if(!defined $old_v);
1621
        my $module=$soc->soc_get_module($instance_id);
1622
        my $category=$soc->soc_get_category($instance_id);
1623
        my $new_v=$ip->ip_get($category,$module,"version");
1624
        $new_v=0 if(!defined $new_v);
1625
        return ($old_v,$new_v);
1626
}
1627 16 alirezamon
 
1628 38 alirezamon
sub check_for_ni{
1629
        my $self=shift;
1630
        my $ckeck=0;
1631
        my @instances=$self->soc_get_all_instances();
1632
        foreach my $id (@instances){
1633
                my $category = $self->soc_get_category($id);
1634
                if ($category eq 'NoC') {
1635
                $ckeck=1;
1636
                }
1637
        }
1638
        return $ckeck;
1639 16 alirezamon
 
1640 38 alirezamon
}
1641 16 alirezamon
 
1642
 
1643 34 alirezamon
sub get_ram_init{
1644
        my $soc=shift;
1645
        my $window = def_popwin_size(80,50,"Memory initial file setting setting",'percent');
1646
        my $table = def_table(10, 6, FALSE);
1647
 
1648
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1649
        $scrolled_win->set_policy( "automatic", "automatic" );
1650
        $scrolled_win->add_with_viewport($table);
1651
        my $row=0;
1652
        my $col=0;
1653
        my @instances=$soc->soc_get_all_instances();
1654
        foreach my $id (@instances){
1655
                my $category = $soc->soc_get_category($id);
1656
                if ($category eq 'RAM') {
1657
                        my $ram_name=  $soc->soc_get_instance_name($id);
1658
                        $table->attach (gen_label_in_left("$ram_name"),$col,$col+1, $row, $row+1,'fill','shrink',2,2);$col++;
1659
                        my $init_type=gen_combobox_object ($soc,'RAM_INIT','type',"Dont_Care,Fill_0,Fill_1,Search_in_sw,Fixed_file","Search_in_sw",undef);
1660
                        my $init_inf= "Define how the memory must be initialized :
1661
 Dont_Care: The memory wont be initialized
1662
 Fill_0: All memory bits will fill with value zero
1663
 Fill_1: All memory bits will fill with value one
1664
 Search_in_sw: Each instance of this processing core
1665
               use different initial file that is
1666
               located in its SW folder.
1667
 Fixed_file: All instance of this processing core
1668
             use the same initial file";
1669
 
1670
                        $row++;
1671
                }
1672
        }
1673
 
1674
 
1675
        $window->add($scrolled_win);
1676
        $window->show_all;
1677
}
1678 16 alirezamon
 
1679
 
1680 34 alirezamon
sub software_edit_soc {
1681
        my $soc=shift;
1682
        my $name=$soc->object_get_attribute('soc_name');
1683
        if (length($name)==0){
1684 38 alirezamon
                message_dialog("Please define the Tile name!");
1685 34 alirezamon
                return ;
1686
        }
1687
        my $target_dir  = "$ENV{'PRONOC_WORK'}/SOC/$name";
1688
        my $sw  = "$target_dir/sw";
1689
        my ($app,$table,$tview) = software_main($sw);
1690 16 alirezamon
 
1691 34 alirezamon
 
1692 16 alirezamon
 
1693
 
1694 34 alirezamon
        my $make = def_image_button('icons/gen.png','Compile');
1695 38 alirezamon
        my $regen= def_image_button('icons/refresh.png','Regenerate main.c');
1696
        my $prog= def_image_button('icons/write.png','Program the memory');
1697
 
1698 34 alirezamon
        $table->attach ($regen,0, 1, 1,2,'shrink','shrink',0,0);
1699 38 alirezamon
        $table->attach ($make,5, 6, 1,2,'shrink','shrink',0,0);
1700
        $table->attach ($prog,9, 10, 1,2,'shrink','shrink',0,0);
1701 34 alirezamon
        $regen -> signal_connect ("clicked" => sub{
1702
                my $dialog = Gtk2::MessageDialog->new (my $window,
1703
                                      'destroy-with-parent',
1704
                                      'question', # message type
1705
                                      'yes-no', # which set of buttons?
1706 38 alirezamon
                                      "Are you sure you want to regenaret the main.c file? Note that any changes you have made will be lost");
1707 34 alirezamon
                my $response = $dialog->run;
1708
                if ($response eq 'yes') {
1709
 
1710
                        save_file ("$sw/main.c",main_c_template($name));
1711
                        $app->load_source("$sw/main.c");
1712
                }
1713 38 alirezamon
                $dialog->destroy;
1714 16 alirezamon
 
1715 34 alirezamon
        });
1716 16 alirezamon
 
1717 34 alirezamon
        $make -> signal_connect("clicked" => sub{
1718
                $app->do_save();
1719
                run_make_file($sw,$tview);
1720 16 alirezamon
 
1721 34 alirezamon
        });
1722 16 alirezamon
 
1723 38 alirezamon
        #Programe the board 
1724
        $prog-> signal_connect("clicked" => sub{
1725
                my $error = 0;
1726
                my $bash_file="$target_dir/sw/program.sh";
1727 42 alirezamon
                my $jtag_intfc="$sw/jtag_intfc.sh";
1728 38 alirezamon
 
1729
                add_info(\$tview,"Programe the board using quartus_pgm and $bash_file file\n");
1730
                #check if the programming file exists
1731
                unless (-f $bash_file) {
1732
                        add_colored_info(\$tview,"\tThe $bash_file does not exists! \n", 'red');
1733
                        $error=1;
1734
                }
1735 42 alirezamon
                #check if the jtag_intfc.sh file exists
1736
                unless (-f $jtag_intfc) {
1737
                        add_colored_info(\$tview,"\tThe $jtag_intfc does not exists!. Press the compile button and select your FPGA board first to generate $jtag_intfc file\n", 'red');
1738
                        $error=1;
1739
                }
1740 38 alirezamon
 
1741
                return if($error);
1742
                my $command = "cd $target_dir/sw; sh program.sh";
1743
                add_info(\$tview,"$command\n");
1744
                my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($command);
1745
                if(length $stderr>1){
1746
                        add_colored_info(\$tview,"$stderr\n",'red');
1747
                        add_colored_info(\$tview,"Memory was not programed successfully!\n",'red');
1748
                }else {
1749
 
1750
                        if($exit){
1751
                                add_colored_info(\$tview,"$stdout\n",'red');
1752
                                add_colored_info(\$tview,"Memory was not programed successfully!\n",'red');
1753
                        }else{
1754
                                add_info(\$tview,"$stdout\n");
1755
                                add_colored_info(\$tview,"Memory is programed successfully!\n",'blue');
1756
 
1757
                        }
1758
 
1759
                }
1760
        });
1761
 
1762 34 alirezamon
}
1763 16 alirezamon
 
1764 34 alirezamon
 
1765 38 alirezamon
sub soc_mem_prog {
1766
         my $string='
1767
#!/bin/sh
1768 34 alirezamon
 
1769
 
1770 38 alirezamon
#JTAG_INTFC="$PRONOC_WORK/toolchain/bin/JTAG_INTFC"
1771
source ./jtag_intfc.sh
1772
 
1773
#reset and disable cpus, then release the reset but keep the cpus disabled
1774
 
1775
$JTAG_INTFC -n 127  -d  "I:1,D:2:3,D:2:2,I:0"
1776
 
1777
# jtag instruction
1778
#       0: bypass
1779
#       1: getting data
1780
# jtag data :
1781
#       bit 0 is reset
1782
#       bit 1 is disable
1783
# I:1  set jtag_enable  in active mode
1784
# D:2:3 load jtag_enable data register with 0x3 reset=1 disable=1
1785
# D:2:2 load jtag_enable data register with 0x2 reset=0 disable=1
1786
# I:0  set jtag_enable  in bypass mode
1787
 
1788
 
1789
 
1790
#programe the memory
1791
 
1792
        sh write_memory.sh
1793
 
1794
 
1795
#Enable the cpu
1796
$JTAG_INTFC -n 127  -d  "I:1,D:2:0,I:0"
1797
# I:1  set jtag_enable  in active mode
1798
# D:2:0 load jtag_enable data register with 0x0 reset=0 disable=0
1799
# I:0  set jtag_enable  in bypass mode
1800
';
1801
return $string;
1802
 
1803
}
1804
 
1805
 
1806
 
1807
 
1808 16 alirezamon
############
1809
#    main
1810
############
1811
sub socgen_main{
1812
 
1813
        my $infc = interface->interface_new();
1814
        my $ip = ip->lib_new ();
1815
        my $soc = soc->soc_new();
1816 25 alirezamon
        set_gui_status($soc,"ideal",0);
1817 38 alirezamon
 
1818 16 alirezamon
        #my $soc= eval { do 'lib/soc/soc.SOC' };
1819 28 alirezamon
        #message_dialog("$ENV{'PRONOC_WORK'}\n");
1820 16 alirezamon
 
1821
        # main window
1822
        #my $window = def_win_size(1000,800,"Top");
1823
        #  The main table containg the lib tree, selected modules and info section 
1824
        my $main_table = Gtk2::Table->new (20, 12, FALSE);
1825
 
1826
        # The box which holds the info, warning, error ...  mesages
1827
        my ($infobox,$info)= create_text();
1828
 
1829
 
1830
        my $refresh_dev_win = Gtk2::Button->new_from_stock('ref');
1831
 
1832
        # A tree view for holding a library
1833 25 alirezamon
        my $tree_box = create_tree ($info,$ip,$soc);
1834 16 alirezamon
 
1835
 
1836
 
1837
        $main_table->set_row_spacings (4);
1838
        $main_table->set_col_spacings (1);
1839
 
1840 25 alirezamon
        my  $device_win=show_active_dev($soc,$ip,$infc,\$refresh_dev_win,$info);
1841 16 alirezamon
 
1842
 
1843 34 alirezamon
        my $generate = def_image_button('icons/gen.png','Generate RTL');
1844 38 alirezamon
        my $compile  = def_image_button('icons/gate.png','Compile RTL');
1845 34 alirezamon
        my $software = def_image_button('icons/binary.png','Software');
1846
        my $diagram  = def_image_button('icons/diagram.png','Diagram');
1847 42 alirezamon
        my $unset    = def_image_button('icons/intfc.png','Unset Intfc.');
1848
 
1849 34 alirezamon
        my $ram      = def_image_button('icons/RAM.png','Memory');
1850 25 alirezamon
 
1851 16 alirezamon
 
1852
 
1853
 
1854
 
1855
 
1856 42 alirezamon
        my $wb = def_image_button('icons/setting.png','WB addr');
1857 16 alirezamon
 
1858 25 alirezamon
 
1859
 
1860 16 alirezamon
        my $open = def_image_button('icons/browse.png','Load Tile');
1861
 
1862
 
1863 25 alirezamon
        my $entry=gen_entry_object($soc,'soc_name',undef,undef,undef,undef);
1864
        my $entrybox=labele_widget_info(" Tile name:",$entry);
1865 16 alirezamon
 
1866
 
1867
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
1868 34 alirezamon
 
1869
 
1870
 
1871
 
1872
        #$main_table->attach_defaults ($tree_box , 0, 2, 0, 17);
1873
        #$main_table->attach_defaults ($device_win , 2, 12, 0, 17);
1874
        #$main_table->attach_defaults ($infobox  , 0, 12, 17,19);
1875
 
1876
 
1877
        my $h1=gen_hpaned($tree_box,.15,$device_win);
1878
        my $v2=gen_vpaned($h1,.55,$infobox);
1879
        $main_table->attach_defaults ($v2  , 0, 12, 0,19);
1880
 
1881
 
1882
 
1883
 
1884 16 alirezamon
 
1885 42 alirezamon
        $main_table->attach ($open,0, 1, 19,20,'expand','shrink',2,2);
1886
        $main_table->attach_defaults ($entrybox,1, 3, 19,20);
1887
        $main_table->attach ($unset, 3,4, 19,20,'expand','shrink',2,2);
1888
 
1889 34 alirezamon
        $main_table->attach ($wb, 4,6, 19,20,'expand','shrink',2,2);
1890
        $main_table->attach ($diagram, 6, 7, 19,20,'expand','shrink',2,2);
1891
        $main_table->attach ($generate, 7, 8, 19,20,'expand','shrink',2,2);
1892
        $main_table->attach ($software, 8, 9, 19,20,'expand','shrink',2,2);
1893
        #$main_table->attach ($ram, 9, 10, 19,20,'expand','shrink',2,2);
1894
        $main_table->attach ($compile, 10, 12, 19,20,'expand','shrink',2,2);
1895
 
1896 16 alirezamon
 
1897 34 alirezamon
        $diagram-> signal_connect("clicked" => sub{
1898
                show_tile_diagram ($soc);
1899
        });
1900 28 alirezamon
 
1901
 
1902
        $generate-> signal_connect("clicked" => sub{
1903
                my $name=$soc->object_get_attribute('soc_name');
1904
 
1905
                if (length($name)==0){
1906 38 alirezamon
                        message_dialog("Please define the Tile name!");
1907 28 alirezamon
                        return ;
1908
                }
1909
 
1910
 
1911
                my @tmp=split('_',$name);
1912
                if ( $tmp[-1] =~ /^[0-9]+$/ ){
1913
                        message_dialog("The soc name must not end with '_number'!");
1914
                        return ;
1915
                }
1916 34 alirezamon
                my $error = check_verilog_identifier_syntax($name);
1917
                if ( defined $error ){
1918
                        message_dialog("The \"$name\" is given with an unacceptable formatting. This name will be used as top level verilog module name so it must follow Verilog identifier declaration formatting:\n $error");
1919 28 alirezamon
                        return ;
1920
                }
1921
 
1922
                my $target_dir  = "$ENV{'PRONOC_WORK'}/SOC/$name";
1923
                my $hw_dir      = "$target_dir/src_verilog";
1924
                my $sw_path     = "$target_dir/sw";
1925
 
1926
                $soc->object_add_attribute('global_param','CORE_ID',0);
1927 42 alirezamon
                $soc->object_add_attribute('global_param','SW_LOC',$sw_path);
1928
 
1929
                unlink  "$hw_dir/file_list";
1930 28 alirezamon
                generate_soc($soc,$info,$target_dir,$hw_dir,$sw_path,1,1);
1931 34 alirezamon
                #message_dialog("SoC \"$name\" has been created successfully at $target_dir/ " );
1932 38 alirezamon
                my $has_ni= check_for_ni($soc);
1933
                if($has_ni){
1934
                        my $dialog = Gtk2::MessageDialog->new (my $window,
1935
                                              'destroy-with-parent',
1936
                                              'question', # message type
1937
                                              'yes-no', # which set of buttons?
1938
                                              "Processing Tile  \"$name\" has been created successfully at $target_dir/.  In order to include this tile in MPSoC Generator you need to restar the ProNoC. Do you ant to reset the ProNoC now?");
1939
                        my $response = $dialog->run;
1940
                        if ($response eq 'yes') {
1941
                                exec($^X, $0, @ARGV);# reset ProNoC to apply changes    
1942
                        }
1943
                        $dialog->destroy;
1944
                } else {
1945
                        message_dialog("Processing Tile  \"$name\" has been created successfully at $target_dir/.");
1946
 
1947
                }
1948 28 alirezamon
 
1949 34 alirezamon
 
1950
 
1951
 
1952 28 alirezamon
        });
1953
 
1954 34 alirezamon
        $software -> signal_connect("clicked" => sub{
1955
                software_edit_soc($soc);
1956
 
1957
        });
1958 42 alirezamon
 
1959
        $unset-> signal_connect("clicked" => sub{
1960
                set_unset_infc($soc);
1961
        });
1962 34 alirezamon
 
1963
        $ram-> signal_connect("clicked" => sub{
1964
                get_ram_init($soc);
1965
 
1966
        });
1967
 
1968 38 alirezamon
 
1969 34 alirezamon
        $compile -> signal_connect("clicked" => sub{
1970 38 alirezamon
                $soc->object_add_attribute('compile','compilers',"QuartusII,Verilator,Modelsim");
1971 34 alirezamon
                my $name=$soc->object_get_attribute('soc_name');
1972
                if (length($name)==0){
1973 38 alirezamon
                        message_dialog("Please define the Tile name!");
1974 34 alirezamon
                        return ;
1975
                }
1976
                my $target_dir  = "$ENV{'PRONOC_WORK'}/SOC/$name";
1977 38 alirezamon
                my $hw_dir      = "$target_dir/src_verilog";
1978
                my $sw_path     = "$target_dir/sw";
1979 34 alirezamon
                my $top         = "$target_dir/src_verilog/${name}_top.v";
1980 38 alirezamon
                if (-f $top){
1981 42 alirezamon
                        unlink  "$hw_dir/file_list";
1982 38 alirezamon
                        generate_soc($soc,$info,$target_dir,$hw_dir,$sw_path,1,1);
1983 34 alirezamon
                        select_compiler($soc,$name,$top,$target_dir);
1984
                } else {
1985
                        message_dialog("Cannot find $top file. Please run RTL Generator first!");
1986
                        return;
1987
                }
1988
        });
1989
 
1990 28 alirezamon
        $wb-> signal_connect("clicked" => sub{
1991
                wb_address_setting($soc);
1992
 
1993
        });
1994
 
1995
        $open-> signal_connect("clicked" => sub{
1996 34 alirezamon
                load_soc($soc,$info,$ip);
1997 28 alirezamon
 
1998
        });
1999
 
2000
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
2001
                $sc_win->set_policy( "automatic", "automatic" );
2002
                $sc_win->add_with_viewport($main_table);
2003
 
2004
 
2005
 
2006 16 alirezamon
        #check soc status every 0.5 second. referesh device table if there is any changes 
2007
        Glib::Timeout->add (100, sub{
2008 25 alirezamon
                my ($state,$timeout)= get_gui_status($soc);
2009
 
2010 16 alirezamon
                if ($timeout>0){
2011
                        $timeout--;
2012 25 alirezamon
                        set_gui_status($soc,$state,$timeout);
2013
 
2014 34 alirezamon
                }elsif ($state eq 'save_project'){
2015
                        # Write object file
2016
                        my $name=$soc->object_get_attribute('soc_name',undef);
2017
                        open(FILE,  ">lib/soc/$name.SOC") || die "Can not open: $!";
2018
                        print FILE perl_file_header("$name.SOC");
2019
                        print FILE Data::Dumper->Dump([\%$soc],['soc']);
2020
                        close(FILE) || die "Error closing file: $!";
2021
                        set_gui_status($soc,"ideal",0);
2022 16 alirezamon
                }
2023
                elsif( $state ne "ideal" ){
2024
                        $refresh_dev_win->clicked;
2025 25 alirezamon
                        my $saved_name=$soc->object_get_attribute('soc_name',undef);
2026 16 alirezamon
                        if(defined $saved_name) {$entry->set_text($saved_name);}
2027 25 alirezamon
                        set_gui_status($soc,"ideal",0);
2028 16 alirezamon
                }
2029
                return TRUE;
2030
 
2031
        } );
2032
 
2033
 
2034
 
2035
        return $sc_win;
2036
        #return $main_table;
2037
 
2038
 
2039
}
2040 34 alirezamon
 
2041
 
2042
 
2043
 
2044
 
2045
 

powered by: WebSVN 2.1.0

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