2023-01-23 06:13:33 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2023 Antmicro <www.antmicro.com>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
2023-02-23 03:09:33 -05:00
|
|
|
from litex.gen import *
|
2023-02-16 03:02:14 -05:00
|
|
|
|
|
|
|
from litex_boards.platforms import antmicro_sdi_mipi_video_converter
|
2023-01-23 06:13:33 -05:00
|
|
|
|
|
|
|
from litex.soc.cores.ram import NXLRAM
|
|
|
|
from litex.soc.cores.clock import NXPLL
|
|
|
|
from litex.build.generic_platform import *
|
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
from litex.soc.integration.soc_core import *
|
2023-02-08 08:06:25 -05:00
|
|
|
from litex.soc.integration.soc import SoCRegion
|
2023-01-23 06:13:33 -05:00
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
from litex.soc.cores.led import LedChaser
|
|
|
|
|
|
|
|
kB = 1024
|
|
|
|
mB = 1024*kB
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
2023-02-16 03:02:14 -05:00
|
|
|
class _CRG(LiteXModule):
|
2023-01-23 06:13:33 -05:00
|
|
|
def __init__(self, platform, sys_clk_freq):
|
2023-02-16 03:02:14 -05:00
|
|
|
self.cd_por = ClockDomain()
|
|
|
|
self.cd_sys = ClockDomain()
|
2023-01-23 06:13:33 -05:00
|
|
|
|
|
|
|
# Built in OSC
|
2023-02-16 03:02:14 -05:00
|
|
|
self.hf_clk = NXOSCA()
|
2023-01-23 06:13:33 -05:00
|
|
|
hf_clk_freq = 25e6
|
|
|
|
self.hf_clk.create_hf_clk(self.cd_por, hf_clk_freq)
|
|
|
|
|
|
|
|
# Power on reset
|
|
|
|
por_count = Signal(16, reset=2**16-1)
|
2023-02-16 03:02:14 -05:00
|
|
|
por_done = Signal()
|
2023-01-23 06:13:33 -05:00
|
|
|
self.comb += por_done.eq(por_count == 0)
|
|
|
|
self.sync.por += If(~por_done, por_count.eq(por_count - 1))
|
|
|
|
|
|
|
|
# PLL
|
2023-02-16 03:02:14 -05:00
|
|
|
self.sys_pll = sys_pll = NXPLL(platform=platform, create_output_port_clocks=True)
|
2023-01-23 06:13:33 -05:00
|
|
|
sys_pll.register_clkin(self.cd_por.clk, hf_clk_freq)
|
|
|
|
sys_pll.create_clkout(self.cd_sys, sys_clk_freq)
|
2023-02-15 05:45:42 -05:00
|
|
|
self.specials += AsyncResetSynchronizer(self.cd_sys, ~self.sys_pll.locked | ~por_done)
|
2023-01-23 06:13:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
|
|
|
mem_map = {
|
2023-02-16 03:02:14 -05:00
|
|
|
"rom" : 0x00000000,
|
|
|
|
"sram" : 0x40000000,
|
|
|
|
"main_ram" : 0x60000000,
|
|
|
|
"csr" : 0xf0000000,
|
2023-01-23 06:13:33 -05:00
|
|
|
}
|
|
|
|
|
2023-02-16 03:02:14 -05:00
|
|
|
def __init__(self, sys_clk_freq=int(75e6), device="LIFCL-40-9BG256C", toolchain="radiant",
|
|
|
|
with_led_chaser = True,
|
|
|
|
**kwargs):
|
|
|
|
platform = antmicro_sdi_mipi_video_converter.Platform(device=device, toolchain=toolchain)
|
2023-01-23 06:13:33 -05:00
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2023-02-16 03:02:14 -05:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq)
|
2023-01-23 06:13:33 -05:00
|
|
|
|
|
|
|
# SoCCore -----------------------------------------_----------------------------------------
|
|
|
|
|
|
|
|
# Disable Integrated SRAM since we want to instantiate LRAM specifically for it
|
|
|
|
kwargs["integrated_sram_size"] = 0
|
2023-02-16 03:02:14 -05:00
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Antmicro SDI MIPI Video Converter Board", **kwargs)
|
2023-01-23 06:13:33 -05:00
|
|
|
|
|
|
|
# 128KB LRAM (used as SRAM) ---------------------------------------------------------------
|
2023-02-16 03:02:14 -05:00
|
|
|
self.spram = NXLRAM(32, 64*kB)
|
2023-02-08 08:06:25 -05:00
|
|
|
self.bus.add_slave("sram", self.spram.bus, SoCRegion(origin=self.mem_map["sram"], size=16*kB))
|
2023-01-23 06:13:33 -05:00
|
|
|
|
2023-02-16 03:02:14 -05:00
|
|
|
self.main_ram = NXLRAM(32, 64*kB)
|
2023-02-08 08:06:25 -05:00
|
|
|
self.bus.add_slave("main_ram", self.main_ram.bus, SoCRegion(origin=self.mem_map["main_ram"], size=64*kB))
|
2023-01-23 06:13:33 -05:00
|
|
|
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
if with_led_chaser:
|
2023-02-16 03:02:14 -05:00
|
|
|
self.leds = LedChaser(
|
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
2023-01-23 06:13:33 -05:00
|
|
|
|
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
2023-02-15 05:45:42 -05:00
|
|
|
|
2023-01-23 06:13:33 -05:00
|
|
|
def main():
|
2023-02-16 03:02:14 -05:00
|
|
|
from litex.build.parser import LiteXArgumentParser
|
|
|
|
parser = LiteXArgumentParser(platform=antmicro_sdi_mipi_video_converter.Platform, description="LiteX SoC on Antmicro SDI MIPI Video Converter Board.")
|
|
|
|
parser.add_target_argument("--device", default="LIFCL-40-9BG256C", help="FPGA device (LIFCL-40-9BG400C, LIFCL-40-8BG400CES, or LIFCL-40-8BG400CES2).")
|
|
|
|
parser.add_target_argument("--sys-clk-freq", default=75e6, help="System clock frequency.")
|
|
|
|
parser.add_target_argument("--programmer", default="radiant", help="Programmer (radiant or ecpprog).")
|
|
|
|
parser.add_target_argument("--prog-target", default="direct", help="Programming Target (direct or flash).")
|
2023-01-23 06:13:33 -05:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
soc = BaseSoC(
|
2023-02-16 03:02:14 -05:00
|
|
|
sys_clk_freq = int(float(args.sys_clk_freq)),
|
|
|
|
device = args.device,
|
|
|
|
toolchain = args.toolchain,
|
|
|
|
**parser.soc_argdict
|
2023-01-23 06:13:33 -05:00
|
|
|
)
|
2023-02-16 03:02:14 -05:00
|
|
|
builder = Builder(soc, **parser.builder_argdict)
|
2023-01-23 06:13:33 -05:00
|
|
|
if args.build:
|
2023-02-16 03:02:14 -05:00
|
|
|
builder.build(**parser.toolchain_argdict)
|
2023-01-23 06:13:33 -05:00
|
|
|
|
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer(args.prog_target, args.programmer)
|
|
|
|
if args.programmer == "ecpprog" and args.prog_target == "flash":
|
2023-02-15 05:45:42 -05:00
|
|
|
prog.flash(address=args.address,
|
|
|
|
bitstream=builder.get_bitstream_filename(mode="sram"))
|
2023-01-23 06:13:33 -05:00
|
|
|
else:
|
|
|
|
if args.programmer == "radiant":
|
|
|
|
os.system("sudo modprobe -rf ftdi_sio")
|
|
|
|
|
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram"))
|
|
|
|
|
|
|
|
if args.programmer == "radiant":
|
|
|
|
os.system("sudo modprobe ftdi_sio")
|
|
|
|
|
2023-02-15 05:45:42 -05:00
|
|
|
|
2023-01-23 06:13:33 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|