add LiteScopeIO example
This commit is contained in:
parent
f35f93a7c5
commit
5c40ff02cb
|
@ -100,7 +100,7 @@ class LiteScopeIODriver():
|
||||||
def build(self):
|
def build(self):
|
||||||
for key, value in self.regs.d.items():
|
for key, value in self.regs.d.items():
|
||||||
if self.name in key:
|
if self.name in key:
|
||||||
key.replace(self.name +"_")
|
key = key.replace(self.name +"_", "")
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
def write(self, value):
|
def write(self, value):
|
||||||
|
@ -139,7 +139,7 @@ class LiteScopeLADriver():
|
||||||
def build(self):
|
def build(self):
|
||||||
for key, value in self.regs.d.items():
|
for key, value in self.regs.d.items():
|
||||||
if self.name == key[:len(self.name)]:
|
if self.name == key[:len(self.name)]:
|
||||||
key.replace(self.name + "_")
|
key = key.replace(self.name + "_")
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
value = 1
|
value = 1
|
||||||
for name, length in self.layout:
|
for name, length in self.layout:
|
||||||
|
|
|
@ -11,6 +11,8 @@ from misoclib import identifier
|
||||||
|
|
||||||
from litescope.common import *
|
from litescope.common import *
|
||||||
from litescope.bridge.uart2wb import LiteScopeUART2WB
|
from litescope.bridge.uart2wb import LiteScopeUART2WB
|
||||||
|
from litescope.frontend.io import LiteScopeIO
|
||||||
|
|
||||||
|
|
||||||
class _CRG(Module):
|
class _CRG(Module):
|
||||||
def __init__(self, clk_in):
|
def __init__(self, clk_in):
|
||||||
|
@ -72,7 +74,9 @@ class GenSoC(Module):
|
||||||
|
|
||||||
class LiteScopeSoC(GenSoC, AutoCSR):
|
class LiteScopeSoC(GenSoC, AutoCSR):
|
||||||
default_platform = "de0nano"
|
default_platform = "de0nano"
|
||||||
csr_map = {}
|
csr_map = {
|
||||||
|
"io": 10
|
||||||
|
}
|
||||||
csr_map.update(GenSoC.csr_map)
|
csr_map.update(GenSoC.csr_map)
|
||||||
|
|
||||||
def __init__(self, platform, export_mila=False):
|
def __init__(self, platform, export_mila=False):
|
||||||
|
@ -80,4 +84,8 @@ class LiteScopeSoC(GenSoC, AutoCSR):
|
||||||
GenSoC.__init__(self, platform, clk_freq)
|
GenSoC.__init__(self, platform, clk_freq)
|
||||||
self.submodules.crg = _CRG(platform.request("clk50"))
|
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
|
default_subtarget = LiteScopeSoC
|
||||||
|
|
|
@ -5,3 +5,6 @@ CMD = PYTHONPATH=$(LSDIR) $(PYTHON)
|
||||||
|
|
||||||
test_regs:
|
test_regs:
|
||||||
$(CMD) test_regs.py
|
$(CMD) test_regs.py
|
||||||
|
|
||||||
|
test_io:
|
||||||
|
$(CMD) 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()
|
Loading…
Reference in New Issue