Skip to content

Commit d73d750

Browse files
committedJul 24, 2015
misoclib/com/uart: cleanup and add irq condition parameters
- reintroduce RX/TX split (ease comprehension) - use FIFO wrapper function from Migen. - add tx_irq_condition and rx_irq_condition
1 parent b1ea334 commit d73d750

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed
 

Diff for: ‎misoclib/com/uart/__init__.py

+26-19
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from migen.bank.description import *
33
from migen.bank.eventmanager import *
44
from migen.genlib.record import Record
5-
from migen.actorlib.fifo import SyncFIFO, AsyncFIFO
5+
from migen.actorlib.fifo import FIFO
66

77

88
class UART(Module, AutoCSR):
99
def __init__(self, phy,
10-
tx_fifo_depth=16,
11-
rx_fifo_depth=16,
10+
tx_fifo_depth=16, tx_irq_condition="empty",
11+
rx_fifo_depth=16, rx_irq_condition="non-empty",
Has conversations. Original line has conversations.
1212
phy_cd="sys"):
1313
self._rxtx = CSR(8)
1414
self._txfull = CSRStatus()
@@ -21,30 +21,37 @@ def __init__(self, phy,
2121

2222
# # #
2323

24-
if phy_cd == "sys":
25-
tx_fifo = SyncFIFO([("data", 8)], tx_fifo_depth)
26-
rx_fifo = SyncFIFO([("data", 8)], rx_fifo_depth)
27-
# Generate TX IRQ when tx_fifo becomes empty
28-
tx_irq = tx_fifo.source.stb
29-
else:
30-
tx_fifo = ClockDomainsRenamer({"write": "sys", "read": phy_cd})(
31-
AsyncFIFO([("data", 8)], tx_fifo_depth))
32-
rx_fifo = ClockDomainsRenamer({"write": phy_cd, "read": "sys"})(
33-
AsyncFIFO([("data", 8)], rx_fifo_depth))
34-
# Generate TX IRQ when tx_fifo becomes non-full
35-
tx_irq = ~tx_fifo.sink.ack
36-
self.submodules += tx_fifo, rx_fifo
24+
# TX
25+
tx_fifo = FIFO([("data", 8)], tx_fifo_depth, source_cd=phy_cd)
26+
self.submodules += tx_fifo
27+
28+
tx_irqs = {
29+
"empty": tx_fifo.source.stb,
30+
"non-full": ~tx_fifo.sink.ack
31+
}
32+
3733
self.comb += [
3834
tx_fifo.sink.stb.eq(self._rxtx.re),
3935
tx_fifo.sink.data.eq(self._rxtx.r),
4036
self._txfull.status.eq(~tx_fifo.sink.ack),
4137
Record.connect(tx_fifo.source, phy.sink),
42-
self.ev.tx.trigger.eq(tx_irq),
38+
self.ev.tx.trigger.eq(tx_irqs[tx_irq_condition])
39+
]
40+
4341

42+
# RX
43+
rx_fifo = FIFO([("data", 8)], rx_fifo_depth, sink_cd=phy_cd)
44+
self.submodules += rx_fifo
45+
46+
rx_irqs = {
47+
"non-empty": ~rx_fifo.source.stb,
48+
"full": rx_fifo.sink.ack
49+
}
50+
51+
self.comb += [
4452
Record.connect(phy.source, rx_fifo.sink),
4553
self._rxempty.status.eq(~rx_fifo.source.stb),
4654
self._rxtx.w.eq(rx_fifo.source.data),
4755
rx_fifo.source.ack.eq(self.ev.rx.clear),
48-
# Generate RX IRQ when rx_fifo becomes non-empty
49-
self.ev.rx.trigger.eq(~rx_fifo.source.stb),
56+
self.ev.rx.trigger.eq(rx_irqs[rx_irq_condition])
5057
]

0 commit comments

Comments
 (0)
Please sign in to comment.