2012-03-14 13:26:05 -04:00
|
|
|
from migen.fhdl.structure import *
|
2013-03-10 14:32:38 -04:00
|
|
|
from migen.fhdl.module import Module
|
2013-02-24 06:31:00 -05:00
|
|
|
from migen.genlib.misc import timeline
|
|
|
|
from migen.genlib.fsm import FSM
|
2012-03-15 15:29:26 -04:00
|
|
|
|
|
|
|
from milkymist.asmicon.multiplexer import *
|
2012-03-14 13:26:05 -04:00
|
|
|
|
2013-03-10 14:32:38 -04:00
|
|
|
class Refresher(Module):
|
2012-03-17 19:12:03 -04:00
|
|
|
def __init__(self, a, ba, tRP, tREFI, tRFC):
|
2012-03-15 15:29:26 -04:00
|
|
|
self.req = Signal()
|
2012-03-18 17:11:01 -04:00
|
|
|
self.ack = Signal() # 1st command 1 cycle after assertion of ack
|
|
|
|
self.cmd = CommandRequest(a, ba)
|
2012-03-14 13:26:05 -04:00
|
|
|
|
2013-03-10 14:32:38 -04:00
|
|
|
###
|
|
|
|
|
2012-03-15 15:29:26 -04:00
|
|
|
# Refresh sequence generator:
|
|
|
|
# PRECHARGE ALL --(tRP)--> AUTO REFRESH --(tRFC)--> done
|
|
|
|
seq_start = Signal()
|
|
|
|
seq_done = Signal()
|
2013-03-10 14:32:38 -04:00
|
|
|
self.sync += [
|
2012-03-18 17:11:01 -04:00
|
|
|
self.cmd.a.eq(2**10),
|
|
|
|
self.cmd.ba.eq(0),
|
|
|
|
self.cmd.cas_n.eq(1),
|
|
|
|
self.cmd.ras_n.eq(1),
|
2012-03-30 10:26:50 -04:00
|
|
|
self.cmd.we_n.eq(1),
|
|
|
|
seq_done.eq(0)
|
2012-03-15 15:29:26 -04:00
|
|
|
]
|
2013-03-10 14:32:38 -04:00
|
|
|
self.sync += timeline(seq_start, [
|
2012-03-18 17:11:01 -04:00
|
|
|
(1, [
|
|
|
|
self.cmd.ras_n.eq(0),
|
|
|
|
self.cmd.we_n.eq(0)
|
2012-03-15 15:29:26 -04:00
|
|
|
]),
|
2013-03-10 14:32:38 -04:00
|
|
|
(1+tRP, [
|
2012-03-18 17:11:01 -04:00
|
|
|
self.cmd.cas_n.eq(0),
|
|
|
|
self.cmd.ras_n.eq(0)
|
2012-03-15 15:29:26 -04:00
|
|
|
]),
|
2013-03-10 14:32:38 -04:00
|
|
|
(1+tRP+tRFC, [
|
2012-03-15 15:29:26 -04:00
|
|
|
seq_done.eq(1)
|
|
|
|
])
|
|
|
|
])
|
|
|
|
|
|
|
|
# Periodic refresh counter
|
2013-03-10 14:32:38 -04:00
|
|
|
counter = Signal(max=tREFI)
|
2012-03-15 15:29:26 -04:00
|
|
|
start = Signal()
|
2013-03-10 14:32:38 -04:00
|
|
|
self.sync += [
|
2012-03-15 15:29:26 -04:00
|
|
|
start.eq(0),
|
|
|
|
If(counter == 0,
|
|
|
|
start.eq(1),
|
2013-03-10 14:32:38 -04:00
|
|
|
counter.eq(tREFI - 1)
|
2012-03-15 15:29:26 -04:00
|
|
|
).Else(
|
|
|
|
counter.eq(counter - 1)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
# Control FSM
|
|
|
|
fsm = FSM("IDLE", "WAIT_GRANT", "WAIT_SEQ")
|
2013-03-10 14:32:38 -04:00
|
|
|
self.submodules += fsm
|
2012-03-15 15:29:26 -04:00
|
|
|
fsm.act(fsm.IDLE, If(start, fsm.next_state(fsm.WAIT_GRANT)))
|
|
|
|
fsm.act(fsm.WAIT_GRANT,
|
|
|
|
self.req.eq(1),
|
|
|
|
If(self.ack,
|
|
|
|
seq_start.eq(1),
|
|
|
|
fsm.next_state(fsm.WAIT_SEQ)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
fsm.act(fsm.WAIT_SEQ,
|
|
|
|
self.req.eq(1),
|
|
|
|
If(seq_done, fsm.next_state(fsm.IDLE))
|
|
|
|
)
|