Skip to content

Commit 2eb6f38

Browse files
Merge pull request #74 from VOGL-electronic/move_LiteXModule
move to LiteXModule
2 parents 6ab6cbd + 54b1c1a commit 2eb6f38

File tree

8 files changed

+45
-58
lines changed

8 files changed

+45
-58
lines changed

litespi/__init__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
from migen import *
88

9-
from litex.soc.integration.doc import AutoDoc
10-
from litex.soc.interconnect import wishbone, stream
11-
from litex.soc.interconnect.csr import *
9+
from litex.gen import *
10+
11+
from litex.soc.interconnect import stream
1212

1313
from litespi.common import *
1414
from litespi.crossbar import LiteSPICrossbar
@@ -23,7 +23,7 @@ def __init__(self):
2323
self.cs = Signal()
2424

2525

26-
class LiteSPI(Module, AutoCSR, AutoDoc):
26+
class LiteSPI(LiteXModule):
2727
"""SPI Controller wrapper.
2828
2929
The ``LiteSPI`` class provides a wrapper that can instantiate both ``LiteSPIMMAP`` and ``LiteSPIMaster`` and connect them to the PHY.
@@ -73,11 +73,11 @@ def __init__(self, phy, clock_domain="sys",
7373
with_master=True, master_tx_fifo_depth=1, master_rx_fifo_depth=1,
7474
with_csr=True, with_mmap_write=False):
7575

76-
self.submodules.crossbar = crossbar = LiteSPICrossbar(clock_domain)
76+
self.crossbar = crossbar = LiteSPICrossbar(clock_domain)
7777
self.comb += phy.cs.eq(crossbar.cs)
7878

7979
if with_mmap:
80-
self.submodules.mmap = mmap = LiteSPIMMAP(flash=phy.flash,
80+
self.mmap = mmap = LiteSPIMMAP(flash=phy.flash,
8181
endianness=mmap_endianness,
8282
with_csr=with_csr,
8383
with_write=with_mmap_write)
@@ -90,7 +90,7 @@ def __init__(self, phy, clock_domain="sys",
9090
if hasattr(phy, "dummy_bits"):
9191
self.comb += phy.dummy_bits.eq(mmap._spi_dummy_bits)
9292
if with_master:
93-
self.submodules.master = master = LiteSPIMaster(
93+
self.master = master = LiteSPIMaster(
9494
tx_fifo_depth = master_tx_fifo_depth,
9595
rx_fifo_depth = master_rx_fifo_depth)
9696
port_master = crossbar.get_port(master.cs)

litespi/clkgen.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
from migen import *
88

9-
from litex.soc.integration.doc import AutoDoc, ModuleDoc
9+
from litex.gen import *
1010

1111
from litex.build.io import SDROutput, DDROutput
1212

13-
class DDRLiteSPIClkGen(Module, AutoDoc):
13+
class DDRLiteSPIClkGen(LiteXModule):
1414
"""SPI Clock generator
1515
1616
The ``DDRLiteSPIClkGen`` class provides a generic SPI clock generator.
@@ -33,7 +33,7 @@ def __init__(self, pads):
3333
self.specials += DDROutput(i1=en, i2=0, o=pads.clk)
3434

3535

36-
class LiteSPIClkGen(Module, AutoDoc):
36+
class LiteSPIClkGen(LiteXModule):
3737
"""SPI Clock generator
3838
3939
The ``LiteSPIClkGen`` class provides a generic SPI clock generator.

litespi/core/master.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
# SPDX-License-Identifier: BSD-2-Clause
66

77
from migen import *
8-
from migen.genlib.fsm import FSM, NextState
8+
9+
from litex.gen import *
910

1011
from litex.soc.interconnect import stream
1112
from litex.soc.interconnect.csr import *
1213

1314
from litespi.common import *
1415

1516

16-
class LiteSPIMaster(Module, AutoCSR):
17+
class LiteSPIMaster(LiteXModule):
1718
"""Generic LiteSPI Master
1819
1920
The ``LiteSPIMaster`` class provides a generic SPI master that can be controlled using CSRs.
@@ -61,9 +62,8 @@ def __init__(self, cs_width=1, tx_fifo_depth=1, rx_fifo_depth=1):
6162
# # #
6263

6364
# FIFOs.
64-
tx_fifo = stream.SyncFIFO(spi_core2phy_layout, depth=tx_fifo_depth)
65-
rx_fifo = stream.SyncFIFO(spi_phy2core_layout, depth=rx_fifo_depth)
66-
self.submodules += tx_fifo, rx_fifo
65+
self.tx_fifo = tx_fifo = stream.SyncFIFO(spi_core2phy_layout, depth=tx_fifo_depth)
66+
self.rx_fifo = rx_fifo = stream.SyncFIFO(spi_phy2core_layout, depth=rx_fifo_depth)
6767
self.comb += self.sink.connect(rx_fifo.sink)
6868
self.comb += tx_fifo.source.connect(self.source)
6969

litespi/core/mmap.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from migen import *
99

10+
from litex.gen import *
11+
1012
from litex.gen.genlib.misc import WaitTimer
1113

1214
from litex.soc.interconnect import wishbone, stream
@@ -29,7 +31,7 @@
2931
8: 0b11111111,
3032
}
3133

32-
class LiteSPIMMAP(Module, AutoCSR):
34+
class LiteSPIMMAP(LiteXModule):
3335
"""Memory-mapped SPI Flash controller.
3436
3537
The ``LiteSPIMMAP`` class provides a Wishbone slave that must be connected to a LiteSPI PHY.
@@ -83,8 +85,7 @@ def __init__(self, flash, clock_domain="sys", endianness="big", with_csr=True, w
8385
# Burst Control.
8486
burst_cs = Signal()
8587
burst_adr = Signal(len(bus.adr), reset_less=True)
86-
burst_timeout = WaitTimer(MMAP_DEFAULT_TIMEOUT)
87-
self.submodules += burst_timeout
88+
self.burst_timeout = burst_timeout = WaitTimer(MMAP_DEFAULT_TIMEOUT)
8889

8990
write = Signal()
9091
write_enabled = Signal()
@@ -123,7 +124,7 @@ def __init__(self, flash, clock_domain="sys", endianness="big", with_csr=True, w
123124
self.data_write = Signal(32)
124125

125126
# FSM.
126-
self.submodules.fsm = fsm = FSM(reset_state="IDLE")
127+
self.fsm = fsm = FSM(reset_state="IDLE")
127128
fsm.act("IDLE",
128129
# Keep CS active after Burst for Timeout.
129130
burst_timeout.wait.eq(1),

litespi/gen.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(self, platform, module, mode="x4", rate="1:1", divisor="1",
8383
sim = False
8484
):
8585
# CRG --------------------------------------------------------------------------------------
86-
self.submodules.crg = CRG(platform.request("clk"), platform.request("rst"))
86+
self.crg = CRG(platform.request("clk"), platform.request("rst"))
8787

8888
# SoCMini ----------------------------------------------------------------------------------
8989
SoCMini.__init__(self, platform, clk_freq=int(1e6))
@@ -123,32 +123,28 @@ def print_supported_modules():
123123

124124
if sim:
125125
from litespi.phy.model import LiteSPIPHYModel
126-
spiflash_phy = LiteSPIPHYModel(spiflash_module, init=[i for i in range(16)]) # FIXME: Allow custom init?
127-
self.submodules += spiflash_phy
126+
self.spiflash_phy = spiflash_phy = LiteSPIPHYModel(spiflash_module, init=[i for i in range(16)]) # FIXME: Allow custom init?
128127
else:
129128
pads = self.platform.request("spiflash" if mode == "x1" else "spiflash4x")
130-
spiflash_phy = LiteSPIPHY(
129+
self.spiflash_phy = spiflash_phy = LiteSPIPHY(
131130
pads = pads,
132131
flash = spiflash_module,
133132
device = platform.device,
134133
default_divisor = int(divisor),
135134
rate = rate
136135
)
137-
self.submodules += spiflash_phy
138-
139136

140137
# SPI Flash Core / MMAP --------------------------------------------------------------------
141138

142139
assert bus_standard in ["wishbone", "axi-lite"]
143140

144-
spiflash_core = LiteSPI(
141+
self.spiflash_core = spiflash_core = LiteSPI(
145142
phy = spiflash_phy,
146143
mmap_endianness = bus_endianness,
147144
with_master = with_master,
148145
with_mmap = True,
149146
with_csr = False
150147
)
151-
self.submodules += spiflash_core
152148

153149
# Wishbone.
154150
if bus_standard == "wishbone":

litespi/phy/generic.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,17 @@
55
# SPDX-License-Identifier: BSD-2-Clause
66

77
from migen import *
8-
from migen.genlib.cdc import MultiReg
98

10-
from litex.gen.genlib.misc import WaitTimer
9+
from litex.gen import *
1110

1211
from litespi.common import *
1312

14-
from litex.soc.interconnect.csr import *
15-
16-
from litex.soc.integration.doc import AutoDoc
17-
1813
from litespi.phy.generic_sdr import LiteSPISDRPHYCore
1914
from litespi.phy.generic_ddr import LiteSPIDDRPHYCore
2015

2116
# LiteSPI PHY --------------------------------------------------------------------------------------
2217

23-
class LiteSPIPHY(Module, AutoCSR, AutoDoc):
18+
class LiteSPIPHY(LiteXModule):
2419
"""LiteSPI PHY instantiator
2520
2621
The ``LiteSPIPHY`` class instantiate generic PHY - ``LiteSPIPHYCore`` that can be connected to the ``LiteSPICore``,
@@ -64,22 +59,22 @@ class LiteSPIPHY(Module, AutoCSR, AutoDoc):
6459
def __init__(self, pads, flash, device="xc7", clock_domain="sys", default_divisor=9, cs_delay=10, rate="1:1", extra_latency=0):
6560
assert rate in ["1:1", "1:2"]
6661
if rate == "1:1":
67-
self.phy = LiteSPISDRPHYCore(pads, flash, device, clock_domain, default_divisor, cs_delay)
62+
phy = LiteSPISDRPHYCore(pads, flash, device, clock_domain, default_divisor, cs_delay)
6863
if rate == "1:2":
69-
self.phy = LiteSPIDDRPHYCore(pads, flash, cs_delay, extra_latency)
64+
phy = LiteSPIDDRPHYCore(pads, flash, cs_delay, extra_latency)
7065

7166
self.flash = flash
7267

73-
self.source = self.phy.source
74-
self.sink = self.phy.sink
75-
self.cs = self.phy.cs
68+
self.source = phy.source
69+
self.sink = phy.sink
70+
self.cs = phy.cs
7671

7772
# # #
7873

7974
if clock_domain != "sys":
80-
self.phy = ClockDomainsRenamer(clock_domain)(self.phy)
75+
phy = ClockDomainsRenamer(clock_domain)(phy)
8176

82-
self.submodules.spiflash_phy = self.phy
77+
self.spiflash_phy = phy
8378

8479
def get_csrs(self):
8580
return self.spiflash_phy.get_csrs()

litespi/phy/generic_ddr.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@
55
# SPDX-License-Identifier: BSD-2-Clause
66

77
from migen import *
8-
from migen.genlib.cdc import MultiReg
8+
9+
from litex.gen import *
910

1011
from litex.gen.genlib.misc import WaitTimer
1112

1213
from litespi.common import *
1314
from litespi.clkgen import DDRLiteSPIClkGen
1415

1516
from litex.soc.interconnect import stream
16-
from litex.soc.interconnect.csr import *
1717

1818
from litex.build.io import DDRTristate
1919

20-
from litex.soc.integration.doc import AutoDoc
21-
22-
2320
# LiteSPI DDR PHY Core -----------------------------------------------------------------------------
2421

25-
class LiteSPIDDRPHYCore(Module, AutoCSR, AutoDoc):
22+
class LiteSPIDDRPHYCore(LiteXModule):
2623
"""LiteSPI PHY DDR instantiator
2724
2825
The ``DDRLiteSPIPHYCore`` class provides a generic PHY that can be connected to the ``LiteSPICore``.
@@ -73,12 +70,11 @@ def __init__(self, pads, flash, cs_delay, extra_latency=0):
7370
assert not flash.ddr
7471

7572
# Clock Generator.
76-
self.submodules.clkgen = clkgen = DDRLiteSPIClkGen(pads)
73+
self.clkgen = clkgen = DDRLiteSPIClkGen(pads)
7774

7875
# CS control.
79-
cs_timer = WaitTimer(cs_delay + 1) # Ensure cs_delay cycles between XFers.
76+
self.cs_timer = cs_timer = WaitTimer(cs_delay + 1) # Ensure cs_delay cycles between XFers.
8077
cs_enable = Signal()
81-
self.submodules += cs_timer
8278
self.comb += cs_timer.wait.eq(self.cs)
8379
self.comb += cs_enable.eq(cs_timer.done)
8480
self.comb += pads.cs_n.eq(~cs_enable)
@@ -141,7 +137,7 @@ def __init__(self, pads, flash, cs_delay, extra_latency=0):
141137
)
142138

143139
# FSM.
144-
self.submodules.fsm = fsm = FSM(reset_state="WAIT-CMD-DATA")
140+
self.fsm = fsm = FSM(reset_state="WAIT-CMD-DATA")
145141
fsm.act("WAIT-CMD-DATA",
146142
# Stop Clk.
147143
NextValue(clkgen.en, 0),

litespi/phy/generic_sdr.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from migen import *
99

10+
from litex.gen import *
11+
1012
from litex.gen.genlib.misc import WaitTimer
1113

1214
from litespi.common import *
@@ -17,11 +19,9 @@
1719

1820
from litex.build.io import SDROutput, SDRInput, SDRTristate
1921

20-
from litex.soc.integration.doc import AutoDoc
21-
2222
# LiteSPI PHY Core ---------------------------------------------------------------------------------
2323

24-
class LiteSPISDRPHYCore(Module, AutoCSR, AutoDoc):
24+
class LiteSPISDRPHYCore(LiteXModule):
2525
"""LiteSPI PHY instantiator
2626
2727
The ``LiteSPIPHYCore`` class provides a generic PHY that can be connected to the ``LiteSPICore``.
@@ -88,13 +88,12 @@ def __init__(self, pads, flash, device, clock_domain, default_divisor, cs_delay)
8888
assert not flash.ddr
8989

9090
# Clock Generator.
91-
self.submodules.clkgen = clkgen = LiteSPIClkGen(pads, device)
91+
self.clkgen = clkgen = LiteSPIClkGen(pads, device)
9292
self.comb += clkgen.div.eq(spi_clk_divisor)
9393

9494
# CS control.
95-
cs_timer = WaitTimer(cs_delay + 1) # Ensure cs_delay cycles between XFers.
95+
self.cs_timer = cs_timer = WaitTimer(cs_delay + 1) # Ensure cs_delay cycles between XFers.
9696
cs_enable = Signal()
97-
self.submodules += cs_timer
9897
self.comb += cs_timer.wait.eq(self.cs)
9998
self.comb += cs_enable.eq(cs_timer.done)
10099
self.comb += pads.cs_n.eq(~cs_enable)
@@ -168,7 +167,7 @@ def __init__(self, pads, flash, device, clock_domain, default_divisor, cs_delay)
168167
)
169168

170169
# FSM.
171-
self.submodules.fsm = fsm = FSM(reset_state="WAIT-CMD-DATA")
170+
self.fsm = fsm = FSM(reset_state="WAIT-CMD-DATA")
172171
fsm.act("WAIT-CMD-DATA",
173172
# Wait for CS and a CMD from the Core.
174173
If(cs_enable & sink.valid,

0 commit comments

Comments
 (0)