summaryrefslogtreecommitdiffhomepage
path: root/source/pkt_filter.v
blob: e632d3228b3860f110771e603a38bcf0aa5701ab (plain)
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
/* 
 *	pkt_filter.v
 *
 *   Copyright (C) 2018, 2019 Mind Chasers Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *	function: packet filter / CAM wrapper with keep / drop logic 
 *	 
 */
 
`timescale 1ns /10ps

module pkt_filter #(parameter DEPTH = 4,
			parameter DEPTHW = 2,
			parameter WIDTH = 32)
(
	input	rstn,
	input	clk,
	
	// input for programming
	input   sel,
	input 	we,
	input 	[DEPTHW+1:0] addr,
	input 	[7:0]	d_in,
	
	// registered data
	input[7:0] rx_data_m1, 
	input[7:0] rx_data_m2, 
	input[7:0] rx_data_m3, 
	input[7:0] rx_data_m4,
	
	// filter
	input new_frame,	// assert for each new frame to reset state machines
	input block,
	input invert,
	input trigger,
	output reg keep
);

reg trigger_m1;


/* trigger_m1 is used to sync the CAM search with testing the results below */
always @(posedge clk or negedge rstn)
	if (!rstn)
		trigger_m1 <= 1'b0;
	else
		trigger_m1 <= trigger;

/* keep is a one shot */
always @(posedge clk or negedge rstn)
	if (!rstn)
		keep <= 1'b0;
	else if (trigger_m1)
		if ( block )
			keep <= 1'b0;
		else if ( !invert )
			keep <= match;
		else begin
			keep <= ~match;
		end	
	else
		keep <= 1'b0;
	
cam  #(.DEPTH(DEPTH), .DEPTHW(DEPTHW), .WIDTH(WIDTH)) cam_0(
	.rstn( rstn ),
	.clk( clk ),
	
	// input for programming
	.sel( sel ),
	.we( we ),
	.addr( addr ),
	.d_in( d_in ),
	// cam action
	.search( trigger ),
	.search_address( { rx_data_m4, rx_data_m3, rx_data_m2, rx_data_m1 } ),
	.match( match )
);
	
	
	
endmodule