gateware.spi: style

This commit is contained in:
Robert Jördens 2016-02-29 11:48:29 +01:00
parent ad34927b0a
commit 948fefa69a
1 changed files with 16 additions and 18 deletions

View File

@ -282,10 +282,9 @@ class SPIMaster(Module):
])
assert len(xfer) <= len(bus.dat_w)
# SPI
spi = SPIMachine(data_width, clock_width=len(config.div_read),
self.submodules.spi = spi = SPIMachine(
data_width, clock_width=len(config.div_read),
bits_width=len(xfer.read_length))
self.submodules += spi
wb_we = Signal()
pending = Signal()
@ -344,12 +343,12 @@ class SPIMaster(Module):
self.comb += [
clk_t.oe.eq(~config.offline),
clk_t.o.eq((spi.cg.clk & spi.cs) ^ config.clk_polarity),
mosi_t.oe.eq(~config.offline & spi.cs &
(spi.oe | ~config.half_duplex)),
clk_t.o.eq((spi.cg.clk & spi.cs) ^ config.clk_polarity),
mosi_t.o.eq(spi.reg.o),
spi.reg.i.eq(Mux(config.half_duplex, mosi_t.i,
getattr(pads, "miso", mosi_t.i))),
mosi_t.o.eq(spi.reg.o),
]
@ -438,19 +437,15 @@ def _test_gen(bus):
hex(wdata), hex(rdata), hex(a), hex(b))
class _TestPads:
def __init__(self):
self.cs_n = Signal(3)
self.cs_n = Signal(2)
self.clk = Signal()
self.mosi = Signal()
self.miso = Signal()
if __name__ == "__main__":
from migen.fhdl.specials import Tristate
class T(Module):
class _TestTristate(Module):
def __init__(self, t):
oe = Signal()
self.comb += [
@ -458,7 +453,9 @@ if __name__ == "__main__":
oe.eq(t.oe),
t.i.eq(t.o),
]
Tristate.lower = staticmethod(lambda dr: T(dr))
if __name__ == "__main__":
from migen.fhdl.specials import Tristate
pads = _TestPads()
dut = SPIMaster(pads)
@ -466,4 +463,5 @@ if __name__ == "__main__":
# from migen.fhdl.verilog import convert
# print(convert(dut))
Tristate.lower = _TestTristate
run_simulation(dut, _test_gen(dut.bus), vcd_name="spi_master.vcd")