split out unit test into separate file
[soc.git] / TLB / CamEntry.py
1 from nmigen import Module, Signal
2
3 class CamEntry:
4 def __init__(self, key_size, data_size):
5 # Internal
6 self.key = Signal(key_size)
7
8 # Input
9 self.write = Signal(1) # Read => 0 Write => 1
10 self.key_in = Signal(key_size) # Reference key for the CAM
11 self.data_in = Signal(data_size) # Data input when writing
12
13 # Output
14 self.match = Signal(1) # Result of the internal/input key comparison
15 self.data = Signal(data_size)
16
17
18 def get_fragment(self, platform=None):
19 m = Module()
20 with m.If(self.write == 1):
21 m.d.sync += [
22 self.key.eq(self.key_in),
23 self.data.eq(self.data_in),
24 self.match.eq(1)
25 ]
26 with m.Else():
27 with m.If(self.key_in == self.key):
28 m.d.sync += self.match.eq(0)
29 with m.Else():
30 m.d.sync += self.match.eq(1)
31
32 return m