Merge pull request #1598 from tpwrules/fix-litex-term
tools/litex-term: completely eliminate multiprocessing
This commit is contained in:
commit
4fa0ea2fdb
|
@ -14,7 +14,6 @@ import os
|
||||||
import time
|
import time
|
||||||
import serial
|
import serial
|
||||||
import threading
|
import threading
|
||||||
import multiprocessing
|
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
|
@ -100,23 +99,25 @@ class CrossoverUART:
|
||||||
def open(self):
|
def open(self):
|
||||||
self.bus.open()
|
self.bus.open()
|
||||||
self.file, self.name = pty.openpty()
|
self.file, self.name = pty.openpty()
|
||||||
self.pty2crossover_thread = multiprocessing.Process(target=self.pty2crossover)
|
self.alive = True
|
||||||
self.crossover2pty_thread = multiprocessing.Process(target=self.crossover2pty)
|
self.pty2crossover_thread = threading.Thread(target=self.pty2crossover, daemon=True)
|
||||||
|
self.crossover2pty_thread = threading.Thread(target=self.crossover2pty, daemon=True)
|
||||||
self.pty2crossover_thread.start()
|
self.pty2crossover_thread.start()
|
||||||
self.crossover2pty_thread.start()
|
self.crossover2pty_thread.start()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.bus.close()
|
self.bus.close()
|
||||||
self.pty2crossover_thread.terminate()
|
self.alive = False
|
||||||
self.crossover2pty_thread.terminate()
|
self.pty2crossover_thread.join(timeout=0.1)
|
||||||
|
self.crossover2pty_thread.join(timeout=0.1)
|
||||||
|
|
||||||
def pty2crossover(self):
|
def pty2crossover(self):
|
||||||
while True:
|
while self.alive:
|
||||||
r = os.read(self.file, 1)
|
r = os.read(self.file, 1)
|
||||||
self.rxtx.write(ord(r))
|
self.rxtx.write(ord(r))
|
||||||
|
|
||||||
def crossover2pty(self):
|
def crossover2pty(self):
|
||||||
while True:
|
while self.alive:
|
||||||
if self.rxfull.read():
|
if self.rxfull.read():
|
||||||
length = 16
|
length = 16
|
||||||
elif not self.rxempty.read():
|
elif not self.rxempty.read():
|
||||||
|
@ -140,32 +141,34 @@ class JTAGUART:
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
self.file, self.name = pty.openpty()
|
self.file, self.name = pty.openpty()
|
||||||
self.jtag2tcp_thread = multiprocessing.Process(target=self.jtag2tcp)
|
self.alive = True
|
||||||
|
self.jtag2tcp_thread = threading.Thread(target=self.jtag2tcp, daemon=True)
|
||||||
self.jtag2tcp_thread.start()
|
self.jtag2tcp_thread.start()
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
self.pty2tcp_thread = multiprocessing.Process(target=self.pty2tcp)
|
self.pty2tcp_thread = threading.Thread(target=self.pty2tcp, daemon=True)
|
||||||
self.tcp2pty_thread = multiprocessing.Process(target=self.tcp2pty)
|
self.tcp2pty_thread = threading.Thread(target=self.tcp2pty, daemon=True)
|
||||||
self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.tcp.connect(("localhost", self.port))
|
self.tcp.connect(("localhost", self.port))
|
||||||
self.pty2tcp_thread.start()
|
self.pty2tcp_thread.start()
|
||||||
self.tcp2pty_thread.start()
|
self.tcp2pty_thread.start()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.jtag2tcp_thread.terminate()
|
self.alive = False
|
||||||
self.pty2tcp_thread.terminate()
|
self.jtag2tcp_thread.join(timeout=0.1)
|
||||||
self.tcp2pty_thread.terminate()
|
self.pty2tcp_thread.join(timeout=0.1)
|
||||||
|
self.tcp2pty_thread.join(timeout=0.1)
|
||||||
|
|
||||||
def jtag2tcp(self):
|
def jtag2tcp(self):
|
||||||
prog = OpenOCD(self.config)
|
prog = OpenOCD(self.config)
|
||||||
prog.stream(self.port, self.chain)
|
prog.stream(self.port, self.chain)
|
||||||
|
|
||||||
def pty2tcp(self):
|
def pty2tcp(self):
|
||||||
while True:
|
while self.alive:
|
||||||
r = os.read(self.file, 1)
|
r = os.read(self.file, 1)
|
||||||
self.tcp.send(r)
|
self.tcp.send(r)
|
||||||
|
|
||||||
def tcp2pty(self):
|
def tcp2pty(self):
|
||||||
while True:
|
while self.alive:
|
||||||
r = self.tcp.recv(1)
|
r = self.tcp.recv(1)
|
||||||
os.write(self.file, bytes(r))
|
os.write(self.file, bytes(r))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue