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
|
2012-03-15 15:26:04 -04:00
|
|
|
from migen.corelogic.misc import timeline
|
2011-12-13 11:33:12 -05:00
|
|
|
|
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-03-15 15:26:04 -04:00
|
|
|
self.adr_width = adr_width
|
|
|
|
self.rd_timing = rd_timing
|
|
|
|
|
2012-02-15 10:55:13 -05:00
|
|
|
self.bus = wishbone.Interface()
|
2012-11-29 17:38:04 -05:00
|
|
|
self.adr = Signal(adr_width-1)
|
|
|
|
self.d = Signal(16)
|
2011-12-18 16:02:05 -05:00
|
|
|
self.oe_n = Signal()
|
|
|
|
self.we_n = Signal()
|
|
|
|
self.ce_n = Signal()
|
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)]
|
2012-03-15 15:26:04 -04:00
|
|
|
sync = timeline(self.bus.cyc & self.bus.stb, [
|
|
|
|
(0, [self.adr.eq(Cat(0, self.bus.adr[:self.adr_width-2]))]),
|
|
|
|
(self.rd_timing, [
|
|
|
|
self.bus.dat_r[16:].eq(self.d),
|
|
|
|
self.adr.eq(Cat(1, self.bus.adr[:self.adr_width-2]))]),
|
|
|
|
(2*self.rd_timing, [
|
|
|
|
self.bus.dat_r[:16].eq(self.d),
|
|
|
|
self.bus.ack.eq(1)]),
|
|
|
|
(2*self.rd_timing + 1, [
|
|
|
|
self.bus.ack.eq(0)])
|
|
|
|
])
|
2012-04-02 13:22:17 -04:00
|
|
|
return Fragment(comb, sync)
|