reading registers in hw using python -
my aim read registers on fpga using python script. have implemented registers on hardware (fpga) , trying read registers.there programs in c able read registers. have write read/write program in python can integrate verifcation environment (written in python). new python (beginner level) wish can guide me through suggestions , comments. below code implemented.
this 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 nf descriptor # open file nf = os.open( "/dev/nf10", os.o_rdwr ) print "opened nf descriptor" # file object 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)
you won't able in pure python. if c code have in shared library (.dll in windows, .so in linux), may able access using ctypes module. if not, have wrap c code in either shared library or python extension module (more complex on c side, simpler on python side).
for examples of kind of thing, recommend o'reilly book "real world instrumentation python", j.m. hughes.
Comments
Post a Comment