1 from nmigen
import Module
, Signal
, Elaboratable
4 class CamEntry(Elaboratable
):
5 """ Content Addressable Memory (CAM) Entry
7 The purpose of this module is to represent an entry within a CAM.
8 This module when given a read command will compare the given data
9 and output whether a match was found or not. When given a write
10 command it will write the given data into internal registers.
13 def __init__(self
, data_size
):
15 * data_size: (bit count) The size of the data
18 self
.command
= Signal(2) # 00 => NA 01 => Read 10 => Write 11 => Reset
19 self
.data_in
= Signal(data_size
) # Data input when writing
22 self
.match
= Signal(1) # Result of the internal/input key comparison
23 self
.data
= Signal(data_size
)
25 def elaborate(self
, platform
=None):
27 with m
.Switch(self
.command
):
29 m
.d
.sync
+= self
.match
.eq(0)
31 with m
.If(self
.data
== self
.data_in
):
32 m
.d
.sync
+= self
.match
.eq(1)
34 m
.d
.sync
+= self
.match
.eq(0)
37 self
.data
.eq(self
.data_in
),