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 42

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

powered by: WebSVN 2.1.0

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