Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
scouting-demonstrator
SCONE
Commits
cef468e0
Commit
cef468e0
authored
Feb 01, 2021
by
Gaia Grosso
Browse files
modified exceptions at line 116; changed variable reg at line 6 (used twice)
parent
e168c3ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
main.py
View file @
cef468e0
...
...
@@ -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"
:
"0x0000000
1
"
,
"location"
:
"0x0000000
0
"
,
"offset"
:
0
,
"width"
:
32
},
"register1"
:
{
"location"
:
"0x0000000
2
"
,
"location"
:
"0x0000000
4
"
,
"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
][
"regist
t
er"
][
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
>
3
0
:
if
offset
>
3
1
:
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
>
3
1
:
if
offset
+
width
>
3
2
:
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.'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment