1 from nmigen
import Module
, Signal
4 def __init__(self
, key_size
, data_size
):
6 self
.key
= Signal(key_size
)
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
14 self
.match
= Signal(1) # Result of the internal/input key comparison
15 self
.data
= Signal(data_size
)
18 def get_fragment(self
, platform
=None):
20 with m
.If(self
.write
== 1):
22 self
.key
.eq(self
.key_in
),
23 self
.data
.eq(self
.data_in
),
27 with m
.If(self
.key_in
== self
.key
):
28 m
.d
.sync
+= self
.match
.eq(0)
30 m
.d
.sync
+= self
.match
.eq(1)