tools/remove/etherbone: cosmetic cleanup, add assert for maximum burst size (255).
This commit is contained in:
parent
6fe2bcd1f0
commit
9b696373a2
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
# This file is part of LiteX.
|
# This file is part of LiteX.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2015-2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
# Copyright (c) 2015-2020 Florent Kermarrec <florent@enjoy-digital.fr>
|
||||||
# Copyright (c) 2017 Tim Ansell <mithro@mithis.com>
|
# Copyright (c) 2017 Tim Ansell <mithro@mithis.com>
|
||||||
# SPDX-License-Identifier: BSD-2-Clause
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import struct
|
||||||
|
|
||||||
from litex.soc.interconnect.packet import HeaderField, Header
|
from litex.soc.interconnect.packet import HeaderField, Header
|
||||||
|
|
||||||
|
# Etherbone Constants / Headers / Helpers ----------------------------------------------------------
|
||||||
|
|
||||||
etherbone_magic = 0x4e6f
|
etherbone_magic = 0x4e6f
|
||||||
etherbone_version = 1
|
etherbone_version = 1
|
||||||
|
@ -25,12 +26,12 @@ etherbone_packet_header_fields = {
|
||||||
"addr_size": HeaderField(3, 4, 4), # 1=8bits, 2=16bits, 4=32bits, 8=64bits
|
"addr_size": HeaderField(3, 4, 4), # 1=8bits, 2=16bits, 4=32bits, 8=64bits
|
||||||
"port_size": HeaderField(3, 0, 4), # Same as above
|
"port_size": HeaderField(3, 0, 4), # Same as above
|
||||||
}
|
}
|
||||||
etherbone_packet_header = Header(etherbone_packet_header_fields,
|
etherbone_packet_header = Header(
|
||||||
etherbone_packet_header_length,
|
fields = etherbone_packet_header_fields,
|
||||||
swap_field_bytes=True)
|
length = etherbone_packet_header_length,
|
||||||
|
swap_field_bytes = True)
|
||||||
|
|
||||||
|
|
||||||
# When reading/writing to a FIFO, you don't increase
|
|
||||||
# the address after each write.
|
|
||||||
etherbone_record_header_length = 4
|
etherbone_record_header_length = 4
|
||||||
etherbone_record_header_fields = {
|
etherbone_record_header_fields = {
|
||||||
"bca": HeaderField(0, 0, 1), # ReplyToCfgSpace - ??? (C)onfig (A)dress
|
"bca": HeaderField(0, 0, 1), # ReplyToCfgSpace - ??? (C)onfig (A)dress
|
||||||
|
@ -46,9 +47,10 @@ etherbone_record_header_fields = {
|
||||||
|
|
||||||
"rcount": HeaderField(3, 0, 8), # Reads
|
"rcount": HeaderField(3, 0, 8), # Reads
|
||||||
}
|
}
|
||||||
etherbone_record_header = Header(etherbone_record_header_fields,
|
etherbone_record_header = Header(
|
||||||
etherbone_record_header_length,
|
fields = etherbone_record_header_fields,
|
||||||
swap_field_bytes=True)
|
length = etherbone_record_header_length,
|
||||||
|
swap_field_bytes = True)
|
||||||
|
|
||||||
|
|
||||||
def split_bytes(v, n, endianness="big"):
|
def split_bytes(v, n, endianness="big"):
|
||||||
|
@ -64,6 +66,7 @@ def get_field_data(field, datas):
|
||||||
v = merge_bytes(datas[field.byte:field.byte+math.ceil(field.width/8)])
|
v = merge_bytes(datas[field.byte:field.byte+math.ceil(field.width/8)])
|
||||||
return (v >> field.offset) & (2**field.width-1)
|
return (v >> field.offset) & (2**field.width-1)
|
||||||
|
|
||||||
|
# Packet -------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class Packet(list):
|
class Packet(list):
|
||||||
def __init__(self, init=[]):
|
def __init__(self, init=[]):
|
||||||
|
@ -72,6 +75,7 @@ class Packet(list):
|
||||||
for data in init:
|
for data in init:
|
||||||
self.append(data)
|
self.append(data)
|
||||||
|
|
||||||
|
# Etherbone Write / Read ---------------------------------------------------------------------------
|
||||||
|
|
||||||
class EtherboneWrite:
|
class EtherboneWrite:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
|
@ -88,9 +92,12 @@ class EtherboneRead:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "RD32 @ 0x{:08x}".format(self.addr)
|
return "RD32 @ 0x{:08x}".format(self.addr)
|
||||||
|
|
||||||
|
# Etherbone Writes ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
class EtherboneWrites(Packet):
|
class EtherboneWrites(Packet):
|
||||||
def __init__(self, init=[], base_addr=0, datas=[]):
|
def __init__(self, init=[], base_addr=0, datas=[]):
|
||||||
|
if isinstance(datas, list) and len(datas) > 255:
|
||||||
|
raise ValueError(f"Burst size of {len(datas)} exceeds maximum of 255 allowed by Etherbone.")
|
||||||
Packet.__init__(self, init)
|
Packet.__init__(self, init)
|
||||||
self.base_addr = base_addr
|
self.base_addr = base_addr
|
||||||
self.writes = []
|
self.writes = []
|
||||||
|
@ -140,9 +147,12 @@ class EtherboneWrites(Packet):
|
||||||
r += write.__repr__() + "\n"
|
r += write.__repr__() + "\n"
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
# Etherbone Reads ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
class EtherboneReads(Packet):
|
class EtherboneReads(Packet):
|
||||||
def __init__(self, init=[], base_ret_addr=0, addrs=[]):
|
def __init__(self, init=[], base_ret_addr=0, addrs=[]):
|
||||||
|
if isinstance(addrs, list) and len(addrs) > 255:
|
||||||
|
raise ValueError(f"Burst size of {len(addrs)} exceeds maximum of 255 allowed by Etherbone.")
|
||||||
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 = []
|
||||||
|
@ -192,6 +202,7 @@ class EtherboneReads(Packet):
|
||||||
r += read.__repr__() + "\n"
|
r += read.__repr__() + "\n"
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
# Etherbone Record ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
class EtherboneRecord(Packet):
|
class EtherboneRecord(Packet):
|
||||||
def __init__(self, init=[]):
|
def __init__(self, init=[]):
|
||||||
|
@ -288,6 +299,7 @@ class EtherboneRecord(Packet):
|
||||||
r += self.reads.__repr__()
|
r += self.reads.__repr__()
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
# Etherbone Packet ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
class EtherbonePacket(Packet):
|
class EtherbonePacket(Packet):
|
||||||
def __init__(self, init=[]):
|
def __init__(self, init=[]):
|
||||||
|
@ -356,6 +368,7 @@ class EtherbonePacket(Packet):
|
||||||
r += record.__repr__(i)
|
r += record.__repr__(i)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
# Etherbone IPC ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class EtherboneIPC:
|
class EtherboneIPC:
|
||||||
def send_packet(self, socket, packet):
|
def send_packet(self, socket, packet):
|
||||||
|
|
Loading…
Reference in New Issue