Adding CamEntry which is used in the CAM.
authorDaniel Benusovich <flyingmonkeys1996@gmail.com>
Sat, 16 Feb 2019 21:26:50 +0000 (13:26 -0800)
committerDaniel Benusovich <flyingmonkeys1996@gmail.com>
Sat, 16 Feb 2019 21:26:50 +0000 (13:26 -0800)
TLB/CamEntry.py [new file with mode: 0644]

diff --git a/TLB/CamEntry.py b/TLB/CamEntry.py
new file mode 100644 (file)
index 0000000..6351d0e
--- /dev/null
@@ -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