2011-12-22 18:35:53 -05:00
|
|
|
from migen.fhdl.structure import *
|
|
|
|
from migen.flow.actor import *
|
2012-01-06 08:32:00 -05:00
|
|
|
from migen.corelogic.record import *
|
2011-12-22 18:35:53 -05:00
|
|
|
from migen.corelogic import divider
|
|
|
|
|
2012-01-06 08:32:00 -05:00
|
|
|
class Adder(Actor):
|
2011-12-22 18:35:53 -05:00
|
|
|
def __init__(self, width):
|
2012-01-06 08:32:00 -05:00
|
|
|
self.operands = Record([('a', BV(width)), ('b', BV(width))])
|
2012-01-06 11:24:05 -05:00
|
|
|
self.result = Record([('sum', BV(width+1))])
|
2011-12-22 18:35:53 -05:00
|
|
|
Actor.__init__(self,
|
|
|
|
SchedulingModel(SchedulingModel.COMBINATORIAL),
|
2012-01-06 09:35:17 -05:00
|
|
|
self.operands, self.result)
|
2012-01-06 08:32:00 -05:00
|
|
|
|
2011-12-22 18:35:53 -05:00
|
|
|
def get_process_fragment(self):
|
2012-01-06 08:32:00 -05:00
|
|
|
return Fragment([self.result.sum.eq(self.operands.a + self.operands.b)])
|
2011-12-22 18:35:53 -05:00
|
|
|
|
|
|
|
class Divider(Actor):
|
|
|
|
def __init__(self, width):
|
|
|
|
self.div = divider.Inst(width)
|
2012-01-06 08:32:00 -05:00
|
|
|
self.operands = Record([('dividend', self.div.dividend_i), ('divisor', self.div.divisor_i)])
|
|
|
|
self.result = Record([('quotient', self.div.quotient_o), ('remainder', self.div.remainder_o)])
|
2011-12-22 18:35:53 -05:00
|
|
|
Actor.__init__(self,
|
|
|
|
SchedulingModel(SchedulingModel.SEQUENTIAL, width),
|
2012-01-06 09:35:17 -05:00
|
|
|
self.operands, self.result)
|
2012-01-06 08:32:00 -05:00
|
|
|
|
2011-12-22 18:35:53 -05:00
|
|
|
def get_process_fragment(self):
|
|
|
|
return self.div.get_fragment() + Fragment([self.div.start_i.eq(self.trigger)])
|