Remove uses of declare_signal

This commit is contained in:
Sebastien Bourdeauducq 2011-12-18 21:47:48 +01:00
parent dd42b2daff
commit 107f03fd4b
5 changed files with 49 additions and 53 deletions

View file

@ -7,13 +7,13 @@ class Bank:
self.description = description self.description = description
self.address = address self.address = address
self.interface = Slave() self.interface = Slave()
declare_signal(self, "_sel")
def get_fragment(self): def get_fragment(self):
comb = [] comb = []
sync = [] sync = []
comb.append(self._sel.eq(self.interface.a_i[9:] == Constant(self.address, BV(5)))) sel = Signal()
comb.append(sel.eq(self.interface.a_i[9:] == Constant(self.address, BV(5))))
nregs = len(self.description) nregs = len(self.description)
nbits = bits_for(nregs-1) nbits = bits_for(nregs-1)
@ -33,11 +33,11 @@ class Bank:
bwcases.append(bwra) bwcases.append(bwra)
else: else:
comb.append(reg.dev_r.eq(self.interface.d_i[:reg.raw.width])) comb.append(reg.dev_r.eq(self.interface.d_i[:reg.raw.width]))
comb.append(reg.dev_re.eq(self._sel & \ comb.append(reg.dev_re.eq(sel & \
self.interface.we_i & \ self.interface.we_i & \
(self.interface.a_i[:nbits] == Constant(i, BV(nbits))))) (self.interface.a_i[:nbits] == Constant(i, BV(nbits)))))
if bwcases: if bwcases:
sync.append(If(self._sel & self.interface.we_i, Case(self.interface.a_i[:nbits], *bwcases))) sync.append(If(sel & self.interface.we_i, Case(self.interface.a_i[:nbits], *bwcases)))
# Bus reads # Bus reads
brcases = [] brcases = []
@ -63,7 +63,7 @@ class Bank:
brcases.append([Constant(i, BV(nbits)), self.interface.d_o.eq(reg.dev_w)]) brcases.append([Constant(i, BV(nbits)), self.interface.d_o.eq(reg.dev_w)])
if brcases: if brcases:
sync.append(self.interface.d_o.eq(Constant(0, BV(8)))) sync.append(self.interface.d_o.eq(Constant(0, BV(8))))
sync.append(If(self._sel, Case(self.interface.a_i[:nbits], *brcases))) sync.append(If(sel, Case(self.interface.a_i[:nbits], *brcases)))
else: else:
comb.append(self.interface.d_o.eq(Constant(0, BV(8)))) comb.append(self.interface.d_o.eq(Constant(0, BV(8))))

View file

@ -1,5 +1,3 @@
from functools import partial
from migen.fhdl.structure import * from migen.fhdl.structure import *
from migen.corelogic import roundrobin, multimux from migen.corelogic import roundrobin, multimux
from migen.bus.simple import Simple, get_sig_name from migen.bus.simple import Simple, get_sig_name
@ -84,26 +82,25 @@ class Decoder:
return x return x
self.addresses = list(map(mkconst, addresses)) self.addresses = list(map(mkconst, addresses))
ns = len(self.slaves)
d = partial(declare_signal, self)
d("_slave_sel", BV(ns))
d("_slave_sel_r", BV(ns))
def get_fragment(self): def get_fragment(self):
comb = [] comb = []
sync = [] sync = []
ns = len(self.slaves)
slave_sel = Signal(BV(ns))
slave_sel_r = Signal(BV(ns))
# decode slave addresses # decode slave addresses
i = 0 i = 0
hi = self.master.adr_o.bv.width - self.offset hi = self.master.adr_o.bv.width - self.offset
for addr in self.addresses: for addr in self.addresses:
comb.append(self._slave_sel[i].eq( comb.append(slave_sel[i].eq(
self.master.adr_o[hi-addr.bv.width:hi] == addr)) self.master.adr_o[hi-addr.bv.width:hi] == addr))
i += 1 i += 1
if self.register: if self.register:
sync.append(self._slave_sel_r.eq(self._slave_sel)) sync.append(slave_sel_r.eq(slave_sel))
else: else:
comb.append(self._slave_sel_r.eq(self._slave_sel)) comb.append(slave_sel_r.eq(slave_sel))
# connect master->slaves signals except cyc # connect master->slaves signals except cyc
m2s_names = [(get_sig_name(x, False), get_sig_name(x, True)) m2s_names = [(get_sig_name(x, False), get_sig_name(x, True))
@ -114,7 +111,7 @@ class Decoder:
# combine cyc with slave selection signals # combine cyc with slave selection signals
i = 0 i = 0
for slave in self.slaves: for slave in self.slaves:
comb.append(slave[1].cyc_i.eq(self.master.cyc_o & self._slave_sel[i])) comb.append(slave[1].cyc_i.eq(self.master.cyc_o & slave_sel[i]))
i += 1 i += 1
# generate master ack (resp. err) by ORing all slave acks (resp. errs) # generate master ack (resp. err) by ORing all slave acks (resp. errs)
@ -130,7 +127,7 @@ class Decoder:
i = 0 i = 0
datav = Constant(0, self.master.dat_i.bv) datav = Constant(0, self.master.dat_i.bv)
for slave in self.slaves: for slave in self.slaves:
datav = datav | (Replicate(self._slave_sel_r[i], self.master.dat_i.bv.width) & slave[1].dat_o) datav = datav | (Replicate(slave_sel_r[i], self.master.dat_i.bv.width) & slave[1].dat_o)
i += 1 i += 1
comb.append(self.master.dat_i.eq(datav)) comb.append(self.master.dat_i.eq(datav))

View file

@ -1,44 +1,42 @@
from functools import partial
from migen.fhdl.structure import * from migen.fhdl.structure import *
class Inst: class Inst:
def __init__(self, w): def __init__(self, w):
self.w = w self.w = w
d = partial(declare_signal, self) start_i = Signal()
dividend_i = Signal(BV(w))
d("start_i") divisor_i = Signal(BV(w))
d("dividend_i", BV(w)) ready_o = Signal()
d("divisor_i", BV(w)) quotient_o = Signal(BV(w))
d("ready_o") remainder_o = Signal(BV(w))
d("quotient_o", BV(w))
d("remainder_o", BV(w))
d("_qr", BV(2*w))
d("_counter", BV(bits_for(w)))
d("_divisor_r", BV(w))
d("_diff", BV(w+1))
def get_fragment(self): def get_fragment(self):
w = self.w
qr = Signal(BV(2*w))
counter = Signal(BV(bits_for(w)))
divisor_r = Signal(BV(w))
diff = Signal(BV(w+1))
comb = [ comb = [
self.quotient_o.eq(self._qr[:self.w]), self.quotient_o.eq(qr[:w]),
self.remainder_o.eq(self._qr[self.w:]), self.remainder_o.eq(qr[w:]),
self.ready_o.eq(self._counter == Constant(0, self._counter.bv)), self.ready_o.eq(counter == Constant(0, counter.bv)),
self._diff.eq(self.remainder_o - self._divisor_r) diff.eq(self.remainder_o - divisor_r)
] ]
sync = [ sync = [
If(self.start_i, If(self.start_i,
self._counter.eq(self.w), counter.eq(w),
self._qr.eq(self.dividend_i), qr.eq(self.dividend_i),
self._divisor_r.eq(self.divisor_i) divisor_r.eq(self.divisor_i)
).Elif(~self.ready_o, ).Elif(~self.ready_o,
If(self._diff[self.w], If(diff[w],
self._qr.eq(Cat(0, self._qr[:2*self.w-1])) qr.eq(Cat(0, qr[:2*w-1]))
).Else( ).Else(
self._qr.eq(Cat(1, self._qr[:self.w-1], self._diff[:self.w])) qr.eq(Cat(1, qr[:w-1], diff[:w]))
), ),
self._counter.eq(self._counter - Constant(1, self._counter.bv)) counter.eq(counter - Constant(1, counter.bv))
) )
] ]
return Fragment(comb, sync) return Fragment(comb, sync)

View file

@ -4,8 +4,8 @@ class Inst:
def __init__(self, n): def __init__(self, n):
self.n = n self.n = n
self.bn = bits_for(self.n-1) self.bn = bits_for(self.n-1)
declare_signal(self, "request", BV(self.n)) request = Signal(BV(self.n))
declare_signal(self, "grant", BV(self.bn)) grant = Signal(BV(self.bn))
def get_fragment(self): def get_fragment(self):
cases = [] cases = []

View file

@ -5,27 +5,28 @@ class Inst:
self.trigger = trigger self.trigger = trigger
self.events = events self.events = events
self.lastevent = max([e[0] for e in events]) self.lastevent = max([e[0] for e in events])
declare_signal(self, "_counter", BV(bits_for(self.lastevent)))
def get_fragment(self): def get_fragment(self):
counterlogic = If(self._counter != Constant(0, self._counter.bv), counter = Signal(BV(bits_for(self.lastevent)))
self._counter.eq(self._counter + Constant(1, self._counter.bv))
counterlogic = If(counter != Constant(0, counter.bv),
counter.eq(counter + Constant(1, counter.bv))
).Elif(self.trigger, ).Elif(self.trigger,
self._counter.eq(Constant(1, self._counter.bv)) counter.eq(Constant(1, counter.bv))
) )
# insert counter reset if it doesn't automatically overflow # insert counter reset if it doesn't automatically overflow
# (test if self.lastevent+1 is a power of 2) # (test if self.lastevent+1 is a power of 2)
if (self.lastevent & (self.lastevent + 1)) != 0: if (self.lastevent & (self.lastevent + 1)) != 0:
counterlogic = If(self._counter == self.lastevent, counterlogic = If(counter == self.lastevent,
self._counter.eq(Constant(0, self._counter.bv)) counter.eq(Constant(0, counter.bv))
).Else( ).Else(
counterlogic counterlogic
) )
def get_cond(e): def get_cond(e):
if e[0] == 0: if e[0] == 0:
return self.trigger & (self._counter == Constant(0, self._counter.bv)) return self.trigger & (counter == Constant(0, counter.bv))
else: else:
return self._counter == Constant(e[0], self._counter.bv) return counter == Constant(e[0], counter.bv)
sync = [If(get_cond(e), *e[1]) for e in self.events] sync = [If(get_cond(e), *e[1]) for e in self.events]
sync.append(counterlogic) sync.append(counterlogic)
return Fragment(sync=sync) return Fragment(sync=sync)