# 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
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"):
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
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
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
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
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
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
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