-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfifo.py
151 lines (118 loc) · 2.56 KB
/
fifo.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/env/python
# Simple test access of netpp simulation server
NETPP = "/home/strubi/src/netpp"
import sys
sys.path.append(NETPP + "/Debug")
sys.path.append(NETPP + "/python")
import time
import netpp
def dump(seq):
c = 0
for i in seq:
print "%02x" % (ord(i)),
c += 1
if c == 16:
c = 0
print
print
def find_mismatch(b0, b1):
for i in range(len(b0)):
if b0[i] != b1[i]:
print "Mismatch from %d" % i,
print "should be: %02x, is: %02x" % (ord(b0[i]), ord(b1[i]))
break
return i
def test_blk(r, bufsize, throttle = 1, delay = 0.01):
t = ""
l = 0
fifo = r.Fifo
r.Throttle.set(throttle)
COUNT_WRAP = 0x0100
n = bufsize / 2
should = ""
c = 0
for i in range(n):
should += chr((c >> 8) & 0xff) + chr(c & 0xff)
c += 1
if c == COUNT_WRAP:
c = 0
a = netpp.Buffer(bufsize)
print "buf size: %d bytes, reference size: %d" % (bufsize, len(should))
retry = 0
while l < bufsize:
fill = fifo.InFill.get()
# print fill
if fill >= bufsize:
fifo.Buffer.get(a)
# dump(a)
t += str(a)
l += len(a)
retry = 0
elif delay > 0.0:
print "Polling... %.1f s (retry %d).." % (delay, retry)
r.Throttle.set(0)
time.sleep(delay)
r.Throttle.set(throttle)
retry += 1
if retry > 10:
print "Got nothing for 10 retries"
break
if len(t) > len(should):
print "Truncated %d" % (len(t) - len(should))
t = t[:len(should)]
if should != t:
if len(t) != len(should):
print "Length mismatch"
else:
i = find_mismatch(should, t)
print "Position", i
dump(should[i:i+16])
dump(t[i:i+16])
f = open("dump.bin", "w")
f.write(t)
f.close()
else:
print "Buffer ok!"
dev = netpp.connect("localhost")
r = dev.sync()
enable = r.Enable
reset = r.Reset
enable.set(0)
reset.set(1)
time.sleep(0.1)
reset.set(0)
enable.set(1)
# r.Throttle.set(0)
# time.sleep(0.5)
# r.Throttle.set(1)
# time.sleep(0.1)
# test_blk(r, 512, 0)
# r.Throttle.set(0)
# time.sleep(0.5)
# r.Throttle.set(1)
# time.sleep(0.1)
# print "read block, throttled"
# test_blk(r, 64, 1, 0.0)
# d = buffer(20 * "0123456789")
# r.Fifo.Buffer.set(d)
print "read n blocks, accelerated"
for i in range(8 * 64):
test_blk(r, 512, 1, 1.0)
print "read n blocks, non-throttled"
for i in range(4):
test_blk(r, 512, 0, 0.0)
fifo = getattr(r, ":tb_soc:virtual_fifo:")
print 80 * "-"
print "Flush..."
while fifo.InFill.get() > 128:
test_blk(r, 128, 1, 0.1)
# Let FIFO flood:
r.Throttle.set(0)
time.sleep(0.2)
r.Throttle.set(1)
print "See if more data coming..."
try:
c = fifo.Buffer.get()
print "Had left in buffer:", len(c)
except TypeError:
print "Empty buffer"