1 from migen
.fhdl
.std
import *
3 from misoclib
.mem
.sdram
.module
import IS42S16160
4 from misoclib
.mem
.sdram
.phy
import gensdrphy
5 from misoclib
.mem
.sdram
.core
.lasmicon
import LASMIconSettings
6 from misoclib
.soc
.sdram
import SDRAMSoC
10 def __init__(self
, period_in
, name
, phase_shift
, operation_mode
):
11 self
.clk_in
= Signal()
12 self
.clk_out
= Signal()
14 self
.specials
+= Instance("ALTPLL",
15 p_bandwidth_type
= "AUTO",
17 p_clk0_duty_cycle
= 50,
18 p_clk0_multiply_by
= 2,
19 p_clk0_phase_shift
= "{}".format(str(phase_shift
)),
20 p_compensate_clock
= "CLK0",
21 p_inclk0_input_frequency
= int(period_in
*1000),
22 p_intended_device_family
= "Cyclone IV E",
23 p_lpm_hint
= "CBX_MODULE_PREFIX={}_pll".format(name
),
24 p_lpm_type
= "altpll",
25 p_operation_mode
= operation_mode
,
35 i_phasecounterselect
=0xf,
49 def __init__(self
, platform
):
50 self
.clock_domains
.cd_sys
= ClockDomain()
51 self
.clock_domains
.cd_sys_ps
= ClockDomain()
52 self
.clock_domains
.cd_por
= ClockDomain(reset_less
=True)
54 clk50
= platform
.request("clk50")
56 sys_pll
= _PLL(20, "sys", 0, "NORMAL")
57 self
.submodules
+= sys_pll
59 sys_pll
.clk_in
.eq(clk50
),
60 self
.cd_sys
.clk
.eq(sys_pll
.clk_out
)
63 sdram_pll
= _PLL(20, "sdram", -3000, "ZERO_DELAY_BUFFER")
64 self
.submodules
+= sdram_pll
66 sdram_pll
.clk_in
.eq(clk50
),
67 self
.cd_sys_ps
.clk
.eq(sdram_pll
.clk_out
)
70 # Power on Reset (vendor agnostic)
72 self
.sync
.por
+= rst_n
.eq(1)
74 self
.cd_por
.clk
.eq(self
.cd_sys
.clk
),
75 self
.cd_sys
.rst
.eq(~rst_n
),
76 self
.cd_sys_ps
.rst
.eq(~rst_n
)
79 self
.comb
+= platform
.request("sdram_clock").eq(self
.cd_sys_ps
.clk
)
82 class BaseSoC(SDRAMSoC
):
83 default_platform
= "de0nano"
85 def __init__(self
, platform
, sdram_controller_settings
=LASMIconSettings(), **kwargs
):
86 SDRAMSoC
.__init
__(self
, platform
,
88 integrated_rom_size
=0x8000,
89 sdram_controller_settings
=sdram_controller_settings
,
92 self
.submodules
.crg
= _CRG(platform
)
94 if not self
.integrated_main_ram_size
:
95 self
.submodules
.sdrphy
= gensdrphy
.GENSDRPHY(platform
.request("sdram"),
96 IS42S16160(self
.clk_freq
))
97 self
.register_sdram_phy(self
.sdrphy
)
99 default_subtarget
= BaseSoC