litescope/examples/targets/simple.py

76 lines
2.4 KiB
Python
Raw Normal View History

# This file is Copyright (c) 2015-2018 Florent Kermarrec <florent@enjoy-digital.fr>
# License: BSD
from migen import *
from migen.genlib.io import CRG
2015-09-07 05:49:54 -04:00
2020-02-26 16:02:14 -05:00
from litex.soc.integration.soc_core import SoCMini
2015-09-07 05:49:54 -04:00
from litescope import LiteScopeIO, LiteScopeAnalyzer
2020-02-26 16:02:14 -05:00
# LiteScope SoC ------------------------------------------------------------------------------------
2020-02-26 16:02:14 -05:00
class LiteScopeSoC(SoCMini):
2015-09-07 05:49:54 -04:00
def __init__(self, platform):
sys_clk_freq = int((1e9/platform.default_clk_period))
2020-02-26 16:02:14 -05:00
# SoCMini ----------------------------------------------------------------------------------
SoCMini.__init__(self, platform, sys_clk_freq,
csr_data_width = 32,
with_uart = True,
uart_name = "bridge",
ident = "Litescope example design",
ident_version = True,
2015-09-07 05:49:54 -04:00
)
2020-02-26 16:02:14 -05:00
# CRG --------------------------------------------------------------------------------------
self.submodules.crg = CRG(platform.request(platform.default_clk_name))
2020-02-26 16:02:14 -05:00
# Litescope IO -----------------------------------------------------------------------------
self.submodules.io = LiteScopeIO(8)
2020-02-26 16:02:14 -05:00
self.add_csr("io")
2015-09-07 05:49:54 -04:00
for i in range(8):
try:
self.comb += platform.request("user_led", i).eq(self.io.output[i])
2015-09-07 05:49:54 -04:00
except:
pass
2020-02-26 16:02:14 -05:00
# Litescope Analyzer -----------------------------------------------------------------------
analyzer_groups = {}
2020-02-26 16:02:14 -05:00
# Counter group
2018-05-28 12:05:31 -04:00
counter = Signal(16, name_override="counter")
2020-02-26 16:02:14 -05:00
zero = Signal(name_override="zero")
2015-11-24 15:13:23 -05:00
self.sync += counter.eq(counter + 1)
2018-05-28 12:05:31 -04:00
self.comb += zero.eq(counter == 0)
analyzer_groups[0] = [
2018-05-28 12:05:31 -04:00
zero,
2020-02-26 16:02:14 -05:00
counter,
]
2020-02-26 16:02:14 -05:00
# Communication group
analyzer_groups[1] = [
platform.lookup_request("serial").tx,
platform.lookup_request("serial").rx,
2020-02-26 16:02:14 -05:00
self.bus.masters["uart_bridge"],
]
2020-02-26 16:02:14 -05:00
# FSM group
2018-07-20 03:36:42 -04:00
fsm = FSM(reset_state="STATE1")
self.submodules += fsm
fsm.act("STATE1",
NextState("STATE2")
)
fsm.act("STATE2",
NextState("STATE1")
)
analyzer_groups[2] = [
2020-02-26 16:02:14 -05:00
fsm,
2018-07-20 03:36:42 -04:00
]
2020-02-26 16:02:14 -05:00
# Analyzer
self.submodules.analyzer = LiteScopeAnalyzer(analyzer_groups, 512, csr_csv="test/analyzer.csv")
self.add_csr("analyzer")
2015-09-07 05:49:54 -04:00
default_subtarget = LiteScopeSoC