Commit afc17628 authored by Federico Vaga's avatar Federico Vaga

sw:*: update fw framework variable support

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 244aa3cb
......@@ -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
......
......@@ -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",
......
......@@ -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;
}
......
......@@ -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);
......
Markdown is supported
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