2022-06-13 11:12:32 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2022 Icenowy Zheng <icenowy@aosc.io>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
from litex.gen import LiteXModule
|
|
|
|
|
2022-10-29 22:50:01 -04:00
|
|
|
from litex_boards.platforms import sitlinv_a_e115fb
|
2022-06-13 11:12:32 -04:00
|
|
|
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.builder import *
|
2022-06-15 05:55:22 -04:00
|
|
|
from litex.soc.cores.clock import CycloneIVPLL
|
|
|
|
from litex.soc.cores.led import LedChaser
|
2022-06-13 11:12:32 -04:00
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2022-06-13 11:12:32 -04:00
|
|
|
def __init__(self, platform, sys_clk_freq):
|
2022-10-27 10:58:55 -04:00
|
|
|
self.rst = Signal()
|
|
|
|
self.cd_sys = ClockDomain()
|
2022-06-13 11:12:32 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
|
|
# Clk / Rst
|
|
|
|
clk25 = platform.request("clk25")
|
2022-06-15 05:55:22 -04:00
|
|
|
rst_n = platform.request("cpu_reset_n")
|
2022-06-13 11:12:32 -04:00
|
|
|
|
|
|
|
# PLL
|
2022-10-27 10:58:55 -04:00
|
|
|
self.pll = pll = CycloneIVPLL(speedgrade="-7")
|
2022-06-13 11:12:32 -04:00
|
|
|
self.comb += pll.reset.eq(~rst_n | self.rst)
|
|
|
|
pll.register_clkin(clk25, 25e6)
|
2022-06-15 05:55:22 -04:00
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
2022-06-13 11:12:32 -04:00
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2022-11-08 05:54:17 -05:00
|
|
|
def __init__(self, sys_clk_freq=50e6, with_led_chaser=True, **kwargs):
|
2022-10-29 22:50:01 -04:00
|
|
|
platform = sitlinv_a_e115fb.Platform()
|
2022-06-13 11:12:32 -04:00
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq)
|
2022-06-13 11:12:32 -04:00
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on A-E115FB", **kwargs)
|
|
|
|
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
if with_led_chaser:
|
|
|
|
ledn = platform.request_all("user_led_n")
|
2022-10-27 10:58:55 -04:00
|
|
|
self.leds = LedChaser(pads=ledn, sys_clk_freq=sys_clk_freq)
|
2022-06-13 11:12:32 -04:00
|
|
|
|
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
2022-11-06 15:39:52 -05:00
|
|
|
from litex.build.parser import LiteXArgumentParser
|
2022-11-08 04:41:35 -05:00
|
|
|
parser = LiteXArgumentParser(platform=sitlinv_a_e115fb.Platform, description="LiteX SoC on A-E115FB.")
|
|
|
|
parser.add_target_argument("--sys-clk-freq", default=50e6, type=float, help="System clock frequency.")
|
2022-06-13 11:12:32 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
soc = BaseSoC(
|
2022-11-08 04:41:35 -05:00
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
2022-11-07 02:43:26 -05:00
|
|
|
**parser.soc_argdict
|
2022-06-13 11:12:32 -04:00
|
|
|
)
|
2022-11-05 03:07:14 -04:00
|
|
|
builder = Builder(soc, **parser.builder_argdict)
|
2022-06-13 11:12:32 -04:00
|
|
|
if args.build:
|
2022-11-05 03:07:14 -04:00
|
|
|
builder.build(**parser.toolchain_argdict)
|
2022-06-13 11:12:32 -04:00
|
|
|
|
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer()
|
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram"))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|