I am currently working with Petalinux project which I am trying to read/write data from-to /dev/mem actually connected to 2 BRAM modules.
DMABRAM1 = "/amba_pl@0/axi_bram_ctrl@a0000000";
DMABRAM2 = "/amba_pl@0/axi_bram_ctrl@a0004000";
axi_bram_ctrl@a0000000 {
xlnx,single-port-bram = <0x01>;
xlnx,bram-inst-mode = "EXTERNAL";
compatible = "xlnx,axi-bram-ctrl-4.1";
xlnx,bram-addr-width = <0x0a>;
axi_bram_ctrl@a0004000 {
xlnx,single-port-bram = <0x01>;
xlnx,bram-inst-mode = "EXTERNAL";
compatible = "xlnx,axi-bram-ctrl-4.1";
xlnx,bram-addr-width = <0x0a>;
def read_addr(mem, addr, length):
global MAP_MASK #which is mmap.PAGESIZE - 1
mem.seek(addr & MAP_MASK)
val = 0x0
for i in range(length):
val |= mem.read_byte() << (i * 8)
return val
BRAM_1_BASE = 0xa0000000
f = os.open("/dev/mem", os.O_RDWR | os.O_SYNC)
mem = mmap.mmap(f, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_READ | mmap.PROT_WRITE,offset=BRAM_1_BASE & ~MAP_MASK)
#timer starts here..
while BRAM_1_BASE < 0xa0004000:
read_addr(mem, BRAM_1_BASE, length=128)
BRAM_1_BASE = BRAM_1_BASE + 0x80
#timer ends here..
I tried using threads and coroutines, also changed length and BRAM_BASE increment but the maximum speed I can get is close to 1MBps. I also tested the speed with dd command from dev/mem to dev/zero and got 1.3GBps.
I divide 1 by time interval and calculate the multiplication with 16384 to get speed in KBps unit.
I strongly believe that I am doing something wrong but can not solve the problem.
Thanks.