1 from fractions
import Fraction
3 from operator
import itemgetter
4 from collections
import defaultdict
6 from migen
.fhdl
.std
import *
7 from migen
.bus
import wishbone
, csr
, lasmibus
, dfi
8 from migen
.bus
import wishbone2lasmi
, wishbone2csr
9 from migen
.bank
import csrgen
10 from mibuild
.generic_platform
import ConstraintError
12 from misoclib
import mxcrg
, lm32
, norflash
, uart
, s6ddrphy
, dfii
, lasmicon
, \
13 identifier
, timer
, minimac3
, framebuffer
, dvisampler
, gpio
, memtest
15 clk_freq
= (83 + Fraction(1, 3))*1000000
16 sram_size
= 4096 # in bytes
17 l2_size
= 8192 # in bytes
19 clk_period_ns
= 1000000000/clk_freq
20 def ns(t
, margin
=True):
23 return ceil(t
/clk_period_ns
)
25 sdram_geom
= lasmicon
.GeomSettings(
30 sdram_timing
= lasmicon
.TimingSettings(
35 tREFI
=ns(7800, False),
44 def __init__(self
, platform
):
45 self
.clk50
= platform
.request("clk50")
46 self
.trigger_reset
= 0
48 self
.trigger_reset
= platform
.request("user_btn", 1)
49 except ConstraintError
:
51 self
.norflash_rst_n
= platform
.request("norflash_rst_n")
52 ddram_clock
= platform
.request("ddram_clock")
53 self
.ddr_clk_p
= ddram_clock
.p
54 self
.ddr_clk_n
= ddram_clock
.n
55 eth_clocks
= platform
.request("eth_clocks")
56 self
.eth_phy_clk
= eth_clocks
.phy
57 self
.eth_rx_clk
= eth_clocks
.rx
58 self
.eth_tx_clk
= eth_clocks
.tx
72 "dvisampler0_edid_mem": 9,
74 "dvisampler1_edid_mem": 11,
88 known_platform_id
= defaultdict(lambda: 0x554E, {
93 def __init__(self
, platform
, platform_name
, with_memtest
):
97 self
.submodules
.ddrphy
= s6ddrphy
.S6DDRPHY(platform
.request("ddram"), memtype
="DDR", nphases
=2, cl
=3, rd_bitslip
=0, wr_bitslip
=3, dqs_ddr_alignment
="C1")
98 self
.submodules
.dfii
= dfii
.DFIInjector(sdram_geom
.mux_a
, sdram_geom
.bank_a
,
99 self
.ddrphy
.phy_settings
.dfi_d
, self
.ddrphy
.phy_settings
.nphases
)
100 self
.submodules
.dficon0
= dfi
.Interconnect(self
.dfii
.master
, self
.ddrphy
.dfi
)
105 self
.submodules
.lasmicon
= lasmicon
.LASMIcon(self
.ddrphy
.phy_settings
, sdram_geom
, sdram_timing
)
106 self
.submodules
.dficon1
= dfi
.Interconnect(self
.lasmicon
.dfi
, self
.dfii
.slave
)
108 n_lasmims
= 1 # wishbone bridging
109 if platform_name
== "mixxeo":
110 n_lasmims
+= 4 # framebuffer (2-channel mixing) + 2 DVI samplers
111 if platform_name
== "m1":
112 n_lasmims
+= 1 # framebuffer (single channel)
114 n_lasmims
+= 2 # writer + reader
115 self
.submodules
.lasmixbar
= lasmibus
.Crossbar([self
.lasmicon
.lasmic
], n_lasmims
, self
.lasmicon
.nrowbits
)
117 lasmims
= list(self
.lasmixbar
.masters
)
118 lasmim_wb
= lasmims
.pop()
119 if platform_name
== "mixxeo":
120 lasmim_fb0
, lasmim_fb1
, lasmim_dvi0
, lasmim_dvi1
= (lasmims
.pop() for i
in range(4))
121 if platform_name
== "m1":
122 lasmim_fb
= lasmims
.pop()
124 lasmim_mtw
, lasmim_mtr
= lasmims
.pop(), lasmims
.pop()
130 self
.submodules
.cpu
= lm32
.LM32()
131 self
.submodules
.norflash
= norflash
.NorFlash(platform
.request("norflash"), 12)
132 self
.submodules
.sram
= wishbone
.SRAM(sram_size
)
133 self
.submodules
.minimac
= minimac3
.MiniMAC(platform
.request("eth"))
134 self
.submodules
.wishbone2lasmi
= wishbone2lasmi
.WB2LASMI(l2_size
//4, lasmim_wb
)
135 self
.submodules
.wishbone2csr
= wishbone2csr
.WB2CSR()
137 # norflash 0x00000000 (shadow @0x80000000)
138 # SRAM/debug 0x10000000 (shadow @0x90000000)
139 # USB 0x20000000 (shadow @0xa0000000)
140 # Ethernet 0x30000000 (shadow @0xb0000000)
141 # SDRAM 0x40000000 (shadow @0xc0000000)
142 # CSR bridge 0x60000000 (shadow @0xe0000000)
143 self
.submodules
.wishbonecon
= wishbone
.InterconnectShared(
148 (lambda a
: a
[26:29] == 0, self
.norflash
.bus
),
149 (lambda a
: a
[26:29] == 1, self
.sram
.bus
),
150 (lambda a
: a
[26:29] == 3, self
.minimac
.membus
),
151 (lambda a
: a
[27:29] == 2, self
.wishbone2lasmi
.wishbone
),
152 (lambda a
: a
[27:29] == 3, self
.wishbone2csr
.wishbone
)
159 self
.submodules
.crg
= mxcrg
.MXCRG(MXClockPads(platform
), clk_freq
)
160 self
.submodules
.uart
= uart
.UART(platform
.request("serial"), clk_freq
, baud
=115200)
161 self
.submodules
.identifier
= identifier
.Identifier(self
.known_platform_id
[platform_name
], int(clk_freq
),
163 self
.submodules
.timer0
= timer
.Timer()
164 if platform_name
== "mixxeo":
165 self
.submodules
.leds
= gpio
.GPIOOut(platform
.request("user_led"))
166 self
.submodules
.fb
= framebuffer
.MixFramebuffer(platform
.request("vga_out"), platform
.request("dvi_out"),
167 lasmim_fb0
, lasmim_fb1
)
168 self
.submodules
.dvisampler0
= dvisampler
.DVISampler(platform
.request("dvi_in", 0), lasmim_dvi0
)
169 self
.submodules
.dvisampler1
= dvisampler
.DVISampler(platform
.request("dvi_in", 1), lasmim_dvi1
)
170 if platform_name
== "m1":
171 self
.submodules
.buttons
= gpio
.GPIOIn(Cat(platform
.request("user_btn", 0), platform
.request("user_btn", 2)))
172 self
.submodules
.leds
= gpio
.GPIOOut(Cat(*[platform
.request("user_led", i
) for i
in range(2)]))
173 self
.submodules
.fb
= framebuffer
.Framebuffer(platform
.request("vga"), None, lasmim_fb
)
175 self
.submodules
.memtest_w
= memtest
.MemtestWriter(lasmim_mtw
)
176 self
.submodules
.memtest_r
= memtest
.MemtestReader(lasmim_mtr
)
178 self
.submodules
.csrbankarray
= csrgen
.BankArray(self
,
179 lambda name
, memory
: self
.csr_map
[name
if memory
is None else name
+ "_" + memory
.name_override
])
180 self
.submodules
.csrcon
= csr
.Interconnect(self
.wishbone2csr
.csr
, self
.csrbankarray
.get_buses())
185 for k
, v
in sorted(self
.interrupt_map
.items(), key
=itemgetter(1)):
187 self
.comb
+= self
.cpu
.interrupt
[v
].eq(getattr(self
, k
).ev
.irq
)
193 self
.ddrphy
.clk4x_wr_strb
.eq(self
.crg
.clk4x_wr_strb
),
194 self
.ddrphy
.clk4x_rd_strb
.eq(self
.crg
.clk4x_rd_strb
)