MCPcopy
hub / github.com/AsahiLinux/m1n1 / UartInterface

Class UartInterface

proxyclient/m1n1/proxy.py:113–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111# Otherwise reports a remote Error
112
113class UartInterface(Reloadable):
114 REQ_NOP = 0x00AA55FF
115 REQ_PROXY = 0x01AA55FF
116 REQ_MEMREAD = 0x02AA55FF
117 REQ_MEMWRITE = 0x03AA55FF
118 REQ_BOOT = 0x04AA55FF
119 REQ_EVENT = 0x05AA55FF
120
121 CHECKSUM_SENTINEL = 0xD0DECADE
122 DATA_END_SENTINEL = 0xB0CACC10
123
124 ST_OK = 0
125 ST_BADCMD = -1
126 ST_INVAL = -2
127 ST_XFERERR = -3
128 ST_CSUMERR = -4
129
130 CMD_LEN = 56
131 REPLY_LEN = 36
132 EVENT_HDR_LEN = 8
133
134 DEFAULT_UART_DEV="/dev/m1n1"
135 DEFAULT_BAUD_RATE=115200
136 if platform.system() == 'Darwin':
137 DEFAULT_UART_DEV="/dev/cu.usbmodemP_01"
138
139 def __init__(self, device=None, debug=False):
140 self.debug = debug
141 self.devpath = None
142 if device is None:
143 device = os.environ.get("M1N1DEVICE", self.DEFAULT_UART_DEV)
144 if isinstance(device, str):
145 baud = self.DEFAULT_BAUD_RATE
146 if ":" in device:
147 device, baud = device.rsplit(":", 1)
148 baud = int(baud)
149 self.devpath = device
150 self.baudrate = baud
151
152 # wait for it to come back
153 if os.environ.get("M1N1WAIT", 0) and not os.path.exists(self.devpath):
154 print("Waiting for %s to appear.." % self.devpath)
155 for n in range(100): # 10s
156 time.sleep(0.1)
157 if os.path.exists(self.devpath):
158 break
159 time.sleep(0.1) # wait for udev to settle (avoid permissions issues)
160
161 device = Serial(self.devpath, baud)
162
163 self.dev = device
164 self.dev.timeout = 0
165 self.dev.flushOutput()
166 self.dev.flushInput()
167 self.pted = False
168 #d = self.dev.read(1)
169 #while d != "":
170 #d = self.dev.read(1)

Callers 3

run_guest.pyFile · 0.85
setup.pyFile · 0.85
proxy.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected