litex/misoclib/sdram/lasmicon/refresher.py

69 lines
1.4 KiB
Python
Raw Normal View History

2013-05-22 11:10:13 -04:00
from migen.fhdl.std import *
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 misoclib.sdram.lasmicon.multiplexer import *
2012-03-14 13:26:05 -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)
2014-10-17 05:14:35 -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()
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),
self.cmd.we_n.eq(1),
seq_done.eq(0)
2012-03-15 15:29:26 -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
]),
(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
]),
(1+tRP+tRFC, [
2012-03-15 15:29:26 -04:00
seq_done.eq(1)
])
])
2014-10-17 05:14:35 -04:00
2012-03-15 15:29:26 -04:00
# Periodic refresh counter
counter = Signal(max=tREFI)
2012-03-15 15:29:26 -04:00
start = Signal()
self.sync += [
2012-03-15 15:29:26 -04:00
start.eq(0),
If(counter == 0,
start.eq(1),
counter.eq(tREFI - 1)
2012-03-15 15:29:26 -04:00
).Else(
counter.eq(counter - 1)
)
]
2014-10-17 05:14:35 -04:00
2012-03-15 15:29:26 -04:00
# Control FSM
2013-06-25 16:25:10 -04:00
fsm = FSM()
self.submodules += fsm
2013-06-25 16:25:10 -04:00
fsm.act("IDLE", If(start, NextState("WAIT_GRANT")))
fsm.act("WAIT_GRANT",
2012-03-15 15:29:26 -04:00
self.req.eq(1),
If(self.ack,
seq_start.eq(1),
2013-06-25 16:25:10 -04:00
NextState("WAIT_SEQ")
2012-03-15 15:29:26 -04:00
)
)
2013-06-25 16:25:10 -04:00
fsm.act("WAIT_SEQ",
2012-03-15 15:29:26 -04:00
self.req.eq(1),
2013-06-25 16:25:10 -04:00
If(seq_done, NextState("IDLE"))
2012-03-15 15:29:26 -04:00
)