litex/milkymist/norflash/__init__.py

29 lines
908 B
Python
Raw Normal View History

2011-12-16 15:30:22 -05:00
from migen.fhdl.structure import *
2011-12-13 11:33:12 -05:00
from migen.bus import wishbone
from migen.corelogic import timeline
2012-01-21 06:25:22 -05:00
class NorFlash:
2011-12-13 11:33:12 -05:00
def __init__(self, adr_width, rd_timing):
2012-01-27 16:21:08 -05:00
self.bus = wishbone.Slave()
2011-12-18 16:02:05 -05:00
self.adr = Signal(BV(adr_width-1))
self.d = Signal(BV(16))
self.oe_n = Signal()
self.we_n = Signal()
self.ce_n = Signal()
2012-01-21 06:25:22 -05:00
self.timeline = timeline.Timeline(self.bus.cyc_i & self.bus.stb_i,
2012-01-13 11:28:58 -05:00
[(0, [self.adr.eq(Cat(0, self.bus.adr_i[:adr_width-2]))]),
2011-12-13 11:33:12 -05:00
(rd_timing, [
2011-12-16 15:30:22 -05:00
self.bus.dat_o[16:].eq(self.d),
2012-01-13 11:28:58 -05:00
self.adr.eq(Cat(1, self.bus.adr_i[:adr_width-2]))]),
2011-12-13 11:33:12 -05:00
(2*rd_timing, [
2011-12-16 15:30:22 -05:00
self.bus.dat_o[:16].eq(self.d),
self.bus.ack_o.eq(1)]),
2011-12-13 11:33:12 -05:00
(2*rd_timing+1, [
2011-12-16 15:30:22 -05:00
self.bus.ack_o.eq(0)])])
2011-12-13 11:33:12 -05:00
2011-12-16 10:02:49 -05:00
def get_fragment(self):
2011-12-16 15:30:22 -05:00
comb = [self.oe_n.eq(0), self.we_n.eq(1),
2011-12-16 16:25:26 -05:00
self.ce_n.eq(0)]
return Fragment(comb, pads={self.adr, self.d, self.oe_n, self.we_n, self.ce_n}) \
2011-12-16 10:02:49 -05:00
+ self.timeline.get_fragment()