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 32

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

powered by: WebSVN 2.1.0

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