[> Status:
Early development phase
+Simulation:
+-tb_spi2Csr : Test Spi <--> Csr Bridge : [Ok]
+-tb_TriggerCsr : Test Trigger with Csr : [Ok]
+-tb_RecorderCsr : Test Recorder with Csr : [Ok]
+-tb_MigScope : Global Test with Csr : [Ok]
+
+Example Design:
+-de0_nano : Generate Signals in FPGA and probe them with migScope : [Wip]
+
+
[> Contact
E-mail: florent@enjoy-digital.fr
# ----------------------------------
################################################################################
#
-# In this example, signals are generated inside generated inside the FPGA.
-# We will use migScope to record those signals it and visualize them.
+# In this example signals are generated in the FPGA.
+# We will use migScope to record those signals and visualize them.
#
# Example architecture:
# ----------------------
-# migScope Config <-- Python Client (Host) --> Vcd Output
-# |
+# migScope Config --> Python Client (Host) --> Vcd Output
+# & Trig |
# Arduino (Uart<-->Spi Bridge)
# |
# De0 Nano
self._offset = RegisterField("offset", self.depth_width, reset=1)
self._get = RegisterField("get", reset=0)
- self._get_dat = RegisterField("get_dat", self.width, reset=1,access_bus=READ_ONLY, access_dev=WRITE_ONLY)
+ self._get_dat = RegisterField("get_dat", self.width, reset=1, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
regs = [self._rst, self._arm, self._done,
self._size, self._offset,
-def dec2bin(d,nb=0):
+def dec2bin(d, nb=0):
if d=="x":
return "x"*nb
elif d==0:
import sys
def get_operands(s):
- return sorted(re.findall("[A-z0-9_]+",s))
+ return sorted(re.findall("[A-z0-9_]+", s))
def gen_truth_table(s):
operands = get_operands(s)
try :
if self.values[cnt+1] != self.val:
r += "b"
- r += dec2bin(self.values[cnt+1],self.width)
+ r += dec2bin(self.values[cnt+1], self.width)
r += " "
r += self.vcd_id
r += "\n"
def main():
myvcd = Vcd()
- myvcd.add(Var("wire",1,"foo1",[0,1,0,1,0,1]))
- myvcd.add(Var("wire",2,"foo2",[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0]))
- myvcd.add(Var("wire",3,"foo3"))
- myvcd.add(Var("wire",4,"foo4"))
+ myvcd.add(Var("wire", 1, "foo1", [0,1,0,1,0,1]))
+ myvcd.add(Var("wire", 2, "foo2", [1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0]))
+ myvcd.add(Var("wire", 3, "foo3"))
+ myvcd.add(Var("wire", 4, "foo4"))
ramp = [i%128 for i in range(1024)]
- myvcd.add(Var("wire",16,"ramp",ramp))
+ myvcd.add(Var("wire", 16, "ramp", ramp))
print(myvcd)
if __name__ == '__main__':
sync += [self.o.eq(self._o)]
else:
comb += [self.o.eq(self._o)]
- return Fragment(comb=comb,sync=sync,memories=memories)
+ return Fragment(comb=comb, sync=sync, memories=memories)
def connect_to_reg(self, reg):
comb = []
for port in self.ports:
setattr(self,port.reg_name,RegisterField(port.reg_name, port.reg_size, reset=0,
access_bus=WRITE_ONLY, access_dev=READ_ONLY))
- self.sum_reg = RegisterField(self.sum.reg_name, self.sum.reg_size, reset=0,access_bus=WRITE_ONLY, access_dev=READ_ONLY)
+ self.sum_reg = RegisterField(self.sum.reg_name, self.sum.reg_size, reset=0, access_bus=WRITE_ONLY, access_dev=READ_ONLY)
regs = []
objects = self.__dict__
# Term Prog
term_trans = []
- term_trans += [term_prog(trigger0.ports[0].reg_base,0x00000000)]
- term_trans += [term_prog(trigger0.ports[1].reg_base,0x00000004)]
- term_trans += [term_prog(trigger0.ports[2].reg_base,0x00000008)]
- term_trans += [term_prog(trigger0.ports[3].reg_base,0x0000000C)]
+ term_trans += [term_prog(trigger0.ports[0].reg_base, 0x00000000)]
+ term_trans += [term_prog(trigger0.ports[1].reg_base, 0x00000004)]
+ term_trans += [term_prog(trigger0.ports[2].reg_base, 0x00000008)]
+ term_trans += [term_prog(trigger0.ports[3].reg_base, 0x0000000C)]
for t in term_trans:
for r in t:
yield r
sum_tt = gen_truth_table("term0 | term1 | term2 | term3")
sum_trans = []
for i in range(len(sum_tt)):
- sum_trans.append(sum_prog(trigger0.sum.reg_base,i,sum_tt[i]))
+ sum_trans.append(sum_prog(trigger0.sum.reg_base, i, sum_tt[i]))
for t in sum_trans:
for r in t:
yield r
global dat_rdy
if dat_rdy:
print("%08X" %s.rd(recorder0._get_dat.field.w))
- global dat_vcd
+ global dat_vcd
dat_vcd.append(s.rd(recorder0._get_dat.field.w))
def end_simulation(s):
s.interrupt = csr_master0.done
myvcd = Vcd()
- myvcd.add(Var("wire",32,"trig_dat",dat_vcd))
- f = open("tb_Miscope_Out.vcd","w")
+ myvcd.add(Var("wire", 32, "trig_dat", dat_vcd))
+ f = open("tb_Miscope_Out.vcd", "w")
f.write(str(myvcd))
f.close()
while not rec_done:
yield None
- global dat_rdy
+ global dat_rdy
for t in range(32):
yield TWrite(7, 1)
dat_rdy = False
csr_master0 = csr.Initiator(csr_transactions())
# Recorder
- recorder0 = recorder.Recorder(0,32,1024)
+ recorder0 = recorder.Recorder(0, 32, 1024)
# Csr Interconnect
- csrcon0 = csr.Interconnect(csr_master0.bus,
+ csrcon0 = csr.Interconnect(csr_master0.bus,
[
recorder0.bank.interface
])
def recorder_data(s):
global arm_done
if arm_done:
- s.wr(recorder0.trig_hit,1)
+ s.wr(recorder0.trig_hit, 1)
arm_done = False
global trig_dat
fragment = autofragment.from_local()
fragment += Fragment(sim=[end_simulation])
fragment += Fragment(sim=[recorder_data])
- sim = Simulator(fragment, Runner(),TopLevel("tb_RecorderCsr.vcd"))
+ sim = Simulator(fragment, Runner(), TopLevel("tb_RecorderCsr.vcd"))
sim.run(10000)
main()
for i in range(4):
yield TWrite(off+3-i, (dat>>(8*i))&0xFF)
-
def sum_prog(off, addr, dat):
we = 2
yield TWrite(off+3, addr%0xFF)
for t in term_trans:
for r in t:
yield r
-
+
sum_trans = []
- sum_trans += [sum_prog(0x00,i,1) for i in range(8)]
- sum_trans += [sum_prog(0x00,i,0) for i in range(8)]
+ sum_trans += [sum_prog(0x00, i, 1) for i in range(8)]
+ sum_trans += [sum_prog(0x00, i, 0) for i in range(8)]
for t in sum_trans:
for r in t:
yield r
-
+
sum_tt = gen_truth_table("i1 & i2 & i3 & i4")
sum_trans = []
for i in range(len(sum_tt)):
- sum_trans.append(sum_prog(0x00,i,sum_tt[i]))
+ sum_trans.append(sum_prog(0x00, i, sum_tt[i]))
print(sum_tt)
for t in sum_trans:
for r in t:
def main():
# Csr Master
csr_master0 = csr.Initiator(csr_transactions())
-
+
# Trigger
term0 = trigger.Term(32)
term1 = trigger.Term(32)
[
trigger0.bank.interface
])
-
+
# Term Test
def term_stimuli(s):
if csr_done:
- s.wr(term0.i,0xDEADBEEF)
- s.wr(term1.i,0xCAFEFADE)
- s.wr(term2.i,0xDEADBEEF)
- s.wr(term3.i,0xCAFEFADE)
-
+ s.wr(term0.i, 0xDEADBEEF)
+ s.wr(term1.i ,0xCAFEFADE)
+ s.wr(term2.i, 0xDEADBEEF)
+ s.wr(term3.i, 0xCAFEFADE)
+
# Simulation
def end_simulation(s):
s.interrupt = csr_master0.done
-
+
fragment = autofragment.from_local()
fragment += Fragment(sim=[end_simulation])
fragment += Fragment(sim=[term_stimuli])
- sim = Simulator(fragment, Runner(),TopLevel("tb_TriggerCsr.vcd"))
+ sim = Simulator(fragment, Runner(), TopLevel("tb_TriggerCsr.vcd"))
sim.run(2000)
main()
yield TWrite(0x0001, 0xA5)
yield TWrite(0x0002, 0x5A)
yield TWrite(0x0003, 0xA5)
-
+
for i in range(10):
yield None
-
+
yield TRead(0x0000)
yield TRead(0x0001)
yield TRead(0x0002)
yield TRead(0x0003)
-
+
for i in range(100):
yield None
def do_simulation(self, s):
a_w = self.spi.a_width
d_w = self.spi.d_width
-
+
if not self.done:
if self.transaction is None:
try:
s.wr(self.spi.spi_clk, 1)
else:
s.wr(self.spi.spi_clk, 0)
-
+
# Mosi Addr
if self.transaction_cnt < a_w*self.clk_ratio:
bit = a_w-1-int((self.transaction_cnt)/self.clk_ratio)
s.wr(self.spi.spi_mosi, data)
else:
s.wr(self.spi.spi_mosi, 0)
-
+
# Cs_n
if self.transaction_cnt < (a_w + d_w)*self.clk_ratio:
s.wr(self.spi.spi_cs_n,0)
s.wr(self.spi.spi_clk, 0)
s.wr(self.spi.spi_mosi, 0)
self.transaction = None
-
+
# Incr transaction_cnt
self.transaction_cnt +=1
-
+
elif isinstance(self.transaction, TRead):
# Clk
s.wr(self.spi.spi_clk, 1)
else:
s.wr(self.spi.spi_clk, 0)
-
+
# Mosi Addr
if self.transaction_cnt < a_w*self.clk_ratio:
bit = a_w-1-int((self.transaction_cnt)/self.clk_ratio)
bit = d_w-1-int((self.transaction_cnt-a_w*self.clk_ratio)/self.clk_ratio)
if s.rd(self.spi.spi_miso):
self.r_dat = set_bit(self.r_dat, bit)
-
+
# Cs_n
if self.transaction_cnt < (a_w + d_w)*self.clk_ratio:
s.wr(self.spi.spi_cs_n,0)
s.wr(self.spi.spi_mosi, 0)
self.transaction = None
print("%02X" %self.r_dat)
-
+
# Incr transaction_cnt
self.transaction_cnt +=1
-
def main():
# Csr Slave
scratch_reg0 = RegisterField("scratch_reg0", 32, reset=0, access_dev=READ_ONLY)
scratch_reg3 = RegisterField("scratch_reg4", 32, reset=0, access_dev=READ_ONLY)
regs = [scratch_reg0, scratch_reg1, scratch_reg2, scratch_reg3]
bank0 = csrgen.Bank(regs,address=0x0000)
-
+
# Spi2Csr
spi2csr0 = spi2Csr.Spi2Csr(16,8)
-
-
+
+
# Csr Interconnect
csrcon0 = csr.Interconnect(spi2csr0.csr,
[
# Spi Master
spi_master0 = SpiMaster(spi2csr0, 8, spi_transactions())
-
+
# Simulation
def end_simulation(s):
s.interrupt = spi_master0.done
-
-
+
+
fragment = autofragment.from_local()
fragment += Fragment(sim=[end_simulation])
sim = Simulator(fragment, Runner(),TopLevel("tb_spi2Csr.vcd"))