litex/examples/de1/client/test_MigLa.py

90 lines
2.1 KiB
Python
Raw Normal View History

2012-09-14 08:08:20 -04:00
from migen.fhdl.structure import *
from migen.fhdl import verilog, autofragment
from migen.bus import csr
from migen.bus.transactions import *
from migen.bank import description, csrgen
from migen.bank.description import *
import sys
sys.path.append("../../../")
2012-09-17 11:00:47 -04:00
from migScope import trigger, recorder, migIo, migLa
2012-09-14 08:08:20 -04:00
from migScope.tools.truthtable import *
2012-09-14 18:57:52 -04:00
from migScope.tools.vcd import *
2012-09-14 08:08:20 -04:00
import spi2Csr
from spi2Csr.tools.uart2Spi import *
#==============================================================================
# P A R A M E T E R S
#==============================================================================
# Bus Width
trig_width = 16
dat_width = 16
# Record Size
2012-09-15 16:29:50 -04:00
record_size = 4096
2012-09-14 08:08:20 -04:00
# Csr Addr
2012-09-17 11:00:47 -04:00
MIGIO_ADDR = 0x0000
MIGLA_ADDR = 0x0200
2012-09-14 08:08:20 -04:00
2012-09-17 11:00:47 -04:00
csr = Uart2Spi(1,115200,debug=False)
2012-09-14 08:08:20 -04:00
# MigScope Configuration
# migIo
2012-09-17 11:00:47 -04:00
migIo0 = migIo.MigIo(MIGIO_ADDR, 8, "IO",csr)
2012-09-14 08:08:20 -04:00
# Trigger
term0 = trigger.Term(trig_width)
2012-09-17 11:00:47 -04:00
trigger0 = trigger.Trigger(trig_width, [term0])
recorder0 = recorder.Recorder(dat_width, record_size)
2012-09-14 08:08:20 -04:00
2012-09-17 11:00:47 -04:00
migLa0 = migLa.MigLa(MIGLA_ADDR, trigger0, recorder0, csr)
2012-09-14 08:08:20 -04:00
#==============================================================================
# T E S T M I G L A
#==============================================================================
dat_vcd = []
recorder0.size(1024)
2012-09-14 08:08:20 -04:00
def capture():
global trigger0
global recorder0
global dat_vcd
sum_tt = gen_truth_table("term0")
2012-09-17 11:00:47 -04:00
migLa0.trig.sum.write(sum_tt)
migLa0.rec.reset()
migLa0.rec.offset(0)
migLa0.rec.arm()
print("-Recorder [Armed]")
print("-Waiting Trigger...", end = ' ')
2012-09-17 11:00:47 -04:00
while(not migLa0.rec.is_done()):
time.sleep(0.1)
print("[Done]")
print("-Receiving Data...", end = ' ')
sys.stdout.flush()
2012-09-17 11:00:47 -04:00
dat_vcd += migLa0.rec.read(1024)
print("[Done]")
print("Capturing Ramp..")
print("----------------------")
term0.write(0x0000)
csr.write(0x0000, 0)
capture()
2012-09-15 16:29:50 -04:00
print("Capturing Square..")
print("----------------------")
term0.write(0x0000)
csr.write(0x0000, 1)
capture()
2012-09-14 18:57:52 -04:00
print("Capturing Sinus..")
print("----------------------")
term0.write(0x0080)
csr.write(0x0000, 2)
capture()
2012-09-14 08:08:20 -04:00
2012-09-14 18:57:52 -04:00
myvcd = Vcd()
myvcd.add(Var("wire", 16, "trig_dat", dat_vcd))
2012-09-14 18:57:52 -04:00
myvcd.write("test_MigLa.vcd")