Permalink
Browse files

Use new module, autoreg and eventmanager Migen APIs

  • Loading branch information...
1 parent 2059592 commit a9b723568a7d5b84859687a07b8283e22b12ea39 @sbourdeauducq sbourdeauducq committed Mar 10, 2013
View
@@ -1,12 +1,12 @@
#ifndef __CSRBASE_H
#define __CSRBASE_H
-#define UART_BASE 0xe0000000
-#define DFII_BASE 0xe0000800
-#define ID_BASE 0xe0001000
-#define TIMER0_BASE 0xe0001800
-#define MINIMAC_BASE 0xe0002000
-#define FB_BASE 0xe0002800
-#define ASMIPROBE_BASE 0xe0003000
+#define UART_BASE 0xe0000000
+#define DFII_BASE 0xe0000800
+#define IDENTIFIER_BASE 0xe0001000
+#define TIMER0_BASE 0xe0001800
+#define MINIMAC_BASE 0xe0002000
+#define FB_BASE 0xe0002800
+#define ASMIPROBE_BASE 0xe0003000
#endif /* __CSRBASE_H */
@@ -1,4 +1,5 @@
from migen.fhdl.structure import *
+from migen.fhdl.module import Module
from migen.bus import dfi, asmibus
from milkymist.asmicon.refresher import *
@@ -34,13 +35,12 @@ def __init__(self, tRP, tRCD, tWR, tREFI, tRFC, CL, rd_delay, read_time, write_t
self.write_time = write_time
self.slot_time = slot_time
-class ASMIcon:
+class ASMIcon(Module):
def __init__(self, phy_settings, geom_settings, timing_settings, full_selector=False):
self.phy_settings = phy_settings
self.geom_settings = geom_settings
self.timing_settings = timing_settings
self.full_selector = full_selector
- self.finalized = False
self.dfi = dfi.Interface(self.geom_settings.mux_a,
self.geom_settings.bank_a,
@@ -50,26 +50,14 @@ def __init__(self, phy_settings, geom_settings, timing_settings, full_selector=F
self.address_align = log2_int(burst_length)
aw = self.geom_settings.bank_a + self.geom_settings.row_a + self.geom_settings.col_a - self.address_align
dw = self.phy_settings.dfi_d*self.phy_settings.nphases
- self.hub = asmibus.Hub(aw, dw, self.timing_settings.slot_time)
+ self.submodules.hub = asmibus.Hub(aw, dw, self.timing_settings.slot_time)
- def finalize(self):
- if self.finalized:
- raise FinalizeError
- self.finalized = True
- self.hub.finalize()
+ def do_finalize(self):
slots = self.hub.get_slots()
- self.refresher = Refresher(self.geom_settings.mux_a, self.geom_settings.bank_a,
+ self.submodules.refresher = Refresher(self.geom_settings.mux_a, self.geom_settings.bank_a,
self.timing_settings.tRP, self.timing_settings.tREFI, self.timing_settings.tRFC)
- self.bank_machines = [BankMachine(self.geom_settings, self.timing_settings, self.address_align, i, slots, self.full_selector)
+ self.submodules.bank_machines = [BankMachine(self.geom_settings, self.timing_settings, self.address_align, i, slots, self.full_selector)
for i in range(2**self.geom_settings.bank_a)]
- self.multiplexer = Multiplexer(self.phy_settings, self.geom_settings, self.timing_settings,
+ self.submodules.multiplexer = Multiplexer(self.phy_settings, self.geom_settings, self.timing_settings,
self.bank_machines, self.refresher,
self.dfi, self.hub)
-
- def get_fragment(self):
- if not self.finalized:
- raise FinalizeError
- return self.hub.get_fragment() + \
- self.refresher.get_fragment() + \
- sum([bm.get_fragment() for bm in self.bank_machines], Fragment()) + \
- self.multiplexer.get_fragment()
@@ -1,4 +1,5 @@
from migen.fhdl.structure import *
+from migen.fhdl.module import Module
from migen.bus.asmibus import *
from migen.genlib.roundrobin import *
from migen.genlib.fsm import FSM
@@ -33,97 +34,81 @@ def col(self, address):
else:
return Cat(Replicate(0, self.address_align), address[:self._b1])
-class _Selector:
+class _Selector(Module):
def __init__(self, slicer, bankn, slots):
- self.slicer = slicer
- self.bankn = bankn
- self.slots = slots
-
- self.nslots = len(self.slots)
+ nslots = len(slots)
self.stb = Signal()
self.ack = Signal()
- self.tag = Signal(max=self.nslots)
- self.adr = Signal(self.slots[0].adr.nbits)
+ self.tag = Signal(max=nslots)
+ self.adr = Signal(slots[0].adr.nbits)
self.we = Signal()
# derived classes should drive rr.request
- self.rr = RoundRobin(self.nslots, SP_CE)
+ self.submodules.rr = RoundRobin(nslots, SP_CE)
- def get_fragment(self):
- comb = []
- rr = self.rr
-
+ ###
+
# Multiplex
+ rr = self.rr
state = Signal(2)
- comb += [
- state.eq(Array(slot.state for slot in self.slots)[rr.grant]),
- self.adr.eq(Array(slot.adr for slot in self.slots)[rr.grant]),
- self.we.eq(Array(slot.we for slot in self.slots)[rr.grant]),
+ self.comb += [
+ state.eq(Array(slot.state for slot in slots)[rr.grant]),
+ self.adr.eq(Array(slot.adr for slot in slots)[rr.grant]),
+ self.we.eq(Array(slot.we for slot in slots)[rr.grant]),
self.stb.eq(
- (self.slicer.bank(self.adr) == self.bankn) \
+ (slicer.bank(self.adr) == bankn) \
& (state == SLOT_PENDING)),
rr.ce.eq(self.ack | ~self.stb),
self.tag.eq(rr.grant)
]
- comb += [If((rr.grant == i) & self.stb & self.ack, slot.process.eq(1))
- for i, slot in enumerate(self.slots)]
-
- return Fragment(comb) + rr.get_fragment()
+ self.comb += [If((rr.grant == i) & self.stb & self.ack, slot.process.eq(1))
+ for i, slot in enumerate(slots)]
+
+ self.complete_selector(slicer, bankn, slots)
class _SimpleSelector(_Selector):
- def get_fragment(self):
- comb = []
- for i, slot in enumerate(self.slots):
- comb.append(self.rr.request[i].eq(
- (self.slicer.bank(slot.adr) == self.bankn) & \
- (slot.state == SLOT_PENDING)
- ))
-
- return Fragment(comb) + _Selector.get_fragment(self)
+ def complete_selector(self, slicer, bankn, slots):
+ for i, slot in enumerate(slots):
+ self.comb += self.rr.request[i].eq(
+ (slicer.bank(slot.adr) == bankn) & \
+ (slot.state == SLOT_PENDING))
class _FullSelector(_Selector):
- def get_fragment(self):
- comb = []
- sync = []
+ def complete_selector(self, slicer, bankn, slots):
rr = self.rr
# List outstanding requests for our bank
outstandings = []
- for slot in self.slots:
+ for slot in slots:
outstanding = Signal()
- comb.append(outstanding.eq(
- (self.slicer.bank(slot.adr) == self.bankn) & \
- (slot.state == SLOT_PENDING)
- ))
+ self.comb += outstanding.eq(
+ (slicer.bank(slot.adr) == bankn) & \
+ (slot.state == SLOT_PENDING))
outstandings.append(outstanding)
# Row tracking
- openrow_r = Signal(self.slicer.geom_settings.row_a)
- openrow_n = Signal(self.slicer.geom_settings.row_a)
- openrow = Signal(self.slicer.geom_settings.row_a)
- comb += [
- openrow_n.eq(self.slicer.row(self.adr)),
+ openrow_r = Signal(slicer.geom_settings.row_a)
+ openrow_n = Signal(slicer.geom_settings.row_a)
+ openrow = Signal(slicer.geom_settings.row_a)
+ self.comb += [
+ openrow_n.eq(slicer.row(self.adr)),
If(self.stb,
openrow.eq(openrow_n)
).Else(
openrow.eq(openrow_r)
)
]
- sync += [
- If(self.stb & self.ack,
- openrow_r.eq(openrow_n)
- )
- ]
+ self.sync += If(self.stb & self.ack, openrow_r.eq(openrow_n))
hits = []
- for slot, os in zip(self.slots, outstandings):
+ for slot, os in zip(slots, outstandings):
hit = Signal()
- comb.append(hit.eq((self.slicer.row(slot.adr) == openrow) & os))
+ self.comb += hit.eq((slicer.row(slot.adr) == openrow) & os)
hits.append(hit)
# Determine best request
rr = RoundRobin(self.nslots, SP_CE)
has_hit = Signal()
- comb.append(has_hit.eq(optree("|", hits)))
+ self.comb += has_hit.eq(optree("|", hits))
best_hit = [rr.request[i].eq(hit)
for i, hit in enumerate(hits)]
@@ -135,84 +120,72 @@ def get_fragment(self):
*best_fallback
)
- if self.slots[0].time:
+ if slots[0].time:
# Implement anti-starvation timer
matures = []
- for slot, os in zip(self.slots, outstandings):
+ for slot, os in zip(slots, outstandings):
mature = Signal()
comb.append(mature.eq(slot.mature & os))
matures.append(mature)
has_mature = Signal()
- comb.append(has_mature.eq(optree("|", matures)))
+ self.comb += has_mature.eq(optree("|", matures))
best_mature = [rr.request[i].eq(mature)
for i, mature in enumerate(matures)]
select_stmt = If(has_mature, *best_mature).Else(select_stmt)
- comb.append(select_stmt)
-
- return Fragment(comb, sync) + _Selector.get_fragment(self)
+ self.comb += select_stmt
-class _Buffer:
+class _Buffer(Module):
def __init__(self, source):
- self.source = source
-
self.stb = Signal()
self.ack = Signal()
- self.tag = Signal(self.source.tag.bv)
- self.adr = Signal(self.source.adr.bv)
+ self.tag = Signal(source.tag.bv)
+ self.adr = Signal(source.adr.bv)
self.we = Signal()
- def get_fragment(self):
+ ###
+
en = Signal()
- comb = [
+ self.comb += [
en.eq(self.ack | ~self.stb),
- self.source.ack.eq(en)
+ source.ack.eq(en)
]
- sync = [
+ self.sync += [
If(en,
- self.stb.eq(self.source.stb),
- self.tag.eq(self.source.tag),
- self.adr.eq(self.source.adr),
- self.we.eq(self.source.we)
+ self.stb.eq(source.stb),
+ self.tag.eq(source.tag),
+ self.adr.eq(source.adr),
+ self.we.eq(source.we)
)
]
- return Fragment(comb, sync)
-class BankMachine:
+class BankMachine(Module):
def __init__(self, geom_settings, timing_settings, address_align, bankn, slots, full_selector):
- self.geom_settings = geom_settings
- self.timing_settings = timing_settings
- self.address_align = address_align
- self.bankn = bankn
- self.slots = slots
- self.full_selector = full_selector
-
self.refresh_req = Signal()
self.refresh_gnt = Signal()
self.cmd = CommandRequestRW(geom_settings.mux_a, geom_settings.bank_a,
bits_for(len(slots)-1))
- def get_fragment(self):
- comb = []
- sync = []
-
+ ###
+
# Sub components
- slicer = _AddressSlicer(self.geom_settings, self.address_align)
- if self.full_selector:
- selector = _FullSelector(slicer, self.bankn, self.slots)
- buf = _Buffer(selector)
- cmdsource = buf
+ slicer = _AddressSlicer(geom_settings, address_align)
+ if full_selector:
+ selector = _FullSelector(slicer, bankn, slots)
+ self.submodules.buf = _Buffer(selector)
+ cmdsource = self.buf
else:
- selector = _SimpleSelector(slicer, self.bankn, self.slots)
+ selector = _SimpleSelector(slicer, bankn, slots)
cmdsource = selector
+ self.submodules += selector
# Row tracking
has_openrow = Signal()
- openrow = Signal(self.geom_settings.row_a)
+ openrow = Signal(geom_settings.row_a)
hit = Signal()
- comb.append(hit.eq(openrow == slicer.row(cmdsource.adr)))
+ self.comb += hit.eq(openrow == slicer.row(cmdsource.adr))
track_open = Signal()
track_close = Signal()
- sync += [
+ self.sync += [
If(track_open,
has_openrow.eq(1),
openrow.eq(slicer.row(cmdsource.adr))
@@ -224,23 +197,23 @@ def get_fragment(self):
# Address generation
s_row_adr = Signal()
- comb += [
- self.cmd.ba.eq(self.bankn),
+ self.comb += [
+ self.cmd.ba.eq(bankn),
If(s_row_adr,
self.cmd.a.eq(slicer.row(cmdsource.adr))
).Else(
self.cmd.a.eq(slicer.col(cmdsource.adr))
)
]
- comb.append(self.cmd.tag.eq(cmdsource.tag))
+ self.comb += self.cmd.tag.eq(cmdsource.tag)
# Respect write-to-precharge specification
precharge_ok = Signal()
- t_unsafe_precharge = 2 + self.timing_settings.tWR - 1
+ t_unsafe_precharge = 2 + timing_settings.tWR - 1
unsafe_precharge_count = Signal(max=t_unsafe_precharge+1)
- comb.append(precharge_ok.eq(unsafe_precharge_count == 0))
- sync += [
+ self.comb += precharge_ok.eq(unsafe_precharge_count == 0)
+ self.sync += [
If(self.cmd.stb & self.cmd.ack & self.cmd.is_write,
unsafe_precharge_count.eq(t_unsafe_precharge)
).Elif(~precharge_ok,
@@ -250,9 +223,10 @@ def get_fragment(self):
# Control and command generation FSM
fsm = FSM("REGULAR", "PRECHARGE", "ACTIVATE", "REFRESH", delayed_enters=[
- ("TRP", "ACTIVATE", self.timing_settings.tRP-1),
- ("TRCD", "REGULAR", self.timing_settings.tRCD-1)
+ ("TRP", "ACTIVATE", timing_settings.tRP-1),
+ ("TRCD", "REGULAR", timing_settings.tRCD-1)
])
+ self.submodules += fsm
fsm.act(fsm.REGULAR,
If(self.refresh_req,
fsm.next_state(fsm.REFRESH)
@@ -298,12 +272,3 @@ def get_fragment(self):
track_close.eq(1),
If(~self.refresh_req, fsm.next_state(fsm.REGULAR))
)
-
- if self.full_selector:
- buf_fragment = buf.get_fragment()
- else:
- buf_fragment = Fragment()
- return Fragment(comb, sync) + \
- selector.get_fragment() + \
- buf_fragment + \
- fsm.get_fragment()
Oops, something went wrong.

0 comments on commit a9b7235

Please sign in to comment.