mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
add register interface to Trigger
This commit is contained in:
parent
051e8ac570
commit
f586b13d4b
2 changed files with 46 additions and 6 deletions
|
@ -225,10 +225,12 @@ class Sum:
|
||||||
|
|
||||||
class Trigger:
|
class Trigger:
|
||||||
def __init__(self,address, trig_width, dat_width, ports):
|
def __init__(self,address, trig_width, dat_width, ports):
|
||||||
|
self.address = address
|
||||||
self.trig_width = trig_width
|
self.trig_width = trig_width
|
||||||
self.dat_width = dat_width
|
self.dat_width = dat_width
|
||||||
self.ports = ports
|
self.ports = ports
|
||||||
assert (len(self.ports) <= 4), "Nb Ports > 4 (This version support 4 ports Max)"
|
assert (len(self.ports) <= 4), "Nb Ports > 4 (This version support 4 ports Max)"
|
||||||
|
self._sum = Sum(len(self.ports))
|
||||||
|
|
||||||
self.in_trig = Signal(BV(self.trig_width))
|
self.in_trig = Signal(BV(self.trig_width))
|
||||||
self.in_dat = Signal(BV(self.dat_width))
|
self.in_dat = Signal(BV(self.dat_width))
|
||||||
|
@ -236,6 +238,27 @@ class Trigger:
|
||||||
self.hit = Signal()
|
self.hit = Signal()
|
||||||
self.dat = Signal(BV(self.dat_width))
|
self.dat = Signal(BV(self.dat_width))
|
||||||
|
|
||||||
|
# Csr interface
|
||||||
|
for i in range(len(self.ports)):
|
||||||
|
if isinstance(self.ports[i],Term):
|
||||||
|
setattr(self,"_term_reg%d"%i,RegisterField("rst", 1*self.trig_width, reset=0,
|
||||||
|
access_bus=WRITE_ONLY, access_dev=READ_ONLY))
|
||||||
|
elif isinstance(self.ports[i],EdgeDetector):
|
||||||
|
setattr(self,"_edge_reg%d"%i,RegisterField("rst", 3*self.trig_width, reset=0,
|
||||||
|
access_bus=WRITE_ONLY, access_dev=READ_ONLY))
|
||||||
|
elif isinstance(self.ports[i],RangeDetector):
|
||||||
|
setattr(self,"_range_reg%d"%i,RegisterField("rst", 2*self.trig_width, reset=0,
|
||||||
|
access_bus=WRITE_ONLY, access_dev=READ_ONLY))
|
||||||
|
|
||||||
|
self._sum_reg = RegisterField("_sum_reg", 17, reset=0,access_bus=WRITE_ONLY, access_dev=READ_ONLY)
|
||||||
|
|
||||||
|
regs = []
|
||||||
|
objects = self.__dict__
|
||||||
|
for object in objects:
|
||||||
|
if "_reg" in object:
|
||||||
|
regs.append(objects[object])
|
||||||
|
regs.append(self._sum_reg)
|
||||||
|
self.bank = csrgen.Bank(regs,address=address)
|
||||||
|
|
||||||
def get_fragment(self):
|
def get_fragment(self):
|
||||||
comb = []
|
comb = []
|
||||||
|
@ -245,20 +268,36 @@ class Trigger:
|
||||||
|
|
||||||
# Connect output of trig elements to sum
|
# Connect output of trig elements to sum
|
||||||
# Todo : Add sum tree to have more that 4 inputs
|
# Todo : Add sum tree to have more that 4 inputs
|
||||||
_sum = Sum(len(self.ports))
|
|
||||||
comb+= [_sum.i[j].eq(self.ports[j].o) for j in range(len(self.ports))]
|
comb+= [self._sum.i[j].eq(self.ports[j].o) for j in range(len(self.ports))]
|
||||||
|
|
||||||
# Connect sum ouput to hit
|
# Connect sum ouput to hit
|
||||||
comb+= [self.hit.eq(_sum.o)]
|
comb+= [self.hit.eq(self._sum.o)]
|
||||||
|
|
||||||
# Add ports & sum to frag
|
# Add ports & sum to frag
|
||||||
frag = _sum.get_fragment()
|
frag = self.bank.get_fragment()
|
||||||
|
frag += self._sum.get_fragment()
|
||||||
for port in self.ports:
|
for port in self.ports:
|
||||||
frag += port.get_fragment()
|
frag += port.get_fragment()
|
||||||
|
|
||||||
|
|
||||||
comb+= [self.dat.eq(self.in_dat)]
|
comb+= [self.dat.eq(self.in_dat)]
|
||||||
|
|
||||||
|
|
||||||
|
#Connect Registers
|
||||||
|
for i in range(len(self.ports)):
|
||||||
|
if isinstance(self.ports[i],Term):
|
||||||
|
comb += [self.ports[i].t.eq(getattr(self,"_term_reg%d"%i).field.r[0:self.trig_width])]
|
||||||
|
elif isinstance(self.ports[i],EdgeDetector):
|
||||||
|
comb += [self.ports[i].r_mask.eq(getattr(self,"_edge_reg%d"%i).field.r[0:1*self.trig_width])]
|
||||||
|
comb += [self.ports[i].f_mask.eq(getattr(self,"_edge_reg%d"%i).field.r[1*self.trig_width:2*self.trig_width])]
|
||||||
|
comb += [self.ports[i].b_mask.eq(getattr(self,"_edge_reg%d"%i).field.r[2*self.trig_width:3*self.trig_width])]
|
||||||
|
elif isinstance(self.ports[i],RangeDetector):
|
||||||
|
comb += [self.ports[i].low.eq(getattr(self,"_range_reg%d"%i).field.r[0:1*self.trig_width])]
|
||||||
|
comb += [self.ports[i].high.eq(getattr(self,"_range_reg%d"%i).field.r[1*self.trig_width:2*self.trig_width])]
|
||||||
|
|
||||||
|
comb += [
|
||||||
|
self._sum.prog_dat.eq(self._sum_reg.field.r[0:16]),
|
||||||
|
self._sum.prog.eq(self._sum_reg.field.r[16]),
|
||||||
|
]
|
||||||
return frag + Fragment(comb=comb, sync=sync)
|
return frag + Fragment(comb=comb, sync=sync)
|
||||||
|
|
||||||
|
|
||||||
|
|
1
top.py
1
top.py
|
@ -79,6 +79,7 @@ term2 = migScope.EdgeDetector(32)
|
||||||
term3 = migScope.Term(32)
|
term3 = migScope.Term(32)
|
||||||
|
|
||||||
trigger0 = migScope.Trigger(0,32,64,[term0, term1, term2, term3])
|
trigger0 = migScope.Trigger(0,32,64,[term0, term1, term2, term3])
|
||||||
|
#trigger0 = migScope.Trigger(0,32,64,[term0])
|
||||||
v = verilog.convert(trigger0.get_fragment())
|
v = verilog.convert(trigger0.get_fragment())
|
||||||
print(v)
|
print(v)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue