Clean up
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Sun, 9 Sep 2012 21:46:26 +0000 (23:46 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Sun, 9 Sep 2012 21:46:26 +0000 (23:46 +0200)
README
examples/de0_nano/top.py
migScope/recorder.py
migScope/tools/conv.py
migScope/tools/truthtable.py
migScope/tools/vcd.py
migScope/trigger.py
sim/tb_Migscope.py
sim/tb_RecorderCsr.py
sim/tb_TriggerCsr.py
sim/tb_spi2Csr.py

diff --git a/README b/README
index 7c968f1dd111048d36dd9d772581af582342f814..8b93ce0bc93ffd551e825ef79bce033c87116b1e 100644 (file)
--- a/README
+++ b/README
@@ -7,5 +7,15 @@ or external signals.
 [> 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
index e37422bace17c82a4da1eda7c8cd35bd783594fa..5d5abf73cbbba8e24f6f4036b6b839f8a18f6645 100644 (file)
 #                  ----------------------------------
 ################################################################################
 #
-# 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
index a3366f9bf4bc25a77a3729f4a5c5ffb8720eca7a..edbe1c2981240d24594e83bf5f13e636720d232a 100644 (file)
@@ -135,7 +135,7 @@ class Recorder:
                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,
index df6394d963342805cbfa6979fb8a77b1fa021dee..66b88db8d2e0bc34b8cf99a585f4853f3deb944a 100644 (file)
@@ -1,4 +1,4 @@
-def dec2bin(d,nb=0):
+def dec2bin(d, nb=0):
        if d=="x":
                return "x"*nb
        elif d==0:
index 6f091080ff8fcb225c7ad78aa57bee47e55f6808..ed53e2d3a5adf03ca473d0eeda0745e8c015378f 100644 (file)
@@ -3,7 +3,7 @@ import re
 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)
index d7b1246f758f038ba9229d79287642c1ec56d447..3d89188a55e8c379cc3a4d24298e4978a0ff019a 100644 (file)
@@ -24,7 +24,7 @@ class Var:
                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"
@@ -158,12 +158,12 @@ class Vcd:
 
 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__':
index 3acf3c0b4e971983b29e9242ea02495e5aed0a86..2e9d1da9634d26dfaa2191523be050d955d77632 100644 (file)
@@ -209,7 +209,7 @@ class Sum:
                        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 = []
@@ -242,7 +242,7 @@ class Trigger:
                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__
index 8cf51345a1b449d3a2c7bea0e316b779b48197a2..8f55bbadfaba120b4b6f15f59f09680385dd4486 100644 (file)
@@ -41,10 +41,10 @@ def csr_transactions(trigger0, recorder0):
 
        # 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
@@ -53,7 +53,7 @@ def csr_transactions(trigger0, recorder0):
        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
@@ -151,7 +151,7 @@ def main():
                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))
 
        
@@ -159,8 +159,8 @@ def main():
        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()
        
index 1fa6b8bf410129fc4e8178f03e26145c64ef21b2..e36d78448b0c915625397d5020ff4949ca7355a4 100644 (file)
@@ -45,7 +45,7 @@ def csr_transactions():
        while not rec_done:
                yield None
 
-       global dat_rdy  
+       global dat_rdy
        for t in range(32):
                yield TWrite(7, 1)
                dat_rdy = False
@@ -66,10 +66,10 @@ def main():
        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
                        ])
@@ -78,7 +78,7 @@ def main():
        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
@@ -100,7 +100,7 @@ def main():
        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()
index 3bf02785f6013b3d7d524c8649bee629d292eace..eb2f8d1d424a54716a04cf8d6acb51cfe5246d75 100644 (file)
@@ -16,7 +16,6 @@ def term_prog(off, dat):
        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)
@@ -39,18 +38,18 @@ def csr_transactions():
        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:
@@ -66,7 +65,7 @@ def csr_transactions():
 def main():
        # Csr Master
        csr_master0 = csr.Initiator(csr_transactions())
-
+       
        # Trigger
        term0 = trigger.Term(32)
        term1 = trigger.Term(32)
@@ -79,24 +78,24 @@ def main():
                        [
                                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()
index cee3925c49cd093f416d1c1c8efd495164781272..ef3b2d6b284a26e21faf20419b520006d3f2c96f 100644 (file)
@@ -22,15 +22,15 @@ def spi_transactions():
        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 
 
@@ -47,7 +47,7 @@ class SpiMaster(PureSimulable):
        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:
@@ -66,7 +66,7 @@ class SpiMaster(PureSimulable):
                                                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)
@@ -82,7 +82,7 @@ class SpiMaster(PureSimulable):
                                                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)
@@ -91,10 +91,10 @@ class SpiMaster(PureSimulable):
                                                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
@@ -102,7 +102,7 @@ class SpiMaster(PureSimulable):
                                                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)
@@ -119,7 +119,7 @@ class SpiMaster(PureSimulable):
                                                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)
@@ -129,12 +129,11 @@ class SpiMaster(PureSimulable):
                                                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)
@@ -143,11 +142,11 @@ def main():
        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, 
                        [
@@ -156,12 +155,12 @@ def main():
        
        # 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"))