From bed5aafd6c902c901f96ba89f89b68c3b0eaca3c Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Sun, 24 May 2020 10:55:25 +0200 Subject: [PATCH] tools: add litex_crossover to be able to use lxterm (and serialboot) over a crossover UART (bridged over UART/Ethernet/PCIe/USB, etc...). This is still a proof of concept but can be used/tested with: lxsim --with-etherbone --uart-name=crossover --csr-csv=csr.csv lxserver --udp --udp-ip=192.168.1.51 lxcrossover (will indicate the virtual_tty) lxterm virtual_tty --- litex/tools/litex_crossover.py | 40 ++++++++++++++++++++++++++++++++++ setup.py | 2 ++ 2 files changed, 42 insertions(+) create mode 100755 litex/tools/litex_crossover.py diff --git a/litex/tools/litex_crossover.py b/litex/tools/litex_crossover.py new file mode 100755 index 000000000..de44c4984 --- /dev/null +++ b/litex/tools/litex_crossover.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +# This file is Copyright (c) 2020 Florent Kermarrec +# License: BSD + +# Proof of Concept to use the crossover UART with lxterm over a bridge. + +import os +import pty +import threading + +from litex import RemoteClient + +wb = RemoteClient() +wb.open() + +# # # + +def pty2crossover(m): + while True: + r = os.read(m, 1) + wb.regs.uart_xover_rxtx.write(ord(r)) + +def crossover2pty(m): + while True: + if wb.regs.uart_xover_rxempty.read() == 0: + r = wb.regs.uart_xover_rxtx.read() + os.write(m, bytes(chr(r).encode("utf-8"))) + +m, s = pty.openpty() +print("LiteX Crossover UART created: {}".format(os.ttyname(s))) + +pty2crossover_thread = threading.Thread(target=pty2crossover, args=[m]) +pty2crossover_thread.start() + +crossover2pty(m) + +# # # + +wb.close() diff --git a/setup.py b/setup.py index 7429e9203..a8656a593 100755 --- a/setup.py +++ b/setup.py @@ -39,12 +39,14 @@ setup( "litex_term=litex.tools.litex_term:main", "litex_server=litex.tools.litex_server:main", "litex_sim=litex.tools.litex_sim:main", + "litex_crossover=litex.tools.litex_crossover:main" "litex_read_verilog=litex.tools.litex_read_verilog:main", "litex_simple=litex.boards.targets.simple:main", # short names "lxterm=litex.tools.litex_term:main", "lxserver=litex.tools.litex_server:main", "lxsim=litex.tools.litex_sim:main", + "lxcrossover=litex.tools.litex_crossover:main", ], }, )