litex/examples/de0_nano/client/test_mila.py

87 lines
2.2 KiB
Python
Raw Normal View History

2013-09-21 07:04:07 -04:00
from miscope import mila
from miscope.std.truthtable import *
from miscope.std.vcd import *
from miscope.com.uart2csr.host.uart2csr import *
from csr import *
2013-03-21 07:23:44 -04:00
#==============================================================================
# P A R A M E T E R S
#==============================================================================
2013-09-21 07:04:07 -04:00
uart = Uart2Csr(3, 115200)
class MiLaCtrl():
def __init__(self, bus):
self.bus = bus
def prog_term(self, trigger, mask):
mila_trigger_port0_trig_write(self.bus, trigger)
mila_trigger_port0_mask_write(self.bus, mask)
def prog_sum(self, datas):
for adr, dat in enumerate(datas):
mila_trigger_sum_prog_adr_write(self.bus, adr)
mila_trigger_sum_prog_dat_write(self.bus, dat)
mila_trigger_sum_prog_we_write(self.bus, 1)
def is_done(self):
return mila_recorder_done_read(self.bus)
def trigger(self, offset, length):
mila_recorder_offset_write(self.bus, offset)
mila_recorder_length_write(self.bus, length)
mila_recorder_trigger_write(self.bus, 1)
def read(self):
r = []
empty = mila_recorder_read_empty_read(self.bus)
while(not empty):
r.append(mila_recorder_read_dat_read(self.bus))
empty = mila_recorder_read_empty_read(self.bus)
mila_recorder_read_en_write(self.bus, 1)
return r
2013-03-21 07:23:44 -04:00
# Mila Param
trig_w = 16
dat_w = 16
2013-09-21 07:04:07 -04:00
rec_length = 512
rec_offset = 0
2013-03-21 07:23:44 -04:00
#==============================================================================
2013-09-21 07:04:07 -04:00
# T E S T M I L A
2013-03-21 07:23:44 -04:00
#==============================================================================
dat_vcd = VcdDat(dat_w)
2013-09-21 07:04:07 -04:00
mila = MiLaCtrl(uart)
def capture():
2013-03-21 07:23:44 -04:00
global dat_vcd
sum_tt = gen_truth_table("term")
2013-09-21 07:04:07 -04:00
mila.prog_sum(sum_tt)
mila.trigger(rec_offset, rec_length)
print("-Recorder [Triggered]")
2013-03-21 07:23:44 -04:00
print("-Waiting Trigger...", end=' ')
2013-09-21 07:04:07 -04:00
while(not mila.is_done()):
2013-03-21 07:23:44 -04:00
time.sleep(0.1)
print("[Done]")
print("-Receiving Data...", end=' ')
sys.stdout.flush()
2013-09-21 07:04:07 -04:00
dat_vcd += mila.read()
2013-03-21 07:23:44 -04:00
print("[Done]")
print("Capturing ...")
print("----------------------")
2013-09-21 07:04:07 -04:00
mila.prog_term(0x0000, 0xFFFF)
capture()
2013-03-21 07:23:44 -04:00
mila_layout = [
("freqgen", 1),
("event_rising", 1),
("event_falling", 1),
("cnt", 8),
]
myvcd = Vcd()
myvcd.add_from_layout(mila_layout, dat_vcd)
myvcd.write("test_mila.vcd")