Skip to content

Commit aa67c65

Browse files
committed
frontend/dma: Allow DMA loop status to be reported on 32-bit or 64-bit (32-bit = original behavior and default).
1 parent ce3db4e commit aa67c65

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

litepcie/frontend/dma.py

+41-4
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,10 @@ class LitePCIeDMAStatus(LiteXModule):
758758
the internal DMA status and the last 8 words for optional external status. The mapping as follows:
759759
760760
0: Sync Word (0x5aa55aa5).
761-
1: DMA Writer Loop Status.
762-
2: DMA Reader Loop Status.
761+
1: DMA Writer Loop Status 32-bit LSB.
762+
2: DMA Reader Loop Status 32-bit LSB.
763+
3: DMA Writer Loop Status 32-bit MSB (Optional).
764+
4: DMA Reader Loop Status 32-bit MSB (Optional).
763765
3-7: Reserved
764766
8-15: External (Optional, from user logic/design).
765767
@@ -769,7 +771,8 @@ class LitePCIeDMAStatus(LiteXModule):
769771
- DMA Reader IRQ.
770772
Allowing a Synchronous or Asynchrounous update with the DMAs.
771773
"""
772-
def __init__(self, endpoint, writer, reader, address_width=32):
774+
def __init__(self, endpoint, writer, reader, address_width=32, status_width=32):
775+
assert status_width in [32, 64]
773776
self.control = CSRStorage(fields=[
774777
CSRField("enable", offset=0, size=1, description="Status Enable"),
775778
CSRField("update", offset=4, size=2, description="Status Update Event", values=[
@@ -798,6 +801,38 @@ def __init__(self, endpoint, writer, reader, address_width=32):
798801
status[1].eq(writer.table.loop_status.status),
799802
status[2].eq(reader.table.loop_status.status),
800803
]
804+
if status_width == 64:
805+
class DMAStatusMSB(LiteXModule):
806+
def __init__(self, enable, lsb):
807+
self.value = value = Signal(32)
808+
809+
# # #
810+
811+
lsb_new = lsb[-16:]
812+
lsb_last = Signal(16)
813+
814+
self.sync += [
815+
lsb_last.eq(lsb_new),
816+
If((lsb_new == 0x0000) & (lsb_last == 0xffff),
817+
value.eq(value + 1)
818+
),
819+
If(enable == 0,
820+
value.eq(0)
821+
),
822+
]
823+
824+
self.writer_status_msb = DMAStatusMSB(
825+
enable = writer.enable,
826+
lsb = writer.table.loop_status.status,
827+
)
828+
self.reader_status_msb = DMAStatusMSB(
829+
enable = reader.enable,
830+
lsb = reader.table.loop_status.status,
831+
)
832+
self.comb += [
833+
status[3].eq(self.writer_status_msb.value),
834+
status[4].eq(self.reader_status_msb.value),
835+
]
801836

802837
# 7-15: External.
803838
for i in range(8):
@@ -887,7 +922,7 @@ def __init__(self, phy, endpoint, with_table=True, table_depth=256, address_widt
887922
# Monitor.
888923
with_monitor = False,
889924
# Status.
890-
with_status = False,
925+
with_status = False, status_width=32,
891926
):
892927
# Parameters -------------------------------------------------------------------------------
893928
self.data_width = data_width or phy.data_width
@@ -962,6 +997,8 @@ def __init__(self, phy, endpoint, with_table=True, table_depth=256, address_widt
962997
writer = self.writer,
963998
reader = self.reader,
964999
address_width = address_width,
1000+
status_width = status_width,
1001+
9651002
)
9661003

9671004
def add_plugin_module(self, m):

0 commit comments

Comments
 (0)