-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNMID_cmp.v
189 lines (171 loc) · 5.39 KB
/
NMID_cmp.v
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
//===============================================================//
// Module name: NMID comparer for FAST2.0;
// Communication with lijunnan([email protected])
// Last edited time: 2018/11/15 (_zZ asdfghjkllllllllllllllllllllllllllllllllllllllllll)
// Function outline: USG_v0.1
//===============================================================//
`timescale 1ns/1ps
module NMID_cmp(
clk,
reset,
pktin_data_wr,
pktin_data,
pktin_data_wr_p,
pktin_data_p,
pktout_data_wr_p,
pktout_data_p,
pktout_data_wr,
pktout_data
);
/* width or depth or words info. of signals
*/
parameter LMID = 7, // lmid of firewall;
w_pkt = 134; // the width of packet if FAST2.0;
input clk;
input reset;
input pktin_data_wr;
input [w_pkt-1:0] pktin_data;
input pktin_data_wr_p;
input [w_pkt-1:0] pktin_data_p;
output reg pktout_data_wr_p;
output reg [w_pkt-1:0] pktout_data_p;
output reg pktout_data_wr;
output reg [w_pkt-1:0] pktout_data;
/*************************************************************************************/
/*** varialbe declaration */
/** FIFOs used to buffer packet, pfv,
* and fifo_1 used to buffer packets returned from function module,
* while fifo_2 used to buffer packets whose NMID not equal to LMID;
*/
reg rdreq_pkt_1, rdreq_pkt_2;
reg wrreq_pkt_2;
reg [w_pkt-1:0] data_pkt_2;
wire [w_pkt-1:0] q_pkt_1, q_pkt_2;
wire empty_pkt_1, empty_pkt_2;
/** temps: '1' represent NMID not equal to LMID*/
reg unequalTag;
/** states */
reg [3:0] state_output;
parameter IDLE_S = 4'd0,
READ_FIFO_S = 4'd1,
WAIT_PKT_TAIL_S = 4'd2;
/*************************************************************************************/
/** if module_bitmap[LMID] is '1', sending the packet to the function module*/
always @(posedge clk or negedge reset) begin
if (!reset) begin
pktout_data_wr_p <= 1'b0;
pktout_data_p <= {w_pkt{1'b0}};
wrreq_pkt_2 <= 1'b0;
data_pkt_2 <= {w_pkt{1'b0}};
unequalTag <= 1'b0;
end
else begin
// wait for packet's header;
if((pktin_data_wr == 1'b1) && (pktin_data[133:132] == 2'b01)) begin
if(pktin_data[26+LMID] == 1'b1) begin // valid, send to function module;
pktout_data_wr_p <= 1'b1;
unequalTag <= 1'b0;
end
else begin // not equal;
wrreq_pkt_2 <= 1'b1;
unequalTag <= 1'b1;
end
end
else begin // data except packet's header;
pktout_data_wr_p <= pktin_data_wr & ~unequalTag;
wrreq_pkt_2 <= pktin_data_wr & unequalTag;
end
pktout_data_p <= pktin_data;
data_pkt_2 <= pktin_data;
end
end
/*************************************************************************************/
/** state for output packets */
always @(posedge clk or negedge reset) begin
if (!reset) begin
// output signals inilization;
pktout_data_wr <= 1'b0;
pktout_data <= {w_pkt{1'b0}};
// intermediate register inilization;
rdreq_pkt_1 <= 1'b0;
rdreq_pkt_2 <= 1'b0;
// state inilizaition;
state_output <= IDLE_S;
end
else begin
case(state_output)
IDLE_S: begin
// initialization;
pktout_data_wr <= 1'b0;
// fifo is not empty and (output is ready);
if(empty_pkt_2 == 1'b0) begin
rdreq_pkt_2 <= 1'b1;
state_output <= READ_FIFO_S;
end
else if(empty_pkt_1 == 1'b0) begin
rdreq_pkt_1 <= 1'b1;
state_output <= READ_FIFO_S;
end
else begin
state_output <= IDLE_S;
end
end
READ_FIFO_S: begin
pktout_data_wr <= 1'b1;
if(rdreq_pkt_1 == 1'b1) begin
pktout_data <= q_pkt_1;
end
else begin
pktout_data <= q_pkt_2;
end
state_output <= WAIT_PKT_TAIL_S;
end
WAIT_PKT_TAIL_S: begin
pktout_data_wr <= 1'b1;
if(rdreq_pkt_1 == 1'b1) pktout_data <= q_pkt_1;
else pktout_data <= q_pkt_2;
/** state */
if((q_pkt_1[133:132] == 2'b10) && (rdreq_pkt_1 == 1'b1)) begin
rdreq_pkt_1 <= 1'b0;
rdreq_pkt_2 <= 1'b0;
state_output <= IDLE_S;
end
else if((q_pkt_2[133:132] == 2'b10) && (rdreq_pkt_2 == 1'b1)) begin
rdreq_pkt_1 <= 1'b0;
rdreq_pkt_2 <= 1'b0;
state_output <= IDLE_S;
end
else begin
state_output <= WAIT_PKT_TAIL_S;
end
end
default: begin
state_output <= IDLE_S;
end
endcase
end
end
/*** submodules */
fifo_134_256 pkt_buffer_1 (
.clk(clk), // input wire clk
.srst(!reset), // input wire srst
.din(pktin_data_p), // input wire [133 : 0] din
.wr_en(pktin_data_wr_p), // input wire wr_en
.rd_en(rdreq_pkt_1), // input wire rd_en
.dout(q_pkt_1), // output wire [133 : 0] dout
.full(), // output wire full
.empty(empty_pkt_1) // output wire empty
//.data_count() // output wire [7 : 0] data_count
);
fifo_134_256 pkt_buffer_2 (
.clk(clk), // input wire clk
.srst(!reset), // input wire srst
.din(data_pkt_2), // input wire [133 : 0] din
.wr_en(wrreq_pkt_2), // input wire wr_en
.rd_en(rdreq_pkt_2), // input wire rd_en
.dout(q_pkt_2), // output wire [133 : 0] dout
.full(), // output wire full
.empty(empty_pkt_2) // output wire empty
//.data_count() // output wire [7 : 0] data_count
);
endmodule