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 30

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
 
214
 
215
sub gen_noc_v{
216 28 alirezamon
        my $pass_param = shift;
217 16 alirezamon
 
218
        my $noc =  read_file("../src_noc/noc.v");
219
        my @noc_param=$noc->get_modules_parameters_not_local_order('noc');
220
 
221
 
222
        my $noc_v='
223
 
224
//NoC ports
225
        wire [Fw-1      :   0]  ni_flit_out                 [NC-1           :0];
226
        wire [NC-1      :   0]  ni_flit_out_wr;
227
        wire [V-1       :   0]  ni_credit_in                [NC-1           :0];
228
        wire [Fw-1      :   0]  ni_flit_in                  [NC-1           :0];
229
        wire [NC-1      :   0]  ni_flit_in_wr;
230
        wire [V-1       :   0]  ni_credit_out               [NC-1           :0];
231
        wire [NCFw-1    :   0]  flit_out_all;
232
        wire [NC-1      :   0]  flit_out_wr_all;
233
        wire [NCV-1     :   0]  credit_in_all;
234
        wire [NCFw-1    :   0]  flit_in_all;
235
        wire [NC-1      :   0]  flit_in_wr_all;
236
        wire [NCV-1     :   0]  credit_out_all;
237
        wire                                    noc_clk,noc_reset;
238
 
239
    ';
240
 
241
 
242
 
243
        $noc_v="$noc_v
244
//NoC\n \tnoc #(\n";
245
        my $i=0;
246
        foreach my $p (@noc_param){
247
                my $param=($i==0)?  "\t\t.$p($p)":",\n\t\t.$p($p)";
248
                $i=1;
249 28 alirezamon
                #add_text_to_string(\$noc_v,$param);                    
250 16 alirezamon
        }
251 28 alirezamon
        add_text_to_string(\$noc_v,"$pass_param\n\t)\n\tthe_noc\n\t(\n");
252 16 alirezamon
 
253
        my @ports= $noc->get_module_ports_order('noc');
254
        $i=0;
255
        foreach my $p (@ports){
256
                my $port;
257
                if($p eq 'reset' ){
258
                        $port=($i==0)?  "\t\t.$p(noc_reset)":",\n\t\t.$p(noc_reset)";
259
                }elsif( $p eq 'clk'){
260
                        $port=($i==0)?  "\t\t.$p(noc_clk)":",\n\t\t.$p(noc_clk)";
261
                }else {
262
                        $port=($i==0)?  "\t\t.$p($p)":",\n\t\t.$p($p)";
263
                }
264
                $i=1;
265
                add_text_to_string(\$noc_v,$port);
266
        }
267
        add_text_to_string(\$noc_v,"\n\t);\n\n");
268
 
269
add_text_to_string(\$noc_v,'
270
        clk_source  src         (
271
                .clk_in(clk),
272
                .clk_out(noc_clk),
273
                .reset_in(reset),
274
                .reset_out(noc_reset)
275
        );
276
');
277
 
278
 
279
 
280
 
281
add_text_to_string(\$noc_v,'
282
 
283
//NoC port assignment
284
  genvar x,y;
285
  generate
286
    for (x=0;   x<NX; x=x+1) begin :x_loop1
287
        for (y=0;   y<NY;   y=y+1) begin: y_loop1
288
                localparam IP_NUM   =   ((y * NX) +  x);
289
 
290
 
291
            assign  ni_flit_in      [IP_NUM] =   flit_out_all    [(IP_NUM+1)*Fw-1    : IP_NUM*Fw];
292
            assign  ni_flit_in_wr   [IP_NUM] =   flit_out_wr_all [IP_NUM];
293
            assign  credit_in_all   [(IP_NUM+1)*V-1 : IP_NUM*V]     =   ni_credit_out   [IP_NUM];
294
            assign  flit_in_all     [(IP_NUM+1)*Fw-1    : IP_NUM*Fw]    =   ni_flit_out     [IP_NUM];
295
            assign  flit_in_wr_all  [IP_NUM] =   ni_flit_out_wr  [IP_NUM];
296
            assign  ni_credit_in    [IP_NUM] =   credit_out_all  [(IP_NUM+1)*V-1 : IP_NUM*V];
297
 
298
 
299
 
300
 
301
 
302
        end
303
    end
304
endgenerate
305
 
306
'
307
);
308
 
309
 
310
 
311
 
312
 
313
 
314
 
315
 
316
 
317
 
318
 
319
 
320
 
321
 
322
 
323
 
324
 
325
 
326
 
327
 
328
        return $noc_v;
329
 
330
}
331
 
332
 
333
 
334
 
335
sub gen_socs_v{
336 28 alirezamon
        my ($mpsoc,$io_v_ref,$io_def_v,$top_io_ref)=@_;
337
 
338 16 alirezamon
        #generate loop
339
 
340
#       my $socs_v='
341
#       genvar x,y;    
342
#    
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   =   CORE_NUM(x,y);'  ;     
347
 
348
 
349
 
350
#       my @socs= $mpsoc->mpsoc_get_soc_list();
351
#       foreach my $soc (@socs){
352
 
353
#       #tile num condition
354
#               my @tiles= $mpsoc->mpsoc_get_soc_tiles_num($soc);
355
#       if(scalar @tiles>0){
356
#               my $condition="\n\t\tif(";
357
#               my $s=compress_nums( @tiles);
358
#               my @sep=split(',',$s);
359
#                       my $i=0;
360
#                       foreach my $p (@sep){
361
#                               my @range=split(':',$p);
362
#                               my $tt;
363
#                               if($i==0){
364
#                                       $tt= (scalar @range>1)? "(IP_NUM>=$range[0] && IP_NUM<=$range[1])":"(IP_NUM==$range[0])" ;
365
#                               }else{
366
#                               }
367
#                               add_text_to_string(\$condition,$tt);
368
#                               $i=1;
369
#                       }
370
#                       add_text_to_string(\$condition,") begin :${soc}_if\n ");        
371
#                       #soc instance
372
#                       my $soc_v= gen_soc_v($mpsoc,$soc);
373
#         
374
#                       add_text_to_string(\$socs_v,$condition );
375
#                       add_text_to_string(\$socs_v,$soc_v);
376
#                       add_text_to_string(\$socs_v,"\t\tend // ${soc}_if \n");
377
#               }#scalar @tile  
378
# }     #froeach soc
379
 
380
 
381
 
382
 my $socs_v;
383
 
384 25 alirezamon
   my $nx= $mpsoc->object_get_attribute('noc_param',"NX");
385
   my $ny= $mpsoc->object_get_attribute('noc_param',"NY");
386 16 alirezamon
   my $processors_en=0;
387
   for (my $y=0;$y<$ny;$y++){
388
                for (my $x=0; $x<$nx;$x++){
389
                        my $tile_num=($nx*$y)+ $x;
390
                        my ($soc_name,$n,$soc_num)=$mpsoc->mpsoc_get_tile_soc_name($tile_num);
391
 
392
                        if(defined $soc_name) {
393 28 alirezamon
 
394
 
395
 
396
                                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);
397 16 alirezamon
                                add_text_to_string(\$socs_v,$soc_v);
398
                                $processors_en|=$en;
399 28 alirezamon
 
400 16 alirezamon
                        }else{
401
                                #this tile is not connected to any ip. the noc input ports will be connected to ground
402
                                my $soc_v="\n\n // Tile:$tile_num (x=$x,y=$y)   is not assigned to any ip\n";
403
                                $soc_v="$soc_v
404
 
405
        assign ni_credit_out[$tile_num]={V{1'b0}};
406
        assign ni_flit_out[$tile_num]={Fw{1'b0}};
407
        assign ni_flit_out_wr[$tile_num]=1'b0;
408
        ";
409
                add_text_to_string(\$socs_v,$soc_v);
410
 
411
                        }
412
 
413
        }}
414
 
415
    if($processors_en){
416
        add_text_to_string($io_v_ref,",\n\tprocessors_en");
417
        add_text_to_string($io_def_v,"\t input processors_en;");
418 28 alirezamon
        add_text_to_string($top_io_ref,",\n\t\t.processors_en(processors_en_anded_jtag)");
419 16 alirezamon
 
420
    }
421
 
422
 
423
        return $socs_v;
424
 
425
}
426
 
427
##############
428
#       gen_soc_v
429
##############
430
 
431
 
432
 
433
sub   gen_soc_v{
434 28 alirezamon
        my ($mpsoc,$soc_name,$tile_num,$x,$y,$soc_num,$io_v_ref,$io_def_v,$top_io_ref)=@_;
435 16 alirezamon
        my $soc_v;
436
        my $processor_en=0;
437 25 alirezamon
        my $xw= log2($mpsoc->object_get_attribute('noc_param',"NX"));
438
        my $yw= log2($mpsoc->object_get_attribute('noc_param',"NY"));
439 16 alirezamon
        $soc_v="\n\n // Tile:$tile_num (x=$x,y=$y)\n   \t$soc_name #(\n";
440
 
441
        # core id
442
        add_text_to_string(\$soc_v,"\t\t.CORE_ID($tile_num)");
443
 
444
        # ni parameter
445
        my $top=$mpsoc->mpsoc_get_soc($soc_name);
446 30 alirezamon
        my @nis=get_NI_instance_list($top);
447
        my @noc_param=$top->top_get_parameter_list($nis[0]);
448
        my $inst_name=$top->top_get_def_of_instance($nis[0],'instance');
449 16 alirezamon
 
450
        #other parameters
451
        my %params=$top->top_get_default_soc_param();
452
 
453
        foreach my $p (@noc_param){
454
                my $parm_next = $p;
455
                $parm_next =~ s/${inst_name}_//;
456
                my $param=  ",\n\t\t.$p($parm_next)";
457
                add_text_to_string(\$soc_v,$param);
458
        }
459
        foreach my $p (sort keys %params){
460
                my $parm_next= "${soc_name}_${soc_num}_$p";
461
                my $param=  ",\n\t\t.$p($parm_next)";
462
                add_text_to_string(\$soc_v,$param);
463
 
464
        }
465
 
466
        add_text_to_string(\$soc_v,"\n\t)the_${soc_name}_$soc_num(\n");
467
 
468
        my @intfcs=$top->top_get_intfc_list();
469
 
470
        my $i=0;
471 25 alirezamon
 
472
        my $dir = Cwd::getcwd();
473
        my $mpsoc_name=$mpsoc->object_get_attribute('mpsoc_name');
474 28 alirezamon
        my $target_dir  = "$ENV{'PRONOC_WORK'}/MPSOC/$mpsoc_name";
475 25 alirezamon
        my $soc_file="$target_dir/src_verilog/tiles/$soc_name.v";
476
 
477
        my $vdb =read_file($soc_file);
478
 
479
        my %soc_localparam = $vdb->get_modules_parameters($soc_name);
480
 
481
 
482 16 alirezamon
        foreach my $intfc (@intfcs){
483
 
484
                # ni intfc      
485
                if( $intfc eq 'socket:ni[0]'){
486
                        my @ports=$top->top_get_intfc_ports_list($intfc);
487
 
488
                        foreach my $p (@ports){
489
                                my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
490
                                my $q=($intfc_port eq "current_x")? "$xw\'d$x" :
491
                                                                  ($intfc_port eq "current_y")? "$yw\'d$y" :"ni_$intfc_port\[$tile_num\]";
492
                                add_text_to_string(\$soc_v,',') if ($i);
493
                                add_text_to_string(\$soc_v,"\n\t\t.$p($q)");
494
                                $i=1;
495
 
496
 
497
                        }
498
                }
499
                # clk source
500
                elsif( $intfc eq 'plug:clk[0]'){
501
                        my @ports=$top->top_get_intfc_ports_list($intfc);
502
                        foreach my $p (@ports){
503
                                my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
504
                                add_text_to_string(\$soc_v,',') if ($i);
505
                            add_text_to_string(\$soc_v,"\n\t\t.$p(clk)");
506
                            $i=1;
507
 
508
                        }
509
                }
510
                #reset
511
                elsif( $intfc eq 'plug:reset[0]'){
512
                        my @ports=$top->top_get_intfc_ports_list($intfc);
513
                        foreach my $p (@ports){
514
                                my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
515
                                add_text_to_string(\$soc_v,',') if ($i);
516
                            add_text_to_string(\$soc_v,"\n\t\t.$p(reset)");
517
                            $i=1;
518
 
519
                        }
520
 
521
 
522
 
523
                }
524
                elsif( $intfc eq 'plug:enable[0]'){
525
                        my @ports=$top->top_get_intfc_ports_list($intfc);
526
                        foreach my $p (@ports){
527
                                my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
528
                                add_text_to_string(\$soc_v,',') if ($i);
529
                            add_text_to_string(\$soc_v,"\n\t\t.$p(processors_en)");
530
                            $processor_en=1;
531
                            $i=1;
532
 
533
                        }
534
 
535
 
536
                }
537
                else {
538
                #other interface
539
                        my @ports=$top->top_get_intfc_ports_list($intfc);
540
                        foreach my $p (@ports){
541
                        my($inst,$range,$type,$intfc_name,$intfc_port)= $top->top_get_port($p);
542
                        my $io_port="${soc_name}_${soc_num}_${p}";
543 25 alirezamon
                        #resolve range parameter
544
                        if (defined $range ){
545
                                my @a= split (/\b/,$range);
546
                                foreach my $l (@a){
547
                                        #if defined in parameter list ignore it
548
                                        next  if(defined $params{$l});
549
                                        ($range=$range)=~ s/\b$l\b/$soc_localparam{$l}/g      if(defined $soc_localparam{$l});
550
                                        #else s
551
 
552
                                        #print "$l\n";
553
                                }
554
 
555
                        }
556 16 alirezamon
                        #io name 
557
                        add_text_to_string($io_v_ref,",\n\t$io_port");
558 28 alirezamon
                        add_text_to_string($top_io_ref,",\n\t\t.$io_port($io_port)");
559 16 alirezamon
                        #io definition
560
                        my $new_range = add_instantc_name_to_parameters(\%params,"${soc_name}_$soc_num",$range);
561
                        #my $new_range=$range;
562
                        my $port_def=(length ($range)>1 )?      "\t$type\t [ $new_range    ] $io_port;\n": "\t$type\t\t\t$io_port;\n";
563
 
564
 
565
                        add_text_to_string($io_def_v,"$port_def");
566
                        add_text_to_string(\$soc_v,',') if ($i);
567
                        add_text_to_string(\$soc_v,"\n\t\t.$p($io_port)");
568
                        $i=1;
569
 
570
                        }
571
 
572
 
573
                }
574
 
575
 
576
        }
577
 
578
        add_text_to_string(\$soc_v,"\n\t);\n");
579
 
580
 
581
 
582
 
583
 
584
 
585
 
586
 
587
 
588
 
589
        return ($soc_v,$processor_en);
590
 
591
}
592
 
593
 
594
sub log2{
595
        my $num=shift;
596
        my $log=0;
597 25 alirezamon
        while( (1<< $log)  < $num) {
598 16 alirezamon
                                $log++;
599
        }
600
        return  $log;
601
}
602
 
603
 
604 25 alirezamon
 
605
sub gen_emulate_top_v{
606
                my $emulate=shift;
607
                my ($localparam, $pass_param)=gen_noc_param_v( $emulate);
608
                my $top_v="
609
 
610
module  emulator_top (
611
        output [0:0]LEDR,
612
        output [0:0]LEDG,
613
        input  [0:0]KEY,
614
        input  CLOCK_50
615
);
616
 
617
 
618
 
619
 
620
        $localparam
621
 
622
 
623
        wire reset_in,jtag_reset,reset,reset_sync;
624
 
625
        assign  reset_in        =       ~KEY[0];
626
        assign  LEDG[0]         =       reset;
627
        assign  reset           =       (jtag_reset | reset_in);
628
        wire done;
629
        reg[31:0]time_cnt;
630
 
631
        // a reset source which can be controled using jtag
632
        jtag_source_probe #(
633
                .VJTAG_INDEX(127),
634
                .Dw(1)  //source/probe width in bits
635
        )the_reset(
636
                .probe(done),
637
                .source(jtag_reset)
638
        );
639
 
640
        altera_reset_synchronizer rst_sync
641
        (
642
                .reset_in(reset),
643
                .clk(CLOCK_50),
644
                .reset_out(reset_sync)
645
        );
646
 
647
 
648
 
649
        noc_emulator #(
650
                $pass_param
651
 
652
                    // simulation
653
                   // parameter MAX_PCK_NUM=2560000,
654
                   // parameter MAX_SIM_CLKs=1000000,
655
                  //  parameter MAX_PCK_SIZ=10,
656
                 //   parameter TIMSTMP_FIFO_NUM=16
657
        )
658
        emulate_top
659
        (
660
                .reset(reset_sync),
661
                .clk(CLOCK_50),
662
                .done(done)
663
        );
664
 
665
 
666
         jtag_source_probe #(
667
                .VJTAG_INDEX(126),
668
                .Dw(32) //source/probe width in bits
669
 
670
 
671
        )
672
        src_pb
673
        (
674
                .probe(time_cnt),
675
                .source()
676
        );
677
 
678
 
679
        always @(posedge CLOCK_50 or posedge reset)begin
680
                if(reset) begin
681
                        time_cnt<=0;
682
                end else begin
683
                         if(!done) time_cnt<=time_cnt+1;
684
                end
685
        end
686
 
687
 
688
 assign LEDR[0]=done;
689
 
690
 
691
endmodule
692
 
693
 
694
                ";
695
                return $top_v;
696
 
697
 
698
 
699
 
700
}
701
 
702
 
703 16 alirezamon
1

powered by: WebSVN 2.1.0

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