add LiteScopeIO example
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 22 Jan 2015 23:08:04 +0000 (00:08 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 22 Jan 2015 23:15:42 +0000 (00:15 +0100)
litescope/host/driver.py
targets/simple.py
test/Makefile
test/test_io.py [new file with mode: 0644]

index 316451971c773dc5b6a6a1ece0f296fe4418a6c3..0d6beb64089aacda57c592e557a9bd1c606586da 100644 (file)
@@ -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:
index 40c9993cbcf3dfa504a21d143393f2f5c0fcad80..13f734af5f81126566e39b565e59f63913aca755 100644 (file)
@@ -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
index 6d23bdcc1af1fc52eedb1c6a319c259c1e4fec78..cba12bec1f29a0f07f28fc80c052b6adc3c714b2 100644 (file)
@@ -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 (file)
index 0000000..8f3f2e0
--- /dev/null
@@ -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()