pytholite/io: fix Wishbone writes + support sel attribute
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 23 Nov 2012 12:40:46 +0000 (13:40 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 23 Nov 2012 12:40:46 +0000 (13:40 +0100)
migen/pytholite/io.py

index f81dbca1d7671efc065e2a0bd7e96b8e5faa2fcd..bf40a70d307667f772d196a0b38214817ded22c1 100644 (file)
@@ -94,9 +94,18 @@ def _gen_wishbone_io(compiler, modelname, model, to_model, from_model, bus):
        ]
        
        if model == TWrite:
-               state.append(bus.we.eq(1))
                if from_model:
                        raise TypeError("Attempted to read from write transaction")
+               state += [
+                       bus.we.eq(1),
+                       bus.dat_w.eq(compiler.ec.visit_expr(to_model["data"]))
+               ]
+               sel = to_model["sel"]
+               if isinstance(sel, ast.Name) and sel.id == "None":
+                       nbytes = (len(bus.dat_w) + 7)//8
+                       state.append(bus.sel.eq(2**nbytes-1))
+               else:
+                       state.append(bus.sel.eq(compiler.ec.visit_expr(sel)))
        else:
                state.append(bus.we.eq(0))
                ec = _BusReadExprCompiler(compiler.symdict, modelname, bus.dat_r)