forked from M-Labs/artiq
1
0
Fork 0

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