litex/milkymist/asmicon/refresher.py

76 lines
1.6 KiB
Python
Raw Normal View History

2012-03-14 13:26:05 -04:00
from migen.fhdl.structure import *
2012-03-15 15:29:26 -04:00
from migen.corelogic.misc import timeline
from migen.corelogic.fsm import FSM
from milkymist.asmicon.multiplexer import *
2012-03-14 13:26:05 -04:00
class Refresher:
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.tRP = tRP
self.tREFI = tREFI
self.tRFC = tRFC
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
def get_fragment(self):
2012-03-15 15:29:26 -04:00
comb = []
sync = []
# Refresh sequence generator:
# PRECHARGE ALL --(tRP)--> AUTO REFRESH --(tRFC)--> done
seq_start = Signal()
seq_done = Signal()
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),
self.cmd.we_n.eq(1),
seq_done.eq(0)
2012-03-15 15:29:26 -04:00
]
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
]),
2012-03-18 17:11:01 -04:00
(1+self.tRP, [
self.cmd.cas_n.eq(0),
self.cmd.ras_n.eq(0)
2012-03-15 15:29:26 -04:00
]),
2012-03-18 17:11:01 -04:00
(1+self.tRP+self.tRFC, [
2012-03-15 15:29:26 -04:00
seq_done.eq(1)
])
])
# Periodic refresh counter
counter = Signal(max=self.tREFI)
2012-03-15 15:29:26 -04:00
start = Signal()
sync += [
start.eq(0),
If(counter == 0,
start.eq(1),
counter.eq(self.tREFI - 1)
).Else(
counter.eq(counter - 1)
)
]
# Control FSM
fsm = FSM("IDLE", "WAIT_GRANT", "WAIT_SEQ")
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))
)
return Fragment(comb, sync) + fsm.get_fragment()