Updating CAM to (hopefully) full functionality. Needs more testing first though
authorDaniel Benusovich <flyingmonkeys1996@gmail.com>
Sat, 23 Feb 2019 23:01:42 +0000 (15:01 -0800)
committerDaniel Benusovich <flyingmonkeys1996@gmail.com>
Sat, 23 Feb 2019 23:01:42 +0000 (15:01 -0800)
TLB/src/Cam.py
TLB/test/test_cam.py

index 92d6e6756514afa052b5414d7ed55b9c8e631fb2..42b7f028b1bda677faf7c9dbb04b1a3abf90090d 100644 (file)
@@ -22,13 +22,9 @@ class Cam():
     #  cam_size: (entry count) The number of entries int he CAM
     def __init__(self, key_size, data_size, cam_size):
         # Internal
-        self.clk = ClockDomain(reset_less=True)
-        self.key_size = key_size
-        self.data_size = data_size
         self.cam_size = cam_size
         self.entry_array = Array(CamEntry(key_size, data_size) \
                             for x in range(cam_size))
-        self.encoder_input = Signal(cam_size)
 
         # Input
         self.command = Signal(2) # 00 => NA 01 => Read 10 => Write 11 => Search
@@ -65,9 +61,10 @@ class Cam():
             m.d.comb += [
                    self.entry_array[index].key_in.eq(self.key_in),
                    self.entry_array[index].data_in.eq(self.data_in),
-                   self.encoder_input[index].eq(self.entry_array[index].match)
+                   encoder.i[index].eq(self.entry_array[index].match)
             ]
         
+              
         with m.Switch(self.command):
             # Read
             with m.Case("01"):
@@ -82,18 +79,14 @@ class Cam():
                     self.entry_array[self.address].key_in.eq(self.key_in),
                     self.entry_array[self.address].data_in.eq(self.data_in)
                 ]
-            # Search
-            with m.Case("11"):
-                m.d.comb += encoder.i.eq(self.encoder_input)
+            # NA / Searching
+            with m.Case():
                 with m.If(encoder.n == 0):
                     m.d.comb += [
-                        self.data_hit.eq(0),
-                        self.data_out.eq(self.entry_array[encoder.o].data)                            
+                        self.data_hit.eq(1),
+                        self.data_out.eq(self.entry_array[encoder.o].data)
                     ]
                 with m.Else():
-                    m.d.comb += self.data_hit.eq(1)
-            # NA
-            with m.Case():
-                m.d.comb += self.data_hit.eq(0)
+                    m.d.comb += self.data_hit.eq(0)
                 
         return m
index 925a14eb188e99ea52ac0fb8156cb95990bd4de0..c5141a932f53f4d7f5201859d0bab864562ddd56 100644 (file)
@@ -9,17 +9,11 @@ from Cam import Cam
 from test_helper import assert_eq, assert_ne
 
 def set_cam(dut, c, a, k, d):
-    print("asdf")
     yield dut.command.eq(c)
     yield dut.address.eq(a)
     yield dut.key_in.eq(k)
     yield dut.data_in.eq(d)
-    yield
-    yield dut.command.eq(0)
-    yield dut.address.eq(0)
-    yield dut.key_in.eq(0)
-    yield dut.data_in.eq(0)
-    yield    
+    yield   
     
 def check_data_hit(dut, dh, op):
     out_dh = yield dut.data_hit
@@ -48,7 +42,7 @@ def testbench(dut):
     data = 0
     data_hit = 0
     yield from set_cam(dut, command, address, key, data)
-    #yield from check_data_hit(dut, data_hit, 0)
+    yield from check_data_hit(dut, data_hit, 0)
     
     # Search
     command = 3
@@ -57,7 +51,7 @@ def testbench(dut):
     data = 0
     data_hit = 0
     yield from set_cam(dut, command, address, key, data)
-    #yield from check_data_hit(dut, data_hit, 0)    
+    yield from check_data_hit(dut, data_hit, 0)    
     
     # Write Entry 0
     command = 2
@@ -66,7 +60,7 @@ def testbench(dut):
     data = 4
     data_hit = 0
     yield from set_cam(dut, command, address, key, data)
-    #yield from check_data_hit(dut, data_hit, 0) 
+    yield from check_data_hit(dut, data_hit, 0) 
     
     # Read Entry 0
     command = 1
@@ -75,7 +69,7 @@ def testbench(dut):
     data = 4
     data_hit = 0
     yield from set_cam(dut, command, address, key, data)
-    #yield from check_all(dut, data_hit, data, 0, 0) 
+    yield from check_all(dut, data_hit, data, 0, 0) 
     
     # Search 
     command = 3
@@ -84,7 +78,8 @@ def testbench(dut):
     data = 4
     data_hit = 1
     yield from set_cam(dut, command, address, key, data)
-    #yield from check_all(dut, data_hit, data, 0, 0)     
+    yield
+    yield from check_all(dut, data_hit, data, 0, 0)     
     
     yield