Repository navigation
Expand file tree
/
Copy pathnet_emulation.sv
More file actions
169 lines (128 loc) · 4.56 KB
/
Copy pathnet_emulation.sv
File metadata and controls
169 lines (128 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
`include "config.sv"
//`timescale 10ps/1ps
/////////////////////////////////////////////
///////// MODULE DEF FOR SYNTHESIS //////////
/////////////////////////////////////////////
`ifdef SYNTHESIS
module net_emulation (
input logic clkp, clkn,
input rst,
output logic [`PORTS-1:0] input_fifo_error,
output logic [`PORTS-1:0] dest_error);
// Internal signals specific to synthesis
// Chipscope signals
/////////////////////////////////////////////
//////// MODULE DEF FOR SIMULATION //////////
/////////////////////////////////////////////
`else
module net_emulation ();
// Internal signals specific to simulation
logic rst;
logic [`PORTS-1:0] input_fifo_error;
//logic [`PORTS-1:0] dest_error;
`endif
/////////////////////////////////////////////
//////// COMMON SIGNALS FOR SYNTH/SIM ///////
/////////////////////////////////////////////
logic clk;
logic [29:0] timestamp;
logic measure;
logic source_on;
packet_t pkt_in [0:`PORTS-1] /* synthesis keep */;
packet_t pkt_out [0:`PORTS-1] /* synthesis keep */;
logic [`PORTS-1:0] net_full /* synthesis keep */;
logic [`PORTS-1:0] nearly_full;
//logic [15:0] pkt_count_source [0:`PORTS-1] /* synthesis keep */;
//logic [15:0] pkt_count_dest [0:`PORTS-1] /* synthesis keep */;
//logic [23:0] latency [0:`PORTS-1] /* synthesis keep */;
genvar i;
`ifdef VHDL
logic [`PKT_SIZE*`PORTS-1:0] pkt_in_vhdl /* synthesis keep */;
logic [`PKT_SIZE*`PORTS-1:0] pkt_out_vhdl /* synthesis keep */;
integer k;
`endif
//////////////////////////////////////////////////////////////////////
////////////// COMMON CODE FOR SIM AND SYNTH /////////////////////////
//////////////////////////////////////////////////////////////////////
// Instantiate pkt_sources
generate for (i=0;i<`PORTS;i++)
begin: source_loop
packet_source #(i) pkts (clk, (rst | (!source_on)), timestamp, net_full[i], pkt_in[i], input_fifo_error[i]);
end
endgenerate
// Instantiate pkt sink
packet_sink sinks (clk, rst, pkt_out, pkt_in, timestamp, input_fifo_error, net_full,nearly_full, measure);
// Timestamp counter
always_ff @(posedge clk)
if (rst)
timestamp <= 0;
else
timestamp <= timestamp + 1;
//////////////////////////////////////////////////////////////////////
////////////////////// INSTANTIATE NETWORK ///////////////////////////
//////////////////////////////////////////////////////////////////////
`ifdef VHDL
// VHDL network model
generate for (i=0;i<`PORTS;i++) begin
always_comb begin
pkt_in_vhdl[(i+1)*`PKT_SIZE-1:i*`PKT_SIZE] = {pkt_in[i].data, pkt_in[i].source, pkt_in[i].dest, pkt_in[i].valid};
pkt_out[i].data = pkt_out_vhdl[(i+1)*`PKT_SIZE-1:i*`PKT_SIZE+(2*log2(`PORTS))+1];
pkt_out[i].source = pkt_out_vhdl[i*`PKT_SIZE+(2*log2(`PORTS)):i*`PKT_SIZE+log2(`PORTS)+1];
pkt_out[i].dest = pkt_out_vhdl[i*`PKT_SIZE+log2(`PORTS):i*`PKT_SIZE+1];
pkt_out[i].valid = pkt_out_vhdl[i*`PKT_SIZE];
end
end
endgenerate
network #(`PORTS, log2(`PORTS), `FIFO_DEPTH, `PAYLOAD) inst_net(clk, rst, pkt_in_vhdl, pkt_out_vhdl, full, nearly_full);
`else
// SystemVerilog network model
network inst_net(clk, rst, pkt_in, pkt_out, net_full, nearly_full);
`endif
/////////////////////////////////////////////
////////// CODE SPECIFIC TO SYNTH ///////////
/////////////////////////////////////////////
`ifdef SYNTHESIS
// Generate system clock
assign clk = clkp;
// Set rate via chipscope
// Simulation timing control
/////////////////////////////////////////////
/////////// CODE SPECIFIC TO SIM ////////////
/////////////////////////////////////////////
`else
//Generate clock
initial begin
clk = 0;
forever #(`CLK_PERIOD/2) clk = ~clk;
end
// Generate reset
initial begin
rst = 1;
measure = 0;
source_on = 1;
`ifdef VCD_PATH // Open VCD file
$display("Setting up VCD file\n");
$dumpfile("synth/vcd/netemulation.vcd");
$dumpvars(0,`VCD_PATH);
`endif
#(100ns)
rst = 0;
#(`WARMUP_PERIOD)
$display("Starting measurement period at simulation time %t.\n", $realtime);
measure = 1;
`ifdef VCD // Start VCD dump
$dumpon;
`endif
#(`MEASURE_PERIOD)
$display("Ending measurement period at simulation time %t.\n", $realtime);
source_on = 0;
`ifdef VCD_FILE // End VCD dump
$dumpoff;
`endif
#(`COOLDOWN_PERIOD)
measure = 0;
#100ns
$finish;
end
`endif
endmodule