de44c4984fbe6a1dfb3b2f81ffdf151f2d62acb2
[litex.git] / litex / tools / litex_crossover_uart.py
1 #!/usr/bin/env python3
2
3 # This file is Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr>
4 # License: BSD
5
6 # Proof of Concept to use the crossover UART with lxterm over a bridge.
7
8 import os
9 import pty
10 import threading
11
12 from litex import RemoteClient
13
14 wb = RemoteClient()
15 wb.open()
16
17 # # #
18
19 def pty2crossover(m):
20 while True:
21 r = os.read(m, 1)
22 wb.regs.uart_xover_rxtx.write(ord(r))
23
24 def crossover2pty(m):
25 while True:
26 if wb.regs.uart_xover_rxempty.read() == 0:
27 r = wb.regs.uart_xover_rxtx.read()
28 os.write(m, bytes(chr(r).encode("utf-8")))
29
30 m, s = pty.openpty()
31 print("LiteX Crossover UART created: {}".format(os.ttyname(s)))
32
33 pty2crossover_thread = threading.Thread(target=pty2crossover, args=[m])
34 pty2crossover_thread.start()
35
36 crossover2pty(m)
37
38 # # #
39
40 wb.close()