Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fhdl: simpler syntax
- Loading branch information
Sebastien Bourdeauducq
committed
Dec 16, 2011
1 parent
39b7190
commit c7b9dfc
Showing
13 changed files
with
187 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,22 @@ | ||
| from migen.bus import wishbone | ||
| from migen.bus import csr | ||
| from migen.fhdl import structure as f | ||
| from migen.fhdl.structure import * | ||
| from migen.corelogic import timeline | ||
|
|
||
| class Inst(): | ||
| def __init__(self): | ||
| self.wishbone = wishbone.Slave("to_csr") | ||
| self.csr = csr.Master("from_wishbone") | ||
| self.timeline = timeline.Inst(self.wishbone.cyc_i & self.wishbone.stb_i, | ||
| [(1, [f.Assign(self.csr.we_o, self.wishbone.we_i)]), | ||
| (2, [f.Assign(self.wishbone.ack_o, 1)]), | ||
| (3, [f.Assign(self.wishbone.ack_o, 0)])]) | ||
| [(1, [self.csr.we_o.eq(self.wishbone.we_i)]), | ||
| (2, [self.wishbone.ack_o.eq(1)]), | ||
| (3, [self.wishbone.ack_o.eq(0)])]) | ||
|
|
||
| def get_fragment(self): | ||
| sync = [ | ||
| f.Assign(self.csr.we_o, 0), | ||
| f.Assign(self.csr.d_o, self.wishbone.dat_i), | ||
| f.Assign(self.csr.a_o, self.wishbone.adr_i[2:16]), | ||
| f.Assign(self.wishbone.dat_o, self.csr.d_i) | ||
| self.csr.we_o.eq(0), | ||
| self.csr.d_o.eq(self.wishbone.dat_i), | ||
| self.csr.a_o.eq(self.wishbone.adr_i[2:16]), | ||
| self.wishbone.dat_o.eq(self.csr.d_i) | ||
| ] | ||
| return f.Fragment(sync=sync) + self.timeline.get_fragment() | ||
| return Fragment(sync=sync) + self.timeline.get_fragment() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,44 @@ | ||
| from functools import partial | ||
|
|
||
| from migen.fhdl import structure as f | ||
| from migen.fhdl.structure import * | ||
|
|
||
| class Inst: | ||
| def __init__(self, w): | ||
| self.w = w | ||
|
|
||
| d = partial(f.declare_signal, self) | ||
| d = partial(declare_signal, self) | ||
|
|
||
| d("start_i") | ||
| d("dividend_i", f.BV(w)) | ||
| d("divisor_i", f.BV(w)) | ||
| d("dividend_i", BV(w)) | ||
| d("divisor_i", BV(w)) | ||
| d("ready_o") | ||
| d("quotient_o", f.BV(w)) | ||
| d("remainder_o", f.BV(w)) | ||
| d("quotient_o", BV(w)) | ||
| d("remainder_o", BV(w)) | ||
|
|
||
| d("_qr", f.BV(2*w)) | ||
| d("_counter", f.BV(f.bits_for(w))) | ||
| d("_divisor_r", f.BV(w)) | ||
| d("_diff", f.BV(w+1)) | ||
| 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): | ||
| a = f.Assign | ||
| comb = [ | ||
| a(self.quotient_o, self._qr[:self.w]), | ||
| a(self.remainder_o, self._qr[self.w:]), | ||
| a(self.ready_o, self._counter == f.Constant(0, self._counter.bv)), | ||
| a(self._diff, self.remainder_o - self._divisor_r) | ||
| self.quotient_o.eq(self._qr[:self.w]), | ||
| self.remainder_o.eq(self._qr[self.w:]), | ||
| self.ready_o.eq(self._counter == Constant(0, self._counter.bv)), | ||
| self._diff.eq(self.remainder_o - self._divisor_r) | ||
| ] | ||
| sync = [ | ||
| f.If(self.start_i == 1, [ | ||
| a(self._counter, self.w), | ||
| a(self._qr, self.dividend_i), | ||
| a(self._divisor_r, self.divisor_i) | ||
| ], [ | ||
| f.If(self.ready_o == 0, [ | ||
| f.If(self._diff[self.w] == 1, | ||
| [a(self._qr, f.Cat(0, self._qr[:2*self.w-1]))], | ||
| [a(self._qr, f.Cat(1, self._qr[:self.w-1], self._diff[:self.w]))]), | ||
| a(self._counter, self._counter - f.Constant(1, self._counter.bv)), | ||
| ]) | ||
| ]) | ||
| If(self.start_i, | ||
| self._counter.eq(self.w), | ||
| self._qr.eq(self.dividend_i), | ||
| self._divisor_r.eq(self.divisor_i) | ||
| ).Elif(~self.ready_o, | ||
| If(self._diff[self.w], | ||
| self._qr.eq(Cat(0, self._qr[:2*self.w-1])) | ||
| ).Else( | ||
| self._qr.eq(Cat(1, self._qr[:self.w-1], self._diff[:self.w])) | ||
| ), | ||
| self._counter.eq(self._counter - Constant(1, self._counter.bv)) | ||
| ) | ||
| ] | ||
| return f.Fragment(comb, sync) | ||
| return Fragment(comb, sync) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| from migen.fhdl import structure as f | ||
| from migen.fhdl.structure import * | ||
|
|
||
| def multimux(sel, inputs, output): | ||
| n = len(inputs) | ||
| i = 0 | ||
| comb = [] | ||
| for osig in output: | ||
| choices = [x[i] for x in inputs] | ||
| cases = [(f.Constant(j, sel.bv), [f.Assign(osig, choices[j])]) for j in range(n)] | ||
| default = cases.pop()[1] | ||
| comb.append(f.Case(sel, cases, default)) | ||
| cases = [[Constant(j, sel.bv), osig.eq(choices[j])] for j in range(n)] | ||
| cases[n-1][0] = Default() | ||
| comb.append(Case(sel, *cases)) | ||
| i += 1 | ||
| return comb |
Oops, something went wrong.