Commit cef468e0 authored by Gaia Grosso's avatar Gaia Grosso
Browse files

modified exceptions at line 116; changed variable reg at line 6 (used twice)

parent e168c3ed
......@@ -3,7 +3,7 @@ import argparse
import math
import ctypes
so_file = "./functions.so"
reg = ctypes.CDLL(so_file)
cfunc = ctypes.CDLL(so_file)
# example of input format --> to be discussed and moved to json file
config_dict = {
......@@ -27,13 +27,13 @@ config_dict = {
"driver" : "/dev/wz-xdma1_user",
"register" : {
"register0" : {
"location": "0x00000001",
"location": "0x00000000",
"offset" : 0,
"width" : 32
},
"register1" : {
"location": "0x00000002",
"location": "0x00000004",
"offset" : 30,
"width" : 2
}
......@@ -48,7 +48,7 @@ actions = ["get", "set"]
def ReadProperty(device, location, offset, width, verbose=0):
read_32bits = ctypes.c_uint(0);
isRead = reg.read_bits(device, location, ctypes.byref(read_32bits), ctypes.c_uint(verbose))
isRead = cfunc.read_bits(device, location, ctypes.byref(read_32bits), ctypes.c_uint(verbose))
if isRead == -1:
print("An error occured while executing C function read_bits")
return -1
......@@ -63,7 +63,7 @@ def ReadProperty(device, location, offset, width, verbose=0):
def WriteProperty(device, location, offset, width, write_value, verbose=0):
read_value = ctypes.c_uint(0);
isRead = reg.read_bits(device, location, ctypes.byref(read_value), ctypes.c_uint(verbose))
isRead = cfunc.read_bits(device, location, ctypes.byref(read_value), ctypes.c_uint(verbose))
if isRead == -1:
print("An error occured while executing C function read_bits")
return -1
......@@ -75,7 +75,7 @@ def WriteProperty(device, location, offset, width, write_value, verbose=0):
mask = (2**width-1)<<offset
notmask = (2**32-1)-mask
output = ((write_value.value<<offset) & mask) | (read_value.value & notmask)
isWritten = reg.write_bits(device, location, output, ctypes.c_uint(verbose))
isWritten = cfunc.write_bits(device, location, output, ctypes.c_uint(verbose))
if isWritten == -1:
print("An error occured while executing C function write_bits.")
return -1
......@@ -106,20 +106,20 @@ if __name__ == '__main__':
reg = args.register
device = config_dict[board]["driver"]
location = config_dict[board]["register"][reg]["location"]
offset = config_dict[board]["registter"][reg]["offset"]
offset = config_dict[board]["register"][reg]["offset"]
width = config_dict[board]["register"][reg]["width"]
action = args.action
value = int(args.value)
value = args.value
verbose = args.dump
filelog = args.filelog
output = 0
# exceptions:
if offset > 30:
if offset > 31:
print("Offset value %i is out of range 0-30. Check the configuration file."%(offset))
exit()
if width == 0:
print("Width must be grater than 0. Check the configuration file.")
if offset+width > 31:
if offset+width > 32:
print("Mask ends out of range. Check the configuration file.")
exit()
......@@ -157,7 +157,7 @@ if __name__ == '__main__':
exit()
else:
writevalue = ctypes.c_uint(value) #unsigned int (32 bits)
writevalue = ctypes.c_uint(int(value)) #unsigned int (32 bits)
output = WriteProperty(device, location, offset, width, writevalue, verbose=verbose)
if output == -1:
print('The value could not be updated.')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment