xc7k480t/nitefury_pcie_xdma_ddr/dma_test.py

55 lines
1.3 KiB
Python

#!/usr/bin/env python3
import os
import time
##############################################
def Test(size=4096,addr=0):
# Generate some data
TRANSFER_SIZE = size
tx_data = bytearray(os.urandom(TRANSFER_SIZE))
# Open files
fd_h2c = os.open("/dev/xdma0_h2c_0", os.O_WRONLY)
fd_c2h = os.open("/dev/xdma0_c2h_0", os.O_RDONLY)
# Send data to FPGA
start = time.time()
os.pwrite(fd_h2c, tx_data, addr);
end = time.time()
duration = end-start;
# Print time
BPS = TRANSFER_SIZE / (duration);
print("Sent in " + str((duration)*1000.0) + " milliseconds (" + str(BPS/1000000) + " MBPS)")
# Receive data from FPGA
start = time.time()
rx_data = os.pread(fd_c2h, TRANSFER_SIZE, addr);
end = time.time()
duration = end-start;
# Print time
BPS = TRANSFER_SIZE / (duration);
print("Received in " + str((duration)*1000.0) + " milliseconds (" + str(BPS/1000000) + " MBPS)")
# Make sure data matches
if tx_data != rx_data:
print ("Whoops")
else:
print ("OK")
# done
os.close(fd_h2c)
os.close(fd_c2h)
##############################################
if __name__ == '__main__':
Test(8192,0x100000000)
Test(0x40000000,0x000000000)
Test(0x40000000,0x080000000)