My aim is to read some registers on the FPGA using python script. I have implemented some registers on the hardware (FPGA) and I am trying to read the registers.There are some programs in C which are able to read the registers. But I have to write the read/write program in python so that I can integrate it with my verifcation environment (written in python). I am new to python (beginner level) so I wish you can guide me through your suggestions and comments. Below is the code which I implemented.
This is my code.
#!/usr/bin/env python
import array
import fcntl
import re
import socket
import struct
import os
#connectedSockets = {}
# IOCTL Commands
SIOCREGREAD = 0x89F0
SIOCREGWRITE = 0x89F1
reg = 0x58000008
# open the NF descriptor
# Open a file
nf = os.open( "/dev/nf10", os.O_RDWR )
print "Opened NF descriptor"
# Now get a file object for the above file.
nf0 = os.fdopen(nf, "w+")
#print "opened nf0 file object"
inner_struct = struct.pack("II", reg, 0x0)
inner_struct_pinned = array.array('c', inner_struct)
print inner_struct_pinned
fcntl.ioctl(nf0, SIOCREGREAD,)
retval = struct.unpack("II", inner_struct_pinned)[0]
print retval
os.fdclose(nf)