2020-11-23 11:11:52 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteEth
|
|
|
|
#
|
|
|
|
# Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
# LiteEth Etherbone test utility.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
from litex import RemoteClient
|
2020-11-25 09:15:08 -05:00
|
|
|
from litex.tools.remote.comm_udp import CommUDP
|
|
|
|
|
|
|
|
# Constants ----------------------------------------------------------------------------------------
|
2020-11-23 11:11:52 -05:00
|
|
|
|
2020-11-23 11:36:54 -05:00
|
|
|
KiB = 1024
|
|
|
|
MiB = 1024*KiB
|
|
|
|
|
2020-11-25 09:15:08 -05:00
|
|
|
comms = {
|
|
|
|
"cli": RemoteClient,
|
|
|
|
"udp": CommUDP
|
|
|
|
}
|
|
|
|
|
2020-11-23 11:11:52 -05:00
|
|
|
# Identifier Test ----------------------------------------------------------------------------------
|
|
|
|
|
2020-11-25 09:15:08 -05:00
|
|
|
def ident_test(comm, port):
|
|
|
|
wb = comms[comm](port=port, csr_csv="csr.csv")
|
2020-11-23 11:11:52 -05:00
|
|
|
wb.open()
|
|
|
|
|
|
|
|
fpga_identifier = ""
|
|
|
|
|
|
|
|
for i in range(256):
|
|
|
|
c = chr(wb.read(wb.bases.identifier_mem + 4*i) & 0xff)
|
|
|
|
fpga_identifier += c
|
|
|
|
if c == "\0":
|
|
|
|
break
|
|
|
|
|
|
|
|
print(fpga_identifier)
|
|
|
|
|
|
|
|
wb.close()
|
|
|
|
|
|
|
|
# Access Test --------------------------------------------------------------------------------------
|
|
|
|
|
2020-11-25 09:15:08 -05:00
|
|
|
def access_test(comm, port):
|
|
|
|
wb = comms[comm](port=port, csr_csv="csr.csv")
|
2020-11-23 11:11:52 -05:00
|
|
|
wb.open()
|
|
|
|
|
|
|
|
data = 0x12345678
|
|
|
|
addr = 0x100
|
|
|
|
|
|
|
|
print("Write over Etherbone at 0x{:08x}: 0x{:08x}.".format(addr, data))
|
|
|
|
wb.write(wb.mems.sram.base + addr, data)
|
|
|
|
print("Read over Etherbone at 0x{:08x}: 0x{:08x}.".format(addr, wb.read(wb.mems.sram.base + addr)))
|
|
|
|
|
|
|
|
wb.close()
|
|
|
|
|
|
|
|
# SRAM Test ----------------------------------------------------------------------------------------
|
|
|
|
|
2020-11-25 09:15:08 -05:00
|
|
|
def sram_test(comm, port):
|
|
|
|
wb = comms[comm](port=port, csr_csv="csr.csv")
|
2020-11-23 11:11:52 -05:00
|
|
|
wb.open()
|
|
|
|
|
|
|
|
def mem_dump(base, length):
|
|
|
|
for addr in range(base, base + length, 4):
|
|
|
|
if (addr%16 == 0):
|
|
|
|
if addr != base:
|
|
|
|
print("")
|
|
|
|
print("0x{:08x}".format(addr), end=" ")
|
|
|
|
data = wb.read(addr)
|
|
|
|
for i in reversed(range(4)):
|
|
|
|
print("{:02x}".format((data >> (8*i)) & 0xff), end=" ")
|
|
|
|
print("")
|
|
|
|
|
|
|
|
def mem_write(base, datas):
|
|
|
|
for n, addr in enumerate(range(base, base + 4*len(datas), 4)):
|
|
|
|
if (addr%16 == 0):
|
|
|
|
if addr != base:
|
|
|
|
print("")
|
|
|
|
print("0x{:08x}".format(addr), end=" ")
|
|
|
|
data = datas[n]
|
|
|
|
for i in reversed(range(4)):
|
|
|
|
print("{:02x}".format((data >> (8*i)) & 0xff), end=" ")
|
|
|
|
wb.write(addr, data)
|
|
|
|
print("")
|
|
|
|
|
|
|
|
|
|
|
|
print("Fill SRAM with counter:")
|
|
|
|
mem_write(wb.mems.sram.base, [i for i in range(128//4)])
|
|
|
|
print("")
|
|
|
|
|
|
|
|
print("Dump SRAM:")
|
|
|
|
mem_dump(wb.mems.sram.base, 128)
|
|
|
|
print("")
|
|
|
|
|
|
|
|
print("Fill SRAM with 4 32-bit words:")
|
|
|
|
mem_write(wb.mems.sram.base, [0x01234567, 0x89abcdef, 0x5aa55aa5, 0xa55aa55a])
|
|
|
|
print("")
|
|
|
|
|
|
|
|
print("Dump SRAM:")
|
|
|
|
mem_dump(wb.mems.sram.base, 128)
|
|
|
|
print("")
|
|
|
|
|
|
|
|
wb.close()
|
|
|
|
|
2020-11-23 11:36:54 -05:00
|
|
|
# Speed Test ---------------------------------------------------------------------------------------
|
|
|
|
|
2020-11-25 09:15:08 -05:00
|
|
|
def speed_test(comm, port):
|
|
|
|
wb = comms[comm](port=port, csr_csv="csr.csv")
|
2020-11-23 11:36:54 -05:00
|
|
|
wb.open()
|
|
|
|
|
2020-11-24 13:46:43 -05:00
|
|
|
test_size = 16*KiB
|
2020-11-26 05:36:12 -05:00
|
|
|
burst_size = 255
|
2020-11-23 11:36:54 -05:00
|
|
|
|
|
|
|
print("Testing write speed... ", end="")
|
|
|
|
start = time.time()
|
2020-11-24 13:46:43 -05:00
|
|
|
for i in range(test_size//(4*burst_size)):
|
|
|
|
wb.write(wb.mems.sram.base, [j for j in range(burst_size)])
|
2020-11-23 11:36:54 -05:00
|
|
|
end = time.time()
|
|
|
|
duration = (end - start)
|
2020-11-25 09:15:08 -05:00
|
|
|
print("{:8.2f} KiB/s".format(test_size/(duration*KiB)))
|
2020-11-23 11:36:54 -05:00
|
|
|
|
2020-11-25 09:15:08 -05:00
|
|
|
print("Testing read speed... ", end="")
|
2020-11-23 11:36:54 -05:00
|
|
|
start = time.time()
|
2020-11-24 13:46:43 -05:00
|
|
|
for i in range(test_size//(4*burst_size)):
|
|
|
|
wb.read(wb.mems.sram.base, length=burst_size)
|
2020-11-23 11:36:54 -05:00
|
|
|
end = time.time()
|
|
|
|
duration = (end - start)
|
2020-11-25 09:15:08 -05:00
|
|
|
print("{:8.2f} KiB/s".format(test_size/(duration*KiB)))
|
2020-11-23 11:36:54 -05:00
|
|
|
|
|
|
|
wb.close()
|
|
|
|
|
2020-11-23 11:11:52 -05:00
|
|
|
# Run ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="LiteEth Etherbone test utility")
|
|
|
|
parser.add_argument("--port", default="1234", help="Host bind port")
|
2020-11-25 09:15:08 -05:00
|
|
|
parser.add_argument("--udp", action="store_true", help="Use CommUDP directly instead of RemoteClient")
|
2020-11-23 11:11:52 -05:00
|
|
|
parser.add_argument("--ident", action="store_true", help="Read FPGA identifier")
|
|
|
|
parser.add_argument("--access", action="store_true", help="Test single Write/Read access over Etherbone")
|
|
|
|
parser.add_argument("--sram", action="store_true", help="Test SRAM access over Etherbone")
|
2020-11-23 11:36:54 -05:00
|
|
|
parser.add_argument("--speed", action="store_true", help="Test speed over Etherbone")
|
2020-11-23 11:11:52 -05:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
port = int(args.port, 0)
|
2020-11-25 09:15:08 -05:00
|
|
|
comm = "cli" if not args.udp else "udp"
|
2020-11-23 11:11:52 -05:00
|
|
|
|
|
|
|
if args.ident:
|
2020-11-25 09:15:08 -05:00
|
|
|
ident_test(comm=comm, port=port)
|
2020-11-23 11:11:52 -05:00
|
|
|
|
|
|
|
if args.access:
|
2020-11-25 09:15:08 -05:00
|
|
|
access_test(comm=comm, port=port)
|
2020-11-23 11:11:52 -05:00
|
|
|
|
|
|
|
if args.sram:
|
2020-11-25 09:15:08 -05:00
|
|
|
sram_test(comm=comm, port=port)
|
2020-11-23 11:11:52 -05:00
|
|
|
|
2020-11-23 11:36:54 -05:00
|
|
|
if args.speed:
|
2020-11-25 09:15:08 -05:00
|
|
|
speed_test(comm=comm, port=port)
|
2020-11-23 11:36:54 -05:00
|
|
|
|
2020-11-23 11:11:52 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|