`include "pronoc_def.v"
|
`include "pronoc_def.v"
|
|
|
/**********************************************************************
|
/**********************************************************************
|
** File: mesh_torus_noc.v
|
** File: mesh_torus_noc.v
|
**
|
**
|
** Copyright (C) 2014-2017 Alireza Monemi
|
** Copyright (C) 2014-2017 Alireza Monemi
|
**
|
**
|
** This file is part of ProNoC
|
** This file is part of ProNoC
|
**
|
**
|
** ProNoC ( stands for Prototype Network-on-chip) is free software:
|
** ProNoC ( stands for Prototype Network-on-chip) is free software:
|
** you can redistribute it and/or modify it under the terms of the GNU
|
** you can redistribute it and/or modify it under the terms of the GNU
|
** Lesser General Public License as published by the Free Software Foundation,
|
** Lesser General Public License as published by the Free Software Foundation,
|
** either version 2 of the License, or (at your option) any later version.
|
** either version 2 of the License, or (at your option) any later version.
|
**
|
**
|
** ProNoC is distributed in the hope that it will be useful, but WITHOUT
|
** ProNoC is distributed in the hope that it will be useful, but WITHOUT
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
** Public License for more details.
|
** Public License for more details.
|
**
|
**
|
** You should have received a copy of the GNU Lesser General Public
|
** You should have received a copy of the GNU Lesser General Public
|
** License along with ProNoC. If not, see .
|
** License along with ProNoC. If not, see .
|
**
|
**
|
**
|
**
|
** Description:
|
** Description:
|
** the NoC top module. It generate one of the mesh, torus, ring, or line topologies by
|
** the NoC top module. It generate one of the mesh, torus, ring, or line topologies by
|
** connecting routers
|
** connecting routers
|
**
|
**
|
**************************************************************/
|
**************************************************************/
|
|
|
|
|
`define router_id(x,y) ((y * NX) + x)
|
`define router_id(x,y) ((y * NX) + x)
|
`define endp_id(x,y,l) ((y * NX) + x) * NL + l
|
`define endp_id(x,y,l) ((y * NX) + x) * NL + l
|
|
|
|
|
|
|
module mesh_torus_noc_top
|
module mesh_torus_noc_top #(
|
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
|
);
|
);
|
|
|
|
`NOC_CONF
|
|
|
input clk,reset;
|
input clk,reset;
|
//Endpoints ports
|
//Endpoints ports
|
input smartflit_chanel_t chan_in_all [NE-1 : 0];
|
input smartflit_chanel_t chan_in_all [NE-1 : 0];
|
output smartflit_chanel_t chan_out_all [NE-1 : 0];
|
output smartflit_chanel_t chan_out_all [NE-1 : 0];
|
|
|
//Events
|
//Events
|
output router_event_t router_event [NR-1 : 0][MAX_P-1 : 0];
|
output router_event_t router_event [NR-1 : 0][MAX_P-1 : 0];
|
|
|
//all routers port
|
//all routers port
|
smartflit_chanel_t router_chan_in [NR-1 :0][MAX_P-1 : 0];
|
smartflit_chanel_t router_chan_in [NR-1 :0][MAX_P-1 : 0];
|
smartflit_chanel_t router_chan_out [NR-1 :0][MAX_P-1 : 0];
|
smartflit_chanel_t router_chan_out [NR-1 :0][MAX_P-1 : 0];
|
|
|
wire [RAw-1 : 0] current_r_addr [NR-1 : 0];
|
wire [RAw-1 : 0] current_r_addr [NR-1 : 0];
|
|
|
// mesh torus
|
|
localparam
|
|
EAST = 3'd1,
|
|
NORTH = 3'd2,
|
|
WEST = 3'd3,
|
|
SOUTH = 3'd4;
|
|
//ring line
|
|
localparam
|
|
FORWARD = 2'd1,
|
|
BACKWARD= 2'd2;
|
|
|
|
|
|
genvar x,y,l;
|
genvar x,y,l;
|
generate
|
generate
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
if( TOPOLOGY == "RING" || TOPOLOGY == "LINE") begin : ring_line
|
if( TOPOLOGY == "RING" || TOPOLOGY == "LINE") begin : ring_line
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
for (x=0; x
|
for (x=0; x
|
|
|
|
|
assign current_r_addr [x] = x[RAw-1: 0];
|
assign current_r_addr [x] = x[RAw-1: 0];
|
|
|
router_top #(
|
router_top #(
|
|
.NOC_ID(NOC_ID),
|
.P (MAX_P )
|
.P (MAX_P )
|
) the_router (
|
) the_router (
|
.current_r_id (x),
|
.current_r_id (x),
|
.current_r_addr (current_r_addr [x]),
|
.current_r_addr (current_r_addr [x]),
|
.chan_in (router_chan_in [x]),
|
.chan_in (router_chan_in [x]),
|
.chan_out (router_chan_out[x]),
|
.chan_out (router_chan_out[x]),
|
.router_event (router_event[x]),
|
.router_event (router_event[x]),
|
.clk (clk ),
|
.clk (clk ),
|
.reset (reset ));
|
.reset (reset ));
|
|
|
if(x < NX-1) begin: not_last_node
|
if(x < NX-1) begin: not_last_node
|
assign router_chan_in[x][FORWARD] = router_chan_out [(x+1)][BACKWARD];
|
assign router_chan_in[x][FORWARD] = router_chan_out [(x+1)][BACKWARD];
|
end else begin :last_node
|
end else begin :last_node
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
if(TOPOLOGY == "LINE") begin : line_last_x
|
if(TOPOLOGY == "LINE") begin : line_last_x
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[x][FORWARD]= {SMARTFLIT_CHANEL_w{1'b0}};
|
assign router_chan_in[x][FORWARD]= {SMARTFLIT_CHANEL_w{1'b0}};
|
end else begin : ring_last_x
|
end else begin : ring_last_x
|
assign router_chan_in[x][FORWARD]= router_chan_out [0][BACKWARD];
|
assign router_chan_in[x][FORWARD]= router_chan_out [0][BACKWARD];
|
end
|
end
|
end
|
end
|
|
|
if(x>0)begin :not_first_x
|
if(x>0)begin :not_first_x
|
assign router_chan_in[x][BACKWARD]= router_chan_out [(x-1)][FORWARD];
|
assign router_chan_in[x][BACKWARD]= router_chan_out [(x-1)][FORWARD];
|
end else begin :first_x
|
end else begin :first_x
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
if(TOPOLOGY == "LINE") begin : line_first_x
|
if(TOPOLOGY == "LINE") begin : line_first_x
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[x][BACKWARD]={SMARTFLIT_CHANEL_w{1'b0}};
|
assign router_chan_in[x][BACKWARD]={SMARTFLIT_CHANEL_w{1'b0}};
|
end else begin : ring_first_x
|
end else begin : ring_first_x
|
assign router_chan_in[x][BACKWARD]= router_chan_out [(NX-1)][FORWARD];
|
assign router_chan_in[x][BACKWARD]= router_chan_out [(NX-1)][FORWARD];
|
end
|
end
|
end
|
end
|
|
|
// connect other local ports
|
// connect other local ports
|
for (l=0; l
|
for (l=0; l
|
localparam ENDPID = `endp_id(x,0,l);
|
localparam ENDPID = `endp_id(x,0,l);
|
localparam LOCALP = (l==0) ? l : l + R2R_CHANELS_MESH_TORI; // first local port is connected to router port 0. The rest are connected at the end
|
localparam LOCALP = (l==0) ? l : l + R2R_CHANELS_MESH_TORI; // first local port is connected to router port 0. The rest are connected at the end
|
assign router_chan_in[x][LOCALP]= chan_in_all [ENDPID];
|
assign router_chan_in[x][LOCALP]= chan_in_all [ENDPID];
|
assign chan_out_all [ENDPID] = router_chan_out[x][LOCALP];
|
assign chan_out_all [ENDPID] = router_chan_out[x][LOCALP];
|
|
|
end// locals
|
end// locals
|
end//x
|
end//x
|
|
|
end else begin :mesh_torus
|
end else begin :mesh_torus
|
for (y=0; y
|
for (y=0; y
|
for (x=0; x
|
for (x=0; x
|
localparam R_ADDR = (y<
|
localparam R_ADDR = (y<
|
localparam RID = (y * NX) + x;
|
localparam RID = (y * NX) + x;
|
assign current_r_addr [RID] = R_ADDR[RAw-1 :0];
|
assign current_r_addr [RID] = R_ADDR[RAw-1 :0];
|
|
|
router_top #(
|
router_top #(
|
|
.NOC_ID(NOC_ID),
|
.P (MAX_P )
|
.P (MAX_P )
|
) the_router (
|
) the_router (
|
.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]),
|
.chan_in (router_chan_in [RID]),
|
.chan_out (router_chan_out[RID]),
|
.chan_out (router_chan_out[RID]),
|
.router_event (router_event[RID]),
|
.router_event (router_event[RID]),
|
.clk (clk ),
|
.clk (clk ),
|
.reset (reset ));
|
.reset (reset ));
|
|
|
|
|
/*
|
/*
|
in [x,y][east] <------ out [x+1 ,y ][west] ;
|
in [x,y][east] <------ out [x+1 ,y ][west] ;
|
in [x,y][north] <------ out [x ,y-1][south] ;
|
in [x,y][north] <------ out [x ,y-1][south] ;
|
in [x,y][west] <------ out [x-1 ,y ][east] ;
|
in [x,y][west] <------ out [x-1 ,y ][east] ;
|
in [x,y][south] <------ out [x ,y+1][north] ;
|
in [x,y][south] <------ out [x ,y+1][north] ;
|
*/
|
*/
|
|
|
|
|
if(x < NX-1) begin: not_last_x
|
if(x < NX-1) begin: not_last_x
|
assign router_chan_in[`router_id(x,y)][EAST]= router_chan_out [`router_id(x+1,y)][WEST];
|
assign router_chan_in[`router_id(x,y)][EAST]= router_chan_out [`router_id(x+1,y)][WEST];
|
//assign router_credit_in_all [`SELECT_WIRE(x,y,EAST,V)] = router_credit_out_all [`SELECT_WIRE((x+1),y,WEST,V)];
|
//assign router_credit_in_all [`SELECT_WIRE(x,y,EAST,V)] = router_credit_out_all [`SELECT_WIRE((x+1),y,WEST,V)];
|
end else begin :last_x
|
end else begin :last_x
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
if(TOPOLOGY == "MESH") begin :last_x_mesh
|
if(TOPOLOGY == "MESH") begin :last_x_mesh
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[`router_id(x,y)][EAST] = {SMARTFLIT_CHANEL_w{1'b0}};
|
assign router_chan_in[`router_id(x,y)][EAST] = {SMARTFLIT_CHANEL_w{1'b0}};
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
end else if(TOPOLOGY == "TORUS") begin : last_x_torus
|
end else if(TOPOLOGY == "TORUS") begin : last_x_torus
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[`router_id(x,y)][EAST] = router_chan_out [`router_id(0,y)][WEST];
|
assign router_chan_in[`router_id(x,y)][EAST] = router_chan_out [`router_id(0,y)][WEST];
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
end else if(TOPOLOGY == "FMESH") begin : last_x_fmesh //connect to endp
|
end else if(TOPOLOGY == "FMESH") begin : last_x_fmesh //connect to endp
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
localparam EAST_ID = NX*NY*NL + 2*NX + NY +y;
|
localparam EAST_ID = NX*NY*NL + 2*NX + NY +y;
|
assign router_chan_in [`router_id(x,y)][EAST] = chan_in_all [EAST_ID];
|
assign router_chan_in [`router_id(x,y)][EAST] = chan_in_all [EAST_ID];
|
assign chan_out_all [EAST_ID] = router_chan_out [`router_id(x,y)][EAST];
|
assign chan_out_all [EAST_ID] = router_chan_out [`router_id(x,y)][EAST];
|
end //topology
|
end //topology
|
end
|
end
|
|
|
|
|
if(y>0) begin : not_first_y
|
if(y>0) begin : not_first_y
|
assign router_chan_in[`router_id(x,y)][NORTH] = router_chan_out [`router_id(x,(y-1))][SOUTH];
|
assign router_chan_in[`router_id(x,y)][NORTH] = router_chan_out [`router_id(x,(y-1))][SOUTH];
|
end else begin :first_y
|
end else begin :first_y
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
if(TOPOLOGY == "MESH") begin : first_y_mesh
|
if(TOPOLOGY == "MESH") begin : first_y_mesh
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[`router_id(x,y)][NORTH] = {SMARTFLIT_CHANEL_w{1'b0}};
|
assign router_chan_in[`router_id(x,y)][NORTH] = {SMARTFLIT_CHANEL_w{1'b0}};
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
end else if(TOPOLOGY == "TORUS") begin :first_y_torus
|
end else if(TOPOLOGY == "TORUS") begin :first_y_torus
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[`router_id(x,y)][NORTH] = router_chan_out [`router_id(x,(NY-1))][SOUTH];
|
assign router_chan_in[`router_id(x,y)][NORTH] = router_chan_out [`router_id(x,(NY-1))][SOUTH];
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
end else if(TOPOLOGY == "FMESH") begin : first_y_fmesh //connect to endp
|
end else if(TOPOLOGY == "FMESH") begin : first_y_fmesh //connect to endp
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
localparam NORTH_ID = NX*NY*NL + x;
|
localparam NORTH_ID = NX*NY*NL + x;
|
assign router_chan_in [`router_id(x,y)][NORTH] = chan_in_all [NORTH_ID];
|
assign router_chan_in [`router_id(x,y)][NORTH] = chan_in_all [NORTH_ID];
|
assign chan_out_all [NORTH_ID] = router_chan_out [`router_id(x,y)][NORTH];
|
assign chan_out_all [NORTH_ID] = router_chan_out [`router_id(x,y)][NORTH];
|
end//topology
|
end//topology
|
end//y>0
|
end//y>0
|
|
|
|
|
if(x>0)begin :not_first_x
|
if(x>0)begin :not_first_x
|
assign router_chan_in[`router_id(x,y)][WEST] = router_chan_out [`router_id((x-1),y)][EAST];
|
assign router_chan_in[`router_id(x,y)][WEST] = router_chan_out [`router_id((x-1),y)][EAST];
|
end else begin :first_x
|
end else begin :first_x
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
if(TOPOLOGY == "MESH") begin :first_x_mesh
|
if(TOPOLOGY == "MESH") begin :first_x_mesh
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[`router_id(x,y)][WEST] = {SMARTFLIT_CHANEL_w{1'b0}};
|
assign router_chan_in[`router_id(x,y)][WEST] = {SMARTFLIT_CHANEL_w{1'b0}};
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
end else if(TOPOLOGY == "TORUS") begin :first_x_torus
|
end else if(TOPOLOGY == "TORUS") begin :first_x_torus
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[`router_id(x,y)][WEST] = router_chan_out [`router_id((NX-1),y)][EAST] ;
|
assign router_chan_in[`router_id(x,y)][WEST] = router_chan_out [`router_id((NX-1),y)][EAST] ;
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
end else if(TOPOLOGY == "FMESH") begin : first_x_fmesh //connect to endp
|
end else if(TOPOLOGY == "FMESH") begin : first_x_fmesh //connect to endp
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
localparam WEST_ID = NX*NY*NL +2*NX + y;
|
localparam WEST_ID = NX*NY*NL +2*NX + y;
|
assign router_chan_in [`router_id(x,y)][WEST] = chan_in_all [WEST_ID];
|
assign router_chan_in [`router_id(x,y)][WEST] = chan_in_all [WEST_ID];
|
assign chan_out_all [WEST_ID] = router_chan_out [`router_id(x,y)][WEST];
|
assign chan_out_all [WEST_ID] = router_chan_out [`router_id(x,y)][WEST];
|
end//topology
|
end//topology
|
end
|
end
|
|
|
if(y < NY-1) begin : firsty
|
if(y < NY-1) begin : firsty
|
assign router_chan_in[`router_id(x,y)][SOUTH] = router_chan_out [`router_id(x,(y+1))][NORTH];
|
assign router_chan_in[`router_id(x,y)][SOUTH] = router_chan_out [`router_id(x,(y+1))][NORTH];
|
end else begin : lasty
|
end else begin : lasty
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
if(TOPOLOGY == "MESH") begin :ly_mesh
|
if(TOPOLOGY == "MESH") begin :ly_mesh
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[`router_id(x,y)][SOUTH]= {SMARTFLIT_CHANEL_w{1'b0}};
|
assign router_chan_in[`router_id(x,y)][SOUTH]= {SMARTFLIT_CHANEL_w{1'b0}};
|
/* verilator lint_off WIDTH */
|
/* verilator lint_off WIDTH */
|
end else if(TOPOLOGY == "TORUS") begin :ly_torus
|
end else if(TOPOLOGY == "TORUS") begin :ly_torus
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
assign router_chan_in[`router_id(x,y)][SOUTH]= router_chan_out [`router_id(x,0)][NORTH];
|
assign router_chan_in[`router_id(x,y)][SOUTH]= router_chan_out [`router_id(x,0)][NORTH];
|
end else if(TOPOLOGY == "FMESH") begin : ly_fmesh //connect to endp
|
end else if(TOPOLOGY == "FMESH") begin : ly_fmesh //connect to endp
|
/* verilator lint_on WIDTH */
|
/* verilator lint_on WIDTH */
|
localparam SOUTH_ID = NX*NY*NL + NX + x;
|
localparam SOUTH_ID = NX*NY*NL + NX + x;
|
assign router_chan_in [`router_id(x,y)][SOUTH] = chan_in_all [SOUTH_ID];
|
assign router_chan_in [`router_id(x,y)][SOUTH] = chan_in_all [SOUTH_ID];
|
assign chan_out_all [SOUTH_ID] = router_chan_out [`router_id(x,y)][SOUTH];
|
assign chan_out_all [SOUTH_ID] = router_chan_out [`router_id(x,y)][SOUTH];
|
end//topology
|
end//topology
|
end
|
end
|
|
|
|
|
// endpoint(s) connection
|
// endpoint(s) connection
|
// connect other local ports
|
// connect other local ports
|
for (l=0; l
|
for (l=0; l
|
localparam ENDPID = `endp_id(x,y,l);
|
localparam ENDPID = `endp_id(x,y,l);
|
localparam LOCALP = (l==0) ? l : l + R2R_CHANELS_MESH_TORI; // first local port is connected to router port 0. The rest are connected at the end
|
localparam LOCALP = (l==0) ? l : l + R2R_CHANELS_MESH_TORI; // first local port is connected to router port 0. The rest are connected at the end
|
|
|
assign router_chan_in [`router_id(x,y)][LOCALP] = chan_in_all [ENDPID];
|
assign router_chan_in [`router_id(x,y)][LOCALP] = chan_in_all [ENDPID];
|
assign chan_out_all [ENDPID] = router_chan_out [`router_id(x,y)][LOCALP];
|
assign chan_out_all [ENDPID] = router_chan_out [`router_id(x,y)][LOCALP];
|
|
|
end// locals
|
end// locals
|
|
|
end //y
|
end //y
|
end //x
|
end //x
|
end// mesh_torus
|
end// mesh_torus
|
|
|
endgenerate
|
endgenerate
|
|
|
endmodule
|
endmodule
|
|
|