litex/migen/bus/wishbone2csr.py

24 lines
655 B
Python
Raw Normal View History

2011-12-16 10:02:55 -05:00
from migen.bus import wishbone
from migen.bus import csr
2011-12-16 15:30:14 -05:00
from migen.fhdl.structure import *
from migen.corelogic.misc import timeline
2011-12-11 09:04:34 -05:00
class WB2CSR:
2011-12-11 09:04:34 -05:00
def __init__(self):
self.wishbone = wishbone.Interface()
self.csr = csr.Interface()
2011-12-11 09:04:34 -05:00
2011-12-16 10:02:55 -05:00
def get_fragment(self):
2011-12-11 09:04:34 -05:00
sync = [
self.csr.we.eq(0),
2012-08-26 15:19:34 -04:00
self.csr.dat_w.eq(self.wishbone.dat_w[:csr.data_width]),
self.csr.adr.eq(self.wishbone.adr[:14]),
self.wishbone.dat_r.eq(self.csr.dat_r)
2011-12-11 09:04:34 -05:00
]
sync += timeline(self.wishbone.cyc & self.wishbone.stb, [
(1, [self.csr.we.eq(self.wishbone.we)]),
(2, [self.wishbone.ack.eq(1)]),
(3, [self.wishbone.ack.eq(0)])
])
return Fragment(sync=sync)