etherbone: simplify model usage

This commit is contained in:
Florent Kermarrec 2015-02-12 12:09:39 +01:00
parent a2455b19af
commit b6aeea676b
2 changed files with 31 additions and 24 deletions

View File

@ -63,10 +63,8 @@ class TB(Module):
for i in range(8):
# test writes
if test_writes:
writes = etherbone.EtherboneWrites(base_addr=0x1000)
writes_data = [j for j in range(16)]
for write_data in writes_data:
writes.add(etherbone.EtherboneWrite(write_data))
writes_datas = [j for j in range(16)]
writes = etherbone.EtherboneWrites(base_addr=0x1000, datas=writes_datas)
record = etherbone.EtherboneRecord()
record.writes = writes
record.reads = None
@ -77,7 +75,7 @@ class TB(Module):
record.wca = 0
record.wff = 0
record.byte_enable = 0xf
record.wcount = 16
record.wcount = len(writes_datas)
record.rcount = 0
packet = etherbone.EtherbonePacket()
@ -88,10 +86,8 @@ class TB(Module):
# test reads
if test_reads:
reads = etherbone.EtherboneReads(base_ret_addr=0x1000)
reads_address = [j for j in range(16)]
for read_address in reads_address:
reads.add(etherbone.EtherboneRead(read_address))
reads_addrs = [j for j in range(16)]
reads = etherbone.EtherboneReads(base_ret_addr=0x1000, addrs=reads_addrs)
record = etherbone.EtherboneRecord()
record.writes = None
record.reads = reads
@ -103,18 +99,17 @@ class TB(Module):
record.wff = 0
record.byte_enable = 0xf
record.wcount = 0
record.rcount = 16
record.rcount = len(reads_addrs)
packet = etherbone.EtherbonePacket()
packet.records = [record]
self.etherbone_model.send(packet)
yield from self.etherbone_model.receive()
loopback_writes_data = []
for write in self.etherbone_model.rx_packet.records.pop().writes.writes:
loopback_writes_data.append(write.data)
loopback_writes_datas = []
loopback_writes_datas = self.etherbone_model.rx_packet.records.pop().writes.get_datas()
# check results
s, l, e = check(writes_data, loopback_writes_data)
s, l, e = check(writes_datas, loopback_writes_datas)
print("shift "+ str(s) + " / length " + str(l) + " / errors " + str(e))
if __name__ == "__main__":

View File

@ -24,15 +24,23 @@ class EtherboneRead:
return "RD32 @ 0x{:08x}".format(self.addr)
class EtherboneWrites(Packet):
def __init__(self, init=[], base_addr=0):
def __init__(self, init=[], base_addr=0, datas=[]):
Packet.__init__(self, init)
self.base_addr = base_addr
self.writes = []
self.encoded = init != []
for data in datas:
self.add(EtherboneWrite(data))
def add(self, write):
self.writes.append(write)
def get_datas(self):
datas = []
for write in self.writes:
datas.append(write.data)
return datas
def encode(self):
if self.encoded:
raise ValueError
@ -67,15 +75,23 @@ class EtherboneWrites(Packet):
return r
class EtherboneReads(Packet):
def __init__(self, init=[], base_ret_addr=0):
def __init__(self, init=[], base_ret_addr=0, addrs=[]):
Packet.__init__(self, init)
self.base_ret_addr = base_ret_addr
self.reads = []
self.encoded = init != []
for addr in addrs:
self.add(EtherboneRead(addr))
def add(self, read):
self.reads.append(read)
def get_addrs(self):
addrs = []
for read in self.reads:
addrs.append(read.addr)
return addrs
def encode(self):
if self.encoded:
raise ValueError
@ -301,12 +317,8 @@ class Etherbone(Module):
if __name__ == "__main__":
# Writes/Reads
writes = EtherboneWrites(base_addr=0x1000)
for i in range(16):
writes.add(EtherboneWrite(i))
reads = EtherboneReads(base_ret_addr=0x2000)
for i in range(16):
reads.add(EtherboneRead(i))
writes = EtherboneWrites(base_addr=0x1000, datas=[i for i in range(16)])
reads = EtherboneReads(base_ret_addr=0x2000, addrs=[i for i in range(16)])
# Record
record = EtherboneRecord()
@ -319,8 +331,8 @@ if __name__ == "__main__":
record.wca = 0
record.wff = 0
record.byte_enable = 0
record.wcount = 16
record.rcount = 16
record.wcount = len(writes.get_datas())
record.rcount = len(reads.get_addrs())
# Packet
packet = EtherbonePacket()