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/] [mpsoc_verilog_gen.pl] - Blame information for rev 34

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

Line No. Rev Author Line
1 16 alirezamon
 
2
 
3
use strict;
4
use warnings;
5
use mpsoc;
6
use soc;
7
use ip;
8
use ip_gen;
9
use Cwd;
10
use rvp;
11
 
12
 
13
 
14
sub mpsoc_generate_verilog{
15 34 alirezamon
        my ($mpsoc,$sw_dir)=@_;
16 25 alirezamon
        my $mpsoc_name=$mpsoc->object_get_attribute('mpsoc_name');
17 34 alirezamon
        my $top_ip=ip_gen->top_gen_new();
18 16 alirezamon
        my $io_v="\tclk,\n\treset";
19 34 alirezamon
 
20
 
21
 
22
        #$top_ip->top_add_port($inst,$port,$range,$type,$intfc_name,$intfc_port);
23
        $top_ip->top_add_port('IO','reset','', 'input' ,'plug:reset[0]','reset_i');
24
        $top_ip->top_add_port('IO','clk','', 'input' ,'plug:clk[0]','clk_i');
25
 
26 16 alirezamon
        my $io_def_v="
27
//IO
28
\tinput\tclk,reset;\n";
29
        my $param_as_in_v;
30 28 alirezamon
        # generate top 
31
        my $top_io="\t\t.clk(clk) ,\n\t\t.reset(reset_ored_jtag)";
32 16 alirezamon
 
33 28 alirezamon
 
34 16 alirezamon
        #generate socs_parameter
35
        my $socs_param= gen_socs_param($mpsoc);
36
 
37
        #generate noc_parameter
38 25 alirezamon
        my ($noc_param,$pass_param)=gen_noc_param_v($mpsoc);
39 16 alirezamon
 
40
        #generate the noc
41 28 alirezamon
        my $noc_v=gen_noc_v($pass_param);
42 16 alirezamon
 
43
        #generate socs
44 34 alirezamon
        my $socs_v=gen_socs_v($mpsoc,\$io_v,\$io_def_v,\$top_io,$top_ip,$sw_dir);
45 16 alirezamon
 
46
        #functions
47
        my $functions=get_functions();
48
 
49
        my $mpsoc_v = (defined $param_as_in_v )? "module $mpsoc_name #(\n $param_as_in_v\n)(\n$io_v\n);\n": "module $mpsoc_name (\n$io_v\n);\n";
50 34 alirezamon
        add_text_to_string (\$mpsoc_v,$noc_param);
51 16 alirezamon
        add_text_to_string (\$mpsoc_v,$functions);
52
        add_text_to_string (\$mpsoc_v,$socs_param);
53 34 alirezamon
 
54 16 alirezamon
        add_text_to_string (\$mpsoc_v,$io_def_v);
55
        add_text_to_string (\$mpsoc_v,$noc_v);
56
        add_text_to_string (\$mpsoc_v,$socs_v);
57
        add_text_to_string (\$mpsoc_v,"\nendmodule\n");
58
 
59 28 alirezamon
        my $top_v = (defined $param_as_in_v )? "module ${mpsoc_name}_top #(\n $param_as_in_v\n)(\n$io_v\n);\n": "module ${mpsoc_name}_top (\n $io_v\n);\n";
60
        add_text_to_string (\$top_v,$socs_param);
61
        add_text_to_string (\$top_v,$io_def_v);
62
        add_text_to_string(\$top_v,"
63
// Allow software to remote reset/enable the cpu via jtag
64
 
65
        wire jtag_cpu_en, jtag_system_reset;
66
 
67
        jtag_system_en jtag_en (
68
                .cpu_en(jtag_cpu_en),
69
                .system_reset(jtag_system_reset)
70 16 alirezamon
 
71 28 alirezamon
        );
72
 
73
        wire reset_ored_jtag = reset | jtag_system_reset;
74
        wire processors_en_anded_jtag = processors_en & jtag_cpu_en;
75
 
76
        ${mpsoc_name} the_${mpsoc_name} (
77
 
78
$top_io
79
 
80
 
81
        );
82
 
83
endmodule
84
 
85
 
86
");
87
 
88
        #my $ins= gen_mpsoc_instance_v($mpsoc,$mpsoc_name,$param_pass_v);
89
 
90
        #add_text_to_string(\$top_v,$local_param_v_all."\n".$io_full_v_all);
91
        #add_text_to_string(\$top_v,$ins);
92 34 alirezamon
        $mpsoc->object_add_attribute('top_ip',undef,$top_ip);
93 28 alirezamon
        return ($mpsoc_v,$top_v);
94 16 alirezamon
}
95
 
96
sub get_functions{
97
        my $p='
98
//functions
99
        function integer log2;
100
                input integer number; begin
101
                        log2=0;
102
                        while(2**log2<number) begin
103
                                log2=log2+1;
104
                        end
105
        end
106
        endfunction // log2
107
 
108
        function integer CORE_NUM;
109
                input integer x,y;
110
                begin
111
                        CORE_NUM = ((y * NX) +  x);
112
                end
113
        endfunction
114
 
115
 
116
 
117
        localparam      Fw      =   2+V+Fpay,
118 25 alirezamon
                                NC     =        (TOPOLOGY=="RING")? NX    :   NX*NY,    //number of cores
119 16 alirezamon
                                Xw      =   log2(NX),
120
                                Yw      =   log2(NY) ,
121
                                Cw      =   (C>1)? log2(C): 1,
122
                                NCw     =   log2(NC),
123
                                NCV     =   NC  * V,
124
                                NCFw    =   NC  * Fw;
125
        ';
126
 
127
        return $p;
128
 
129
 
130
 
131
}
132
 
133
 
134
sub  gen_socs_param{
135
        my $mpsoc=shift;
136
        my $socs_param="
137
//SOC parameters\n";
138 25 alirezamon
        my $nx= $mpsoc->object_get_attribute('noc_param',"NX");
139
    my $ny= $mpsoc->object_get_attribute('noc_param',"NY");
140 16 alirezamon
    my $processors_en=0;
141
    for (my $y=0;$y<$ny;$y++){
142
                for (my $x=0; $x<$nx;$x++){
143
                        my $tile=($nx*$y)+ $x;
144
                        my ($soc_name,$n,$soc_num)=$mpsoc->mpsoc_get_tile_soc_name($tile);
145
                        if(defined $soc_name) {
146
                                my $param=      gen_soc_param($mpsoc,$soc_name,$soc_num,$tile);
147
                                add_text_to_string(\$socs_param,$param);
148
                        }
149
        }}#x&y
150
        $socs_param="$socs_param \n";
151
        return $socs_param;
152
 
153
}
154
 
155
 
156
sub  gen_soc_param {
157
        my ($mpsoc,$soc_name,$soc_num,$tile)=@_;
158
        my $top=$mpsoc->mpsoc_get_soc($soc_name);
159
        my $setting=$mpsoc->mpsoc_get_tile_param_setting($tile);
160
        my %params;
161
        if ($setting eq 'Custom'){
162
                 %params= $top->top_get_custom_soc_param($tile);
163
        }else{
164
                 %params=$top->top_get_default_soc_param();
165
        }
166
        my $params="\n\t //Parameter setting for $soc_name  located in tile: $tile \n";
167
        foreach my $p (sort keys %params){
168
                        $params="$params\t localparam ${soc_name}_${soc_num}_$p=$params{$p};\n";
169
        }
170
 
171
 
172
 
173
        return $params;
174
}
175
 
176
 
177
sub gen_noc_param_v{
178
        my $mpsoc=shift;
179
        my $param_v="\n\n//NoC parameters\n";
180 25 alirezamon
        my $pass_param;
181
        my @params=$mpsoc->object_get_attribute_order('noc_param');
182 16 alirezamon
        foreach my $p (@params){
183 25 alirezamon
                my $val=$mpsoc->object_get_attribute('noc_param',$p);
184 16 alirezamon
                add_text_to_string (\$param_v,"\tlocalparam $p=$val;\n");
185 25 alirezamon
                add_text_to_string (\$pass_param,".$p($p),\n");
186
                #print "$p:$val\n";
187 16 alirezamon
 
188
        }
189 25 alirezamon
        my $class=$mpsoc->object_get_attribute('noc_param',"C");
190 16 alirezamon
        my $str;
191
        if( $class > 1){
192 30 alirezamon
                for (my $i=0; $i<=$class-1; $i++){
193
                        my $n="Cn_$i";
194
                        my $val=$mpsoc->object_get_attribute('class_param',$n);
195
                        add_text_to_string (\$param_v,"\tlocalparam $n=$val;\n");
196
                }
197 16 alirezamon
                $str="CLASS_SETTING={";
198
                for (my $i=$class-1; $i>=0;$i--){
199
                        $str=($i==0)?  "${str}Cn_0};\n " : "${str}Cn_$i,";
200
                }
201
        }else {
202
                $str="CLASS_SETTING={V{1\'b1}};\n";
203
        }
204
        add_text_to_string (\$param_v,"\tlocalparam $str");
205 25 alirezamon
        add_text_to_string (\$pass_param,".CLASS_SETTING(CLASS_SETTING),\n");
206
        my $v=$mpsoc->object_get_attribute('noc_param',"V")-1;
207
        my $escape=$mpsoc->object_get_attribute('noc_param',"ESCAP_VC_MASK");
208
        if (! defined $escape){
209
                add_text_to_string (\$param_v,"\tlocalparam [$v :0] ESCAP_VC_MASK=1;\n");
210
                add_text_to_string (\$pass_param,".ESCAP_VC_MASK(ESCAP_VC_MASK),\n");
211
        }
212 16 alirezamon
        add_text_to_string (\$param_v," \tlocalparam  CVw=(C==0)? V : C * V;\n");
213 25 alirezamon
        add_text_to_string (\$pass_param,".CVw(CVw)\n");
214 16 alirezamon
 
215
 
216 25 alirezamon
        return ($param_v,$pass_param);
217 16 alirezamon
 
218
 
219
 
220
}
221
 
222
 
223 32 alirezamon
sub gen_noc_param_h{
224
        my $mpsoc=shift;
225
        my $param_h="\n\n//NoC parameters\n";
226
 
227
        my @params=$mpsoc->object_get_attribute_order('noc_param');
228
        foreach my $p (@params){
229
                my $val=$mpsoc->object_get_attribute('noc_param',$p);
230
                add_text_to_string (\$param_h,"\t#define $p\t$val\n");
231
 
232
                #print "$p:$val\n";
233
 
234
        }
235
        my $class=$mpsoc->object_get_attribute('noc_param',"C");
236
        my $str;
237
        if( $class > 1){
238
                for (my $i=0; $i<=$class-1; $i++){
239
                        my $n="Cn_$i";
240
                        my $val=$mpsoc->object_get_attribute('class_param',$n);
241
                        add_text_to_string (\$param_h,"\t#define $n\t$val\n");
242
                }
243
                $str="CLASS_SETTING  {";
244
                for (my $i=$class-1; $i>=0;$i--){
245
                        $str=($i==0)?  "${str}Cn_0};\n " : "${str}Cn_$i,";
246
                }
247
        }else {
248
                $str="CLASS_SETTING={V{1\'b1}}\n";
249
        }
250
        #add_text_to_string (\$param_h,"\t#define $str");
251
 
252
        my $v=$mpsoc->object_get_attribute('noc_param',"V")-1;
253
        my $escape=$mpsoc->object_get_attribute('noc_param',"ESCAP_VC_MASK");
254
        if (! defined $escape){
255
                #add_text_to_string (\$param_h,"\tlocalparam [$v        :0] ESCAP_VC_MASK=1;\n");
256
                #add_text_to_string (\$pass_param,".ESCAP_VC_MASK(ESCAP_VC_MASK),\n"); 
257
        }
258
        #add_text_to_string (\$param_h," \tlocalparam  CVw=(C==0)? V : C * V;\n");
259
        #add_text_to_string (\$pass_param,".CVw(CVw)\n");
260
 
261
 
262
        return  $param_h;
263
 
264
 
265
 
266
}
267 16 alirezamon
 
268
 
269 32 alirezamon
 
270
 
271
 
272 16 alirezamon
sub gen_noc_v{
273 28 alirezamon
        my $pass_param = shift;
274 16 alirezamon
 
275 34 alirezamon
        my $noc =  read_verilog_file("../src_noc/noc.v");
276 16 alirezamon
        my @noc_param=$noc->get_modules_parameters_not_local_order('noc');
277
 
278
 
279
        my $noc_v='
280
 
281
//NoC ports
282
        wire [Fw-1      :   0]  ni_flit_out                 [NC-1           :0];
283
        wire [NC-1      :   0]  ni_flit_out_wr;
284
        wire [V-1       :   0]  ni_credit_in                [NC-1           :0];
285
        wire [Fw-1      :   0]  ni_flit_in                  [NC-1           :0];
286
        wire [NC-1      :   0]  ni_flit_in_wr;
287
        wire [V-1       :   0]  ni_credit_out               [NC-1           :0];
288
        wire [NCFw-1    :   0]  flit_out_all;
289
        wire [NC-1      :   0]  flit_out_wr_all;
290
        wire [NCV-1     :   0]  credit_in_all;
291
        wire [NCFw-1    :   0]  flit_in_all;
292
        wire [NC-1      :   0]  flit_in_wr_all;
293
        wire [NCV-1     :   0]  credit_out_all;
294
        wire                                    noc_clk,noc_reset;
295
 
296
    ';
297
 
298
 
299
 
300
        $noc_v="$noc_v
301
//NoC\n \tnoc #(\n";
302
        my $i=0;
303
        foreach my $p (@noc_param){
304
                my $param=($i==0)?  "\t\t.$p($p)":",\n\t\t.$p($p)";
305
                $i=1;
306 28 alirezamon
                #add_text_to_string(\$noc_v,$param);                    
307 16 alirezamon
        }
308 28 alirezamon
        add_text_to_string(\$noc_v,"$pass_param\n\t)\n\tthe_noc\n\t(\n");
309 16 alirezamon
 
310
        my @ports= $noc->get_module_ports_order('noc');
311
        $i=0;
312
        foreach my $p (@ports){
313
                my $port;
314
                if($p eq 'reset' ){
315
                        $port=($i==0)?  "\t\t.$p(noc_reset)":",\n\t\t.$p(noc_reset)";
316
                }elsif( $p eq 'clk'){
317
                        $port=($i==0)?  "\t\t.$p(noc_clk)":",\n\t\t.$p(noc_clk)";
318
                }else {
319
                        $port=($i==0)?  "\t\t.$p($p)":",\n\t\t.$p($p)";
320
                }
321
                $i=1;
322
                add_text_to_string(\$noc_v,$port);
323
        }
324
        add_text_to_string(\$noc_v,"\n\t);\n\n");
325
 
326
add_text_to_string(\$noc_v,'
327
        clk_source  src         (
328
                .clk_in(clk),
329
                .clk_out(noc_clk),
330
                .reset_in(reset),
331
                .reset_out(noc_reset)
332
        );
333
');
334
 
335
 
336
 
337
 
338
add_text_to_string(\$noc_v,'
339
 
340
//NoC port assignment
341
  genvar x,y;
342
  generate
343
    for (x=0;   x<NX; x=x+1) begin :x_loop1
344
        for (y=0;   y<NY;   y=y+1) begin: y_loop1
345
                localparam IP_NUM   =   ((y * NX) +  x);
346
 
347
 
348
            assign  ni_flit_in      [IP_NUM] =   flit_out_all    [(IP_NUM+1)*Fw-1    : IP_NUM*Fw];
349
            assign  ni_flit_in_wr   [IP_NUM] =   flit_out_wr_all [IP_NUM];
350
            assign  credit_in_all   [(IP_NUM+1)*V-1 : IP_NUM*V]     =   ni_credit_out   [IP_NUM];
351
            assign  flit_in_all     [(IP_NUM+1)*Fw-1    : IP_NUM*Fw]    =   ni_flit_out     [IP_NUM];
352
            assign  flit_in_wr_all  [IP_NUM] =   ni_flit_out_wr  [IP_NUM];
353
            assign  ni_credit_in    [IP_NUM] =   credit_out_all  [(IP_NUM+1)*V-1 : IP_NUM*V];
354
 
355
 
356
 
357
 
358
 
359
        end
360
    end
361
endgenerate
362
 
363
'
364
);
365
 
366
 
367
 
368
 
369
 
370
 
371
 
372
 
373
 
374
 
375
 
376
 
377
 
378
 
379
 
380
 
381
 
382
 
383
 
384
 
385
        return $noc_v;
386
 
387
}
388
 
389
 
390
 
391
 
392
sub gen_socs_v{
393 34 alirezamon
        my ($mpsoc,$io_v_ref,$io_def_v,$top_io_ref,$top_ip,$sw_dir)=@_;
394 28 alirezamon
 
395 16 alirezamon
        #generate loop
396
 
397
#       my $socs_v='
398
#       genvar x,y;    
399
#    
400
#    generate 
401
#    for (x=0;   x<NX; x=x+1) begin :x_loop1
402
#        for (y=0;   y<NY;   y=y+1) begin: y_loop1
403
#                localparam IP_NUM   =   CORE_NUM(x,y);'  ;     
404
 
405
 
406
 
407
#       my @socs= $mpsoc->mpsoc_get_soc_list();
408
#       foreach my $soc (@socs){
409
 
410
#       #tile num condition
411
#               my @tiles= $mpsoc->mpsoc_get_soc_tiles_num($soc);
412
#       if(scalar @tiles>0){
413
#               my $condition="\n\t\tif(";
414
#               my $s=compress_nums( @tiles);
415
#               my @sep=split(',',$s);
416
#                       my $i=0;
417
#                       foreach my $p (@sep){
418
#                               my @range=split(':',$p);
419
#                               my $tt;
420
#                               if($i==0){
421
#                                       $tt= (scalar @range>1)? "(IP_NUM>=$range[0] && IP_NUM<=$range[1])":"(IP_NUM==$range[0])" ;
422
#                               }else{
423
#                               }
424
#                               add_text_to_string(\$condition,$tt);
425
#                               $i=1;
426
#                       }
427
#                       add_text_to_string(\$condition,") begin :${soc}_if\n ");        
428
#                       #soc instance
429
#                       my $soc_v= gen_soc_v($mpsoc,$soc);
430
#         
431
#                       add_text_to_string(\$socs_v,$condition );
432
#                       add_text_to_string(\$socs_v,$soc_v);
433
#                       add_text_to_string(\$socs_v,"\t\tend // ${soc}_if \n");
434
#               }#scalar @tile  
435
# }     #froeach soc
436
 
437
 
438
 
439
 my $socs_v;
440 34 alirezamon
 
441 25 alirezamon
   my $nx= $mpsoc->object_get_attribute('noc_param',"NX");
442
   my $ny= $mpsoc->object_get_attribute('noc_param',"NY");
443 16 alirezamon
   my $processors_en=0;
444
   for (my $y=0;$y<$ny;$y++){
445
                for (my $x=0; $x<$nx;$x++){
446
                        my $tile_num=($nx*$y)+ $x;
447
                        my ($soc_name,$n,$soc_num)=$mpsoc->mpsoc_get_tile_soc_name($tile_num);
448
 
449
                        if(defined $soc_name) {
450 28 alirezamon
 
451
 
452
 
453 34 alirezamon
                                my ($soc_v,$en)= gen_soc_v($mpsoc,$soc_name,$tile_num,$x,$y,$soc_num,$io_v_ref,$io_def_v,$top_io_ref,$top_ip,$sw_dir);
454 16 alirezamon
                                add_text_to_string(\$socs_v,$soc_v);
455
                                $processors_en|=$en;
456 28 alirezamon
 
457 16 alirezamon
                        }else{
458
                                #this tile is not connected to any ip. the noc input ports will be connected to ground
459
                                my $soc_v="\n\n // Tile:$tile_num (x=$x,y=$y)   is not assigned to any ip\n";
460
                                $soc_v="$soc_v
461
 
462
        assign ni_credit_out[$tile_num]={V{1'b0}};
463
        assign ni_flit_out[$tile_num]={Fw{1'b0}};
464
        assign ni_flit_out_wr[$tile_num]=1'b0;
465
        ";
466
                add_text_to_string(\$socs_v,$soc_v);
467
 
468
                        }
469
 
470
        }}
471
 
472
    if($processors_en){
473
        add_text_to_string($io_v_ref,",\n\tprocessors_en");
474
        add_text_to_string($io_def_v,"\t input processors_en;");
475 28 alirezamon
        add_text_to_string($top_io_ref,",\n\t\t.processors_en(processors_en_anded_jtag)");
476 34 alirezamon
        $top_ip->top_add_port('IO','processors_en','' ,'input','plug:enable[0]','enable_i');
477 16 alirezamon
 
478
    }
479
 
480
 
481
        return $socs_v;
482
 
483
}
484
 
485
##############
486
#       gen_soc_v
487
##############
488
 
489
 
490
 
491
sub   gen_soc_v{
492 34 alirezamon
        my ($mpsoc,$soc_name,$tile_num,$x,$y,$soc_num,$io_v_ref,$io_def_v,$top_io_ref,$top_ip,$sw_path)=@_;
493 16 alirezamon
        my $soc_v;
494
        my $processor_en=0;
495 25 alirezamon
        my $xw= log2($mpsoc->object_get_attribute('noc_param',"NX"));
496
        my $yw= log2($mpsoc->object_get_attribute('noc_param',"NY"));
497 16 alirezamon
        $soc_v="\n\n // Tile:$tile_num (x=$x,y=$y)\n   \t$soc_name #(\n";
498
 
499 34 alirezamon
        # Global parameter
500
        add_text_to_string(\$soc_v,"\t\t.CORE_ID($tile_num),\n\t\t.SW_LOC(\"$sw_path/tile$tile_num\")");
501 16 alirezamon
 
502
        # ni parameter
503
        my $top=$mpsoc->mpsoc_get_soc($soc_name);
504 30 alirezamon
        my @nis=get_NI_instance_list($top);
505
        my @noc_param=$top->top_get_parameter_list($nis[0]);
506
        my $inst_name=$top->top_get_def_of_instance($nis[0],'instance');
507 16 alirezamon
 
508
        #other parameters
509
        my %params=$top->top_get_default_soc_param();
510
 
511
        foreach my $p (@noc_param){
512
                my $parm_next = $p;
513
                $parm_next =~ s/${inst_name}_//;
514
                my $param=  ",\n\t\t.$p($parm_next)";
515
                add_text_to_string(\$soc_v,$param);
516
        }
517
        foreach my $p (sort keys %params){
518
                my $parm_next= "${soc_name}_${soc_num}_$p";
519
                my $param=  ",\n\t\t.$p($parm_next)";
520
                add_text_to_string(\$soc_v,$param);
521
 
522
        }
523
 
524
        add_text_to_string(\$soc_v,"\n\t)the_${soc_name}_$soc_num(\n");
525
 
526
        my @intfcs=$top->top_get_intfc_list();
527
 
528
        my $i=0;
529 25 alirezamon
 
530
        my $dir = Cwd::getcwd();
531
        my $mpsoc_name=$mpsoc->object_get_attribute('mpsoc_name');
532 28 alirezamon
        my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name";
533 25 alirezamon
        my $soc_file="$target_dir/src_verilog/tiles/$soc_name.v";
534
 
535 34 alirezamon
        my $vdb =read_verilog_file($soc_file);
536 25 alirezamon
 
537
        my %soc_localparam = $vdb->get_modules_parameters($soc_name);
538
 
539
 
540 16 alirezamon
        foreach my $intfc (@intfcs){
541
 
542
                # ni intfc      
543
                if( $intfc eq 'socket:ni[0]'){
544
                        my @ports=$top->top_get_intfc_ports_list($intfc);
545
 
546
                        foreach my $p (@ports){
547
                                my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
548
                                my $q=($intfc_port eq "current_x")? "$xw\'d$x" :
549
                                                                  ($intfc_port eq "current_y")? "$yw\'d$y" :"ni_$intfc_port\[$tile_num\]";
550
                                add_text_to_string(\$soc_v,',') if ($i);
551
                                add_text_to_string(\$soc_v,"\n\t\t.$p($q)");
552
                                $i=1;
553
 
554
 
555
                        }
556
                }
557
                # clk source
558
                elsif( $intfc eq 'plug:clk[0]'){
559
                        my @ports=$top->top_get_intfc_ports_list($intfc);
560
                        foreach my $p (@ports){
561
                                my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
562
                                add_text_to_string(\$soc_v,',') if ($i);
563
                            add_text_to_string(\$soc_v,"\n\t\t.$p(clk)");
564
                            $i=1;
565
 
566
                        }
567
                }
568
                #reset
569
                elsif( $intfc eq 'plug:reset[0]'){
570
                        my @ports=$top->top_get_intfc_ports_list($intfc);
571
                        foreach my $p (@ports){
572
                                my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
573
                                add_text_to_string(\$soc_v,',') if ($i);
574
                            add_text_to_string(\$soc_v,"\n\t\t.$p(reset)");
575
                            $i=1;
576
 
577
                        }
578
 
579
 
580
 
581
                }
582
                elsif( $intfc eq 'plug:enable[0]'){
583
                        my @ports=$top->top_get_intfc_ports_list($intfc);
584
                        foreach my $p (@ports){
585
                                my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
586
                                add_text_to_string(\$soc_v,',') if ($i);
587
                            add_text_to_string(\$soc_v,"\n\t\t.$p(processors_en)");
588
                            $processor_en=1;
589
                            $i=1;
590
 
591
                        }
592
 
593
 
594
                }
595
                else {
596
                #other interface
597
                        my @ports=$top->top_get_intfc_ports_list($intfc);
598
                        foreach my $p (@ports){
599
                        my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
600
                        my $io_port="${soc_name}_${soc_num}_${p}";
601 25 alirezamon
                        #resolve range parameter
602
                        if (defined $range ){
603
                                my @a= split (/\b/,$range);
604
                                foreach my $l (@a){
605
                                        #if defined in parameter list ignore it
606
                                        next  if(defined $params{$l});
607
                                        ($range=$range)=~ s/\b$l\b/$soc_localparam{$l}/g      if(defined $soc_localparam{$l});
608
                                        #else s
609
 
610
                                        #print "$l\n";
611
                                }
612
 
613
                        }
614 16 alirezamon
                        #io name 
615
                        add_text_to_string($io_v_ref,",\n\t$io_port");
616 28 alirezamon
                        add_text_to_string($top_io_ref,",\n\t\t.$io_port($io_port)");
617 16 alirezamon
                        #io definition
618
                        my $new_range = add_instantc_name_to_parameters(\%params,"${soc_name}_$soc_num",$range);
619
                        #my $new_range=$range;
620
                        my $port_def=(length ($range)>1 )?      "\t$type\t [ $new_range    ] $io_port;\n": "\t$type\t\t\t$io_port;\n";
621 34 alirezamon
                        $top_ip->top_add_port("${soc_name}_$tile_num" ,$io_port, $new_range ,$type,$intfc_name,$intfc_port);
622 16 alirezamon
 
623
                        add_text_to_string($io_def_v,"$port_def");
624
                        add_text_to_string(\$soc_v,',') if ($i);
625
                        add_text_to_string(\$soc_v,"\n\t\t.$p($io_port)");
626
                        $i=1;
627
 
628
                        }
629
 
630
 
631
                }
632
 
633
 
634
        }
635
 
636
        add_text_to_string(\$soc_v,"\n\t);\n");
637
 
638
 
639
 
640
 
641
 
642
 
643
 
644
 
645
 
646
 
647
        return ($soc_v,$processor_en);
648
 
649
}
650
 
651
 
652
sub log2{
653
        my $num=shift;
654
        my $log=0;
655 25 alirezamon
        while( (1<< $log)  < $num) {
656 16 alirezamon
                                $log++;
657
        }
658
        return  $log;
659
}
660
 
661
 
662 25 alirezamon
 
663
sub gen_emulate_top_v{
664
                my $emulate=shift;
665
                my ($localparam, $pass_param)=gen_noc_param_v( $emulate);
666
                my $top_v="
667
 
668
module  emulator_top (
669
        output [0:0]LEDR,
670
        output [0:0]LEDG,
671
        input  [0:0]KEY,
672
        input  CLOCK_50
673
);
674
 
675
 
676
 
677
 
678
        $localparam
679
 
680
 
681
        wire reset_in,jtag_reset,reset,reset_sync;
682
 
683
        assign  reset_in        =       ~KEY[0];
684
        assign  LEDG[0]         =       reset;
685
        assign  reset           =       (jtag_reset | reset_in);
686
        wire done;
687
        reg[31:0]time_cnt;
688
 
689
        // a reset source which can be controled using jtag
690
        jtag_source_probe #(
691
                .VJTAG_INDEX(127),
692
                .Dw(1)  //source/probe width in bits
693
        )the_reset(
694
                .probe(done),
695
                .source(jtag_reset)
696
        );
697
 
698
        altera_reset_synchronizer rst_sync
699
        (
700
                .reset_in(reset),
701
                .clk(CLOCK_50),
702
                .reset_out(reset_sync)
703
        );
704
 
705
 
706
 
707
        noc_emulator #(
708
                $pass_param
709
 
710
                    // simulation
711
                   // parameter MAX_PCK_NUM=2560000,
712
                   // parameter MAX_SIM_CLKs=1000000,
713
                  //  parameter MAX_PCK_SIZ=10,
714
                 //   parameter TIMSTMP_FIFO_NUM=16
715
        )
716
        emulate_top
717
        (
718
                .reset(reset_sync),
719
                .clk(CLOCK_50),
720
                .done(done)
721
        );
722
 
723
 
724
         jtag_source_probe #(
725
                .VJTAG_INDEX(126),
726
                .Dw(32) //source/probe width in bits
727
 
728
 
729
        )
730
        src_pb
731
        (
732
                .probe(time_cnt),
733
                .source()
734
        );
735
 
736
 
737
        always @(posedge CLOCK_50 or posedge reset)begin
738
                if(reset) begin
739
                        time_cnt<=0;
740
                end else begin
741
                         if(!done) time_cnt<=time_cnt+1;
742
                end
743
        end
744
 
745
 
746
 assign LEDR[0]=done;
747
 
748
 
749
endmodule
750
 
751
 
752
                ";
753
                return $top_v;
754
 
755
 
756
 
757
 
758
}
759
 
760
 
761 16 alirezamon
1

powered by: WebSVN 2.1.0

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