2020-09-17 10:06:33 +08:00
|
|
|
# Import built in I/O, Connectors & Platform template for Humpback
|
2020-09-17 09:55:20 +08:00
|
|
|
from migen.build.platforms.sinara import humpback
|
|
|
|
# Import migen pin record structure
|
|
|
|
from migen.build.generic_platform import *
|
2020-08-09 02:03:47 +08:00
|
|
|
from migen.fhdl.module import Module
|
2020-08-21 11:17:08 +08:00
|
|
|
from migen.fhdl.specials import Instance
|
|
|
|
from migen.genlib.io import *
|
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
|
|
|
|
class UrukulConnector(Module):
|
|
|
|
def __init__(self, platform):
|
2020-09-17 12:59:22 +08:00
|
|
|
# Include extension
|
2020-09-24 17:10:31 +08:00
|
|
|
spi_mosi = [
|
|
|
|
("spi_mosi", 0, Pins("B16"), IOStandard("LVCMOS33"))
|
|
|
|
]
|
2020-09-17 12:59:22 +08:00
|
|
|
spi_cs = [
|
|
|
|
("spi_cs", 0, Pins("B13 B14 B15"), IOStandard("LVCMOS33"))
|
|
|
|
]
|
|
|
|
io_update = [
|
|
|
|
("io_update", 0, Pins("A11"), IOStandard("LVCMOS33"))
|
|
|
|
]
|
|
|
|
|
|
|
|
# Add extensions
|
|
|
|
platform.add_extension(spi_cs)
|
|
|
|
platform.add_extension(io_update)
|
2020-09-24 17:10:31 +08:00
|
|
|
platform.add_extension(spi_mosi)
|
2020-09-17 12:59:22 +08:00
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
# Request EEM I/O & SPI
|
2020-08-23 17:17:09 +08:00
|
|
|
eem0 = [
|
|
|
|
platform.request("eem0", 0),
|
|
|
|
platform.request("eem0", 1),
|
2020-09-17 10:06:33 +08:00
|
|
|
# Supply EEM pin with negative polarity
|
|
|
|
# See issue/PR: https://github.com/m-labs/migen/pull/181
|
2020-08-23 17:17:09 +08:00
|
|
|
platform.request("eem0_n", 2),
|
|
|
|
platform.request("eem0", 3),
|
|
|
|
platform.request("eem0", 4),
|
2020-08-23 22:28:32 +08:00
|
|
|
platform.request("eem0", 5),
|
|
|
|
platform.request("eem0", 6)
|
2020-08-23 17:17:09 +08:00
|
|
|
]
|
2020-08-09 02:03:47 +08:00
|
|
|
spi = platform.request("spi")
|
2020-09-24 17:10:31 +08:00
|
|
|
spi_mosi = platform.request("spi_mosi")
|
2020-09-17 09:55:20 +08:00
|
|
|
spi_cs = platform.request("spi_cs")
|
2020-08-20 09:53:39 +08:00
|
|
|
led = platform.request("user_led")
|
2020-08-23 22:28:32 +08:00
|
|
|
io_update = platform.request("io_update")
|
2020-08-09 02:03:47 +08:00
|
|
|
|
2020-09-17 09:55:20 +08:00
|
|
|
assert len(spi.clk) == 1
|
2020-09-24 17:10:31 +08:00
|
|
|
assert len(spi_mosi) == 1
|
2020-08-23 17:17:09 +08:00
|
|
|
assert len(spi.miso) == 1
|
2020-09-17 09:55:20 +08:00
|
|
|
assert len(spi_cs) == 3
|
|
|
|
assert len(io_update) == 1
|
2020-08-09 02:03:47 +08:00
|
|
|
|
2020-09-17 10:06:33 +08:00
|
|
|
# Flip negative input to positive output
|
2020-08-21 11:36:16 +08:00
|
|
|
self.miso_n = Signal()
|
2020-08-21 11:17:08 +08:00
|
|
|
|
2020-08-23 17:17:09 +08:00
|
|
|
# Very similar setup to Diff setup for iCE40 suggested, but gave B pin instead
|
2020-08-21 11:17:08 +08:00
|
|
|
self.specials += Instance("SB_IO",
|
|
|
|
p_PIN_TYPE=C(0b000001, 6),
|
|
|
|
p_IO_STANDARD="SB_LVDS_INPUT",
|
2020-08-23 17:17:09 +08:00
|
|
|
io_PACKAGE_PIN=eem0[2],
|
2020-08-21 11:36:16 +08:00
|
|
|
o_D_IN_0=self.miso_n
|
2020-08-21 11:17:08 +08:00
|
|
|
)
|
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
# Link EEM to SPI
|
|
|
|
self.comb += [
|
2020-08-20 09:53:39 +08:00
|
|
|
|
2020-09-17 09:55:20 +08:00
|
|
|
eem0[0].p.eq(spi.clk),
|
|
|
|
eem0[0].n.eq(~spi.clk),
|
2020-08-20 09:53:39 +08:00
|
|
|
|
2020-09-24 17:10:31 +08:00
|
|
|
eem0[1].p.eq(spi_mosi),
|
|
|
|
eem0[1].n.eq(~spi_mosi),
|
2020-08-20 09:53:39 +08:00
|
|
|
|
2020-08-21 11:36:16 +08:00
|
|
|
spi.miso.eq(~self.miso_n),
|
2020-08-20 09:53:39 +08:00
|
|
|
|
2020-09-17 09:55:20 +08:00
|
|
|
eem0[3].p.eq(spi_cs[0]),
|
|
|
|
eem0[3].n.eq(~spi_cs[0]),
|
2020-08-20 09:53:39 +08:00
|
|
|
|
2020-09-17 09:55:20 +08:00
|
|
|
eem0[4].p.eq(spi_cs[1]),
|
|
|
|
eem0[4].n.eq(~spi_cs[1]),
|
2020-08-20 09:53:39 +08:00
|
|
|
|
2020-09-17 09:55:20 +08:00
|
|
|
eem0[5].p.eq(spi_cs[2]),
|
|
|
|
eem0[5].n.eq(~spi_cs[2]),
|
2020-08-20 09:53:39 +08:00
|
|
|
|
2020-08-23 22:28:32 +08:00
|
|
|
eem0[6].p.eq(io_update),
|
|
|
|
eem0[6].n.eq(~io_update),
|
|
|
|
|
2020-08-20 09:53:39 +08:00
|
|
|
led.eq(1)
|
2020-08-09 02:03:47 +08:00
|
|
|
]
|
|
|
|
|
2020-08-21 11:17:08 +08:00
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
if __name__ == "__main__":
|
2020-09-17 09:55:20 +08:00
|
|
|
platform = humpback.Platform()
|
2020-08-09 02:03:47 +08:00
|
|
|
platform.build(UrukulConnector(platform))
|