add LiteScopeIO example

This commit is contained in:
Florent Kermarrec 2015-01-23 00:08:04 +01:00
parent f35f93a7c5
commit 5c40ff02cb
4 changed files with 49 additions and 3 deletions

View 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:

View 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

View File

@ -5,3 +5,6 @@ CMD = PYTHONPATH=$(LSDIR) $(PYTHON)
test_regs:
$(CMD) test_regs.py
test_io:
$(CMD) test_io.py

35
test/test_io.py Normal file
View File

@ -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()