2013-05-22 11:10:13 -04:00
|
|
|
from migen.fhdl.std import *
|
2011-12-17 18:29:37 -05:00
|
|
|
from migen.bank.description import *
|
2012-02-06 11:45:31 -05:00
|
|
|
from migen.bank.eventmanager import *
|
2014-07-30 22:23:59 -04:00
|
|
|
from migen.genlib.record import Record
|
2014-09-24 15:30:25 -04:00
|
|
|
from migen.flow.actor import Sink, Source
|
2011-12-13 11:33:12 -05:00
|
|
|
|
2014-09-24 15:30:25 -04:00
|
|
|
class UART(Module, AutoCSR):
|
2015-03-01 05:58:46 -05:00
|
|
|
def __init__(self, phy):
|
2015-02-27 04:36:09 -05:00
|
|
|
self._rxtx = CSR(8)
|
2014-09-24 15:30:25 -04:00
|
|
|
|
|
|
|
self.submodules.ev = EventManager()
|
|
|
|
self.ev.tx = EventSourcePulse()
|
|
|
|
self.ev.rx = EventSourcePulse()
|
|
|
|
self.ev.finalize()
|
|
|
|
###
|
|
|
|
self.sync += [
|
2015-02-27 04:36:09 -05:00
|
|
|
If(self._rxtx.re,
|
2015-03-01 12:25:47 -05:00
|
|
|
phy.sink.stb.eq(1),
|
|
|
|
phy.sink.data.eq(self._rxtx.r),
|
|
|
|
).Elif(phy.sink.ack,
|
|
|
|
phy.sink.stb.eq(0)
|
2014-09-24 15:30:25 -04:00
|
|
|
),
|
2015-03-01 12:25:47 -05:00
|
|
|
If(phy.source.stb,
|
|
|
|
self._rxtx.w.eq(phy.source.data)
|
2014-09-24 15:30:25 -04:00
|
|
|
)
|
|
|
|
]
|
|
|
|
self.comb += [
|
2015-03-01 12:25:47 -05:00
|
|
|
self.ev.tx.trigger.eq(phy.sink.stb & phy.sink.ack),
|
|
|
|
self.ev.rx.trigger.eq(phy.source.stb) #phy.source.ack supposed to be always 1
|
2014-09-24 15:30:25 -04:00
|
|
|
]
|