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 43

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

powered by: WebSVN 2.1.0

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