2018-02-23 07:43:47 -05:00
|
|
|
from migen import *
|
|
|
|
from migen.genlib.io import CRG
|
2015-09-07 05:49:54 -04:00
|
|
|
|
2015-11-11 18:56:49 -05:00
|
|
|
from litex.soc.integration.soc_core import SoCCore
|
2017-04-19 04:46:17 -04:00
|
|
|
from litex.soc.cores.uart import UARTWishboneBridge
|
2015-09-07 05:49:54 -04:00
|
|
|
|
2016-03-31 05:37:00 -04:00
|
|
|
from litescope import LiteScopeIO, LiteScopeAnalyzer
|
|
|
|
|
|
|
|
|
2015-11-11 18:56:49 -05:00
|
|
|
class LiteScopeSoC(SoCCore):
|
2015-09-07 05:49:54 -04:00
|
|
|
csr_map = {
|
2016-03-31 05:37:00 -04:00
|
|
|
"io": 16,
|
|
|
|
"analyzer": 17
|
2015-09-07 05:49:54 -04:00
|
|
|
}
|
2015-11-11 18:56:49 -05:00
|
|
|
csr_map.update(SoCCore.csr_map)
|
2015-09-07 05:49:54 -04:00
|
|
|
|
|
|
|
def __init__(self, platform):
|
2018-05-28 17:43:44 -04:00
|
|
|
sys_clk_freq = int((1e9/platform.default_clk_period))
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq,
|
2015-11-11 18:56:49 -05:00
|
|
|
cpu_type=None,
|
|
|
|
csr_data_width=32,
|
2015-09-07 05:49:54 -04:00
|
|
|
with_uart=False,
|
2018-05-28 12:05:31 -04:00
|
|
|
ident="Litescope example design", ident_version=True,
|
2015-09-07 05:49:54 -04:00
|
|
|
with_timer=False
|
|
|
|
)
|
2018-05-28 17:43:44 -04:00
|
|
|
# crg
|
2015-09-07 05:49:54 -04:00
|
|
|
self.submodules.crg = CRG(platform.request(platform.default_clk_name))
|
|
|
|
|
2018-05-28 17:43:44 -04:00
|
|
|
# bridge
|
|
|
|
self.add_cpu_or_bridge(UARTWishboneBridge(platform.request("serial"),
|
|
|
|
sys_clk_freq, baudrate=115200))
|
|
|
|
self.add_wb_master(self.cpu_or_bridge.wishbone)
|
|
|
|
|
|
|
|
# Litescope IO
|
2016-03-31 05:37:00 -04:00
|
|
|
self.submodules.io = LiteScopeIO(8)
|
2015-09-07 05:49:54 -04:00
|
|
|
for i in range(8):
|
|
|
|
try:
|
2016-03-31 05:37:00 -04:00
|
|
|
self.comb += platform.request("user_led", i).eq(self.io.output[i])
|
2015-09-07 05:49:54 -04:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2018-05-28 17:43:44 -04:00
|
|
|
# Litescope Analyzer
|
|
|
|
analyzer_groups = {}
|
|
|
|
|
|
|
|
# counter group
|
2018-05-28 12:05:31 -04:00
|
|
|
counter = Signal(16, name_override="counter")
|
2018-05-28 17:43:44 -04: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)
|
2018-05-28 17:43:44 -04:00
|
|
|
analyzer_groups[0] = [
|
2018-05-28 12:05:31 -04:00
|
|
|
zero,
|
2018-05-28 17:43:44 -04:00
|
|
|
counter
|
2017-06-22 13:12:33 -04:00
|
|
|
]
|
2018-05-28 17:43:44 -04:00
|
|
|
|
2018-06-04 02:04:10 -04:00
|
|
|
# communication group
|
2018-05-28 17:43:44 -04:00
|
|
|
analyzer_groups[1] = [
|
|
|
|
platform.lookup_request("serial").tx,
|
|
|
|
platform.lookup_request("serial").rx,
|
|
|
|
self.cpu_or_bridge.wishbone
|
2017-06-22 13:12:33 -04:00
|
|
|
]
|
2018-05-28 17:43:44 -04:00
|
|
|
|
2018-07-20 03:36:42 -04:00
|
|
|
# fsm group
|
|
|
|
fsm = FSM(reset_state="STATE1")
|
|
|
|
self.submodules += fsm
|
|
|
|
fsm.act("STATE1",
|
|
|
|
NextState("STATE2")
|
|
|
|
)
|
|
|
|
fsm.act("STATE2",
|
|
|
|
NextState("STATE1")
|
|
|
|
)
|
|
|
|
analyzer_groups[2] = [
|
|
|
|
fsm
|
|
|
|
]
|
|
|
|
|
2018-05-28 17:43:44 -04:00
|
|
|
# analyzer
|
|
|
|
self.submodules.analyzer = LiteScopeAnalyzer(analyzer_groups, 512)
|
2015-09-07 05:49:54 -04:00
|
|
|
|
|
|
|
def do_exit(self, vns):
|
2016-03-31 05:37:00 -04:00
|
|
|
self.analyzer.export_csv(vns, "test/analyzer.csv")
|
2015-09-07 05:49:54 -04:00
|
|
|
|
|
|
|
default_subtarget = LiteScopeSoC
|