Skip to content

Instantly share code, notes, and snippets.

@xobs
Last active February 18, 2019 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xobs/528c30d20a88268614bf7cdebc9f5a65 to your computer and use it in GitHub Desktop.
Save xobs/528c30d20a88268614bf7cdebc9f5a65 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# This variable defines all the external programs that this module
# relies on. lxbuildenv reads this variable in order to ensure
# the build will finish without exiting due to missing third-party
# programs.
LX_DEPENDENCIES = ["riscv", "icestorm", "yosys"]
# Import lxbuildenv to integrate the deps/ directory
import lxbuildenv
# Disable pylint's E1101, which breaks completely on migen
#pylint:disable=E1101
#from migen import *
from migen import Module, Signal, Instance, ClockDomain, If, run_simulation
from migen.genlib.resetsync import AsyncResetSynchronizer
from litex.build.lattice.platform import LatticePlatform
from litex.build.generic_platform import Pins, IOStandard, Misc, Subsignal
from litex.soc.integration import SoCCore
from litex.soc.integration.builder import Builder
from litex.soc.integration.soc_core import csr_map_update
from litex.soc.interconnect import wishbone
from litex.soc.interconnect.csr import CSR, CSRStorage, AutoCSR
def csr_test(dut):
for i in range(20):
counter = yield dut.counter
test_value = yield dut.test_value.r
print("CSR value: {} / {}".format(counter, test_value))
yield
class TestCSR(Module, AutoCSR):
def __init__(self):
self.counter = Signal(8)
self.test_value = CSR(8)
self.result = Signal(8)
self.sync += [
self.counter.eq(self.counter+1),
self.test_value.w.eq(self.counter),
self.result.eq(self.test_value.r),
]
# self.counter = Signal(8)
# self.test_value = CSRStorage(8, write_from_dev=True)
# self.result = Signal(8)
# self.sync += [
# self.test_value.we.eq(1),#self.counter[0]),
# self.counter.eq(self.counter+1),
# self.test_value.dat_w.eq(self.counter),
# self.result.eq(self.test_value.storage)
# ]
def main():
dut = TestCSR()
run_simulation(dut, csr_test(dut), vcd_name="csr-test.vcd")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment