-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathunit.py
More file actions
71 lines (59 loc) · 1.7 KB
/
Copy pathunit.py
File metadata and controls
71 lines (59 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
import array
import emu8051
from forthshell import ForthShell, main
class OutputComplete(Exception):
pass
class DUT(ForthShell):
def __init__(self, *a):
self.start()
self.e = emu8051.emu8051(self.writer, self.reader)
self.uart_out = []
self.uart_in = "TRUE TTH !" + '\r\n'
self.frob()
def boot(self, *a):
pass
def writer(self, reg, val):
# print 'write %x %x' % (reg, val)
if reg == 0xc1:
if val == 30:
raise OutputComplete
self.uart_out.append(chr(val))
def reader(self, reg, val):
# print 'read %x %x' % (reg, val)
if reg == 0x86:
return 4
if reg == 0xe8:
return 2
if reg == 0xc1:
val = ord(self.uart_in[0])
self.uart_in = self.uart_in[1:]
return val
def frob(self):
try:
self.e.run()
except OutputComplete:
pass
r = "".join(self.uart_out)
self.uart_out = []
return r
def interactive_command(self, cmd = None):
self.uart_in = cmd + '\r\n'
sys.stdout.write(self.frob())
def command_response(self, cmd):
self.uart_in = cmd + '\r\n'
return self.frob()
cellsize = 2
def serialize(self):
l = self.command_response('$0 $8000 dump')
lines = l.strip().replace('\r', '').split('\n')
s = []
for l in lines:
l = l.split()
s += [int(b, 16) for b in l[1:17]]
s = array.array('B', s).tostring()
while s.endswith(256 * chr(0xff)):
s = s[:-256]
return array.array('h', s)
if __name__ == '__main__':
main(DUT)