Created
February 18, 2019 09:54
-
-
Save xobs/0ad95e78ebfca1ed73f34690c2637a50 to your computer and use it in GitHub Desktop.
An example of a CSR write failing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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.storage | |
print("CSR value: {} / {}".format(counter, test_value)) | |
yield | |
class TestCSR(Module, AutoCSR): | |
def __init__(self): | |
# self.counter = Signal(8) | |
# self.test_value = CSR() | |
# self.sync += [ | |
# self.counter.eq(self.counter+1), | |
# self.test_value.w.eq(self.counter), | |
# ] | |
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.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