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!"
def set_break(r, addr): "Patch BREAK at pc-1 with NOP instruction to resume on next run" r.VRAM.Offset.set(addr) b = netpp.Buffer(1) # Buffer var to read r.VRAM.Buffer.get(b) prev = b print("Instruction: %02x" % ord(b[0])) bpt = buffer(chr(0)) # Breakpoint r.VRAM.Buffer.set(bpt) return prev
def mem_get_long(soc, addr, n): hi = netpp.Buffer(n * 2) lo = netpp.Buffer(n * 2) addr >>= 1 soc.VRAM_L.Offset.set(addr) soc.VRAM_H.Offset.set(addr) soc.VRAM_H.Buffer.get(hi) soc.VRAM_L.Buffer.get(lo) l = range(len(hi) / 2) print "%02x %02x" % (ord(lo[0]), ord(lo[1])) print "%02x %02x" % (ord(hi[0]), ord(hi[1])) data32 = [ struct.unpack(">L", (hi[i * 2:i * 2 + 2] + lo[i * 2:i * 2 + 2]))[0] for i in l ] return data32
def run_test(r): bus = r.TAP # Local bus buf = netpp.Buffer(32) r.localbus.Addr.set(0) r.localbus.DataBurst.get(buf) dump(buf) a = bus.Data.get() print "dumb method get:" r.localbus.Addr.set(0) b = r.localbus.DataBurst.get() dump(b) b = r.localbus.DataBurst.get() dump(b) b = r.localbus.DataBurst.get() dump(b) # Global bus (accessible through properties) r.SimThrottle.set(0) # Turn off Throttle a = r.SimThrottle.get() # Dummy read to make sure the SimThrottle/off is # effective before we continue # Dump the first 8 addresses: for i in range(8): bus.Addr.set(i) print "Data [%d]: %08x" % (i, bus.Data.get() & 0xffffffff) r.SimThrottle.set(1) # Resume Throttle a = r.SimThrottle.get() # Dummy read to make sure the SimThrottle/off is # The local bus can only be accessed directly, no netpp properties # map to it. r.localbus.Addr.set(0) magic = r.localbus.Data.get() if magic != 0xbaadf00d: print "WARNING: Unsigned integer return. FIXME (Python API)." if magic & 0xffffffff != 0xbaadf00d: print hex(magic) raise ValueError, "Failed to read magic from local bus" return True