Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
mock-turtle
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
hdl-core-lib
mock-turtle
Commits
afc17628
Commit
afc17628
authored
May 08, 2018
by
Federico Vaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sw:*: update fw framework variable support
Signed-off-by:
Federico Vaga
<
federico.vaga@cern.ch
>
parent
244aa3cb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
42 deletions
+97
-42
PyMockTurtle.py
software/lib/PyMockTurtle/PyMockTurtle/PyMockTurtle.py
+52
-0
__init__.py
software/lib/PyMockTurtle/PyMockTurtle/__init__.py
+2
-0
libmockturtle-rt-msg.c
software/lib/libmockturtle-rt-msg.c
+40
-39
mockturtle-variable.c
software/tools/mockturtle-variable.c
+3
-3
No files found.
software/lib/PyMockTurtle/PyMockTurtle/PyMockTurtle.py
View file @
afc17628
...
...
@@ -297,6 +297,18 @@ class TrtlDevice(object):
POINTER
(
TrtlFirmwareVersion
)]
self
.
libtrtl
.
trtl_fw_version
.
restype
=
c_int
self
.
libtrtl
.
trtl_fw_version
.
errcheck
=
self
.
__errcheck_int
# FW VARIABLE
self
.
libtrtl
.
trtl_fw_variable_get
.
argtypes
=
[
c_void_p
,
c_uint
,
c_uint
,
POINTER
(
c_uint32
),
c_uint
]
self
.
libtrtl
.
trtl_fw_variable_get
.
restype
=
c_int
self
.
libtrtl
.
trtl_fw_variable_get
.
errcheck
=
self
.
__errcheck_int
self
.
libtrtl
.
trtl_fw_variable_set
.
argtypes
=
[
c_void_p
,
c_uint
,
c_uint
,
POINTER
(
c_uint32
),
c_uint
]
self
.
libtrtl
.
trtl_fw_variable_set
.
restype
=
c_int
self
.
libtrtl
.
trtl_fw_variable_set
.
errcheck
=
self
.
__errcheck_int
# self.libtrtl.trtl_hmq_filter_add.argtypes = [c_void_p]
# self.libtrtl.trtl_hmq_filter_clean.argtypes = [c_void_p]
# # Return
...
...
@@ -324,6 +336,46 @@ class TrtlDevice(object):
return
ret
class
TrtlFirmwareVariable
(
object
):
"""This class make it possible to use the firmware framework variable
feature like an array. Note that this implementation allows to access
elements one by one. By using the C library it is actually possible
to get/set multiple variables
"""
def
__init__
(
self
,
trtl_hmq
):
self
.
trtl_hmq
=
trtl_hmq
self
.
trtl_cpu
=
self
.
trtl_hmq
.
trtl_cpu
self
.
trtl_dev
=
self
.
trtl_cpu
.
trtl_dev
self
.
libtrtl
=
self
.
trtl_dev
.
libtrtl
def
__getitem__
(
self
,
key
):
try
:
val
=
(
c_uint32
*
2
)(
key
,
0
)
variables
=
cast
(
val
,
POINTER
(
c_uint32
))
self
.
libtrtl
.
trtl_fw_variable_get
(
self
.
trtl_dev
.
tkn
,
self
.
trtl_cpu
.
idx_cpu
,
self
.
trtl_hmq
.
idx_hmq
,
variables
,
1
)
return
val
[
1
]
except
OSError
as
e
:
# raise IndexError if this is the case
raise
e
def
__setitem__
(
self
,
key
,
value
):
try
:
val
=
(
c_uint32
*
2
)(
key
,
value
)
variables
=
cast
(
val
,
POINTER
(
c_uint32
))
self
.
libtrtl
.
trtl_fw_variable_set
(
self
.
trtl_dev
.
tkn
,
self
.
trtl_cpu
.
idx_cpu
,
self
.
trtl_hmq
.
idx_hmq
,
variables
,
1
)
except
OSError
as
e
:
# raise IndexError if this is the case
raise
e
class
TrtlCpu
(
object
):
"""
It is a Python class that represents a Mock Turtle device CPU
...
...
software/lib/PyMockTurtle/PyMockTurtle/__init__.py
View file @
afc17628
...
...
@@ -10,6 +10,7 @@ SPDX-License-Identifier: LGPL-3.0-or-later
from
.PyMockTurtle
import
TrtlHmqHeader
,
TrtlMessage
,
TrtlConfig
,
\
TrtlCpu
,
TrtlHmq
,
TrtlSmem
,
TrtlDevice
,
\
TrtlFirmwareVersion
,
TrtlConfigMq
,
\
TrtlFirmwareVariable
,
\
TRTL_CONFIG_ROM_MAX_CPU
,
\
TRTL_CONFIG_ROM_MAX_HMQ
,
\
TRTL_CONFIG_ROM_MAX_RMQ
...
...
@@ -24,6 +25,7 @@ __all__ = (
"TrtlConfig"
,
"TrtlConfigMq"
,
"TrtlFirmwareVersion"
,
"TrtlFirmwareVariable"
,
"TRTL_CONFIG_ROM_MAX_CPU"
,
"TRTL_CONFIG_ROM_MAX_HMQ"
,
"TRTL_CONFIG_ROM_MAX_RMQ"
,
...
...
software/lib/libmockturtle-rt-msg.c
View file @
afc17628
...
...
@@ -83,6 +83,40 @@ int trtl_fw_ping(struct trtl_dev *trtl,
return
0
;
}
static
int
__trtl_fw_variable
(
struct
trtl_dev
*
trtl
,
unsigned
int
idx_cpu
,
unsigned
int
idx_hmq
,
uint32_t
*
variables
,
unsigned
int
n_variables
,
unsigned
int
msg_id
)
{
struct
trtl_desc
*
wdesc
=
(
struct
trtl_desc
*
)
trtl
;
struct
trtl_msg
msg
;
int
err
;
memset
(
&
msg
,
0
,
sizeof
(
struct
trtl_msg
));
msg
.
hdr
.
msg_id
=
msg_id
;
msg
.
hdr
.
seq
=
wdesc
->
seq
;
msg
.
hdr
.
sync_id
=
msg
.
hdr
.
seq
;
msg
.
hdr
.
flags
=
TRTL_HMQ_HEADER_FLAG_RPC
;
msg
.
hdr
.
len
=
2
*
n_variables
;
memcpy
(
msg
.
data
,
variables
,
sizeof
(
uint32_t
)
*
msg
.
hdr
.
len
);
err
=
trtl_msg_sync
(
trtl
,
idx_cpu
,
idx_hmq
,
&
msg
,
&
msg
,
trtl_default_timeout_ms
);
if
(
err
<
0
)
return
-
1
;
if
(
msg
.
hdr
.
msg_id
!=
TRTL_MSG_ID_VAR_GET
)
{
/* Yes, it answers with GET even on SET */
errno
=
ETRTL_INVALID_MESSAGE
;
return
-
1
;
}
memcpy
(
variables
,
msg
.
data
,
sizeof
(
uint32_t
)
*
msg
.
hdr
.
len
);
return
0
;
}
/**
* It sends/receive a set of variables to/from the Real-Time application.
...
...
@@ -120,26 +154,9 @@ int trtl_fw_variable_set(struct trtl_dev *trtl,
uint32_t
*
variables
,
unsigned
int
n_variables
)
{
struct
trtl_desc
*
wdesc
=
(
struct
trtl_desc
*
)
trtl
;
struct
trtl_msg
msg
;
int
err
;
memset
(
&
msg
,
0
,
sizeof
(
struct
trtl_msg
));
msg
.
hdr
.
msg_id
=
TRTL_MSG_ID_VAR_GET
;
msg
.
hdr
.
seq
=
wdesc
->
seq
;
msg
.
hdr
.
sync_id
=
msg
.
hdr
.
seq
;
memcpy
(
msg
.
data
,
variables
,
sizeof
(
uint32_t
)
*
n_variables
);
err
=
trtl_msg_sync
(
trtl
,
idx_cpu
,
idx_hmq
,
&
msg
,
&
msg
,
trtl_default_timeout_ms
);
if
(
err
<=
0
)
return
-
1
;
memcpy
(
variables
,
msg
.
data
,
sizeof
(
uint32_t
)
*
n_variables
);
return
0
;
return
__trtl_fw_variable
(
trtl
,
idx_cpu
,
idx_hmq
,
variables
,
n_variables
,
TRTL_MSG_ID_VAR_SET
);
}
...
...
@@ -176,26 +193,10 @@ int trtl_fw_variable_get(struct trtl_dev *trtl,
uint32_t
*
variables
,
unsigned
int
n_variables
)
{
struct
trtl_desc
*
wdesc
=
(
struct
trtl_desc
*
)
trtl
;
struct
trtl_msg
msg
;
int
err
;
return
__trtl_fw_variable
(
trtl
,
idx_cpu
,
idx_hmq
,
variables
,
n_variables
,
TRTL_MSG_ID_VAR_GET
)
;
memset
(
&
msg
,
0
,
sizeof
(
struct
trtl_msg
));
msg
.
hdr
.
msg_id
=
TRTL_MSG_ID_VAR_GET
;
msg
.
hdr
.
seq
=
wdesc
->
seq
;
msg
.
hdr
.
sync_id
=
msg
.
hdr
.
seq
;
memcpy
(
msg
.
data
,
variables
,
sizeof
(
uint32_t
)
*
n_variables
);
err
=
trtl_msg_sync
(
trtl
,
idx_cpu
,
idx_hmq
,
&
msg
,
&
msg
,
trtl_default_timeout_ms
);
if
(
err
<=
0
)
return
-
1
;
memcpy
(
variables
,
msg
.
data
,
sizeof
(
uint32_t
)
*
n_variables
);
return
0
;
}
...
...
software/tools/mockturtle-variable.c
View file @
afc17628
...
...
@@ -25,12 +25,12 @@ static void help(char *name)
{
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"%s -D 0x<hex-number> -
i <number> -o
<number> [write <idx> <value> <idx> <value> ...] [read <idx> <idx> ...]
\n\n
"
,
"%s -D 0x<hex-number> -
c <number> -q
<number> [write <idx> <value> <idx> <value> ...] [read <idx> <idx> ...]
\n\n
"
,
name
);
fprintf
(
stderr
,
"It reads/writes variables on a HMQ
\n\n
"
);
fprintf
(
stderr
,
"-D device identificator in hexadecimal format
\n
"
);
fprintf
(
stderr
,
"-
i slot index where send
\n
"
);
fprintf
(
stderr
,
"-
o slot index where receive
\n
"
);
fprintf
(
stderr
,
"-
c CPU core index
\n
"
);
fprintf
(
stderr
,
"-
q HMQ index
\n
"
);
fprintf
(
stderr
,
"-h show this help
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
exit
(
1
);
...
...
Write
Preview
Markdown
is supported
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