2015-03-09 18:29:06 -04:00
|
|
|
import os, pty, time
|
|
|
|
|
2015-03-01 10:52:50 -05:00
|
|
|
from migen.fhdl.std import *
|
|
|
|
from migen.flow.actor import Sink, Source
|
|
|
|
|
|
|
|
class UARTPHYSim(Module):
|
2015-04-13 10:19:55 -04:00
|
|
|
def __init__(self, pads, *args, **kwargs):
|
|
|
|
self.sink = Sink([("data", 8)])
|
|
|
|
self.source = Source([("data", 8)])
|
2015-03-01 10:52:50 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
self.comb += [
|
|
|
|
pads.source_stb.eq(self.sink.stb),
|
|
|
|
pads.source_data.eq(self.sink.data),
|
|
|
|
self.sink.ack.eq(pads.source_ack),
|
2015-03-01 10:52:50 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
self.source.stb.eq(pads.sink_stb),
|
|
|
|
self.source.data.eq(pads.sink_data),
|
|
|
|
pads.sink_ack.eq(self.source.ack)
|
|
|
|
]
|
2015-03-09 18:29:06 -04:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
m, s = pty.openpty()
|
|
|
|
name = os.ttyname(s)
|
|
|
|
print("UART tty: "+name)
|
|
|
|
time.sleep(0.5) # pause for user
|
|
|
|
f = open("/tmp/simserial", "w")
|
|
|
|
f.write(os.ttyname(s))
|
|
|
|
f.close()
|
2015-03-09 18:29:06 -04:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
def do_exit(self, *args, **kwargs):
|
|
|
|
os.remove("/tmp/simserial")
|