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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
module packet_router
#(parameter BUF_SIZE = 9)
(
//wishbone interface for memory mapped CPU frames
input wb_clk_i,
input wb_rst_i,
input wb_we_i,
input wb_stb_i,
input [15:0] wb_adr_i,
input [31:0] wb_dat_i,
output [31:0] wb_dat_o,
output reg wb_ack_o,
output wb_err_o,
output wb_rty_o,
input stream_clk,
input stream_rst,
//input control register
input [31:0] control,
//output status register
output [31:0] status,
output sys_int_o, //want an interrupt?
// Input Interfaces (in to router)
input [35:0] eth_inp_data, input eth_inp_valid, output eth_inp_ready,
// Output Interfaces (out of router)
output [35:0] dsp_out_data, output dsp_out_valid, input dsp_out_ready,
output [35:0] eth_out_data, output eth_out_valid, input eth_out_ready
);
assign wb_err_o = 1'b0; // Unused for now
assign wb_rty_o = 1'b0; // Unused for now
always @(posedge wb_clk_i)
wb_ack_o <= wb_stb_i & ~wb_ack_o;
////////////////////////////////////////////////////////////////////
// CPU interface to this packet router
////////////////////////////////////////////////////////////////////
wire [35:0] cpu_inp_data;
wire cpu_inp_valid;
wire cpu_inp_ready;
wire [35:0] cpu_out_data;
wire cpu_out_valid;
wire cpu_out_ready;
//which buffer: 0 = CPU read buffer, 1 = CPU write buffer
wire which_buf = wb_adr_i[BUF_SIZE+2];
////////////////////////////////////////////////////////////////////
// status and control handshakes
////////////////////////////////////////////////////////////////////
wire cpu_inp_hs_ctrl = control[0];
wire cpu_out_hs_ctrl = control[1];
wire [BUF_SIZE-1:0] cpu_out_line_count = control[BUF_SIZE-1+16:0+16];
wire cpu_inp_hs_stat;
assign status[0] = cpu_inp_hs_stat;
wire [BUF_SIZE-1:0] cpu_inp_line_count;
assign status[BUF_SIZE-1+16:0+16] = cpu_inp_line_count;
wire cpu_out_hs_stat;
assign status[1] = cpu_out_hs_stat;
////////////////////////////////////////////////////////////////////
// Ethernet input control
////////////////////////////////////////////////////////////////////
//TODO: just connect eth input to cpu input for now
//assign cpu_inp_data = eth_inp_data;
//assign cpu_inp_valid = eth_inp_valid;
//assign eth_inp_ready = cpu_inp_ready;
////////////////////////////////////////////////////////////////////
// Ethernet output control
////////////////////////////////////////////////////////////////////
//TODO: just connect eth output to cpu output for now
assign eth_out_data = cpu_out_data;
assign eth_out_valid = cpu_out_valid;
assign cpu_out_ready = eth_out_ready;
////////////////////////////////////////////////////////////////////
// Interface CPU input interface to memory mapped wishbone
////////////////////////////////////////////////////////////////////
localparam CPU_INP_STATE_WAIT_SOF = 0;
localparam CPU_INP_STATE_WAIT_EOF = 1;
localparam CPU_INP_STATE_WAIT_CTRL_HI = 2;
localparam CPU_INP_STATE_WAIT_CTRL_LO = 3;
reg [1:0] cpu_inp_state;
reg [BUF_SIZE-1:0] cpu_inp_addr;
assign cpu_inp_line_count = cpu_inp_addr;
wire [BUF_SIZE-1:0] cpu_inp_addr_next = cpu_inp_addr + 1'b1;
wire cpu_inp_reading = (
cpu_inp_state == CPU_INP_STATE_WAIT_SOF ||
cpu_inp_state == CPU_INP_STATE_WAIT_EOF
)? 1'b1 : 1'b0;
wire cpu_inp_we = cpu_inp_reading;
assign cpu_inp_ready = cpu_inp_reading;
assign cpu_inp_hs_stat = (cpu_inp_state == CPU_INP_STATE_WAIT_CTRL_HI)? 1'b1 : 1'b0;
RAMB16_S36_S36 cpu_inp_buff(
//port A = wishbone memory mapped address space (output only)
.DOA(wb_dat_o),.ADDRA(wb_adr_i[BUF_SIZE+1:2]),.CLKA(wb_clk_i),.DIA(36'b0),.DIPA(4'h0),
.ENA(wb_stb_i & (which_buf == 1'b0)),.SSRA(0),.WEA(wb_we_i),
//port B = packet router interface to CPU (input only)
.DOB(),.ADDRB(cpu_inp_addr),.CLKB(stream_clk),.DIB(cpu_inp_data),.DIPB(4'h0),
.ENB(cpu_inp_we),.SSRB(0),.WEB(cpu_inp_we)
);
always @(posedge stream_clk)
if(stream_rst) begin
cpu_inp_state <= CPU_INP_STATE_WAIT_SOF;
cpu_inp_addr <= 0;
end
else begin
case(cpu_inp_state)
CPU_INP_STATE_WAIT_SOF: begin
if (cpu_inp_ready & cpu_inp_valid & (cpu_inp_data[32] == 1'b1)) begin
cpu_inp_state <= CPU_INP_STATE_WAIT_EOF;
cpu_inp_addr <= cpu_inp_addr_next;
end
end
CPU_INP_STATE_WAIT_EOF: begin
if (cpu_inp_ready & cpu_inp_valid & (cpu_inp_data[33] == 1'b1)) begin
cpu_inp_state <= CPU_INP_STATE_WAIT_CTRL_HI;
end
if (cpu_inp_ready & cpu_inp_valid) begin
cpu_inp_addr <= cpu_inp_addr_next;
end
end
CPU_INP_STATE_WAIT_CTRL_HI: begin
if (cpu_inp_hs_ctrl == 1'b1) begin
cpu_inp_state <= CPU_INP_STATE_WAIT_CTRL_LO;
end
end
CPU_INP_STATE_WAIT_CTRL_LO: begin
if (cpu_inp_hs_ctrl == 1'b0) begin
cpu_inp_state <= CPU_INP_STATE_WAIT_SOF;
end
cpu_inp_addr <= 0; //reset the address counter
end
endcase //cpu_inp_state
end
////////////////////////////////////////////////////////////////////
// Interface CPU output interface to memory mapped wishbone
////////////////////////////////////////////////////////////////////
localparam CPU_OUT_STATE_WAIT_CTRL_HI = 0;
localparam CPU_OUT_STATE_WAIT_CTRL_LO = 1;
localparam CPU_OUT_STATE_UNLOAD = 2;
reg [1:0] cpu_out_state;
reg [BUF_SIZE-1:0] cpu_out_addr;
wire [BUF_SIZE-1:0] cpu_out_addr_next = cpu_out_addr + 1'b1;
reg [BUF_SIZE-1:0] cpu_out_line_count_reg;
reg cpu_out_flag_sof;
reg cpu_out_flag_eof;
assign cpu_out_data[35:32] = {2'b0, cpu_out_flag_eof, cpu_out_flag_sof};
assign cpu_out_valid = (cpu_out_state == CPU_OUT_STATE_UNLOAD)? 1'b1 : 1'b0;
assign cpu_out_hs_stat = (cpu_out_state == CPU_OUT_STATE_WAIT_CTRL_HI)? 1'b1 : 1'b0;
RAMB16_S36_S36 cpu_out_buff(
//port A = wishbone memory mapped address space (input only)
.DOA(),.ADDRA(wb_adr_i[BUF_SIZE+1:2]),.CLKA(wb_clk_i),.DIA(wb_dat_i),.DIPA(4'h0),
.ENA(wb_stb_i & (which_buf == 1'b1)),.SSRA(0),.WEA(wb_we_i),
//port B = packet router interface from CPU (output only)
.DOB(cpu_out_data[31:0]),.ADDRB(cpu_out_addr),.CLKB(stream_clk),.DIB(36'b0),.DIPB(4'h0),
.ENB(1'b1),.SSRB(0),.WEB(1'b0)
);
always @(posedge stream_clk)
if(stream_rst) begin
cpu_out_state <= CPU_OUT_STATE_WAIT_CTRL_HI;
cpu_out_addr <= 0;
end
else begin
case(cpu_out_state)
CPU_OUT_STATE_WAIT_CTRL_HI: begin
if (cpu_out_hs_ctrl == 1'b1) begin
cpu_out_state <= CPU_OUT_STATE_WAIT_CTRL_LO;
end
cpu_out_line_count_reg <= cpu_out_line_count;
cpu_out_addr <= 0; //reset the address counter
end
CPU_OUT_STATE_WAIT_CTRL_LO: begin
if (cpu_out_hs_ctrl == 1'b0) begin
cpu_out_state <= CPU_OUT_STATE_UNLOAD;
cpu_out_addr <= cpu_out_addr_next;
end
cpu_out_flag_sof <= 1'b1;
cpu_out_flag_eof <= 1'b0;
end
CPU_OUT_STATE_UNLOAD: begin
if (cpu_out_ready & cpu_out_valid) begin
cpu_out_addr <= cpu_out_addr_next;
cpu_out_flag_sof <= 1'b0;
if (cpu_out_addr == cpu_out_line_count_reg) begin
cpu_out_flag_eof <= 1'b1;
end
else begin
cpu_out_flag_eof <= 1'b0;
end
if (cpu_out_flag_eof) begin
cpu_out_state <= CPU_OUT_STATE_WAIT_CTRL_HI;
end
end
end
endcase //cpu_out_state
end
////////////////////////////////////////////////////////////////////
// Ethernet input inspector
// - inspect Ethernet and send it to CPU or DSP
////////////////////////////////////////////////////////////////////
localparam ETH_INSP_READ_ETH_PRE = 0;
localparam ETH_INSP_READ_ETH = 1;
localparam ETH_INSP_WRITE_DSP_REGS = 2;
localparam ETH_INSP_WRITE_DSP_LIVE = 3;
localparam ETH_INSP_WRITE_CPU_REGS = 4;
localparam ETH_INSP_WRITE_CPU_LIVE = 5;
localparam ETH_INSP_MAX_NUM_DREGS = 12; //padded_eth + ip + udp + vrt_hdr lines
localparam ETH_INSP_DREGS_DSP_OFFSET = 10; //offset to start dsp at
reg [2:0] eth_insp_state;
reg [3:0] eth_insp_dreg_count; //data registers to buffer headers
wire [3:0] eth_insp_dreg_count_next = eth_insp_dreg_count + 1'b1;
reg [35:0] eth_insp_dregs [ETH_INSP_MAX_NUM_DREGS-1:0];
wire eth_inp_dregs_is_data = 1'b0; //TODO (not data for now)
/////////////////////////////////////
//assign output signals to CPU input
/////////////////////////////////////
assign cpu_inp_data = (eth_insp_state == ETH_INSP_WRITE_CPU_REGS)?
eth_insp_dregs[eth_insp_dreg_count] : eth_inp_data
;
assign cpu_inp_valid =
(eth_insp_state == ETH_INSP_WRITE_CPU_REGS)? 1'b1 : (
(eth_insp_state == ETH_INSP_WRITE_CPU_LIVE)? eth_inp_valid : (
1'b0));
/////////////////////////////////////
//assign output signals to DSP output
/////////////////////////////////////
wire [3:0] eth_insp_dsp_flags = (eth_insp_dreg_count == ETH_INSP_DREGS_DSP_OFFSET)?
4'b0001 : 4'b0000
;
assign dsp_out_data = (eth_insp_state == ETH_INSP_WRITE_DSP_REGS)?
{eth_insp_dsp_flags, eth_insp_dregs[eth_insp_dreg_count][31:0]} : eth_inp_data
;
assign dsp_out_valid =
(eth_insp_state == ETH_INSP_WRITE_DSP_REGS)? 1'b1 : (
(eth_insp_state == ETH_INSP_WRITE_DSP_LIVE)? eth_inp_valid : (
1'b0));
/////////////////////////////////////
//assign output signal to ETH input
/////////////////////////////////////
assign eth_inp_ready =
(eth_insp_state == ETH_INSP_READ_ETH_PRE) ? 1'b1 : (
(eth_insp_state == ETH_INSP_READ_ETH) ? 1'b1 : (
(eth_insp_state == ETH_INSP_WRITE_DSP_LIVE)? dsp_out_ready : (
(eth_insp_state == ETH_INSP_WRITE_CPU_LIVE)? cpu_inp_ready : (
1'b0))));
always @(posedge stream_clk)
if(stream_rst) begin
eth_insp_state <= ETH_INSP_READ_ETH_PRE;
eth_insp_dreg_count <= 0;
end
else begin
case(eth_insp_state)
ETH_INSP_READ_ETH_PRE: begin
if (eth_inp_ready & eth_inp_valid & eth_inp_data[32]) begin
eth_insp_state <= ETH_INSP_READ_ETH;
eth_insp_dreg_count <= eth_insp_dreg_count_next;
eth_insp_dregs[eth_insp_dreg_count] <= eth_inp_data;
end
end
ETH_INSP_READ_ETH: begin
if (eth_inp_ready & eth_inp_valid) begin
eth_insp_dregs[eth_insp_dreg_count] <= eth_inp_data;
if (eth_inp_dregs_is_data & (eth_insp_dreg_count_next == ETH_INSP_MAX_NUM_DREGS)) begin
eth_insp_state <= ETH_INSP_WRITE_DSP_REGS;
eth_insp_dreg_count <= ETH_INSP_DREGS_DSP_OFFSET;
end
else if (eth_inp_data[33] | (eth_insp_dreg_count_next == ETH_INSP_MAX_NUM_DREGS)) begin
eth_insp_state <= ETH_INSP_WRITE_CPU_REGS;
eth_insp_dreg_count <= 0;
end
else begin
eth_insp_dreg_count <= eth_insp_dreg_count_next;
end
end
end
ETH_INSP_WRITE_DSP_REGS: begin
if (dsp_out_ready & dsp_out_valid) begin
eth_insp_dreg_count <= eth_insp_dreg_count_next;
if (eth_insp_dreg_count_next == ETH_INSP_MAX_NUM_DREGS) begin
eth_insp_state <= ETH_INSP_WRITE_DSP_LIVE;
eth_insp_dreg_count <= 0;
end
end
end
ETH_INSP_WRITE_DSP_LIVE: begin
if (dsp_out_ready & dsp_out_valid & eth_inp_data[33]) begin
eth_insp_state <= ETH_INSP_READ_ETH_PRE;
end
end
ETH_INSP_WRITE_CPU_REGS: begin
if (cpu_inp_ready & cpu_inp_valid) begin
eth_insp_dreg_count <= eth_insp_dreg_count_next;
if (cpu_inp_data[33]) begin
eth_insp_state <= ETH_INSP_READ_ETH_PRE;
eth_insp_dreg_count <= 0;
end
else if (eth_insp_dreg_count_next == ETH_INSP_MAX_NUM_DREGS) begin
eth_insp_state <= ETH_INSP_WRITE_CPU_LIVE;
eth_insp_dreg_count <= 0;
end
end
end
ETH_INSP_WRITE_CPU_LIVE: begin
if (cpu_inp_ready & cpu_inp_valid & eth_inp_data[33]) begin
eth_insp_state <= ETH_INSP_READ_ETH_PRE;
end
end
endcase //eth_insp_state
end
endmodule // packet_router
|