2012-08-26 18:44:26 -04:00
|
|
|
from migen.fhdl.structure import *
|
2013-03-21 07:23:44 -04:00
|
|
|
from migen.fhdl import verilog
|
2012-08-26 18:44:26 -04:00
|
|
|
from migen.bus import csr
|
|
|
|
from migen.sim.generic import Simulator, PureSimulable, TopLevel
|
|
|
|
from migen.sim.icarus import Runner
|
|
|
|
from migen.bus.transactions import *
|
|
|
|
|
2013-03-23 08:57:59 -04:00
|
|
|
from miscope.recorder import *
|
2012-08-26 18:44:26 -04:00
|
|
|
|
|
|
|
arm_done = False
|
2013-03-21 07:23:44 -04:00
|
|
|
dat = 0
|
2012-08-26 18:44:26 -04:00
|
|
|
|
|
|
|
rec_done = False
|
|
|
|
|
|
|
|
dat_rdy = False
|
|
|
|
|
2013-03-23 08:57:59 -04:00
|
|
|
rec_size = 128
|
|
|
|
|
2012-08-26 18:44:26 -04:00
|
|
|
def csr_transactions():
|
|
|
|
|
2013-03-23 08:57:59 -04:00
|
|
|
# Reset
|
|
|
|
yield TWrite(REC_RST_BASE, 1)
|
|
|
|
yield TWrite(REC_RST_BASE, 0)
|
|
|
|
|
|
|
|
# RLE
|
|
|
|
yield TWrite(REC_RLE_BASE, 1)
|
2012-08-26 18:44:26 -04:00
|
|
|
|
2013-03-23 08:57:59 -04:00
|
|
|
# Size
|
|
|
|
yield TWrite(REC_SIZE_BASE + 0, 0)
|
|
|
|
yield TWrite(REC_SIZE_BASE + 1, rec_size)
|
2012-08-26 18:44:26 -04:00
|
|
|
|
2013-03-23 08:57:59 -04:00
|
|
|
# Offset
|
|
|
|
yield TWrite(REC_OFFSET_BASE + 0, 0)
|
|
|
|
yield TWrite(REC_OFFSET_BASE + 1, 0)
|
2012-08-26 18:44:26 -04:00
|
|
|
|
2013-03-23 08:57:59 -04:00
|
|
|
# Arm
|
|
|
|
yield TWrite(REC_ARM_BASE, 1)
|
|
|
|
yield TWrite(REC_ARM_BASE, 0)
|
2012-08-26 18:44:26 -04:00
|
|
|
|
|
|
|
for t in range(10):
|
|
|
|
yield None
|
|
|
|
|
|
|
|
global arm_done
|
|
|
|
arm_done = True
|
|
|
|
|
|
|
|
global rec_done
|
|
|
|
while not rec_done:
|
|
|
|
yield None
|
|
|
|
|
2012-09-09 17:46:26 -04:00
|
|
|
global dat_rdy
|
2013-03-23 08:57:59 -04:00
|
|
|
for t in range(rec_size):
|
|
|
|
yield TWrite(REC_READ_BASE, 1)
|
2012-08-26 18:44:26 -04:00
|
|
|
dat_rdy = False
|
2013-03-23 08:57:59 -04:00
|
|
|
yield TWrite(REC_READ_BASE, 0)
|
|
|
|
yield TRead(REC_READ_DATA_BASE + 0)
|
|
|
|
yield TRead(REC_READ_DATA_BASE + 1)
|
|
|
|
yield TRead(REC_READ_DATA_BASE + 2)
|
|
|
|
yield TRead(REC_READ_DATA_BASE + 3)
|
2012-08-26 18:44:26 -04:00
|
|
|
dat_rdy = True
|
|
|
|
|
|
|
|
dat_rdy = False
|
|
|
|
|
|
|
|
for t in range(100):
|
|
|
|
yield None
|
|
|
|
|
|
|
|
def main():
|
|
|
|
# Csr Master
|
|
|
|
csr_master0 = csr.Initiator(csr_transactions())
|
|
|
|
|
|
|
|
# Recorder
|
2013-03-23 08:57:59 -04:00
|
|
|
recorder0 = Recorder(32, 1024)
|
2012-08-26 18:44:26 -04:00
|
|
|
|
|
|
|
# Csr Interconnect
|
2012-09-09 17:46:26 -04:00
|
|
|
csrcon0 = csr.Interconnect(csr_master0.bus,
|
2012-08-26 18:44:26 -04:00
|
|
|
[
|
2013-03-21 07:23:44 -04:00
|
|
|
recorder0.bank.bus
|
2012-08-26 18:44:26 -04:00
|
|
|
])
|
|
|
|
|
|
|
|
# Recorder Data
|
|
|
|
def recorder_data(s):
|
|
|
|
global arm_done
|
|
|
|
if arm_done:
|
2013-03-21 07:23:44 -04:00
|
|
|
s.wr(recorder0.hit, 1)
|
2012-08-26 18:44:26 -04:00
|
|
|
arm_done = False
|
|
|
|
|
2013-03-21 07:23:44 -04:00
|
|
|
global dat
|
2013-03-23 08:57:59 -04:00
|
|
|
s.wr(recorder0.dat, dat//5)
|
2013-03-21 07:23:44 -04:00
|
|
|
dat += 1
|
2012-08-26 18:44:26 -04:00
|
|
|
|
|
|
|
global rec_done
|
2013-03-23 08:57:59 -04:00
|
|
|
if s.rd(recorder0.sequencer.enable) == 0:
|
2012-08-26 18:44:26 -04:00
|
|
|
rec_done = True
|
|
|
|
|
|
|
|
if dat_rdy:
|
2013-03-21 07:23:44 -04:00
|
|
|
print("%08X" %s.rd(recorder0._pull_dat.field.w))
|
2012-08-26 18:44:26 -04:00
|
|
|
|
|
|
|
# Simulation
|
|
|
|
def end_simulation(s):
|
|
|
|
s.interrupt = csr_master0.done
|
|
|
|
|
2013-03-21 07:23:44 -04:00
|
|
|
fragment = csr_master0.get_fragment()
|
|
|
|
fragment += recorder0.get_fragment()
|
|
|
|
fragment += csrcon0.get_fragment()
|
2012-08-26 18:44:26 -04:00
|
|
|
fragment += Fragment(sim=[end_simulation])
|
|
|
|
fragment += Fragment(sim=[recorder_data])
|
2013-03-21 07:23:44 -04:00
|
|
|
sim = Simulator(fragment, TopLevel("tb_RecorderCsr.vcd"))
|
2012-08-26 18:44:26 -04:00
|
|
|
sim.run(10000)
|
|
|
|
|
|
|
|
main()
|
2013-03-21 07:23:44 -04:00
|
|
|
print("Sim Done")
|
2012-08-26 18:44:26 -04:00
|
|
|
input()
|