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/] [topology_verilog_gen.pl] - Diff between revs 54 and 56

Only display areas with differences | Details | Blame | View Log

Rev 54 Rev 56
use strict;
use strict;
use warnings;
use warnings;
 
 
use FindBin;
use FindBin;
use lib $FindBin::Bin;
use lib $FindBin::Bin;
 
 
 
 
 
 
 
 
sub generate_topology_top_v {
sub generate_topology_top_v {
        my ($self,$info,$dir)=@_;
        my ($self,$info,$dir)=@_;
 
 
 
 
        #create topology top file
        #create topology top file
        my $name=$self->object_get_attribute('save_as');
        my $name=$self->object_get_attribute('save_as');
 
 
        my $r;
        my $r;
        my $top="$dir/${name}_noc.sv";
        my $top="$dir/${name}_noc.sv";
    open my $fd, ">$top" or $r = "$!\n";
    open my $fd, ">$top" or $r = "$!\n";
    if(defined $r) {
    if(defined $r) {
        add_colored_info($info,"Error in creating $top: $r",'red');
        add_colored_info($info,"Error in creating $top: $r",'red');
                return;
                return;
    }
    }
    print $fd autogen_warning();
    print $fd autogen_warning();
    print $fd get_license_header($top);
    print $fd get_license_header($top);
        print $fd '
        print $fd '
`include "pronoc_def.v"
`include "pronoc_def.v"
';
';
 
 
    my $param_str ="\tparameter TOPOLOGY = \"$name\",
    my $param_str ="\tparameter TOPOLOGY = \"$name\",
\tparameter ROUTE_NAME = \"${name}_DETERMINISTIC\"";
\tparameter ROUTE_NAME = \"${name}_DETERMINISTIC\"";
 
 
   my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
   my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
   my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
   my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
 
 
#       foreach my $d (@parameters){
#       foreach my $d (@parameters){
#               $param_str = $param_str.",\n\tparameter $d->{param_name} = $d->{value}";
#               $param_str = $param_str.",\n\tparameter $d->{param_name} = $d->{value}";
#       }
#       }
 
 
    my @ends=get_list_of_all_endpoints($self);
    my @ends=get_list_of_all_endpoints($self);
    my @routers=get_list_of_all_routers($self);
    my @routers=get_list_of_all_routers($self);
 
 
    my $MAX_P=0;
    my $MAX_P=0;
    foreach my $p (@routers){
    foreach my $p (@routers){
        my $Pnum=$self->object_get_attribute("$p",'PNUM');
        my $Pnum=$self->object_get_attribute("$p",'PNUM');
        $MAX_P =$Pnum  if($Pnum>$MAX_P );
        $MAX_P =$Pnum  if($Pnum>$MAX_P );
    }
    }
 
 
    my $NE= scalar @ends;
    my $NE= scalar @ends;
    my $NR= scalar @routers;
    my $NR= scalar @routers;
 
 
 
 
 
 
 
 
 
 
        #step 2         add routers
        #step 2         add routers
        my @nodes=get_list_of_all_routers($self);
        my @nodes=get_list_of_all_routers($self);
        my $i=0;
        my $i=0;
 
 
        my $ports="\treset,
        my $ports="\treset,
\tclk";
\tclk";
        my $wires='',
        my $wires='',
        my $routers='';
        my $routers='';
 
 
        foreach my $p (@ends){
        foreach my $p (@ends){
                my $instance= $self->object_get_attribute("$p","NAME");
                my $instance= $self->object_get_attribute("$p","NAME");
                $ports=$ports.",\n\t//$instance";
                $ports=$ports.",\n\t//$instance";
                $wires=$wires."
                $wires=$wires."
        /*******************
        /*******************
        *               $instance
        *               $instance
        *******************/
        *******************/
";
";
 
 
                $wires=$wires."\tinput  smartflit_chanel_t ${instance}_chan_in;\n";
                $wires=$wires."\tinput  smartflit_chanel_t ${instance}_chan_in;\n";
                $wires=$wires."\toutput smartflit_chanel_t ${instance}_chan_out;\n";
                $wires=$wires."\toutput smartflit_chanel_t ${instance}_chan_out;\n";
                $wires=$wires."\toutput router_event_t ${instance}_router_event;\n";
                $wires=$wires."\toutput router_event_t ${instance}_router_event;\n";
                $ports=$ports.",\n\t${instance}_chan_in,\n\t${instance}_chan_out,\n\t${instance}_router_event";
                $ports=$ports.",\n\t${instance}_chan_in,\n\t${instance}_chan_out,\n\t${instance}_router_event";
 
 
                foreach my $d (@ports){
                foreach my $d (@ports){
                                my $range = ($d->{pwidth} eq 1)? " " :  " [$d->{pwidth}-1 : 0]";
                                my $range = ($d->{pwidth} eq 1)? " " :  " [$d->{pwidth}-1 : 0]";
                                my $type=$d->{type};
                                my $type=$d->{type};
                                my $ctype= ($type eq 'input')? 'output' : 'input';
                                my $ctype= ($type eq 'input')? 'output' : 'input';
                                if( $d->{endp} eq "yes"){
                                if( $d->{endp} eq "yes"){
                                        #$wires=$wires."\t$type $range ${instance}_$d->{pname};\n";
                                        #$wires=$wires."\t$type $range ${instance}_$d->{pname};\n";
                                        #$wires=$wires."\t$ctype $range ${instance}_$d->{pconnect};\n";
                                        #$wires=$wires."\t$ctype $range ${instance}_$d->{pconnect};\n";
                                        #$ports=$ports.",\n\t${instance}_$d->{pname},\n\t${instance}_$d->{pconnect}";
                                        #$ports=$ports.",\n\t${instance}_$d->{pname},\n\t${instance}_$d->{pconnect}";
                                }
                                }
                }
                }
        }
        }
 
 
 
 
        foreach my $p (@nodes){
        foreach my $p (@nodes){
 
 
                my ($wire,$router) = get_router_instance_v($self,$p,$i,$NE,$NR,$MAX_P);
                my ($wire,$router) = get_router_instance_v($self,$p,$i,$NE,$NR,$MAX_P);
                $wires=$wires.$wire,
                $wires=$wires.$wire,
                $routers=$routers.$router;
                $routers=$routers.$router;
 
 
 
 
                $i++;
                $i++;
        }
        }
 
 
        my $assign="";
        my $assign="";
        foreach my $p (@ends){
        foreach my $p (@ends){
                my $instance= $self->object_get_attribute("$p","NAME");
                my $instance= $self->object_get_attribute("$p","NAME");
                my $pname= "Port[0]";
                my $pname= "Port[0]";
                my $connect = $self->{$p}{'PCONNECT'}{$pname};
                my $connect = $self->{$p}{'PCONNECT'}{$pname};
                if(defined $connect){
                if(defined $connect){
                        my ($cname,$pnode)=split(/\s*,\s*/,$connect);
                        my ($cname,$pnode)=split(/\s*,\s*/,$connect);
                        my $cinstance= $self->object_get_attribute("$cname","NAME");
                        my $cinstance= $self->object_get_attribute("$cname","NAME");
                        my ($cp)= sscanf("Port[%u]","$pnode");
                        my ($cp)= sscanf("Port[%u]","$pnode");
                        #$assign = $assign."//Connect $instance output ports 0 to  $cinstance input ports $cp\n";
                        #$assign = $assign."//Connect $instance output ports 0 to  $cinstance input ports $cp\n";
                        my $cpplus=$cp+1;
                        my $cpplus=$cp+1;
 
 
 
 
                        foreach my $p (@ports){
                        foreach my $p (@ports){
                                my $w=$p->{pwidth};
                                my $w=$p->{pwidth};
                                my $range = ($w eq 1)?  " " : "[$w-1 :           0 ]";
                                my $range = ($w eq 1)?  " " : "[$w-1 :           0 ]";
                                my $crange = ($w eq 1)? "[$cp]" : "[($cpplus*$w)-1 :     $cp*$w ]";
                                my $crange = ($w eq 1)? "[$cp]" : "[($cpplus*$w)-1 :     $cp*$w ]";
                                my $cport =  "${cinstance}_$p->{connect}";
                                my $cport =  "${cinstance}_$p->{connect}";
                                my $port ="${instance}_$p->{pconnect}";
                                my $port ="${instance}_$p->{pconnect}";
                                if($p->{type} eq 'input' ){
                                if($p->{type} eq 'input' ){
                                        # $assign=  $assign."\t\tassign  $port $range = $cport $crange;\n" if($p->{endp} eq "yes");             
                                        # $assign=  $assign."\t\tassign  $port $range = $cport $crange;\n" if($p->{endp} eq "yes");             
                                }else{
                                }else{
                                        # $assign=  $assign."\t\tassign  $cport $crange= $port $range;\n" if($p->{endp} eq "yes");              
                                        # $assign=  $assign."\t\tassign  $cport $crange= $port $range;\n" if($p->{endp} eq "yes");              
                                }
                                }
 
 
                         }      #@port
                         }      #@port
                }
                }
 
 
        }
        }
 
 
 
 
 
 
 
 
         print $fd "
         print $fd "
module   ${name}_noc
module   ${name}_noc
        import pronoc_pkg::*;
#(
 
        parameter NOC_ID=0
 
)
        (
        (
   $ports
        $ports
);
);
 
 
         function integer log2;
        `NOC_CONF
      input integer number; begin
 
         log2=(number <=1) ? 1: 0;
 
         while(2**log2<number) begin
 
            log2=log2+1;
 
         end
 
      end
 
    endfunction // log2
 
 
 
        localparam
 
                NE = $NE,
 
                NR = $NR,
 
                RAw=log2(NR);
 
 
 
 
 
 
 
 
 
    input reset,clk;
    input reset,clk;
 
 
    $wires
    $wires
 
 
    $routers
    $routers
 
 
    $assign
    $assign
 
 
endmodule
endmodule
";
";
        add_info($info,"$top file is created\n  ");
        add_info($info,"$top file is created\n  ");
        close $fd;
        close $fd;
 
 
 
 
}
}
 
 
 
 
 
 
 
 
sub get_router_instance_v {
sub get_router_instance_v {
        my ($self,$rname,$current_r,$NE,$NR,$MAX_P)=@_;
        my ($self,$rname,$current_r,$NE,$NR,$MAX_P)=@_;
 
 
 
 
        my $instance= $self->object_get_attribute("$rname","NAME");
        my $instance= $self->object_get_attribute("$rname","NAME");
        my $Pnum=$self->object_get_attribute("$rname",'PNUM');
        my $Pnum=$self->object_get_attribute("$rname",'PNUM');
 
 
        #read ruter parameters and ports
        #read ruter parameters and ports
         my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
         my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
     my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
     my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
 
 
        my $wires_v="
        my $wires_v="
        /*******************
        /*******************
        *               $instance
        *               $instance
        *******************/
        *******************/
\twire ${instance}_clk;
\twire ${instance}_clk;
\twire ${instance}_reset;
\twire ${instance}_reset;
 
 
\twire [RAw-1 :  0] ${instance}_current_r_addr;
\twire [RAw-1 :  0] ${instance}_current_r_addr;
 
 
\tsmartflit_chanel_t    ${instance}_chan_in   [$Pnum-1 : 0];
\tsmartflit_chanel_t    ${instance}_chan_in   [$Pnum-1 : 0];
\tsmartflit_chanel_t    ${instance}_chan_out  [$Pnum-1 : 0];
\tsmartflit_chanel_t    ${instance}_chan_out  [$Pnum-1 : 0];
\trouter_event_t ${instance}_router_event [$Pnum-1 : 0];
\trouter_event_t ${instance}_router_event [$Pnum-1 : 0];
 
 
";
";
 
 
 
 
 
 
 
 
        my $router_v="
        my $router_v="
        /*******************
        /*******************
        *               $instance
        *               $instance
        *******************/
        *******************/
        router_top #(
        router_top #(
 
                .NOC_ID(NOC_ID),
                .P($Pnum)
                .P($Pnum)
        )
        )
        $instance
        $instance
        (
        (
                .clk(${instance}_clk),
                .clk(${instance}_clk),
                .reset(${instance}_reset),
                .reset(${instance}_reset),
                .current_r_id($current_r),
                .current_r_id($current_r),
                .current_r_addr  (${instance}_current_r_addr),
                .current_r_addr  (${instance}_current_r_addr),
                .chan_in   (${instance}_chan_in),
                .chan_in   (${instance}_chan_in),
                .chan_out  (${instance}_chan_out),
                .chan_out  (${instance}_chan_out),
                .router_event (${instance}_router_event)
                .router_event (${instance}_router_event)
        );
        );
";
";
 
 
 
 
$router_v= $router_v."
$router_v= $router_v."
\t\tassign ${instance}_clk = clk;
\t\tassign ${instance}_clk = clk;
\t\tassign ${instance}_reset = reset;
\t\tassign ${instance}_reset = reset;
\t\tassign ${instance}_current_r_addr = $current_r;
\t\tassign ${instance}_current_r_addr = $current_r;
";
";
 
 
 
 
 
 
 
 
for (my $i=0;$i<$Pnum; $i++){
for (my $i=0;$i<$Pnum; $i++){
        my $pname= "Port[${i}]";
        my $pname= "Port[${i}]";
        my $connect = $self->{$rname}{'PCONNECT'}{$pname};
        my $connect = $self->{$rname}{'PCONNECT'}{$pname};
        my $iplus=$i+1;
        my $iplus=$i+1;
        if(defined $connect){
        if(defined $connect){
                my ($cname,$pnode)=split(/\s*,\s*/,$connect);
                my ($cname,$pnode)=split(/\s*,\s*/,$connect);
                my $cinstance= $self->object_get_attribute("$cname","NAME");
                my $cinstance= $self->object_get_attribute("$cname","NAME");
                my $ctype = $self->object_get_attribute("$cname",'TYPE');
                my $ctype = $self->object_get_attribute("$cname",'TYPE');
                my ($cp)= sscanf("Port[%u]","$pnode");
                my ($cp)= sscanf("Port[%u]","$pnode");
                $router_v = $router_v."//Connect $instance port $i to  $cinstance port $cp\n";
                $router_v = $router_v."//Connect $instance port $i to  $cinstance port $cp\n";
                if($ctype ne 'ENDP'){
                if($ctype ne 'ENDP'){
                        $router_v.=" \t\tassign ${instance}_chan_in [$i]   = ${cinstance}_chan_out [$cp];\n";
                        $router_v.=" \t\tassign ${instance}_chan_in [$i]   = ${cinstance}_chan_out [$cp];\n";
                }else{
                }else{
                        $router_v.=" \t\tassign ${instance}_chan_in [$i]  = ${cinstance}_chan_in;\n";
                        $router_v.=" \t\tassign ${instance}_chan_in [$i]  = ${cinstance}_chan_in;\n";
                        $router_v.=" \t\tassign ${cinstance}_chan_out = ${instance}_chan_out [$i];\n";
                        $router_v.=" \t\tassign ${cinstance}_chan_out = ${instance}_chan_out [$i];\n";
                        $router_v.=" \t\tassign ${cinstance}_router_event = ${instance}_router_event [$i];\n";
                        $router_v.=" \t\tassign ${cinstance}_router_event = ${instance}_router_event [$i];\n";
 
 
                }
                }
                my $cpplus=$cp+1;
                my $cpplus=$cp+1;
 
 
                #{name=> "flit_in_all", type=>"input", width=>"PFw", connect=>"flit_out_all",  pwidth=>"Fw" },
                #{name=> "flit_in_all", type=>"input", width=>"PFw", connect=>"flit_out_all",  pwidth=>"Fw" },
 
 
 
 
 
 
                foreach my $p (@ports){
                foreach my $p (@ports){
                        my $w=$p->{pwidth};
                        my $w=$p->{pwidth};
                        my $range = ($w eq 1)?  "[$i]" : "[($iplus*$w)-1 :               $i*$w ]";
                        my $range = ($w eq 1)?  "[$i]" : "[($iplus*$w)-1 :               $i*$w ]";
                        my $crange = ($ctype eq 'ENDP') ? '' :
                        my $crange = ($ctype eq 'ENDP') ? '' :
                        ($w eq 1)? "[$cp]"      : "[($cpplus*$w)-1 :     $cp*$w ]";
                        ($w eq 1)? "[$cp]"      : "[($cpplus*$w)-1 :     $cp*$w ]";
                        my $cport = ($ctype eq 'ENDP') ? "${cinstance}_$p->{pname}" : "${cinstance}_$p->{connect}";
                        my $cport = ($ctype eq 'ENDP') ? "${cinstance}_$p->{pname}" : "${cinstance}_$p->{connect}";
                        my $port ="${instance}_$p->{name}";
                        my $port ="${instance}_$p->{name}";
                        if($ctype eq 'ENDP' && $p->{endp} eq "no" && $p->{type} eq 'input' ){
                        if($ctype eq 'ENDP' && $p->{endp} eq "no" && $p->{type} eq 'input' ){
                                # $router_v=  $router_v."\t\tassign  $port $range = 0;\n";              
                                # $router_v=  $router_v."\t\tassign  $port $range = 0;\n";              
 
 
                        }else{
                        }else{
                                if($p->{type} eq 'input' ){
                                if($p->{type} eq 'input' ){
                                # $router_v=  $router_v."\t\tassign  $port $range = $cport $crange;\n";         
                                # $router_v=  $router_v."\t\tassign  $port $range = $cport $crange;\n";         
                                }else{
                                }else{
                                # $router_v=  $router_v."\t\tassign  $cport $crange= $port $range;\n";  
                                # $router_v=  $router_v."\t\tassign  $cport $crange= $port $range;\n";  
                                }
                                }
                        }
                        }
                 }      #@port
                 }      #@port
 
 
        }else {
        }else {
                        $router_v = $router_v."//Connect $instance port $i to  ground
                        $router_v = $router_v."//Connect $instance port $i to  ground
\t      assign  ${instance}_chan_in [$i]= {SMARTFLIT_CHANEL_w{1'b0}};\n";
\t      assign  ${instance}_chan_in [$i]= {SMARTFLIT_CHANEL_w{1'b0}};\n";
 
 
                        foreach my $p (@ports){
                        foreach my $p (@ports){
                                my $w=$p->{pwidth};
                                my $w=$p->{pwidth};
                                my $range = ($w eq 1)?  "[$i]" : "[($iplus*$w)-1 :               $i*$w ]";
                                my $range = ($w eq 1)?  "[$i]" : "[($iplus*$w)-1 :               $i*$w ]";
                                if($p->{type} eq 'input' ){
                                if($p->{type} eq 'input' ){
                                #       $router_v=  $router_v."\t\tassign  ${instance}_$p->{name} $range = \{$w\{1'b0\}\};\n";          
                                #       $router_v=  $router_v."\t\tassign  ${instance}_$p->{name} $range = \{$w\{1'b0\}\};\n";          
                                }
                                }
                        }
                        }
        }
        }
 
 
}
}
 
 
 
 
        return ($wires_v,$router_v);
        return ($wires_v,$router_v);
}
}
 
 
 
 
 
 
#*******************
#*******************
#       generate_topology_top_genvar_v
#       generate_topology_top_genvar_v
#********************
#********************
 
 
 
 
sub generate_topology_top_genvar_v{
sub generate_topology_top_genvar_v{
        my ($self,$info,$dir)=@_;
        my ($self,$info,$dir)=@_;
 
 
 
 
        #create topology top file
        #create topology top file
        my $name=$self->object_get_attribute('save_as');
        my $name=$self->object_get_attribute('save_as');
        my $r;
        my $r;
        my $top="$dir/${name}_noc_genvar.sv";
        my $top="$dir/${name}_noc_genvar.sv";
    open my $fd, ">$top" or $r = "$!\n";
    open my $fd, ">$top" or $r = "$!\n";
    if(defined $r) {
    if(defined $r) {
        add_colored_info($info,"Error in creating $top: $r",'red');
        add_colored_info($info,"Error in creating $top: $r",'red');
                return;
                return;
    }
    }
    print $fd autogen_warning();
    print $fd autogen_warning();
    print $fd get_license_header($top);
    print $fd get_license_header($top);
        print $fd '
        print $fd '
`include "pronoc_def.v"
`include "pronoc_def.v"
';
';
 
 
    my $param_str ="\tparameter TOPOLOGY = \"$name\",
    my $param_str ="\tparameter TOPOLOGY = \"$name\",
\tparameter ROUTE_NAME = \"${name}_DETERMINISTIC\"";
\tparameter ROUTE_NAME = \"${name}_DETERMINISTIC\"";
 
 
   my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
   my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
   my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
   my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
 
 
        foreach my $d (@parameters){
        foreach my $d (@parameters){
                $param_str = $param_str.",\n\tparameter $d->{param_name} = $d->{value}";
                $param_str = $param_str.",\n\tparameter $d->{param_name} = $d->{value}";
        }
        }
 
 
    my @ends=get_list_of_all_endpoints($self);
    my @ends=get_list_of_all_endpoints($self);
    my @routers=get_list_of_all_routers($self);
    my @routers=get_list_of_all_routers($self);
 
 
    my $MAX_P=0;
    my $MAX_P=0;
    foreach my $p (@routers){
    foreach my $p (@routers){
        my $Pnum=$self->object_get_attribute("$p",'PNUM');
        my $Pnum=$self->object_get_attribute("$p",'PNUM');
        $MAX_P =$Pnum  if($Pnum>$MAX_P );
        $MAX_P =$Pnum  if($Pnum>$MAX_P );
    }
    }
 
 
    my $NE= scalar @ends;
    my $NE= scalar @ends;
    my $NR= scalar @routers;
    my $NR= scalar @routers;
 
 
 
 
 
 
        my @nodes=get_list_of_all_routers($self);
        my @nodes=get_list_of_all_routers($self);
        my $i=0;
        my $i=0;
 
 
        my $ports="\treset,
        my $ports="\treset,
\tclk,
\tclk,
\tchan_in_all,
\tchan_in_all,
\tchan_out_all,
\tchan_out_all,
\trouter_event
\trouter_event
";
";
    my $ports_def="
    my $ports_def="
\tinput  reset;
\tinput  reset;
\tinput  clk;
\tinput  clk;
\tinput  smartflit_chanel_t chan_in_all  [NE-1 : 0];
\tinput  smartflit_chanel_t chan_in_all  [NE-1 : 0];
\toutput smartflit_chanel_t chan_out_all [NE-1 : 0];
\toutput smartflit_chanel_t chan_out_all [NE-1 : 0];
 
 
//Events
//Events
\toutput  router_event_t  router_event [NR-1 : 0][MAX_P-1 : 0];
\toutput  router_event_t  router_event [NR-1 : 0][MAX_P-1 : 0];
 
 
//all routers port
//all routers port
\tsmartflit_chanel_t    router_chan_in   [NR-1 :0][MAX_P-1 : 0];
\tsmartflit_chanel_t    router_chan_in   [NR-1 :0][MAX_P-1 : 0];
\tsmartflit_chanel_t    router_chan_out  [NR-1 :0][MAX_P-1 : 0];
\tsmartflit_chanel_t    router_chan_out  [NR-1 :0][MAX_P-1 : 0];
 
 
 
 
\twire [RAw-1 : 0] current_r_addr [NR-1 : 0];
\twire [RAw-1 : 0] current_r_addr [NR-1 : 0];
 
 
 
 
";
";
 
 
        my $router_wires="";
        my $router_wires="";
        my $endps_wires="";
        my $endps_wires="";
 
 
 
 
 
 
 
 
        foreach my $d (@ports){
        foreach my $d (@ports){
                my $range = ($d->{width} eq 1)? " " :  " [$d->{width}-1 : 0]";
                my $range = ($d->{width} eq 1)? " " :  " [$d->{width}-1 : 0]";
                my $pdef_range = ($d->{pwidth} eq 1)? "[NE-1 : 0]" : "[(NE*$d->{pwidth})-1 : 0]";
                my $pdef_range = ($d->{pwidth} eq 1)? "[NE-1 : 0]" : "[(NE*$d->{pwidth})-1 : 0]";
                my $endp_range = "[$d->{pwidth}-1 : 0]";
                my $endp_range = "[$d->{pwidth}-1 : 0]";
                my $type=$d->{type};
                my $type=$d->{type};
                my $ctype= ($type eq 'input')? 'output' : 'input';
                my $ctype= ($type eq 'input')? 'output' : 'input';
                if( $d->{endp} eq "yes"){
                if( $d->{endp} eq "yes"){
                        #$ports_def=$ports_def."\t$type $pdef_range $d->{name};\n";
                        #$ports_def=$ports_def."\t$type $pdef_range $d->{name};\n";
                        #$ports_def=$ports_def."\t$ctype $pdef_range $d->{connect};\n";                 
                        #$ports_def=$ports_def."\t$ctype $pdef_range $d->{connect};\n";                 
                        #$ports=$ports.",\n\t$d->{name},\n\t$d->{connect}";
                        #$ports=$ports.",\n\t$d->{name},\n\t$d->{connect}";
                }
                }
                        if($d->{width} eq 1){
                        if($d->{width} eq 1){
                                #$router_wires=$router_wires. "\twire [NR-1 :0] router_$d->{name};\n";
                                #$router_wires=$router_wires. "\twire [NR-1 :0] router_$d->{name};\n";
                                #$router_wires=$router_wires. "\twire [NR-1 :0] router_$d->{connect};\n";
                                #$router_wires=$router_wires. "\twire [NR-1 :0] router_$d->{connect};\n";
                        }else{
                        }else{
                                #$router_wires=$router_wires. "\twire $range router_$d->{name} [NR-1 :0];\n";
                                #$router_wires=$router_wires. "\twire $range router_$d->{name} [NR-1 :0];\n";
                                #$router_wires=$router_wires. "\twire $range router_$d->{connect} [NR-1 :0];\n";
                                #$router_wires=$router_wires. "\twire $range router_$d->{connect} [NR-1 :0];\n";
                        }
                        }
                if( $d->{endp} eq "yes"){
                if( $d->{endp} eq "yes"){
                    if($d->{pwidth} eq 1){
                    if($d->{pwidth} eq 1){
                        #$endps_wires=$endps_wires. "\twire [NE-1 :0] ni_$d->{pname};\n";
                        #$endps_wires=$endps_wires. "\twire [NE-1 :0] ni_$d->{pname};\n";
                                #$endps_wires=$endps_wires. "\twire [NE-1 :0] ni_$d->{pconnect};\n";
                                #$endps_wires=$endps_wires. "\twire [NE-1 :0] ni_$d->{pconnect};\n";
                    }else{
                    }else{
                                #$endps_wires=$endps_wires. "\twire $endp_range ni_$d->{pname} [NE-1 :0];\n";
                                #$endps_wires=$endps_wires. "\twire $endp_range ni_$d->{pname} [NE-1 :0];\n";
                                #$endps_wires=$endps_wires. "\twire $endp_range ni_$d->{pconnect} [NE-1 :0];\n";
                                #$endps_wires=$endps_wires. "\twire $endp_range ni_$d->{pconnect} [NE-1 :0];\n";
                    }
                    }
 
 
                }
                }
        }
        }
 
 
 
 
 
 
 
 
        #step 2         add routers
        #step 2         add routers
        my $Tnum=1;
        my $Tnum=1;
 
 
        my $routers='
        my $routers='
        genvar i;
        genvar i;
        generate
        generate
        ';
        ';
        my $offset=0;
        my $offset=0;
        my $assign="";
        my $assign="";
        my $assign_r2r="";
        my $assign_r2r="";
        my $assign_r2e="";
        my $assign_r2e="";
        my $init_h="";
        my $init_h="";
        my $init_gnd_h="";
        my $init_gnd_h="";
        my %new_h;
        my %new_h;
        my $addr=0;
        my $addr=0;
        for ( my $i=2;$i<=12; $i++){
        for ( my $i=2;$i<=12; $i++){
                my $n= $self->object_get_attribute("ROUTER${i}","NUM");
                my $n= $self->object_get_attribute("ROUTER${i}","NUM");
                $n=0 if(!defined $n);
                $n=0 if(!defined $n);
                if($n>0){
                if($n>0){
 
 
                        for(my $rr=0; $rr<$n; $rr=$rr+1) {
                        for(my $rr=0; $rr<$n; $rr=$rr+1) {
                                my $pos= ($offset==0)? $rr : $rr+$offset;
                                my $pos= ($offset==0)? $rr : $rr+$offset;
                                $new_h{"TNUM_${pos}"}="$Tnum";
                                $new_h{"TNUM_${pos}"}="$Tnum";
                                $new_h{"RNUM_${pos}"}="$rr";
                                $new_h{"RNUM_${pos}"}="$rr";
 
 
                                $init_h.="router${Tnum}[$rr]->current_r_addr=$addr;\n";
                                $init_h.="router${Tnum}[$rr]->current_r_addr=$addr;\n";
                                $init_h.="router${Tnum}[$rr]->current_r_id=$addr;\n";
                                $init_h.="router${Tnum}[$rr]->current_r_id=$addr;\n";
                                $addr++;
                                $addr++;
                        }
                        }
                        $offset+=       $n;
                        $offset+=       $n;
                        $Tnum++;
                        $Tnum++;
                }
                }
        }
        }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
        $offset=0;
        $offset=0;
        my $R_num=0;
        my $R_num=0;
        for ( my $i=2;$i<=12; $i++){
        for ( my $i=2;$i<=12; $i++){
                my $n= $self->object_get_attribute("ROUTER${i}","NUM");
                my $n= $self->object_get_attribute("ROUTER${i}","NUM");
                $n=0 if(!defined $n);
                $n=0 if(!defined $n);
                if($n>0){
                if($n>0){
                        my $router_pos= ($offset==0)? 'i' : "i+$offset";
                        my $router_pos= ($offset==0)? 'i' : "i+$offset";
                        #my $instant=get_router_genvar_instance_v($self,$i,$router_pos,$NE,$NR,$MAX_P);
                        #my $instant=get_router_genvar_instance_v($self,$i,$router_pos,$NE,$NR,$MAX_P);
                        my $p = $i-1;
                        my $p = $i-1;
                        $routers=$routers."
                        $routers=$routers."
\tfor( i=0; i<$n; i=i+1) begin : router_${i}_port_lp
\tfor( i=0; i<$n; i=i+1) begin : router_${i}_port_lp
        localparam RID = $router_pos;
        localparam RID = $router_pos;
        assign current_r_addr [RID] = RID[RAw-1: 0];
        assign current_r_addr [RID] = RID[RAw-1: 0];
 
 
        router_top #(
        router_top #(
 
                .NOC_ID(NOC_ID),
                .P($i)
                .P($i)
        )
        )
        router_${i}_port
        router_${i}_port
        (
        (
                .clk(clk),
                .clk(clk),
                .reset(reset),
                .reset(reset),
                .current_r_id(RID),
                .current_r_id(RID),
                .current_r_addr(current_r_addr\[RID\]),
                .current_r_addr(current_r_addr\[RID\]),
                .chan_in  (router_chan_in \[RID\] \[$p : 0\]),
                .chan_in  (router_chan_in \[RID\] \[$p : 0\]),
                .chan_out (router_chan_out\[RID\] \[$p : 0\]),
                .chan_out (router_chan_out\[RID\] \[$p : 0\]),
                .router_event(router_event\[RID\] \[$p : 0\])
                .router_event(router_event\[RID\] \[$p : 0\])
        );
        );
 
 
 
 
 
 
\tend
\tend
                        ";
                        ";
 
 
                        for ( my $j=0;$j<$n; $j++){
                        for ( my $j=0;$j<$n; $j++){
                                my $rname ="ROUTER${i}_$j";
                                my $rname ="ROUTER${i}_$j";
                                my ($ass_v,$r2r_h,$r2e_h, $int_h,$gnd_h);
                                my ($ass_v,$r2r_h,$r2e_h, $int_h,$gnd_h);
                                ($ass_v,$r2r_h,$r2e_h, $int_h,$gnd_h,$R_num) = get_wires_assignment_genvar_v($self,$rname,0,\%new_h,$R_num);
                                ($ass_v,$r2r_h,$r2e_h, $int_h,$gnd_h,$R_num) = get_wires_assignment_genvar_v($self,$rname,0,\%new_h,$R_num);
 
 
                                $assign=$assign.$ass_v;
                                $assign=$assign.$ass_v;
                                $assign_r2r.=$r2r_h;
                                $assign_r2r.=$r2r_h;
                                $assign_r2e.=$r2e_h;
                                $assign_r2e.=$r2e_h;
                                $init_h.=$int_h;
                                $init_h.=$int_h;
                                $init_gnd_h.=$gnd_h;
                                $init_gnd_h.=$gnd_h;
                        }
                        }
 
 
                $offset+=       $n;
                $offset+=       $n;
 
 
                }
                }
        }
        }
 
 
 
 
$routers.="endgenerate\n";
$routers.="endgenerate\n";
 
 
 
 
 
 
 
 
 
 
 
 
         print $fd "
         print $fd "
module   ${name}_noc_genvar
module   ${name}_noc_genvar
   import pronoc_pkg::*;
#(
        (
        parameter NOC_ID=0
 
)(
 
 
    reset,
    reset,
    clk,
    clk,
    chan_in_all,
    chan_in_all,
    chan_out_all,
    chan_out_all,
    router_event
    router_event
);
);
 
 
         function integer log2;
`NOC_CONF
      input integer number; begin
 
         log2=(number <=1) ? 1: 0;
 
         while(2**log2<number) begin
 
            log2=log2+1;
 
         end
 
      end
 
    endfunction // log2
 
 
 
        localparam
 
                NE = $NE,
 
                NR = $NR,
 
                RAw=log2(NR),
 
                MAX_P=$MAX_P;
 
 
 
 
 
$ports_def
$ports_def
 
 
$router_wires
$router_wires
 
 
$endps_wires
$endps_wires
 
 
$routers
$routers
 
 
$assign
$assign
 
 
 
 
 
 
endmodule
endmodule
";
";
 
 
        close $fd;
        close $fd;
        add_info($info,"$top file is created\n  ");
        add_info($info,"$top file is created\n  ");
 
 
        my $project_dir = get_project_dir();
        my $project_dir = get_project_dir();
        $project_dir= "$project_dir/mpsoc";
        $project_dir= "$project_dir/mpsoc";
        my $src_verilator_dir="$project_dir/src_verilator/topology/custom";
        my $src_verilator_dir="$project_dir/src_verilator/topology/custom";
        mkpath("$src_verilator_dir",1,01777) unless -f $src_verilator_dir;
        mkpath("$src_verilator_dir",1,01777) unless -f $src_verilator_dir;
    $top="$src_verilator_dir/${name}_noc.h";
    $top="$src_verilator_dir/${name}_noc.h";
    open $fd, ">$top" or $r = "$!\n";
    open $fd, ">$top" or $r = "$!\n";
    if(defined $r) {
    if(defined $r) {
        add_colored_info($info,"Error in creating $top: $r",'red');
        add_colored_info($info,"Error in creating $top: $r",'red');
                return;
                return;
    }
    }
 
 
  my $fr2r="";
  my $fr2r="";
  for (my $i=0;$i<$R_num ; $i++){
  for (my $i=0;$i<$R_num ; $i++){
        $fr2r.="\n" if($i%10==0);
        $fr2r.="\n" if($i%10==0);
        $fr2r.=($i==0) ? "single_r2r$i" : ",single_r2r$i";
        $fr2r.=($i==0) ? "single_r2r$i" : ",single_r2r$i";
 
 
  }
  }
 
 
  my $fr2e="";
  my $fr2e="";
  for (my $i=0;$i<$NE ; $i++){
  for (my $i=0;$i<$NE ; $i++){
        $fr2e.="\n" if($i%10==0);
        $fr2e.="\n" if($i%10==0);
        $fr2e.=($i==0) ? "single_r2e$i" : ",single_r2e$i";
        $fr2e.=($i==0) ? "single_r2e$i" : ",single_r2e$i";
  }
  }
 
 
 
 
    print $fd "
    print $fd "
 
 
 
 
$assign_r2r
$assign_r2r
 
 
$assign_r2e
$assign_r2e
 
 
 
 
void (*r2r_func_ptr[$R_num])() = {$fr2r};
void (*r2r_func_ptr[$R_num])() = {$fr2r};
void (*r2e_func_ptr[$NE])() = {$fr2e};
void (*r2e_func_ptr[$NE])() = {$fr2e};
 
 
void topology_connect_r2r (int n){
void topology_connect_r2r (int n){
         (*r2r_func_ptr[n])();
         (*r2r_func_ptr[n])();
}
}
 
 
void topology_connect_r2e (int n){
void topology_connect_r2e (int n){
         (*r2e_func_ptr[n])();
         (*r2e_func_ptr[n])();
}
}
 
 
 
 
 
 
void topology_init(void){
void topology_init(void){
        $init_h
        $init_h
        R2R_TABLE_SIZ=$R_num;
        R2R_TABLE_SIZ=$R_num;
        $init_gnd_h
        $init_gnd_h
}
}
";
";
    close $fd;
    close $fd;
        add_info($info,"$top file is created\n  ");
        add_info($info,"$top file is created\n  ");
 
 
}
}
 
 
 
 
 
 
 
 
sub get_router_genvar_instance_v{
sub get_router_genvar_instance_v{
        my ($self,$Pnum,$router_pos,$NE,$NR,$MAX_P)=@_;
        my ($self,$Pnum,$router_pos,$NE,$NR,$MAX_P)=@_;
 
 
        #read ruter parameters and ports
        #read ruter parameters and ports
        my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
        my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
    my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
    my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
 
 
 
 
 
 
        my $router_v="
        my $router_v="
 
 
        router_top #(
        router_top #(
 
                .NOC_ID(NOC_ID),
                .P($Pnum)
                .P($Pnum)
        )
        )
        router_${Pnum}_port
        router_${Pnum}_port
        (
        (
                .clk(clk),
                .clk(clk),
                .reset(reset),
                .reset(reset),
                .current_r_addr($router_pos),
                .current_r_addr($router_pos),
                .current_r_id($router_pos),
                .current_r_id($router_pos),
                .chan_in (router_chan_in\[$router_pos\]),
                .chan_in (router_chan_in\[$router_pos\]),
                .chan_out(router_chan_out\[$router_pos\]),
                .chan_out(router_chan_out\[$router_pos\]),
                .router_event(router_event\[$router_pos\])
                .router_event(router_event\[$router_pos\])
        );
        );
 
 
 
 
 
 
";
";
 
 
return $router_v;
return $router_v;
 
 
 
 
}
}
 
 
 
 
sub get_wires_assignment_genvar_v{
sub get_wires_assignment_genvar_v{
        my ($self,$rname,$reverse,$cref,$R_num)=@_;
        my ($self,$rname,$reverse,$cref,$R_num)=@_;
    $reverse = 0 if(!defined $reverse);
    $reverse = 0 if(!defined $reverse);
        my $instance= $self->object_get_attribute("$rname","NAME");
        my $instance= $self->object_get_attribute("$rname","NAME");
        my $Pnum=$self->object_get_attribute("$rname",'PNUM');
        my $Pnum=$self->object_get_attribute("$rname",'PNUM');
 
 
        #read ruter parameters and ports
        #read ruter parameters and ports
         my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
         my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
     my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
     my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
 
 
        my $assign="";
        my $assign="";
        my $r2e_h="";
        my $r2e_h="";
        my $r2r_h="";
        my $r2r_h="";
        my $init_h="";
        my $init_h="";
        my $gnd_h="";
        my $gnd_h="";
 
 
 
 
 
 
        my @ends=get_list_of_all_endpoints($self);
        my @ends=get_list_of_all_endpoints($self);
    my @routers=get_list_of_all_routers($self);
    my @routers=get_list_of_all_routers($self);
 
 
        my $pos = get_scolar_pos($rname,@routers);
        my $pos = get_scolar_pos($rname,@routers);
        my $type = "ROUTER";
        my $type = "ROUTER";
        if(!defined $pos){
        if(!defined $pos){
                $pos = get_scolar_pos($rname,@ends);
                $pos = get_scolar_pos($rname,@ends);
                $type = "ENDP";
                $type = "ENDP";
        }
        }
 
 
        my %rinfo = %{$cref} if (defined $cref);
        my %rinfo = %{$cref} if (defined $cref);
 
 
for (my $i=0;$i<$Pnum; $i++){
for (my $i=0;$i<$Pnum; $i++){
        my $pname= "Port[${i}]";
        my $pname= "Port[${i}]";
        my $connect = $self->{$rname}{'PCONNECT'}{$pname};
        my $connect = $self->{$rname}{'PCONNECT'}{$pname};
        my $iplus=$i+1;
        my $iplus=$i+1;
        if(defined $connect){
        if(defined $connect){
                my ($cname,$pnode)=split(/\s*,\s*/,$connect);
                my ($cname,$pnode)=split(/\s*,\s*/,$connect);
                my $cinstance= $self->object_get_attribute("$cname","NAME");
                my $cinstance= $self->object_get_attribute("$cname","NAME");
                my $ctype = $self->object_get_attribute("$cname",'TYPE');
                my $ctype = $self->object_get_attribute("$cname",'TYPE');
                my ($cp)= sscanf("Port[%u]","$pnode");
                my ($cp)= sscanf("Port[%u]","$pnode");
                $assign.="//Connect $instance input ports $i to  $cinstance output ports $cp\n";
                $assign.="//Connect $instance input ports $i to  $cinstance output ports $cp\n";
 
 
 
 
                my $cpos =($ctype eq 'ENDP')?  get_scolar_pos($cname,@ends) :  get_scolar_pos($cname,@routers);
                my $cpos =($ctype eq 'ENDP')?  get_scolar_pos($cname,@ends) :  get_scolar_pos($cname,@routers);
 
 
                my $cpplus=$cp+1;
                my $cpplus=$cp+1;
                my $cposplus = $cpos+1;
                my $cposplus = $cpos+1;
                my $posplus=$pos+1;
                my $posplus=$pos+1;
                #{name=> "flit_in_all", type=>"input", width=>"PFw", connect=>"flit_out_all",  pwidth=>"Fw" },
                #{name=> "flit_in_all", type=>"input", width=>"PFw", connect=>"flit_out_all",  pwidth=>"Fw" },
 
 
                my $TNUM_pos  = $rinfo{"TNUM_${pos}"};
                my $TNUM_pos  = $rinfo{"TNUM_${pos}"};
                my $RNUM_pos  = $rinfo{"RNUM_${pos}"};
                my $RNUM_pos  = $rinfo{"RNUM_${pos}"};
                my $TNUM_cpos = $rinfo{"TNUM_${cpos}"};
                my $TNUM_cpos = $rinfo{"TNUM_${cpos}"};
                my $RNUM_cpos = $rinfo{"RNUM_${cpos}"};
                my $RNUM_cpos = $rinfo{"RNUM_${cpos}"};
 
 
                #$assign = $assign."//connet  $instance input port $i to  $cinstance output port $cp\n";
                #$assign = $assign."//connet  $instance input port $i to  $cinstance output port $cp\n";
                if($type  ne 'ENDP'  &&  $ctype eq 'ENDP'){
                if($type  ne 'ENDP'  &&  $ctype eq 'ENDP'){
 
 
                        $assign=  $assign."\t\tassign  router_chan_in \[$pos\]\[$i\] = chan_in_all \[$cpos\];\n" if($reverse==0);
                        $assign=  $assign."\t\tassign  router_chan_in \[$pos\]\[$i\] = chan_in_all \[$cpos\];\n" if($reverse==0);
                        $assign=  $assign."\t\tassign  chan_in_all \[$cpos\] = router_chan_in \[$pos\]\[$i\];\n" if($reverse==1);
                        $assign=  $assign."\t\tassign  chan_in_all \[$cpos\] = router_chan_in \[$pos\]\[$i\];\n" if($reverse==1);
 
 
                        $assign=  $assign."\t\tassign  chan_out_all \[$cpos\] = router_chan_out \[$pos\]\[$i\];\n" if($reverse==0);
                        $assign=  $assign."\t\tassign  chan_out_all \[$cpos\] = router_chan_out \[$pos\]\[$i\];\n" if($reverse==0);
                        $assign=  $assign."\t\tassign  router_chan_out \[$pos\]\[$i\] = chan_out_all \[$cpos\];\n" if($reverse==1);
                        $assign=  $assign."\t\tassign  router_chan_out \[$pos\]\[$i\] = chan_out_all \[$cpos\];\n" if($reverse==1);
 
 
                        $r2e_h.="//Connect $instance input ports $i to  $cinstance output ports $cp\n";
                        $r2e_h.="//Connect $instance input ports $i to  $cinstance output ports $cp\n";
                        $r2e_h.=  "void single_r2e$cpos(void) {connect_r2e($TNUM_pos,$RNUM_pos,$i,$cpos);}\n"   if (defined $TNUM_pos);
                        $r2e_h.=  "void single_r2e$cpos(void) {connect_r2e($TNUM_pos,$RNUM_pos,$i,$cpos);}\n"   if (defined $TNUM_pos);
 
 
 
 
                }elsif ($type  ne 'ENDP'  &&  $ctype ne 'ENDP'){
                }elsif ($type  ne 'ENDP'  &&  $ctype ne 'ENDP'){
                        $assign=  $assign."\t\tassign  router_chan_in \[$pos\]\[$i\] = router_chan_out \[$cpos\]\[$cp\];\n" if($reverse==0);
                        $assign=  $assign."\t\tassign  router_chan_in \[$pos\]\[$i\] = router_chan_out \[$cpos\]\[$cp\];\n" if($reverse==0);
                        $assign=  $assign."\t\tassign  router_chan_out \[$cpos\]\[$cp\] = router_chan_in \[$pos\]\[$i\];\n" if($reverse==1);
                        $assign=  $assign."\t\tassign  router_chan_out \[$cpos\]\[$cp\] = router_chan_in \[$pos\]\[$i\];\n" if($reverse==1);
                        $r2r_h.="//Connect $instance input ports $i to  $cinstance output ports $cp\n";
                        $r2r_h.="//Connect $instance input ports $i to  $cinstance output ports $cp\n";
                        $r2r_h.=  "void single_r2r$R_num(void){conect_r2r($TNUM_pos,$RNUM_pos,$i,$TNUM_cpos,$RNUM_cpos,$cp);}\n" if (defined $TNUM_pos);
                        $r2r_h.=  "void single_r2r$R_num(void){conect_r2r($TNUM_pos,$RNUM_pos,$i,$TNUM_cpos,$RNUM_cpos,$cp);}\n" if (defined $TNUM_pos);
                        $init_h.="\tr2r_cnt_all[$R_num] =(r2r_cnt_table_t){.id1=$pos, .t1=$TNUM_pos, .r1=$RNUM_pos, .p1=$i,.id2=$cpos, .t2=$TNUM_cpos, .r2=$RNUM_cpos, .p2=$cp };\n";
                        $init_h.="\tr2r_cnt_all[$R_num] =(r2r_cnt_table_t){.id1=$pos, .t1=$TNUM_pos, .r1=$RNUM_pos, .p1=$i,.id2=$cpos, .t2=$TNUM_cpos, .r2=$RNUM_cpos, .p2=$cp };\n";
                        $R_num++;
                        $R_num++;
                }
                }
 
 
 
 
 
 
 
 
 
 
        }else {
        }else {
                        my $TNUM_pos  = $rinfo{"TNUM_${pos}" };
                        my $TNUM_pos  = $rinfo{"TNUM_${pos}" };
                        my $RNUM_pos  = $rinfo{"RNUM_${pos}" };
                        my $RNUM_pos  = $rinfo{"RNUM_${pos}" };
 
 
                        $assign = $assign."//Connect $instance port $i to  ground\n";
                        $assign = $assign."//Connect $instance port $i to  ground\n";
                        $assign=  $assign."\t\tassign  router_chan_in  \[$pos\]\[$i\] ={SMARTFLIT_CHANEL_w{1'b0}};\n    " if($reverse==0);
                        $assign=  $assign."\t\tassign  router_chan_in  \[$pos\]\[$i\] ={SMARTFLIT_CHANEL_w{1'b0}};\n    " if($reverse==0);
                        $assign=  $assign."\t\tassign  router_chan_out \[$pos\]\[$i\] ={SMARTFLIT_CHANEL_w{1'b0}};\n    " if($reverse==1);
                        $assign=  $assign."\t\tassign  router_chan_out \[$pos\]\[$i\] ={SMARTFLIT_CHANEL_w{1'b0}};\n    " if($reverse==1);
 
 
                        $gnd_h.="//Connect $instance port $i to  ground\n";
                        $gnd_h.="//Connect $instance port $i to  ground\n";
                        $gnd_h.=  "\tconnect_r2gnd($TNUM_pos,$RNUM_pos,$i);\n" if (defined $TNUM_pos);
                        $gnd_h.=  "\tconnect_r2gnd($TNUM_pos,$RNUM_pos,$i);\n" if (defined $TNUM_pos);
        }
        }
 
 
}
}
 
 
 
 
 
 
        return ($assign,$r2r_h,$r2e_h,$init_h,$gnd_h,$R_num);
        return ($assign,$r2r_h,$r2e_h,$init_h,$gnd_h,$R_num);
}
}
 
 
 
 
 
 
 
 
 
 
sub generate_routing_v {
sub generate_routing_v {
        my ($self,$info,$dir)=@_;
        my ($self,$info,$dir)=@_;
 
 
        my @ends=get_list_of_all_endpoints($self);
        my @ends=get_list_of_all_endpoints($self);
        my @routers=get_list_of_all_routers($self);
        my @routers=get_list_of_all_routers($self);
 
 
#########################       
#########################       
#  conventional_routing
#  conventional_routing
#########################
#########################
 
 
 
 
        #create routing file
        #create routing file
        my $name=$self->object_get_attribute('save_as');
        my $name=$self->object_get_attribute('save_as');
        my $rname=$self->object_get_attribute('routing_name');
        my $rname=$self->object_get_attribute('routing_name');
        my $Vname="T${name}R${rname}";
        my $Vname="T${name}R${rname}";
 
 
        my $r;
        my $r;
        my $top="$dir/${Vname}_conventional_routing.v";
        my $top="$dir/${Vname}_conventional_routing.v";
    open my $fd, ">$top" or $r = "$!\n";
    open my $fd, ">$top" or $r = "$!\n";
    if(defined $r) {
    if(defined $r) {
        add_colored_info($info,"Error in creating $top: $r",'red');
        add_colored_info($info,"Error in creating $top: $r",'red');
                return;
                return;
    }
    }
    print $fd autogen_warning();
    print $fd autogen_warning();
    print $fd get_license_header($top);
    print $fd get_license_header($top);
 
 
 
 
 
 
 
 
 
 
        my $route_str="\talways@(*)begin
        my $route_str="\talways@(*)begin
\t\tdestport=0;
\t\tdestport=0;
\t\tcase(src_e_addr) //source address of each individual NI is fixed. So this CASE will be optimized by the synthesizer for each endpoint.
\t\tcase(src_e_addr) //source address of each individual NI is fixed. So this CASE will be optimized by the synthesizer for each endpoint.
";
";
 
 
        foreach my $src (@ends){
        foreach my $src (@ends){
                my $PNUM=$self->object_get_attribute($src,"PNUM");
                my $PNUM=$self->object_get_attribute($src,"PNUM");
                my $src_num=get_scolar_pos($src,@ends);
                my $src_num=get_scolar_pos($src,@ends);
            my %route;
            my %route;
                $route_str=$route_str."\t\t$src_num: begin
                $route_str=$route_str."\t\t$src_num: begin
\t\t\tcase(dest_e_addr)
\t\t\tcase(dest_e_addr)
";
";
 
 
                foreach my $dst (@ends){
                foreach my $dst (@ends){
                            my $dest_num = get_scolar_pos($dst,@ends);
                            my $dest_num = get_scolar_pos($dst,@ends);
                                my $ref = $self->object_get_attribute('Route',"${src}::$dst");
                                my $ref = $self->object_get_attribute('Route',"${src}::$dst");
                                next if(!defined $ref);
                                next if(!defined $ref);
                                my @path = @{$ref};
                                my @path = @{$ref};
                                my ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$path[1],$path[2] );
                                my ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$path[1],$path[2] );
                                #print " ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$path[1],$path[2] );\n";
                                #print " ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$path[1],$path[2] );\n";
                                $route{$p1} = (defined $route{$p1})? $route{$p1}.",$dest_num" : "$dest_num";
                                $route{$p1} = (defined $route{$p1})? $route{$p1}.",$dest_num" : "$dest_num";
                }
                }
                foreach my $q (sort {$a <=> $b} keys %route){
                foreach my $q (sort {$a <=> $b} keys %route){
                        $route_str=$route_str."\t\t\t$route{$q}: begin
                        $route_str=$route_str."\t\t\t$route{$q}: begin
\t\t\t\tdestport= $q;
\t\t\t\tdestport= $q;
\t\t\tend
\t\t\tend
";
";
                }
                }
                $route_str=$route_str."
                $route_str=$route_str."
\t\t\tdefault: begin
\t\t\tdefault: begin
\t\t\t\tdestport= {DSTPw{1\'bX}};
\t\t\t\tdestport= {DSTPw{1\'bX}};
\t\t\tend
\t\t\tend
\t\t\tendcase\n\t\tend//$src_num\n";
\t\t\tendcase\n\t\tend//$src_num\n";
        }
        }
        $route_str=$route_str."
        $route_str=$route_str."
\t\tdefault: begin
\t\tdefault: begin
\t\t\tdestport= {DSTPw{1\'bX}};
\t\t\tdestport= {DSTPw{1\'bX}};
\t\tend
\t\tend
\t\tendcase\n\tend\n";
\t\tendcase\n\tend\n";
 
 
 
 
 
 
         print $fd "module ${Vname}_conventional_routing  #(
         print $fd "module ${Vname}_conventional_routing  #(
\tparameter RAw = 3,
\tparameter RAw = 3,
\tparameter EAw = 3,
\tparameter EAw = 3,
\tparameter DSTPw=4
\tparameter DSTPw=4
)
)
(
(
\tdest_e_addr,
\tdest_e_addr,
\tsrc_e_addr,
\tsrc_e_addr,
\tdestport
\tdestport
);
);
 
 
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\toutput reg [DSTPw-1 :0] destport;
\toutput reg [DSTPw-1 :0] destport;
 
 
 
 
$route_str
$route_str
 
 
 
 
endmodule
endmodule
 
 
";
";
close($fd);
close($fd);
add_info($info,"$top file is created\n  ");
add_info($info,"$top file is created\n  ");
 
 
##################
##################
#   look_ahead_routing
#   look_ahead_routing
###################
###################
 
 
#create routing file
#create routing file
        $top="$dir/${Vname}_look_ahead_routing.v";
        $top="$dir/${Vname}_look_ahead_routing.v";
    open  $fd, ">$top" or $r = "$!\n";
    open  $fd, ">$top" or $r = "$!\n";
    if(defined $r) {
    if(defined $r) {
        add_colored_info($info,"Error in creating $top: $r",'red');
        add_colored_info($info,"Error in creating $top: $r",'red');
                return;
                return;
    }
    }
    print $fd autogen_warning();
    print $fd autogen_warning();
    print $fd get_license_header($top);
    print $fd get_license_header($top);
 
 
 
 
        $route_str="\talways@(*)begin
        $route_str="\talways@(*)begin
\t\tdestport=0;
\t\tdestport=0;
\t\tcase(current_r_addr) //current_r_addr of each individual router is fixed. So this CASE will be optimized by the synthesizer for each router.
\t\tcase(current_r_addr) //current_r_addr of each individual router is fixed. So this CASE will be optimized by the synthesizer for each router.
";
";
 
 
 
 
 
 
foreach my $router (@routers){
foreach my $router (@routers){
                my $PNUM=$self->object_get_attribute($router,"PNUM");
                my $PNUM=$self->object_get_attribute($router,"PNUM");
                my $router_num=get_scolar_pos($router,@routers);
                my $router_num=get_scolar_pos($router,@routers);
            my %route;
            my %route;
                $route_str=$route_str."\t\t$router_num: begin
                $route_str=$route_str."\t\t$router_num: begin
\t\t\tcase({src_e_addr,dest_e_addr})
\t\t\tcase({src_e_addr,dest_e_addr})
";
";
        # for each src-dest check if $router include in path 
        # for each src-dest check if $router include in path 
        foreach my $src (@ends){
        foreach my $src (@ends){
                foreach my $dst (@ends){
                foreach my $dst (@ends){
                        my $ref = $self->object_get_attribute('Route',"${src}::$dst");
                        my $ref = $self->object_get_attribute('Route',"${src}::$dst");
                        next if(!defined $ref);
                        next if(!defined $ref);
                        my @path = @{$ref};
                        my @path = @{$ref};
                    my $loc= get_scolar_pos($router,@path);
                    my $loc= get_scolar_pos($router,@path);
                    next if(!defined $loc);# this router does not exist in path skip it
                    next if(!defined $loc);# this router does not exist in path skip it
                    my $next_router1=$path[$loc+1];
                    my $next_router1=$path[$loc+1];
                    my $next_router2=$path[$loc+2];
                    my $next_router2=$path[$loc+2];
                    next if(!defined $next_router2);
                    next if(!defined $next_router2);
                    my ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$next_router1,$next_router2);
                    my ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$next_router1,$next_router2);
                    next if(!defined $p1);
                    next if(!defined $p1);
                    my $src_num=get_scolar_pos($src,@ends);
                    my $src_num=get_scolar_pos($src,@ends);
                    my $dest_num = get_scolar_pos($dst,@ends);
                    my $dest_num = get_scolar_pos($dst,@ends);
                        $route{$p1} = (defined $route{$p1})? $route{$p1}.",{E$src_num,E$dest_num}" : "{E$src_num,E$dest_num}";
                        $route{$p1} = (defined $route{$p1})? $route{$p1}.",{E$src_num,E$dest_num}" : "{E$src_num,E$dest_num}";
 
 
                        #print "@path\n";
                        #print "@path\n";
                        #print "(current_router, next_router1, next_router2)=($router, $next_router1, $next_router2)\n";
                        #print "(current_router, next_router1, next_router2)=($router, $next_router1, $next_router2)\n";
                        #print "($p1,$p2)= get_connection_port_num_between_two_nodes(\$self,$next_router1,$next_router2)\n";    
                        #print "($p1,$p2)= get_connection_port_num_between_two_nodes(\$self,$next_router1,$next_router2)\n";    
                        #print "\$route{$p1} ={E$src_num,E$dest_num}\n";
                        #print "\$route{$p1} ={E$src_num,E$dest_num}\n";
                        #print"***************************\n"; 
                        #print"***************************\n"; 
 
 
                }
                }
        }
        }
        foreach my $q (sort {$a <=> $b} keys %route){
        foreach my $q (sort {$a <=> $b} keys %route){
                        $route_str=$route_str."\t\t\t$route{$q}: begin
                        $route_str=$route_str."\t\t\t$route{$q}: begin
\t\t\t\tdestport= $q;
\t\t\t\tdestport= $q;
\t\t\tend
\t\t\tend
";
";
 
 
        }
        }
 
 
        $route_str.="\t\t\tdefault: begin
        $route_str.="\t\t\tdefault: begin
\t\t\t\tdestport= {DSTPw{1\'bX}};
\t\t\t\tdestport= {DSTPw{1\'bX}};
\t\t\tend
\t\t\tend
\t\t\tendcase\n\t\tend//$router_num\n";
\t\t\tendcase\n\t\tend//$router_num\n";
        }
        }
$route_str.="\t\tdefault: begin
$route_str.="\t\tdefault: begin
\t\t\tdestport= {DSTPw{1\'bX}};
\t\t\tdestport= {DSTPw{1\'bX}};
\t\tend
\t\tend
\t\tendcase\n\tend\n";
\t\tendcase\n\tend\n";
 
 
 
 
 
 
my $localparam="";
my $localparam="";
        my $i=0;
        my $i=0;
        foreach my $src (@ends){
        foreach my $src (@ends){
                $localparam= $localparam."localparam [EAw-1 : 0]\tE$i=$i;\n";
                $localparam= $localparam."localparam [EAw-1 : 0]\tE$i=$i;\n";
                $i++;
                $i++;
        }
        }
 
 
 
 
 
 
 
 
 print $fd "
 print $fd "
 
 
 `include \"pronoc_def.v\"
 `include \"pronoc_def.v\"
/*******************
/*******************
*  ${Vname}_look_ahead_routing
*  ${Vname}_look_ahead_routing
*******************/
*******************/
module ${Vname}_look_ahead_routing  #(
module ${Vname}_look_ahead_routing  #(
\tparameter RAw = 3,
\tparameter RAw = 3,
\tparameter EAw = 3,
\tparameter EAw = 3,
\tparameter DSTPw=4
\tparameter DSTPw=4
)
)
(
(
\treset,
\treset,
\tclk,
\tclk,
\tcurrent_r_addr,
\tcurrent_r_addr,
\tdest_e_addr,
\tdest_e_addr,
\tsrc_e_addr,
\tsrc_e_addr,
\tdestport
\tdestport
);
);
 
 
\tinput   [RAw-1   :0] current_r_addr;
\tinput   [RAw-1   :0] current_r_addr;
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\toutput  [DSTPw-1 :0] destport;
\toutput  [DSTPw-1 :0] destport;
\tinput reset,clk;
\tinput reset,clk;
 
 
        reg [EAw-1   :0] dest_e_addr_delay;
        reg [EAw-1   :0] dest_e_addr_delay;
        reg [EAw-1   :0] src_e_addr_delay;
        reg [EAw-1   :0] src_e_addr_delay;
 
 
        always @ (`pronoc_clk_reset_edge )begin
        always @ (`pronoc_clk_reset_edge )begin
        if(`pronoc_reset)begin
        if(`pronoc_reset)begin
                        dest_e_addr_delay<={EAw{1'b0}};
                        dest_e_addr_delay<={EAw{1'b0}};
                        src_e_addr_delay<={EAw{1'b0}};
                        src_e_addr_delay<={EAw{1'b0}};
                end else begin
                end else begin
                        dest_e_addr_delay<=dest_e_addr;
                        dest_e_addr_delay<=dest_e_addr;
                        src_e_addr_delay<=src_e_addr;
                        src_e_addr_delay<=src_e_addr;
                end
                end
        end
        end
 
 
        ${Vname}_look_ahead_routing_comb  #(
        ${Vname}_look_ahead_routing_comb  #(
                .RAw(RAw),
                .RAw(RAw),
                .EAw(EAw),
                .EAw(EAw),
                .DSTPw(DSTPw)
                .DSTPw(DSTPw)
        )
        )
        lkp_cmb
        lkp_cmb
        (
        (
                .current_r_addr(current_r_addr),
                .current_r_addr(current_r_addr),
                .dest_e_addr(dest_e_addr_delay),
                .dest_e_addr(dest_e_addr_delay),
                .src_e_addr(src_e_addr_delay),
                .src_e_addr(src_e_addr_delay),
                .destport(destport)
                .destport(destport)
        );
        );
 
 
 
 
 
 
endmodule
endmodule
 
 
/*******************
/*******************
*  ${Vname}_look_ahead_routing_comb
*  ${Vname}_look_ahead_routing_comb
*******************/
*******************/
 
 
 module ${Vname}_look_ahead_routing_comb  #(
 module ${Vname}_look_ahead_routing_comb  #(
\tparameter RAw = 3,
\tparameter RAw = 3,
\tparameter EAw = 3,
\tparameter EAw = 3,
\tparameter DSTPw=4
\tparameter DSTPw=4
)
)
(
(
\tcurrent_r_addr,
\tcurrent_r_addr,
\tdest_e_addr,
\tdest_e_addr,
\tsrc_e_addr,
\tsrc_e_addr,
\tdestport
\tdestport
);
);
 
 
\tinput   [RAw-1   :0] current_r_addr;
\tinput   [RAw-1   :0] current_r_addr;
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\toutput reg [DSTPw-1 :0] destport;
\toutput reg [DSTPw-1 :0] destport;
 
 
$localparam
$localparam
 
 
$route_str
$route_str
 
 
 
 
endmodule
endmodule
 
 
 
 
";
";
 
 
close($fd);
close($fd);
add_info($info,"$top file is created\n  ");
add_info($info,"$top file is created\n  ");
 
 
#########################       
#########################       
#  conventional_routing_genvar
#  conventional_routing_genvar
#########################
#########################
 
 
 
 
        #create routing file
        #create routing file
        $top="$dir/${Vname}_conventional_routing_genvar.v";
        $top="$dir/${Vname}_conventional_routing_genvar.v";
    open $fd, ">$top" or $r = "$!\n";
    open $fd, ">$top" or $r = "$!\n";
    if(defined $r) {
    if(defined $r) {
        add_colored_info($info,"Error in creating $top: $r",'red');
        add_colored_info($info,"Error in creating $top: $r",'red');
                return;
                return;
    }
    }
    print $fd autogen_warning();
    print $fd autogen_warning();
    print $fd get_license_header($top);
    print $fd get_license_header($top);
 
 
 
 
 
 
 
 
 
 
        $route_str="\tgenerate
        $route_str="\tgenerate
 
 
";
";
 
 
        foreach my $src (@ends){
        foreach my $src (@ends){
                my $PNUM=$self->object_get_attribute($src,"PNUM");
                my $PNUM=$self->object_get_attribute($src,"PNUM");
                my $src_num=get_scolar_pos($src,@ends);
                my $src_num=get_scolar_pos($src,@ends);
            my %route;
            my %route;
                $route_str=$route_str."\tif(SRC_E_ADDR == $src_num) begin : SRC$src_num
                $route_str=$route_str."\tif(SRC_E_ADDR == $src_num) begin : SRC$src_num
\t\talways@(*)begin
\t\talways@(*)begin
\t\t\tdestport= 0;
\t\t\tdestport= 0;
\t\t\tcase(dest_e_addr)
\t\t\tcase(dest_e_addr)
";
";
 
 
                foreach my $dst (@ends){
                foreach my $dst (@ends){
                            my $dest_num = get_scolar_pos($dst,@ends);
                            my $dest_num = get_scolar_pos($dst,@ends);
                                my $ref = $self->object_get_attribute('Route',"${src}::$dst");
                                my $ref = $self->object_get_attribute('Route',"${src}::$dst");
                                next if(!defined $ref);
                                next if(!defined $ref);
                                my @path = @{$ref};
                                my @path = @{$ref};
                                my ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$path[1],$path[2] );
                                my ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$path[1],$path[2] );
                                #print " ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$path[1],$path[2] );\n";
                                #print " ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$path[1],$path[2] );\n";
                                $route{$p1} = (defined $route{$p1})? $route{$p1}.",$dest_num" : "$dest_num";
                                $route{$p1} = (defined $route{$p1})? $route{$p1}.",$dest_num" : "$dest_num";
                }
                }
                foreach my $q (sort {$a <=> $b} keys %route){
                foreach my $q (sort {$a <=> $b} keys %route){
                        $route_str=$route_str."\t\t\t$route{$q}: begin
                        $route_str=$route_str."\t\t\t$route{$q}: begin
\t\t\t\tdestport= $q;
\t\t\t\tdestport= $q;
\t\t\tend
\t\t\tend
";
";
                }
                }
                $route_str=$route_str."\t\t\tdefault: begin
                $route_str=$route_str."\t\t\tdefault: begin
\t\t\t\tdestport= {DSTPw{1\'bX}};
\t\t\t\tdestport= {DSTPw{1\'bX}};
\t\t\tend
\t\t\tend
 
 
\t\t\tendcase\n\t\tend\n\tend//SRC$src_num\n\n";
\t\t\tendcase\n\t\tend\n\tend//SRC$src_num\n\n";
        }
        }
        $route_str=$route_str."\tendgenerate\n";
        $route_str=$route_str."\tendgenerate\n";
 
 
 
 
 
 
         print $fd "module ${Vname}_conventional_routing_genvar  #(
         print $fd "module ${Vname}_conventional_routing_genvar  #(
\tparameter RAw = 3,
\tparameter RAw = 3,
\tparameter EAw = 3,
\tparameter EAw = 3,
\tparameter DSTPw=4,
\tparameter DSTPw=4,
\tparameter SRC_E_ADDR=0
\tparameter SRC_E_ADDR=0
)
)
(
(
\tdest_e_addr,
\tdest_e_addr,
\tdestport
\tdestport
);
);
 
 
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] dest_e_addr;
\toutput reg [DSTPw-1 :0] destport;
\toutput reg [DSTPw-1 :0] destport;
 
 
 
 
$route_str
$route_str
 
 
 
 
endmodule
endmodule
 
 
";
";
close($fd);
close($fd);
add_info($info,"$top file is created\n  ");
add_info($info,"$top file is created\n  ");
 
 
##################
##################
#   look_ahead_routing_genvar
#   look_ahead_routing_genvar
###################
###################
 
 
#create routing file
#create routing file
        $top="$dir/${Vname}_look_ahead_routing_genvar.v";
        $top="$dir/${Vname}_look_ahead_routing_genvar.v";
    open  $fd, ">$top" or $r = "$!\n";
    open  $fd, ">$top" or $r = "$!\n";
    if(defined $r) {
    if(defined $r) {
        add_colored_info($info,"Error in creating $top: $r",'red');
        add_colored_info($info,"Error in creating $top: $r",'red');
                return;
                return;
    }
    }
    print $fd autogen_warning();
    print $fd autogen_warning();
    print $fd get_license_header($top);
    print $fd get_license_header($top);
 
 
 
 
 
 
        $route_str="\talways@(*)begin
        $route_str="\talways@(*)begin
\t\tdestport=0;
\t\tdestport=0;
\t\tcase(current_r_addr) //current_r_addr of each individual router is fixed. So this CASE will be optimized by the synthesizer for each router.
\t\tcase(current_r_addr) //current_r_addr of each individual router is fixed. So this CASE will be optimized by the synthesizer for each router.
";
";
 
 
$route_str="\tgenerate\n";
$route_str="\tgenerate\n";
 
 
 
 
foreach my $router (@routers){
foreach my $router (@routers){
                my $PNUM=$self->object_get_attribute($router,"PNUM");
                my $PNUM=$self->object_get_attribute($router,"PNUM");
                my $router_num=get_scolar_pos($router,@routers);
                my $router_num=get_scolar_pos($router,@routers);
            my %route;
            my %route;
                $route_str=$route_str."\tif(CURRENT_R_ADDR == $router_num) begin :R$router_num
                $route_str=$route_str."\tif(CURRENT_R_ADDR == $router_num) begin :R$router_num
\t\talways@(*)begin
\t\talways@(*)begin
\t\t\tdestport= 0;
\t\t\tdestport= 0;
\t\t\tcase({src_e_addr,dest_e_addr})
\t\t\tcase({src_e_addr,dest_e_addr})
";
";
        # for each src-dest check if $router include in path 
        # for each src-dest check if $router include in path 
        foreach my $src (@ends){
        foreach my $src (@ends){
                foreach my $dst (@ends){
                foreach my $dst (@ends){
                        my $ref = $self->object_get_attribute('Route',"${src}::$dst");
                        my $ref = $self->object_get_attribute('Route',"${src}::$dst");
                        next if(!defined $ref);
                        next if(!defined $ref);
                        my @path = @{$ref};
                        my @path = @{$ref};
                    my $loc= get_scolar_pos($router,@path);
                    my $loc= get_scolar_pos($router,@path);
                    next if(!defined $loc);# this router does not exist in path skip it
                    next if(!defined $loc);# this router does not exist in path skip it
                    my $next_router1=$path[$loc+1];
                    my $next_router1=$path[$loc+1];
                    my $next_router2=$path[$loc+2];
                    my $next_router2=$path[$loc+2];
                    next if(!defined $next_router2);
                    next if(!defined $next_router2);
                    my ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$next_router1,$next_router2);
                    my ($p1,$p2)= get_connection_port_num_between_two_nodes($self,$next_router1,$next_router2);
                    next if(!defined $p1);
                    next if(!defined $p1);
                    my $src_num=get_scolar_pos($src,@ends);
                    my $src_num=get_scolar_pos($src,@ends);
                    my $dest_num = get_scolar_pos($dst,@ends);
                    my $dest_num = get_scolar_pos($dst,@ends);
                        $route{$p1} = (defined $route{$p1})? $route{$p1}.",{E$src_num,E$dest_num}" : "{E$src_num,E$dest_num}";
                        $route{$p1} = (defined $route{$p1})? $route{$p1}.",{E$src_num,E$dest_num}" : "{E$src_num,E$dest_num}";
 
 
                        #print "@path\n";
                        #print "@path\n";
                        #print "(current_router, next_router1, next_router2)=($router, $next_router1, $next_router2)\n";
                        #print "(current_router, next_router1, next_router2)=($router, $next_router1, $next_router2)\n";
                        #print "($p1,$p2)= get_connection_port_num_between_two_nodes(\$self,$next_router1,$next_router2)\n";    
                        #print "($p1,$p2)= get_connection_port_num_between_two_nodes(\$self,$next_router1,$next_router2)\n";    
                        #print "\$route{$p1} ={E$src_num,E$dest_num}\n";
                        #print "\$route{$p1} ={E$src_num,E$dest_num}\n";
                        #print"***************************\n"; 
                        #print"***************************\n"; 
 
 
                }
                }
        }
        }
        foreach my $q (sort {$a <=> $b} keys %route){
        foreach my $q (sort {$a <=> $b} keys %route){
                        $route_str=$route_str."\t\t\t$route{$q}: begin
                        $route_str=$route_str."\t\t\t$route{$q}: begin
\t\t\t\tdestport= $q;
\t\t\t\tdestport= $q;
\t\t\tend
\t\t\tend
";
";
 
 
        }
        }
 
 
        $route_str=$route_str."\t\t\tendcase\n\t\tend\n\tend//R$router_num\n\n";
        $route_str=$route_str."\t\t\tendcase\n\t\tend\n\tend//R$router_num\n\n";
        }
        }
        $route_str=$route_str."\tendgenerate\n";
        $route_str=$route_str."\tendgenerate\n";
 
 
 
 
 
 
 print $fd "
 print $fd "
 `include \"pronoc_def.v\"
 `include \"pronoc_def.v\"
 
 
/*****************************
/*****************************
*       ${Vname}_look_ahead_routing_genvar
*       ${Vname}_look_ahead_routing_genvar
******************************/
******************************/
module ${Vname}_look_ahead_routing_genvar  #(
module ${Vname}_look_ahead_routing_genvar  #(
\tparameter RAw = 3,
\tparameter RAw = 3,
\tparameter EAw = 3,
\tparameter EAw = 3,
\tparameter DSTPw=4,
\tparameter DSTPw=4,
\tparameter CURRENT_R_ADDR=0
\tparameter CURRENT_R_ADDR=0
)
)
(
(
\tdest_e_addr,
\tdest_e_addr,
\tsrc_e_addr,
\tsrc_e_addr,
\tdestport,
\tdestport,
\treset,
\treset,
\tclk
\tclk
);
);
 
 
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\toutput  [DSTPw-1 :0] destport;
\toutput  [DSTPw-1 :0] destport;
\tinput reset,clk;
\tinput reset,clk;
 
 
        reg [EAw-1   :0] dest_e_addr_delay;
        reg [EAw-1   :0] dest_e_addr_delay;
        reg [EAw-1   :0] src_e_addr_delay;
        reg [EAw-1   :0] src_e_addr_delay;
 
 
         always @ (`pronoc_clk_reset_edge )begin
         always @ (`pronoc_clk_reset_edge )begin
        if(`pronoc_reset) begin
        if(`pronoc_reset) begin
                        dest_e_addr_delay<={EAw{1'b0}};
                        dest_e_addr_delay<={EAw{1'b0}};
                        src_e_addr_delay<={EAw{1'b0}};
                        src_e_addr_delay<={EAw{1'b0}};
                end else begin
                end else begin
                        dest_e_addr_delay<=dest_e_addr;
                        dest_e_addr_delay<=dest_e_addr;
                        src_e_addr_delay<=src_e_addr;
                        src_e_addr_delay<=src_e_addr;
                end
                end
        end
        end
 
 
        ${name}_look_ahead_routing_genvar_comb  #(
        ${name}_look_ahead_routing_genvar_comb  #(
                .RAw(RAw),
                .RAw(RAw),
                .EAw(EAw),
                .EAw(EAw),
                .DSTPw(DSTPw),
                .DSTPw(DSTPw),
                .CURRENT_R_ADDR(CURRENT_R_ADDR)
                .CURRENT_R_ADDR(CURRENT_R_ADDR)
        )
        )
        lkp_cmb
        lkp_cmb
        (
        (
 
 
                .dest_e_addr(dest_e_addr_delay),
                .dest_e_addr(dest_e_addr_delay),
                .src_e_addr(src_e_addr_delay),
                .src_e_addr(src_e_addr_delay),
                .destport(destport)
                .destport(destport)
        );
        );
 
 
 
 
 
 
endmodule
endmodule
 
 
/*******************
/*******************
* ${Vname}_look_ahead_routing_genvar_comb
* ${Vname}_look_ahead_routing_genvar_comb
********************/
********************/
 
 
 
 
 module ${Vname}_look_ahead_routing_genvar_comb  #(
 module ${Vname}_look_ahead_routing_genvar_comb  #(
\tparameter RAw = 3,
\tparameter RAw = 3,
\tparameter EAw = 3,
\tparameter EAw = 3,
\tparameter DSTPw=4,
\tparameter DSTPw=4,
\tparameter CURRENT_R_ADDR=0
\tparameter CURRENT_R_ADDR=0
)
)
(
(
\tdest_e_addr,
\tdest_e_addr,
\tsrc_e_addr,
\tsrc_e_addr,
\tdestport
\tdestport
);
);
 
 
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] dest_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\tinput   [EAw-1   :0] src_e_addr;
\toutput  reg [DSTPw-1 :0] destport;
\toutput  reg [DSTPw-1 :0] destport;
 
 
$localparam
$localparam
 
 
$route_str
$route_str
 
 
 
 
endmodule
endmodule
 
 
 
 
";
";
 
 
 
 
close($fd);
close($fd);
add_info($info,"$top file is created\n  ");
add_info($info,"$top file is created\n  ");
 
 
}
}
 
 
 
 
 
 
sub generate_connection_v{
sub generate_connection_v{
        my($self,$info,$dir)=@_;
        my($self,$info,$dir)=@_;
 
 
        #create connection top file
        #create connection top file
        my $name=$self->object_get_attribute('save_as');
        my $name=$self->object_get_attribute('save_as');
 
 
        my $r;
        my $r;
        my $top="$dir/${name}_connection.sv";
        my $top="$dir/${name}_connection.sv";
    open my $fd, ">$top" or $r = "$!\n";
    open my $fd, ">$top" or $r = "$!\n";
    if(defined $r) {
    if(defined $r) {
        add_colored_info($info,"Error in creating $top: $r",'red');
        add_colored_info($info,"Error in creating $top: $r",'red');
                return;
                return;
    }
    }
    print $fd autogen_warning();
    print $fd autogen_warning();
    print $fd get_license_header($top);
    print $fd get_license_header($top);
print $fd '
print $fd '
`include "pronoc_def.v"
`include "pronoc_def.v"
';
';
 
 
 
 
 
 
 
 
 
 
 
 
   my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
   my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
   my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
   my @ports= @{$self->object_get_attribute('Verilog','Router_ports')};
 
 
 
 
 
 
    my @ends=get_list_of_all_endpoints($self);
    my @ends=get_list_of_all_endpoints($self);
    my @routers=get_list_of_all_routers($self);
    my @routers=get_list_of_all_routers($self);
 
 
    my $MAX_P=0;
    my $MAX_P=0;
    foreach my $p (@routers){
    foreach my $p (@routers){
        my $Pnum=$self->object_get_attribute("$p",'PNUM');
        my $Pnum=$self->object_get_attribute("$p",'PNUM');
        $MAX_P =$Pnum  if($Pnum>$MAX_P );
        $MAX_P =$Pnum  if($Pnum>$MAX_P );
    }
    }
 
 
    my $NE= scalar @ends;
    my $NE= scalar @ends;
    my $NR= scalar @routers;
    my $NR= scalar @routers;
 
 
 
 
 
 
        my @nodes=get_list_of_all_routers($self);
        my @nodes=get_list_of_all_routers($self);
        my $i=0;
        my $i=0;
 
 
        my $ports="\treset,
        my $ports="\treset,
\tclk,
\tclk,
\tstart_i,
\tstart_i,
\tstart_o,
\tstart_o,
\ter_addr,
\ter_addr,
\tcurrent_r_addr,
\tcurrent_r_addr,
\tchan_in_all,
\tchan_in_all,
\tchan_out_all,
\tchan_out_all,
\trouter_chan_in,
\trouter_chan_in,
\trouter_chan_out
\trouter_chan_out
";
";
 
 
 
 
    my $ports_def="
    my $ports_def="
\tinput reset;
\tinput reset;
\tinput clk;
\tinput clk;
\tinput start_i;
\tinput start_i;
\toutput [RAw-1 : 0] er_addr [NE-1 : 0]; // provide router address for each connected endpoint
\toutput [RAw-1 : 0] er_addr [NE-1 : 0]; // provide router address for each connected endpoint
\toutput [RAw-1 : 0] current_r_addr [NR-1 : 0]; // provide each router current address  ;
\toutput [RAw-1 : 0] current_r_addr [NR-1 : 0]; // provide each router current address  ;
\toutput [NE-1 : 0] start_o;
\toutput [NE-1 : 0] start_o;
\toutput smartflit_chanel_t chan_in_all [NE-1 : 0];
\toutput smartflit_chanel_t chan_in_all [NE-1 : 0];
\tinput  smartflit_chanel_t chan_out_all [NE-1 : 0];
\tinput  smartflit_chanel_t chan_out_all [NE-1 : 0];
\tinput  smartflit_chanel_t    router_chan_in   [NR-1 :0][MAX_P-1 : 0];
\tinput  smartflit_chanel_t    router_chan_in   [NR-1 :0][MAX_P-1 : 0];
\toutput smartflit_chanel_t    router_chan_out  [NR-1 :0][MAX_P-1 : 0];
\toutput smartflit_chanel_t    router_chan_out  [NR-1 :0][MAX_P-1 : 0];
 
 
";
";
 
 
        my $router_wires="";
        my $router_wires="";
        my $endps_wires="";
        my $endps_wires="";
 
 
 
 
 
 
 
 
        foreach my $d (@ports){
        foreach my $d (@ports){
                my $range = ($d->{width} eq 1)? " " :  " [$d->{width}-1 : 0]";
                my $range = ($d->{width} eq 1)? " " :  " [$d->{width}-1 : 0]";
                my $pdef_range = ($d->{pwidth} eq 1)? "[NE-1 : 0]" : "[$d->{pwidth}-1 : 0]";
                my $pdef_range = ($d->{pwidth} eq 1)? "[NE-1 : 0]" : "[$d->{pwidth}-1 : 0]";
                my $pdef_range2 = ($d->{pwidth} eq 1)? "" : "[NE-1 : 0]";
                my $pdef_range2 = ($d->{pwidth} eq 1)? "" : "[NE-1 : 0]";
                #$ports=$ports.",\n\trouter_$d->{name},\n\trouter_$d->{connect}";
                #$ports=$ports.",\n\trouter_$d->{name},\n\trouter_$d->{connect}";
                my $type=$d->{type};
                my $type=$d->{type};
                my $ctype= ($type eq 'input')? 'output' : 'input';
                my $ctype= ($type eq 'input')? 'output' : 'input';
                if( $d->{endp} eq "yes"){
                if( $d->{endp} eq "yes"){
                        #$ports_def=$ports_def."\t$type\t$pdef_range ni_$d->{pname} $pdef_range2;\n";
                        #$ports_def=$ports_def."\t$type\t$pdef_range ni_$d->{pname} $pdef_range2;\n";
                        #$ports_def=$ports_def."\t$ctype\t$pdef_range ni_$d->{pconnect} $pdef_range2;\n";                       
                        #$ports_def=$ports_def."\t$ctype\t$pdef_range ni_$d->{pconnect} $pdef_range2;\n";                       
                        #$ports=$ports.",\n\tni_$d->{pname},\n\tni_$d->{pconnect}";
                        #$ports=$ports.",\n\tni_$d->{pname},\n\tni_$d->{pconnect}";
                }
                }
                if($d->{width} eq 1){
                if($d->{width} eq 1){
                        #$ports_def=$ports_def. "\t$type\t[NR-1 :0] router_$d->{name};\n";
                        #$ports_def=$ports_def. "\t$type\t[NR-1 :0] router_$d->{name};\n";
                        #$ports_def=$ports_def. "\t$ctype\t[NR-1 :0] router_$d->{connect};\n";
                        #$ports_def=$ports_def. "\t$ctype\t[NR-1 :0] router_$d->{connect};\n";
                }else{
                }else{
                        #$ports_def=$ports_def. "\t$type\t$range router_$d->{name} [NR-1 :0];\n";
                        #$ports_def=$ports_def. "\t$type\t$range router_$d->{name} [NR-1 :0];\n";
                        #$ports_def=$ports_def. "\t$ctype\t$range router_$d->{connect} [NR-1 :0];\n";
                        #$ports_def=$ports_def. "\t$ctype\t$range router_$d->{connect} [NR-1 :0];\n";
                }
                }
 
 
 
 
        }
        }
 
 
 
 
 
 
 
 
        my $routers='
        my $routers='
        genvar i;
        genvar i;
        generate
        generate
        ';
        ';
        my $offset=0;
        my $offset=0;
        my $assign="";
        my $assign="";
        my $R_num=0;
        my $R_num=0;
        for ( my $i=2;$i<=12; $i++){
        for ( my $i=2;$i<=12; $i++){
                my $n= $self->object_get_attribute("ROUTER${i}","NUM");
                my $n= $self->object_get_attribute("ROUTER${i}","NUM");
                $n=0 if(!defined $n);
                $n=0 if(!defined $n);
                if($n>0){
                if($n>0){
                        my $router_pos= ($offset==0)? 'i' : "i+$offset";
                        my $router_pos= ($offset==0)? 'i' : "i+$offset";
                        my $instant=get_router_genvar_instance_v($self,$i,$router_pos,$NE,$NR,$MAX_P);
                        my $instant=get_router_genvar_instance_v($self,$i,$router_pos,$NE,$NR,$MAX_P);
 
 
                        $routers=$routers."
                        $routers=$routers."
\tfor( i=0; i<$n; i=i+1) begin : router_${i}_port_lp
\tfor( i=0; i<$n; i=i+1) begin : router_${i}_port_lp
\t\t$instant
\t\t$instant
 
 
\tend
\tend
                        ";
                        ";
 
 
                        for ( my $j=0;$j<$n; $j++){
                        for ( my $j=0;$j<$n; $j++){
                                my $rname ="ROUTER${i}_$j";
                                my $rname ="ROUTER${i}_$j";
                                my ($ass_v, $r2r_h,$r2e_h, $int_h,$gnd_h,$R_num)=       get_wires_assignment_genvar_v($self,$rname,1,undef,$R_num);
                                my ($ass_v, $r2r_h,$r2e_h, $int_h,$gnd_h,$R_num)=       get_wires_assignment_genvar_v($self,$rname,1,undef,$R_num);
                                $assign=$assign.$ass_v;
                                $assign=$assign.$ass_v;
                        }
                        }
 
 
                $offset+=       $n;
                $offset+=       $n;
 
 
                }
                }
        }
        }
 
 
 
 
 
 
        foreach my $end (@ends){
        foreach my $end (@ends){
                #$assign=$assign.get_wires_assignment_genvar_v($self,$end,1);           
                #$assign=$assign.get_wires_assignment_genvar_v($self,$end,1);           
        }
        }
 
 
        $assign=$assign."\n";
        $assign=$assign."\n";
 
 
 
 
        my $pos=0;
        my $pos=0;
        $assign.="//The router address connected to each endpoint\n";
        $assign.="//The router address connected to each endpoint\n";
        foreach my $end (@ends){
        foreach my $end (@ends){
                my $connect = $self->{$end}{'PCONNECT'}{'Port[0]'};
                my $connect = $self->{$end}{'PCONNECT'}{'Port[0]'};
                my ($Rname,$Rport)=split(/\s*,\s*/,$connect);
                my ($Rname,$Rport)=split(/\s*,\s*/,$connect);
                my $R = get_scolar_pos($Rname,@routers);
                my $R = get_scolar_pos($Rname,@routers);
                my $rname = $self->object_get_attribute("$Rname","NAME");
                my $rname = $self->object_get_attribute("$Rname","NAME");
                my $tname = $self->object_get_attribute("$end","NAME");
                my $tname = $self->object_get_attribute("$end","NAME");
                $assign=$assign."\tassign er_addr [$pos] = $R; //$tname -> $rname\n";
                $assign=$assign."\tassign er_addr [$pos] = $R; //$tname -> $rname\n";
                $pos++;
                $pos++;
        }
        }
 
 
        $assign=$assign."\n";
        $assign=$assign."\n";
 
 
        $pos=0;
        $pos=0;
        foreach my $router (@routers){
        foreach my $router (@routers){
                my $rname = $self->object_get_attribute("$router","NAME");
                my $rname = $self->object_get_attribute("$router","NAME");
                $assign=$assign."\tassign current_r_addr [$pos] = $pos; // $rname\n";
                $assign=$assign."\tassign current_r_addr [$pos] = $pos; // $rname\n";
                $pos++;
                $pos++;
        }
        }
 
 
 
 
 
 
 
 
                 print $fd "
                 print $fd "
module  ${name}_connection
module  ${name}_connection
        import pronoc_pkg::*;
#(
(
        parameter NOC_ID=0
 
)(
    $ports
    $ports
);
);
 
 
         function integer log2;
        `NOC_CONF
      input integer number; begin
 
         log2=(number <=1) ? 1: 0;
 
         while(2**log2<number) begin
 
            log2=log2+1;
 
         end
 
      end
 
    endfunction // log2
 
 
 
        localparam
 
                NE = $NE,
 
                NR = $NR,
 
                RAw=log2(NR),
 
                MAX_P=$MAX_P;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
        localparam
        localparam
                P= MAX_P,
                P= MAX_P,
        PV = V * P,
        PV = V * P,
        PFw = P * Fw,
        PFw = P * Fw,
        CONG_ALw = CONGw * P,
        CONG_ALw = CONGw * P,
        PRAw = P * RAw;
        PRAw = P * RAw;
 
 
 
 
 
 
 
 
 
 
 
 
$ports_def
$ports_def
 
 
$router_wires
$router_wires
 
 
$endps_wires
$endps_wires
 
 
 
 
$assign
$assign
 
 
 
 
        start_delay_gen #(
        start_delay_gen #(
        .NC(NE)
        .NC(NE)
    )
    )
    delay_gen
    delay_gen
    (
    (
        .clk(clk),
        .clk(clk),
        .reset(reset),
        .reset(reset),
        .start_i(start_i),
        .start_i(start_i),
        .start_o(start_o)
        .start_o(start_o)
    );
    );
 
 
 
 
endmodule
endmodule
";
";
 
 
        add_info($info,"$top file is created\n  ");
        add_info($info,"$top file is created\n  ");
        close $fd;
        close $fd;
 
 
 
 
 
 
}
}
 
 
sub add_noc_custom_h{
sub add_noc_custom_h{
        my ($self,$info,$dir)=@_;
        my ($self,$info,$dir)=@_;
        my $name=$self->object_get_attribute('save_as');
        my $name=$self->object_get_attribute('save_as');
        my $str="
        my $str="
                //do not modify this line ===${name}===
                //do not modify this line ===${name}===
                #ifdef IS_${name}_noc
                #ifdef IS_${name}_noc
                        #include \"${name}_noc.h\"
                        #include \"${name}_noc.h\"
                #endif
                #endif
        ";
        ";
 
 
 
 
        my $file = "$dir/../../../src_verilator/topology/custom/custom.h";
        my $file = "$dir/../../../src_verilator/topology/custom/custom.h";
        #check if ***$name**** exist in the file
        #check if ***$name**** exist in the file
        unless (-f $file){
        unless (-f $file){
                add_colored_info($info,"$file dose not exist\n",'red');
                add_colored_info($info,"$file dose not exist\n",'red');
                return;
                return;
        }
        }
        my $r = check_file_has_string($file, "===${name}===");
        my $r = check_file_has_string($file, "===${name}===");
        if ($r==1){
        if ($r==1){
                add_info($info,"The instance  ${name}_noc exists in $file. This file is not modified\n  ",'blue');
                add_info($info,"The instance  ${name}_noc exists in $file. This file is not modified\n  ",'blue');
 
 
        }else{
        }else{
                my $text = read_file_cntent($file,' ');
                my $text = read_file_cntent($file,' ');
        my @a = split('endgenerate',$text);
        my @a = split('endgenerate',$text);
        save_file($file,"$a[0] $str $a[1]");
        save_file($file,"$a[0] $str $a[1]");
        add_info($info,"$file has been modified. The  ${name}_noc has been added to the file\n  ",'blue');
        add_info($info,"$file has been modified. The  ${name}_noc has been added to the file\n  ",'blue');
 
 
        }
        }
 
 
}
}
 
 
 
 
 
 
sub add_routing_instance_v{
sub add_routing_instance_v{
        my ($self,$info,$dir)=@_;
        my ($self,$info,$dir)=@_;
        my $name=$self->object_get_attribute('save_as');
        my $name=$self->object_get_attribute('save_as');
        my $rname=$self->object_get_attribute('routing_name');
        my $rname=$self->object_get_attribute('routing_name');
        my $Vname="T${name}R${rname}";
        my $Vname="T${name}R${rname}";
        #####################################
        #####################################
        #                       custom_ni_routing
        #                       custom_ni_routing
        ####################################
        ####################################
        my $str="
        my $str="
        //do not modify this line ===${Vname}===
        //do not modify this line ===${Vname}===
    if(TOPOLOGY == \"$name\" && ROUTE_NAME== \"$rname\" ) begin : $Vname
    if(TOPOLOGY == \"$name\" && ROUTE_NAME== \"$rname\" ) begin : $Vname
 
 
        ${Vname}_conventional_routing  #(
        ${Vname}_conventional_routing  #(
            .RAw(RAw),
                .RAw(RAw),
            .EAw(EAw),
            .EAw(EAw),
            .DSTPw(DSTPw)
            .DSTPw(DSTPw)
        )
        )
        the_conventional_routing
        the_conventional_routing
        (
        (
            .dest_e_addr(dest_e_addr),
            .dest_e_addr(dest_e_addr),
            .src_e_addr(src_e_addr),
            .src_e_addr(src_e_addr),
            .destport(destport)
            .destport(destport)
        );
        );
 
 
    end
    end
 
 
    endgenerate
    endgenerate
 
 
";
";
 
 
        my $file = "$dir/../common/custom_ni_routing.v";
        my $file = "$dir/../common/custom_ni_routing.v";
        #check if ***$name**** exist in the file
        #check if ***$name**** exist in the file
        unless (-f $file){
        unless (-f $file){
                add_colored_info($info,"$file dose not exist\n",'red');
                add_colored_info($info,"$file dose not exist\n",'red');
                return;
                return;
        }
        }
        my $r = check_file_has_string($file, "===${Vname}===");
        my $r = check_file_has_string($file, "===${Vname}===");
        if ($r==1){
        if ($r==1){
                add_info($info,"The instance  ${Vname}_conventional_routing exists in $file. This file is not modified\n  ",'blue');
                add_info($info,"The instance  ${Vname}_conventional_routing exists in $file. This file is not modified\n  ",'blue');
 
 
        }else{
        }else{
                my $text = read_file_cntent($file,' ');
                my $text = read_file_cntent($file,' ');
        my @a = split('endgenerate',$text);
        my @a = split('endgenerate',$text);
        save_file($file,"$a[0] $str $a[1]");
        save_file($file,"$a[0] $str $a[1]");
        add_info($info,"$file has been modified. The  ${Vname}_conventional_routing has been added to the file\n  ",'blue');
        add_info($info,"$file has been modified. The  ${Vname}_conventional_routing has been added to the file\n  ",'blue');
 
 
        }
        }
 
 
 
 
 
 
        #####################################
        #####################################
        #                       custom_lkh_routing
        #                       custom_lkh_routing
        ####################################
        ####################################
         $str="
         $str="
        //do not modify this line ===${Vname}===
        //do not modify this line ===${Vname}===
    if(TOPOLOGY == \"$name\" && ROUTE_NAME== \"$rname\" ) begin : ${Vname}
    if(TOPOLOGY == \"$name\" && ROUTE_NAME== \"$rname\" ) begin : ${Vname}
 
 
           ${Vname}_look_ahead_routing  #(
           ${Vname}_look_ahead_routing  #(
            .RAw(RAw),
            .RAw(RAw),
            .EAw(EAw),
            .EAw(EAw),
            .DSTPw(DSTPw)
            .DSTPw(DSTPw)
        )
        )
        the_lkh_routing
        the_lkh_routing
        (
        (
            .current_r_addr(current_r_addr),
            .current_r_addr(current_r_addr),
            .dest_e_addr(dest_e_addr),
            .dest_e_addr(dest_e_addr),
            .src_e_addr(src_e_addr),
            .src_e_addr(src_e_addr),
            .destport(destport),
            .destport(destport),
            .reset(reset),
            .reset(reset),
            .clk(clk)
            .clk(clk)
        );
        );
 
 
    end
    end
 
 
    endgenerate
    endgenerate
 
 
";
";
 
 
        $file = "$dir/../common/custom_lkh_routing.v";
        $file = "$dir/../common/custom_lkh_routing.v";
 
 
        unless (-f $file){
        unless (-f $file){
                add_colored_info($info,"$file dose not exist\n",'red');
                add_colored_info($info,"$file dose not exist\n",'red');
                return;
                return;
        }
        }
        $r = check_file_has_string($file, "===${Vname}===");
        $r = check_file_has_string($file, "===${Vname}===");
        if ($r==1){
        if ($r==1){
                add_info($info,"The instance ${Vname}_look_ahead_routing exist in $file. This file is not modified\n  ",'blue');
                add_info($info,"The instance ${Vname}_look_ahead_routing exist in $file. This file is not modified\n  ",'blue');
 
 
        }else{
        }else{
                my $text = read_file_cntent($file,' ');
                my $text = read_file_cntent($file,' ');
        my @a = split('endgenerate',$text);
        my @a = split('endgenerate',$text);
        save_file($file,"$a[0] $str $a[1]");
        save_file($file,"$a[0] $str $a[1]");
        add_info($info,"$file has been modified. The  ${Vname}_look_ahead_routing has been added to the file\n  ",'blue');
        add_info($info,"$file has been modified. The  ${Vname}_look_ahead_routing has been added to the file\n  ",'blue');
 
 
        }
        }
 
 
 
 
}
}
 
 
sub add_noc_instance_v{
sub add_noc_instance_v{
        my ($self,$info,$dir)=@_;
        my ($self,$info,$dir)=@_;
        my $name=$self->object_get_attribute('save_as');
        my $name=$self->object_get_attribute('save_as');
 
 
        #####################################
        #####################################
        #                       add connection
        #                       add connection
        ####################################
        ####################################
 
 
        my $ports="\t\t.reset(reset),
        my $ports="\t\t.reset(reset),
\t\t.clk(clk),
\t\t.clk(clk),
\t\t.start_i(start_i),
\t\t.start_i(start_i),
\t\t.start_o(start_o),
\t\t.start_o(start_o),
\t\t.er_addr(er_addr),
\t\t.er_addr(er_addr),
\t\t.current_r_addr(current_r_addr),
\t\t.current_r_addr(current_r_addr),
\t\t.chan_in_all(chan_in_all),
\t\t.chan_in_all(chan_in_all),
\t\t.chan_out_all(chan_out_all),
\t\t.chan_out_all(chan_out_all),
\t\t.router_chan_in(router_chan_in),
\t\t.router_chan_in(router_chan_in),
\t\t.router_chan_out(router_chan_out)
\t\t.router_chan_out(router_chan_out)
 
 
 
 
";
";
 
 
 
 
 
 
 
 
        my $str="
        my $str="
        //do not modify this line ===${name}===
        //do not modify this line ===${name}===
    if(TOPOLOGY == \"$name\" ) begin : T$name
    if(TOPOLOGY == \"$name\" ) begin : T$name
 
 
        ${name}_connection  connection
        ${name}_connection  #(
        (
                        .NOC_ID(NOC_ID)
 
                ) connection (
$ports
$ports
        );
        );
 
 
    end
    end
 
 
    endgenerate
    endgenerate
 
 
";
";
 
 
        #my $file = "$dir/../common/custom_noc_connection.sv";  
        #my $file = "$dir/../common/custom_noc_connection.sv";  
        #check if ***$name**** exist in the file
        #check if ***$name**** exist in the file
        #unless (-f $file){
        #unless (-f $file){
        #       add_colored_info($info,"$file dose not exist\n",'red');
        #       add_colored_info($info,"$file dose not exist\n",'red');
        #       return; 
        #       return; 
        #}      
        #}      
        #my $r = check_file_has_string($file, "===${name}==="); 
        #my $r = check_file_has_string($file, "===${name}==="); 
        #if ($r==1){
        #if ($r==1){
                #add_info($info,"The instance  ${name}_connection exists in $file. This file is not modified\n  ",'blue');
                #add_info($info,"The instance  ${name}_connection exists in $file. This file is not modified\n  ",'blue');
 
 
        #}else{
        #}else{
                #my $text = read_file_cntent($file,' ');
                #my $text = read_file_cntent($file,' ');
       # my @a = split('endgenerate',$text);
       # my @a = split('endgenerate',$text);
      #  save_file($file,"$a[0] $str $a[1]");
      #  save_file($file,"$a[0] $str $a[1]");
       # add_info($info,"$file has been modified. The  ${name}_connection has been added to the file\n  ",'blue');
       # add_info($info,"$file has been modified. The  ${name}_connection has been added to the file\n  ",'blue');
 
 
        #}
        #}
 
 
 
 
        #####################################
        #####################################
        #               add NoC 
        #               add NoC 
        ####################################
        ####################################
 
 
 
 
         my $param_str ="\t\t.TOPOLOGY(TOPOLOGY),
         my $param_str ="\t\t.TOPOLOGY(TOPOLOGY),
\t\t.ROUTE_NAME(ROUTE_NAME)";
\t\t.ROUTE_NAME(ROUTE_NAME)";
 
 
   my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
   my @parameters=@{$self->object_get_attribute ('Verilog','Router_param')};
 
 
        foreach my $d (@parameters){
        foreach my $d (@parameters){
                $param_str = $param_str.",\n\t\t.$d->{param_name}($d->{param_name})";
                $param_str = $param_str.",\n\t\t.$d->{param_name}($d->{param_name})";
        }
        }
 
 
        $ports="\t\t.reset(reset),
        $ports="\t\t.reset(reset),
\t\t.clk(clk)";
\t\t.clk(clk)";
 
 
 
 
 
 
 
 
        $str="
        $str="
        //do not modify this line ===${name}===
        //do not modify this line ===${name}===
    if(TOPOLOGY == \"$name\" ) begin : T$name
    if(TOPOLOGY == \"$name\" ) begin : T$name
 
 
                ${name}_noc_genvar the_noc
                ${name}_noc_genvar #(
                (
                        .NOC_ID(NOC_ID)
 
                ) the_noc (
                    .reset(reset),
                    .reset(reset),
                    .clk(clk),
                    .clk(clk),
                    .chan_in_all(chan_in_all),
                    .chan_in_all(chan_in_all),
                    .chan_out_all(chan_out_all),
                    .chan_out_all(chan_out_all),
                    .router_event(router_event)
                    .router_event(router_event)
                );
                );
    end
    end
 
 
    endgenerate
    endgenerate
 
 
        ";
        ";
 
 
 
 
 
 
        my $file = "$dir/../common/custom_noc_top.sv";
        my $file = "$dir/../common/custom_noc_top.sv";
        #check if ***$name**** exist in the file
        #check if ***$name**** exist in the file
        unless (-f $file){
        unless (-f $file){
                add_colored_info($info,"$file dose not exist\n",'red');
                add_colored_info($info,"$file dose not exist\n",'red');
                return;
                return;
        }
        }
        my $r = check_file_has_string($file, "===${name}===");
        my $r = check_file_has_string($file, "===${name}===");
        if ($r==1){
        if ($r==1){
                add_info($info,"The instance  ${name}_noc exists in $file. This file is not modified\n  ",'blue');
                add_info($info,"The instance  ${name}_noc exists in $file. This file is not modified\n  ",'blue');
 
 
        }else{
        }else{
                my $text = read_file_cntent($file,' ');
                my $text = read_file_cntent($file,' ');
        my @a = split('endgenerate',$text);
        my @a = split('endgenerate',$text);
        save_file($file,"$a[0] $str $a[1]");
        save_file($file,"$a[0] $str $a[1]");
        add_info($info,"$file has been modified. The  ${name}_noc has been added to the file\n  ",'blue');
        add_info($info,"$file has been modified. The  ${name}_noc has been added to the file\n  ",'blue');
        }
        }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
}
}
 
 
 
 
1
1
 
 

powered by: WebSVN 2.1.0

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