5b605b92e9fbab22100ba083ecbdf3122b815ca2
5 from litex
.gen
import *
7 from litex
.soc
.cores
.clock
import CycloneIVPLL
8 from litex
.soc
.integration
.soc_core
import *
9 from litex
.soc
.integration
.builder
import *
10 from litex
.soc
.interconnect
.csr
import *
11 from migen
.genlib
.resetsync
import AsyncResetSynchronizer
15 # CRG --------------------------------------------------------------------------
17 class _CRG(LiteXModule
):
18 def __init__(self
, platform
, sys_clk_freq
):
20 self
.cd_por
= ClockDomain(reset_less
=True)
21 self
.cd_sys
= ClockDomain()
22 # clock domain used only for reset button sync
23 self
.cd_sync
= ClockDomain()
25 clk50
= platform
.request("clk50")
26 rst_n
= platform
.request("rst_n")
29 por_count
= Signal(16, reset
=2**16 - 1)
31 self
.comb
+= self
.cd_por
.clk
.eq(clk50
)
32 self
.comb
+= por_done
.eq(por_count
== 0)
33 self
.sync
.por
+= If(~por_done
, por_count
.eq(por_count
- 1))
36 self
.pll
= pll
= CycloneIVPLL(speedgrade
="-6")
37 self
.comb
+= pll
.reset
.eq(~por_done | self
.rst
)
38 pll
.register_clkin(clk50
, 50e6
)
39 pll
.create_clkout(self
.cd_sys
, sys_clk_freq
, margin
=0, with_reset
=False)
43 self
.comb
+= sys_rst
.eq(~pll
.locked
)
44 self
.specials
+= AsyncResetSynchronizer(self
.cd_sys
, sys_rst
)
47 self
.comb
+= self
.cd_sync
.clk
.eq(self
.cd_sys
.clk
)
48 self
.specials
+= AsyncResetSynchronizer(self
.cd_sync
, ~rst_n
)
51 # BaseSoC ----------------------------------------------------------------------
53 class BaseSoC(SoCCore
):
54 def __init__(self
, sys_clk_freq
=50e6
,
57 platform
= mmuless_board
.Platform()
59 # CRG ------------------------------------------------------------------
60 self
.crg
= _CRG(platform
, sys_clk_freq
)
62 # SoCCore --------------------------------------------------------------
63 if kwargs
["with_jtagbone"]:
64 if kwargs
.get("uart_name", "serial") == "serial": kwargs
["uart_name"] = "crossover"
66 SoCCore
.__init
__(self
, platform
, sys_clk_freq
,
67 ident
= "LiteX SoC on SiMiaoHub AC440B",
71 # Leds -----------------------------------------------------------------
72 leds
= Cat(*[platform
.request("u_led_n", i
) for i
in range(4)])
73 self
.submodules
.leds
= CSRStorage(len(leds
), description
="Board LEDs")
74 self
.comb
+= leds
.eq(~self
.leds
.storage
)
76 # Buttons --------------------------------------------------------------
77 keys
= Cat(*[platform
.request("u_key_n", i
) for i
in range(2)])
78 self
.submodules
.btns
= CSRStatus(len(keys
), description
="Board buttons")
79 self
.comb
+= self
.btns
.status
.eq(~keys
)
81 self
.comb
+= If(self
.crg
.cd_sync
.rst
, self
.cpu
.reset
.eq(1))
85 # Build ------------------------------------------------------------------------
88 from litex
.build
.parser
import LiteXArgumentParser
89 parser
= LiteXArgumentParser(platform
=mmuless_board
.Platform
, description
="LiteX SoC on SiMiaoHub AC440B")
90 parser
.add_target_argument("--sys-clk-freq", default
=50e6
, type=float, help="System clock frequency.")
91 args
= parser
.parse_args()
94 sys_clk_freq
= args
.sys_clk_freq
,
98 builder
= Builder(soc
, **parser
.builder_argdict
)
100 builder
.build(**parser
.toolchain_argdict
)
103 prog
= soc
.platform
.create_programmer()
104 prog
.load_bitstream(builder
.get_bitstream_filename(mode
="sram"))
106 if __name__
== "__main__":