2019-11-22 13:34:36 -05:00
|
|
|
# This file is Copyright (c) 2017-2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
2019-06-24 04:04:55 -04:00
|
|
|
# License: BSD
|
|
|
|
|
2017-01-18 22:58:04 -05:00
|
|
|
import unittest
|
|
|
|
|
2018-02-23 07:43:47 -05:00
|
|
|
from migen import *
|
2017-01-18 22:58:04 -05:00
|
|
|
|
|
|
|
from litescope import LiteScopeAnalyzer
|
|
|
|
|
|
|
|
|
|
|
|
class TestAnalyzer(unittest.TestCase):
|
2019-11-22 13:34:36 -05:00
|
|
|
def test_analyzer(self):
|
|
|
|
def generator(dut):
|
|
|
|
dut.data = []
|
|
|
|
# Configure Trigger
|
|
|
|
yield from dut.analyzer.trigger.mem_value.write(0x0010)
|
|
|
|
yield from dut.analyzer.trigger.mem_mask.write(0xffff)
|
|
|
|
yield from dut.analyzer.trigger.mem_write.write(1)
|
|
|
|
|
|
|
|
# Configure Subsampler
|
|
|
|
yield from dut.analyzer.subsampler.value.write(2)
|
|
|
|
|
|
|
|
# Configure Storage
|
|
|
|
yield from dut.analyzer.storage.length.write(256)
|
|
|
|
yield from dut.analyzer.storage.offset.write(8)
|
|
|
|
yield from dut.analyzer.storage.enable.write(1)
|
|
|
|
yield
|
|
|
|
for i in range(16):
|
|
|
|
yield
|
|
|
|
# Wait capture
|
|
|
|
while not (yield from dut.analyzer.storage.done.read()):
|
|
|
|
yield
|
|
|
|
# Reade captured datas
|
|
|
|
while (yield from dut.analyzer.storage.mem_valid.read()):
|
|
|
|
dut.data.append((yield from dut.analyzer.storage.mem_data.read()))
|
|
|
|
yield
|
|
|
|
|
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self):
|
|
|
|
counter = Signal(16)
|
|
|
|
self.sync += counter.eq(counter + 1)
|
|
|
|
self.submodules.analyzer = LiteScopeAnalyzer(counter, 512)
|
|
|
|
|
2017-01-18 22:58:04 -05:00
|
|
|
dut = DUT()
|
2019-11-22 13:34:36 -05:00
|
|
|
generators = {"sys" : [generator(dut)]}
|
|
|
|
clocks = {"sys": 10, "scope": 10}
|
|
|
|
run_simulation(dut, generators, clocks)
|
|
|
|
self.assertEqual(dut.data, [524 + 3*i for i in range(256)])
|