From 68a886493c448ec4dbc1191c3a780508d2077328 Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Sat, 16 Feb 2019 13:26:50 -0800 Subject: [PATCH] Adding CamEntry which is used in the CAM. --- TLB/CamEntry.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 TLB/CamEntry.py diff --git a/TLB/CamEntry.py b/TLB/CamEntry.py new file mode 100644 index 00000000..6351d0eb --- /dev/null +++ b/TLB/CamEntry.py @@ -0,0 +1,33 @@ +from nmigen import Module, Signal +from nmigen.cli import main + +class CamEntry(): + def __init__(self, key_size, data_size): + # Internal + key = Signal(key_size) + + # Input + self.write = Signal(1) # Read => 0 Write => 1 + self.key_in = Signal(key_size) # Reference key for the CAM + self.data_in = Signal(data_size) # Data input when writing + + # Output + self.match = Signal(1) # Result of the internal/input key comparison + self.data = Signal(data_size) + + + def elabotate(self, platform): + m = Module() + m.d.comb += [ + If(self.write == 1, + key.eq(self.key_in), + self.data.eq(self.data_in) + ).Else( + If(self.key_in == key, + self.match.eq(0) + ).Else( + self.match.eq(1) + ) + ) + ] + return m \ No newline at end of file -- 2.30.2