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

View File

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