Skip to content

Commit dcf44a8

Browse files
packet_filter: Initial commit
- Added packet filter base class - Updated publisher with the filter class Signed-off-by: Istvan-Zsolt Szekely <istvan.szekely@analog.com>
1 parent 46b53bb commit dcf44a8

File tree

2 files changed

+81
-5
lines changed

2 files changed

+81
-5
lines changed

library/utilities/filter_pkg.sv

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// ***************************************************************************
2+
// ***************************************************************************
3+
// Copyright (C) 2025 Analog Devices, Inc. All rights reserved.
4+
//
5+
// In this HDL repository, there are many different and unique modules, consisting
6+
// of various HDL (Verilog or VHDL) components. The individual modules are
7+
// developed independently, and may be accompanied by separate and unique license
8+
// terms.
9+
//
10+
// The user should read each of these license terms, and understand the
11+
// freedoms and responsabilities that he or she has by using this source/core.
12+
//
13+
// This core is distributed in the hope that it will be useful, but WITHOUT ANY
14+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15+
// A PARTICULAR PURPOSE.
16+
//
17+
// Redistribution and use of source or resulting binaries, with or without modification
18+
// of this file, are permitted under one of the following two license terms:
19+
//
20+
// 1. The GNU General Public License version 2 as published by the
21+
// Free Software Foundation, which can be found in the top level directory
22+
// of this repository (LICENSE_GPL2), and also online at:
23+
// <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
24+
//
25+
// OR
26+
//
27+
// 2. An ADI specific BSD license, which can be found in the top level directory
28+
// of this repository (LICENSE_ADIBSD), and also on-line at:
29+
// https://github.com/analogdevicesinc/hdl/blob/main/LICENSE_ADIBSD
30+
// This will allow to generate bit files and not release the source code,
31+
// as long as it attaches to an ADI device.
32+
//
33+
// ***************************************************************************
34+
// ***************************************************************************
35+
36+
`include "utils.svh"
37+
38+
package filter_pkg;
39+
40+
import logger_pkg::*;
41+
import adi_common_pkg::*;
42+
43+
class adi_filter #(type data_type = int) extends adi_component;
44+
45+
function new(
46+
input string name,
47+
input adi_component parent = null);
48+
49+
super.new(name, parent);
50+
endfunction: new
51+
52+
virtual function bit filter(input data_type data [$]);
53+
return 1'b0;
54+
endfunction: filter
55+
56+
endclass: adi_filter
57+
58+
endpackage

library/utilities/pub_sub_pkg.sv

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,48 @@ package pub_sub_pkg;
6666

6767
protected adi_subscriber #(data_type) subscriber_list[bit[15:0]];
6868

69+
protected adi_filter #(data_type) filter;
70+
6971
function new(
7072
input string name,
7173
input adi_component parent = null);
7274

7375
super.new(name, parent);
7476
endfunction: new
77+
78+
function void setup_filter(input adi_filter #(data_type) filter);
79+
this.filter = filter;
80+
endfunction: setup_filter
81+
82+
function void remove_filter();
83+
this.filter = null;
84+
endfunction: remove_filter
7585

7686
function void subscribe(input adi_subscriber #(data_type) subscriber);
77-
if (this.subscriber_list.exists(subscriber.id))
87+
if (this.subscriber_list.exists(subscriber.id)) begin
7888
this.error($sformatf("Subscriber already on the list!"));
79-
else
89+
end else begin
8090
this.subscriber_list[subscriber.id] = subscriber;
91+
end
8192
endfunction: subscribe
8293

8394
function void unsubscribe(input adi_subscriber #(data_type) subscriber);
84-
if (!this.subscriber_list.exists(subscriber.id))
95+
if (!this.subscriber_list.exists(subscriber.id)) begin
8596
this.error($sformatf("Subscriber does not exist on list!"));
86-
else
97+
end else begin
8798
this.subscriber_list.delete(subscriber.id);
99+
end
88100
endfunction: unsubscribe
89101

90102
function void notify(input data_type data [$]);
91-
foreach (this.subscriber_list[i])
103+
if (this.filter != null) begin
104+
if (!this.filter.filter(data)) begin
105+
return;
106+
end
107+
end
108+
foreach (this.subscriber_list[i]) begin
92109
this.subscriber_list[i].update(data);
110+
end
93111
endfunction: notify
94112

95113
endclass: adi_publisher

0 commit comments

Comments
 (0)