csr/fields: add pulse mode support

This commit is contained in:
Florent Kermarrec 2019-09-14 21:49:34 +02:00
parent 8c080e5fb6
commit 23b01f8f02
1 changed files with 7 additions and 2 deletions

View File

@ -123,13 +123,14 @@ class _CompoundCSR(_CSRBase, Module):
class CSRField(Signal): class CSRField(Signal):
def __init__(self, name, size=1, offset=None, reset=0, description=None, values=None): def __init__(self, name, size=1, offset=None, reset=0, description=None, pulse=False, values=None):
assert name == name.lower() assert name == name.lower()
self.name = name self.name = name
self.size = size self.size = size
self.offset = offset self.offset = offset
self.reset_value = reset self.reset_value = reset
self.description = description self.description = description
self.pulse = pulse
self.values = values self.values = values
Signal.__init__(self, size, name=name, reset=reset) Signal.__init__(self, size, name=name, reset=reset)
@ -301,7 +302,11 @@ class CSRStorage(_CompoundCSR):
self.dat_w = Signal(self.size - self.alignment_bits) self.dat_w = Signal(self.size - self.alignment_bits)
self.sync += If(self.we, self.storage_full.eq(self.dat_w << self.alignment_bits)) self.sync += If(self.we, self.storage_full.eq(self.dat_w << self.alignment_bits))
for field in [*fields]: for field in [*fields]:
self.comb += getattr(self.fields, field.name).eq(self.storage[field.offset:field.offset + field.size]) field_assign = getattr(self.fields, field.name).eq(self.storage[field.offset:field.offset + field.size])
if field.pulse:
self.comb += If(self.storage.re, field_assign)
else:
self.comb += field_assign
def do_finalize(self, busword): def do_finalize(self, busword):
nwords = (self.size + busword - 1)//busword nwords = (self.size + busword - 1)//busword