From 5c40ff02cb72d0c77c9732ba389e7eefcc9ffa2e Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 23 Jan 2015 00:08:04 +0100 Subject: [PATCH] add LiteScopeIO example --- litescope/host/driver.py | 4 ++-- targets/simple.py | 10 +++++++++- test/Makefile | 3 +++ test/test_io.py | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 test/test_io.py diff --git a/litescope/host/driver.py b/litescope/host/driver.py index 31645197..0d6beb64 100644 --- a/litescope/host/driver.py +++ b/litescope/host/driver.py @@ -100,7 +100,7 @@ class LiteScopeIODriver(): def build(self): for key, value in self.regs.d.items(): if self.name in key: - key.replace(self.name +"_") + key = key.replace(self.name +"_", "") setattr(self, key, value) def write(self, value): @@ -139,7 +139,7 @@ class LiteScopeLADriver(): def build(self): for key, value in self.regs.d.items(): if self.name == key[:len(self.name)]: - key.replace(self.name + "_") + key = key.replace(self.name + "_") setattr(self, key, value) value = 1 for name, length in self.layout: diff --git a/targets/simple.py b/targets/simple.py index 40c9993c..13f734af 100644 --- a/targets/simple.py +++ b/targets/simple.py @@ -11,6 +11,8 @@ from misoclib import identifier from litescope.common import * from litescope.bridge.uart2wb import LiteScopeUART2WB +from litescope.frontend.io import LiteScopeIO + class _CRG(Module): def __init__(self, clk_in): @@ -72,7 +74,9 @@ class GenSoC(Module): class LiteScopeSoC(GenSoC, AutoCSR): default_platform = "de0nano" - csr_map = {} + csr_map = { + "io": 10 + } csr_map.update(GenSoC.csr_map) def __init__(self, platform, export_mila=False): @@ -80,4 +84,8 @@ class LiteScopeSoC(GenSoC, AutoCSR): GenSoC.__init__(self, platform, clk_freq) self.submodules.crg = _CRG(platform.request("clk50")) + self.submodules.io = LiteScopeIO(8) + self.leds = Cat(*[platform.request("user_led", i) for i in range(8)]) + self.comb += self.leds.eq(self.io.o) + default_subtarget = LiteScopeSoC diff --git a/test/Makefile b/test/Makefile index 6d23bdcc..cba12bec 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,3 +5,6 @@ CMD = PYTHONPATH=$(LSDIR) $(PYTHON) test_regs: $(CMD) test_regs.py + +test_io: + $(CMD) test_io.py diff --git a/test/test_io.py b/test/test_io.py new file mode 100644 index 00000000..8f3f2e0c --- /dev/null +++ b/test/test_io.py @@ -0,0 +1,35 @@ +import time + +from config import * +from litescope.host.driver import LiteScopeIODriver + +def led_anim0(io): + for i in range(10): + io.write(0xA5) + time.sleep(0.1) + io.write(0x5A) + time.sleep(0.1) + +def led_anim1(io): + for j in range(4): + #Led << + led_data = 1 + for i in range(8): + io.write(led_data) + time.sleep(i*i*0.0020) + led_data = (led_data<<1) + #Led >> + ledData = 128 + for i in range(8): + io.write(led_data) + time.sleep(i*i*0.0020) + led_data = (led_data>>1) + +io = LiteScopeIODriver(wb.regs, "io") +wb.open() +### +led_anim0(io) +led_anim1(io) +print("%02X" %io.read()) +### +wb.close() -- 2.30.2