OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [hdl/] [PATLPP/] [patlpp.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
// PATLPP - PATL Packet Processor
2
// Application Specific Processor for packet processing
3
// 
4
// Instruction set is limited to data movement, FIFO operations, and compares
5
//
6
 
7
`timescale 1ns / 100ps
8
 
9
module patlpp
10
(
11
        input                           en, // module enable
12
        input                           clk, // module clock
13
        input                           rst, // module reset
14
 
15
        input                           in_sof, // start of frame input
16
        input                           in_eof, // end of frame input
17
        input                           in_src_rdy, // source of input ready
18
        output                  in_dst_rdy, // this module destination ready
19
 
20
        output                  out_sof, // start of frame output
21
        output                  out_eof, // end of frame output
22
        output                  out_src_rdy, // this module source ready
23
        input                           out_dst_rdy, // destination of output ready
24
 
25
        input           [7:0]    in_data, // data input
26
        output  [7:0]    out_data, // data output / port output
27
        output  [3:0] outport_addr, // Output Port address
28
        output  [3:0] inport_addr//, // Input Port address
29
        //output        [11:0] chipscope_data
30
);
31
 
32
// Parameters ----------------------------------------------------------------
33
 
34
 
35
// Internal wires ------------------------------------------------------------
36
// - Instruction wires
37
wire                            srst; // Soft reset
38
wire                            high_byte_reg_en; // High byte register enable
39
wire                            output_byte_s; // Output byte select
40
wire                            outport_reg_en; // Output Port Register Enable
41
wire                            inport_reg_en; // Input Port Register Enable
42
wire    [2:0]            data_mux_s; // data mux select
43
wire    [1:0]            op_0_s; // Operand 0 Select
44
wire                            op_1_s; // Operand 1 Select
45
 
46
wire    [3:0]            reg_addr; // register file address
47
wire    [1:0]            reg_wen; // write enable of higher and lower order byte in register file
48
wire                            fcs_add; // add to checksum
49
wire                            fcs_clear; // clear checksum
50
 
51
wire                            sr1_in_en; // shift register 1 input enable
52
wire                            sr2_in_en; // shift register 2 input enable
53
wire                            sr1_out_en; // shift register 1 output enable
54
wire                            sr2_out_en; // shift register 2 output enable
55
 
56
wire                            flag_reg_en; // Flag register enable
57
wire    [2:0]            comp_mode; // Compare mode
58
wire    [1:0]            alu_op; // ALU Operation
59
 
60
wire    [7:0]            const_byte; // byte constant
61
wire    [15:0]   const_word; // word constant
62
 
63
// - Intruction logic inputs
64
wire                            comp_res; // comparator result
65
wire                            fcs_check; // asserted if checksum == 0
66
 
67
// - Datapath wires
68
wire    [15:0]           op0_data; // operand 0 data
69
wire    [15:0]           op1_data; // operand 1 data
70
wire    [15:0]           alu_res_data; // ALU result
71
 
72
wire    [7:0]                    sr1_data_in; // shift register 1 data input
73
wire    [7:0]                    sr2_data_in; // shift register 2 data input
74
wire    [7:0]                    sr1_data_out; // shift register 1 data output
75
wire    [7:0]                    sr2_data_out; // shift register 2 data output
76
 
77
wire    [7:0]                    sr_data_out; // Muxed shift register data
78
 
79
wire    [15:0]           word_data; // word data line
80
wire    [15:0]           mux_output_data; // output data line
81
 
82
wire    [15:0]           reg_data_out; // register file output
83
wire    [15:0]           reg_data_in;
84
 
85
wire    [15:0]           checksum_data_in;
86
wire    [15:0]           checksum_data_out;
87
 
88
wire    [15:0]           alu_op0;
89
wire    [15:0]           alu_op1;
90
 
91
wire    [7:0]                    output_high_byte;
92
wire    [7:0]                    output_low_byte;
93
 
94
reg     [7:0]                    flag_reg;
95
reg     [3:0]                    outport_reg;
96
reg     [3:0]                    inport_reg;
97
 
98
// Wire Connections ----------------------------------------------------------
99
 
100
// Chipscope
101
//assign chipscope_data[11:8] = port_addr;
102
 
103
 
104
// Block Instantiations ------------------------------------------------------
105
microcodelogic mcodelogic_inst
106
(
107
        .clk(clk),
108
        .rst(rst),
109
        .srst(srst),
110
 
111
        .sof_in(in_sof),
112
        .eof_in(in_eof),
113
        .src_rdy_in(in_src_rdy),
114
        .dst_rdy_in(in_dst_rdy),
115
 
116
        .sof_out(out_sof),
117
        .eof_out(out_eof),
118
        .src_rdy_out(out_src_rdy),
119
        .dst_rdy_out(out_dst_rdy),
120
 
121
        .high_byte_reg_en(high_byte_reg_en),
122
        .output_byte_s(output_byte_s),
123
        .outport_reg_en(outport_reg_en),
124
        .inport_reg_en(inport_reg_en),
125
        .data_mux_s(data_mux_s),
126
        .op_0_s(op_0_s),
127
        .op_1_s(op_1_s),
128
 
129
        .reg_addr(reg_addr),
130
        .reg_wen(reg_wen),
131
 
132
        .fcs_add(fcs_add),
133
        .fcs_clear(fcs_clear),
134
        .fcs_check(fcs_check),
135
 
136
        .sr1_in_en(sr1_in_en),
137
        .sr2_in_en(sr2_in_en),
138
        .sr1_out_en(sr1_out_en),
139
        .sr2_out_en(sr2_out_en),
140
 
141
        .flag_reg_en(flag_reg_en),
142
        .comp_mode(comp_mode),
143
        .comp_res(comp_res),
144
 
145
        .alu_op(alu_op),
146
        .const_byte(const_byte),
147
        .const_word(const_word)//,
148
        //.chipscope_data(chipscope_data[7:0])
149
);
150
 
151
comparelogic comp_inst
152
(
153
        .data(alu_res_data),
154
        .mode(comp_mode[1:0]),
155
        .result(comp_res)
156
);
157
 
158
lpm_stopar #(
159
        .WIDTH(8),
160
        .DEPTH(2)
161
) in_sr (
162
        .clk(clk),
163
        .rst(rst),
164
        .en(high_byte_reg_en),
165
        .sin(in_data),
166
        .pout(word_data)
167
);
168
 
169
regfile regfile_inst
170
(
171
        .clk(clk),
172
        .rst(rst),
173
        .wren_low(reg_wen[0]),
174
        .wren_high(reg_wen[1]),
175
        .address(reg_addr),
176
        .data_in(reg_data_in),
177
        .data_out(reg_data_out)
178
);
179
 
180
shiftr sr1
181
(
182
        .en_in(sr1_in_en),
183
        .en_out(sr1_out_en),
184
        .clk(clk),
185
        .rst(rst),
186
        .srst(srst),
187
        .data_in(sr1_data_in),
188
        .data_out(sr1_data_out)
189
);
190
 
191
shiftr sr2
192
(
193
        .en_in(sr2_in_en),
194
        .en_out(sr2_out_en),
195
        .clk(clk),
196
        .rst(rst),
197
        .srst(srst),
198
        .data_in(sr2_data_in),
199
        .data_out(sr2_data_out)
200
);
201
 
202
checksum checksum_inst
203
(
204
        .clk(clk),
205
        .rst(rst),
206
 
207
        .data_in(checksum_data_in),
208
        .checksum_add(fcs_add),
209
        .checksum_clear(fcs_clear),
210
 
211
        .checksum_check(fcs_check),
212
        .checksum_out(checksum_data_out)
213
);
214
 
215
assign alu_op0 = { ( {8{~comp_mode[2]}} & op0_data[15:8] ), op0_data[7:0] };
216
assign alu_op1 = { ( {8{~comp_mode[2]}} & op1_data[15:8] ), op1_data[7:0] };
217
 
218
alunit alunit_inst
219
(
220
        .op0(alu_op0),
221
        .op1(alu_op1),
222
        .op(alu_op),
223
        .res(alu_res_data)
224
);
225
 
226
lpm_mux8 #(
227
        .WIDTH(16)
228
) main_mux
229
(
230
        .in0(const_word),
231
        .in1(checksum_data_out),
232
        .in2(reg_data_out),
233
        .in3(word_data),
234
        .in4({ 8'd0, sr_data_out}),
235
        .in5(alu_res_data),
236
        .in6({ 8'd0, flag_reg}),
237
        .in7(16'd0),
238
        .s(data_mux_s),
239
        .out(mux_output_data)
240
);
241
 
242
lpm_mux4 #(
243
        .WIDTH(16)
244
) mux_op0
245
(
246
        .in0(const_word),
247
        .in1(word_data),
248
        .in2({ 8'd0, flag_reg}),
249
        .in3(reg_data_out),
250
        .s(op_0_s),
251
        .out(op0_data)
252
);
253
 
254
lpm_mux2 #(
255
        .WIDTH(16)
256
) mux_op1
257
(
258
        .in0(const_word),
259
        .in1(reg_data_out),
260
        .s(op_1_s),
261
        .out(op1_data)
262
);
263
 
264
lpm_mux2 #(
265
        .WIDTH(8)
266
) mux_byte_select
267
(
268
        .in0(output_low_byte),
269
        .in1(output_high_byte),
270
        .s(output_byte_s),
271
        .out(out_data)
272
);
273
 
274
lpm_mux2 #(
275
        .WIDTH(8)
276
) sr_data_mux
277
(
278
        .in0(sr1_data_out),
279
        .in1(sr2_data_out),
280
        .s(sr2_out_en),
281
        .out(sr_data_out)
282
);
283
 
284
// Block Connections ---------------------------------------------------------
285
//
286
 
287
assign checksum_data_in = mux_output_data;
288
assign reg_data_in = mux_output_data;
289
assign sr1_data_in = mux_output_data[7:0];
290
assign sr2_data_in = mux_output_data[7:0];
291
assign output_low_byte = mux_output_data[7:0];
292
assign output_high_byte = mux_output_data[15:8];
293
 
294
// Flag Register -------------------------------------------------------------
295
//
296
 
297
always @(posedge clk)
298
begin
299
        if (rst || srst)
300
                flag_reg <= 0;
301
        else if (flag_reg_en)
302
        begin
303
                flag_reg <= {4'b0000, fcs_check, comp_res, in_eof, in_sof};
304
        end
305
end
306
 
307
// Port Address Registers ----------------------------------------------------
308
//
309
always @(posedge clk)
310
begin
311
        if (rst || srst)
312
        begin
313
                outport_reg <= 0;
314
                inport_reg <= 0;
315
        end
316
        else
317
        begin
318
                if (outport_reg_en)
319
                        outport_reg <= mux_output_data[3:0];
320
                if (inport_reg_en)
321
                        inport_reg <= mux_output_data[3:0];
322
        end
323
end
324
 
325
assign outport_addr = outport_reg;
326
assign inport_addr = inport_reg;
327
 
328
// Simulation Code -----------------------------------------------------------
329
//
330
integer file;
331
 
332
initial
333
begin
334
        file = $fopen("outframe.hex");
335
end
336
 
337
always @(posedge clk)
338
begin
339
        if (data_mux_s == 2 || op_1_s == 1)
340
        begin
341
                $display("Read from Reg %d: %h", reg_addr, reg_data_out);
342
        end
343
        if (reg_wen)
344
        begin
345
                $display("Written to Reg %d: %h", reg_addr, reg_data_in);
346
        end
347
        if (srst)
348
                $display("Reset Occured");
349
        if (out_src_rdy && out_dst_rdy)
350
        begin
351
                $display("Output to Port %d: %h", outport_addr, out_data);
352
                if (outport_addr == 0)
353
                        $fdisplay(file, "%h", out_data);
354
        end
355
        if (in_src_rdy && in_dst_rdy)
356
        begin
357
                $display("Input From Port %d: %h", inport_addr, in_data);
358
        end
359
        if (data_mux_s == 5)
360
        begin
361
                $display("ALU Function: %d on Op0: %d and Op1: %d", alu_op, op_0_s, op_1_s);
362
        end
363
end
364
 
365
 
366
endmodule

powered by: WebSVN 2.1.0

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