Commit 6ebae692 authored by Federico Vaga's avatar Federico Vaga

sw:fw:frm: use only one action for variable get/set

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent afc17628
......@@ -145,98 +145,76 @@ static int trtl_fw_buffer_setter(struct trtl_fw_msg *msg_i, struct trtl_fw_msg *
/**
* This is an @ref trtl_fw_action_t function type. Accorind the message request,
* it copies a number of declared variables.
* it get/set a number of declared variables.
*/
static int trtl_fw_variable_getter(struct trtl_fw_msg *msg_i, struct trtl_fw_msg *msg_o)
static int trtl_fw_variable(struct trtl_fw_msg *msg_i, struct trtl_fw_msg *msg_o)
{
struct trtl_fw_variable_msg {
uint32_t index;
uint32_t value;
} *dout = NULL, *din = NULL;
struct trtl_fw_variable *var;
uint32_t *dout, *din , *mem, val;
uint32_t *mem, val;
int i;
if (!HAS_MOCKTURTLE_FRAMEWORK_VARIABLE_ENABLE) {
return -EPERM;
}
/* Only synchronous */
if (!(msg_i->header->flags & TRTL_HMQ_HEADER_FLAG_SYNC))
return -EINVAL;
/* we always have a pair of values */
if (msg_i->header->len & 0x1)
return -EINVAL;
din = msg_i->payload;
dout = msg_o->payload;
msg_o->header->msg_id = TRTL_MSG_ID_VAR_GET;
msg_o->header->len = msg_i->header->len;
/* Write all values in the proper place */
for (i = 0; i < msg_o->header->len; i += 2) {
if (din[i] >= app.n_variables) {
dout[i] = ~0; /* Report invalid index */
continue;
}
dout[i] = din[i];
var = &app.variables[dout[i]];
mem = (uint32_t *) var->addr;
val = (*mem >> var->offset) & var->mask;
dout[i + 1] = val;
pr_debug("%s index %"PRIu32"d/%d | [0x%p] = 0x%08"PRIx32" -> 0x%08"PRIx32" | index in msg (%d/%d)\n\r",
__func__,
dout[i], app.n_variables - 1,
mem, *mem, dout[i + 1],
i + 1, msg_i->header->len - 1);
}
return 0;
}
/**
* This is an @ref trtl_fw_action_t function type. Accorind the message request,
* it writes a number of declared variables. If the message is synchronous
* it copies back the values in the output payload.
*/
static int trtl_fw_variable_setter(struct trtl_fw_msg *msg_i, struct trtl_fw_msg *msg_o)
{
struct trtl_fw_variable *var;
uint32_t *din, *mem, val;
int i;
if (!HAS_MOCKTURTLE_FRAMEWORK_VARIABLE_ENABLE) {
return -EPERM;
}
/* we always have a pair of values */
if (msg_i->header->len & 0x1)
/* Only synchronous */
if (msg_i->header->msg_id == TRTL_MSG_ID_VAR_GET &&
!(msg_i->header->flags & TRTL_HMQ_HEADER_FLAG_SYNC))
return -EINVAL;
din = msg_i->payload;
if (msg_o) {
dout = msg_o->payload;
msg_o->header->msg_id = TRTL_MSG_ID_VAR_GET;
msg_o->header->len = msg_i->header->len;
}
/* Write all values in the proper place */
for (i = 0; i < msg_i->header->len; i += 2) {
if (din[i] >= app.n_variables)
continue;
var = &app.variables[din[i]];
mem = (uint32_t *) var->addr;
val = ((din[i + 1] & var->mask) << var->offset);
if (var->flags & TRTL_FW_VARIABLE_FLAG_FLD)
*mem = (*mem & ~var->mask) | val;
else
*mem = val;
for (i = 0; i < msg_i->header->len / 2; ++i) {
if (din[i].index >= app.n_variables) {
pr_error("%s: Variable index %ld unknown\n\r",
__func__, din[i].index);
return -EINVAL;
}
pr_debug("%s index %"PRIu32"/%d | [0x%p] = 0x%08"PRIx32" <- 0x%08"PRIx32" (0x%08"PRIx32") | index in msg (%d/%d)\n\r",
var = &app.variables[din[i].index];
mem = (uint32_t *) var->addr;
pr_debug("%s index %"PRIu32"d/%d | [0x%p] = 0x%08"PRIx32" -> 0x%08"PRIx32")\n\r",
__func__,
din[i], app.n_variables - 1,
mem, *mem, val, din[i + 1],
i + 1, msg_i->header->len - 1);
}
din[i].index, app.n_variables - 1,
mem, *mem, val);
switch (msg_i->header->msg_id) {
case TRTL_MSG_ID_VAR_SET:
val = ((din[i].value & var->mask) << var->offset);
if (var->flags & TRTL_FW_VARIABLE_FLAG_FLD)
*mem = (*mem & ~var->mask) | val;
else
*mem = val;
/* After a set we always read back => get */
case TRTL_MSG_ID_VAR_GET:
val = (*mem >> var->offset) & var->mask;
break;
default:
return -EINVAL;
}
/* Return back new values. Host can compare with what it sent
to spot errors */
if (msg_i->header->flags & TRTL_HMQ_HEADER_FLAG_SYNC)
return trtl_fw_variable_getter(msg_i, msg_o);
if (dout) {
/* when this is a synchronous action, we have to fill
the output */
dout[i].index = din[i].index;
dout[i].value = val;
}
}
return 0;
}
......@@ -248,8 +226,8 @@ static int trtl_fw_variable_setter(struct trtl_fw_msg *msg_i, struct trtl_fw_msg
static trtl_fw_action_t *trtl_actions_in[] = {
[TRTL_MSG_ID_PING - __TRTL_MSG_ID_MAX_USER] = rt_recv_ping,
[TRTL_MSG_ID_VER - __TRTL_MSG_ID_MAX_USER] = rt_version_getter,
[TRTL_MSG_ID_VAR_SET - __TRTL_MSG_ID_MAX_USER] = trtl_fw_variable_setter,
[TRTL_MSG_ID_VAR_GET - __TRTL_MSG_ID_MAX_USER] = trtl_fw_variable_getter,
[TRTL_MSG_ID_VAR_SET - __TRTL_MSG_ID_MAX_USER] = trtl_fw_variable,
[TRTL_MSG_ID_VAR_GET - __TRTL_MSG_ID_MAX_USER] = trtl_fw_variable,
[TRTL_MSG_ID_BUF_SET - __TRTL_MSG_ID_MAX_USER] = trtl_fw_buffer_setter,
[TRTL_MSG_ID_BUF_GET - __TRTL_MSG_ID_MAX_USER] = trtl_fw_buffer_getter,
};
......
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