Skip to content

Commit 3294479

Browse files
Merge pull request #85 from VOGL-electronic/add_irq
master: add irq
2 parents 3401266 + 5a33949 commit 3294479

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

litespi/__init__.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from litespi.crossbar import LiteSPICrossbar
1515
from litespi.core.master import LiteSPIMaster
1616
from litespi.core.mmap import LiteSPIMMAP
17-
17+
from litespi.phy.generic import LiteSPIPHY
1818

1919
class LiteSPICore(Module):
2020
def __init__(self):
@@ -24,6 +24,7 @@ def __init__(self):
2424

2525

2626
class LiteSPI(LiteXModule):
27+
autocsr_exclude = {"ev"}
2728
"""SPI Controller wrapper.
2829
2930
The ``LiteSPI`` class provides a wrapper that can instantiate both ``LiteSPIMMAP`` and ``LiteSPIMaster`` and connect them to the PHY.
@@ -70,8 +71,8 @@ class LiteSPI(LiteXModule):
7071

7172
def __init__(self, phy, clock_domain="sys",
7273
with_mmap=True, mmap_endianness="big",
73-
with_master=True, master_tx_fifo_depth=1, master_rx_fifo_depth=1,
74-
with_csr=True, with_mmap_write=False, mmap_cs_mask=1):
74+
with_master=True, master_tx_fifo_depth=1, master_rx_fifo_depth=1, master_with_irq=False,
75+
with_csr=True, with_mmap_write=False, mmap_cs_mask=1, **kwargs):
7576

7677
cs_width=len(phy.cs)
7778

@@ -97,12 +98,15 @@ def __init__(self, phy, clock_domain="sys",
9798
self.master = master = LiteSPIMaster(
9899
tx_fifo_depth = master_tx_fifo_depth,
99100
rx_fifo_depth = master_rx_fifo_depth,
101+
with_irq = master_with_irq,
100102
cs_width = cs_width)
101103
port_master = crossbar.get_port(master.cs)
102104
self.comb += [
103105
port_master.source.connect(master.sink),
104106
master.source.connect(port_master.sink),
105107
]
108+
if hasattr(master, "ev"):
109+
self.ev = master.ev
106110

107111
if clock_domain != "sys":
108112
self.comb += [
@@ -114,3 +118,18 @@ def __init__(self, phy, clock_domain="sys",
114118
crossbar.master.source.connect(phy.sink),
115119
phy.source.connect(crossbar.master.sink),
116120
]
121+
122+
class LiteSPIWrapper(LiteXModule):
123+
autocsr_exclude = {"ev"}
124+
def __init__(self, pads=None, module=None, phy=None, **kwargs):
125+
assert pads is not None or module is not None, "Either pads or module must be provided."
126+
# PHY.
127+
self.phy = LiteSPIPHY(pads, module, **kwargs) if phy is None else phy
128+
129+
# Core.
130+
self.core = LiteSPI(self.phy, **kwargs)
131+
132+
if hasattr(self.core, "bus"):
133+
self.bus = self.core.bus
134+
if hasattr(self.core, "ev"):
135+
self.ev = self.core.ev

litespi/core/master.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from litex.soc.interconnect import stream
1212
from litex.soc.interconnect.csr import *
13+
from litex.soc.interconnect.csr_eventmanager import *
1314

1415
from litespi.common import *
1516

@@ -41,7 +42,7 @@ class LiteSPIMaster(LiteXModule):
4142
Slave CS signal.
4243
4344
"""
44-
def __init__(self, cs_width=1, tx_fifo_depth=1, rx_fifo_depth=1):
45+
def __init__(self, cs_width=1, tx_fifo_depth=1, rx_fifo_depth=1, with_irq=False):
4546
self.sink = stream.Endpoint(spi_phy2core_layout)
4647
self.source = stream.Endpoint(spi_core2phy_layout)
4748
self.cs = Signal(cs_width)
@@ -86,3 +87,12 @@ def __init__(self, cs_width=1, tx_fifo_depth=1, rx_fifo_depth=1):
8687
self._status.fields.rx_ready.eq(rx_fifo.source.valid),
8788
self._rxtx.w.eq(rx_fifo.source.data),
8889
]
90+
91+
if with_irq:
92+
self.ev = EventManager()
93+
self.ev.rx_ready = EventSourceProcess(edge="rising")
94+
self.ev.finalize()
95+
96+
self.comb += [
97+
self.ev.rx_ready.trigger.eq(rx_fifo.source.valid),
98+
]

litespi/phy/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class LiteSPIPHY(LiteXModule):
5656
Flash CS signal from ``LiteSPIPHYCore``.
5757
"""
5858

59-
def __init__(self, pads, flash, device="xc7", clock_domain="sys", default_divisor=9, cs_delay=10, rate="1:1", extra_latency=0):
59+
def __init__(self, pads, flash, device="xc7", clock_domain="sys", default_divisor=9, cs_delay=10, rate="1:1", extra_latency=0, **kwargs):
6060
assert rate in ["1:1", "1:2"]
6161
if rate == "1:1":
6262
phy = LiteSPISDRPHYCore(pads, flash, device, clock_domain, default_divisor, cs_delay)

0 commit comments

Comments
 (0)