2
2
from migen .bank .description import *
3
3
from migen .bank .eventmanager import *
4
4
from migen .genlib .record import Record
5
- from migen .actorlib .fifo import SyncFIFO , AsyncFIFO
5
+ from migen .actorlib .fifo import FIFO
6
6
7
7
8
8
class UART (Module , AutoCSR ):
9
9
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. 12
12
phy_cd = "sys" ):
13
13
self ._rxtx = CSR (8 )
14
14
self ._txfull = CSRStatus ()
@@ -21,30 +21,37 @@ def __init__(self, phy,
21
21
22
22
# # #
23
23
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
+
37
33
self .comb += [
38
34
tx_fifo .sink .stb .eq (self ._rxtx .re ),
39
35
tx_fifo .sink .data .eq (self ._rxtx .r ),
40
36
self ._txfull .status .eq (~ tx_fifo .sink .ack ),
41
37
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
+
43
41
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 += [
44
52
Record .connect (phy .source , rx_fifo .sink ),
45
53
self ._rxempty .status .eq (~ rx_fifo .source .stb ),
46
54
self ._rxtx .w .eq (rx_fifo .source .data ),
47
55
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 ])
50
57
]