Commit e6026e35 authored by Federico Vaga's avatar Federico Vaga

wrtd:lib:out: reduce code duplication

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>


NOTE
This commit has been created by `git subtree` on the Mock Turtle repository
on tag mock-turtle-2.0

This commit will not compile
parent 07b9114b
......@@ -105,9 +105,8 @@ static int wrtd_out_trigger_index_get(struct wrtd_desc *wrtd,
return msg.data[sizeof(struct wrnc_proto_header) / 4];
}
static inline int wrtd_out_trigger_hash(struct wrtd_desc *wrtd, uint32_t tid,
uint8_t msgid)
static int wrtd_out_action_one_word(struct wrtd_desc *wrtd,
uint8_t msgid, uint32_t word)
{
struct wrnc_proto_header hdr = {
.msg_id = msgid,
......@@ -122,13 +121,14 @@ static inline int wrtd_out_trigger_hash(struct wrtd_desc *wrtd, uint32_t tid,
memset(&msg, 0, sizeof(struct wrnc_msg));
data = &msg.data[sizeof(struct wrnc_proto_header) / 4];
data[0] = tid;
data[0] = word;
wrnc_message_header_set(&msg, &hdr);
msg.datalen = sizeof(struct wrnc_proto_header) / 4 + hdr.len;
err = wrtd_out_send_and_receive_sync(wrtd, &msg);
if (err)
return -1;
wrnc_message_header_get(&msg, &hdr);
if (hdr.msg_id != RT_ACTION_SEND_ACK) {
errno = EWRTD_INVALID_ANSWER_ACK;
return -1;
......@@ -137,45 +137,21 @@ static inline int wrtd_out_trigger_hash(struct wrtd_desc *wrtd, uint32_t tid,
return 0;
}
static int wrtd_out_trigger_insert(struct wrtd_desc *wrtd, uint32_t tid)
static inline int wrtd_out_trigger_insert(struct wrtd_desc *wrtd, uint32_t tid)
{
return wrtd_out_trigger_hash(wrtd, tid, WRTD_OUT_ACTION_TRIG_ADD);
return wrtd_out_action_one_word(wrtd, WRTD_OUT_ACTION_TRIG_ADD, tid);
}
static int wrtd_out_trigger_remove(struct wrtd_desc *wrtd, uint32_t tid)
static inline int wrtd_out_trigger_remove(struct wrtd_desc *wrtd, uint32_t tid)
{
return wrtd_out_trigger_hash(wrtd, tid, WRTD_OUT_ACTION_TRIG_DEL);
return wrtd_out_action_one_word(wrtd, WRTD_OUT_ACTION_TRIG_DEL, tid);
}
static int wrtd_out_rt_disable(struct wrtd_desc *wrtd, unsigned int output)
static inline int wrtd_out_rt_disable(struct wrtd_desc *wrtd,
unsigned int output)
{
struct wrnc_proto_header hdr = {
.msg_id = WRTD_OUT_ACTION_DISABLE,
.slot_io = (WRTD_IN_FD_CONTROL << 4) |
(WRTD_OUT_FD_CONTROL & 0xF),
.flags = WRNC_PROTO_FLAG_SYNC,
.len = 1,
};
struct wrnc_msg msg;
uint32_t *data;
int err;
memset(&msg, 0, sizeof(struct wrnc_msg));
data = &msg.data[sizeof(struct wrnc_proto_header) / 4];
data[0] = output;
wrnc_message_header_set(&msg, &hdr);
msg.datalen = sizeof(struct wrnc_proto_header) / 4 + hdr.len;
err = wrtd_out_send_and_receive_sync(wrtd, &msg);
if (err)
return -1;
wrnc_message_header_get(&msg, &hdr);
if (hdr.msg_id != RT_ACTION_SEND_ACK) {
errno = EWRTD_INVALID_ANSWER_ACK;
return -1;
}
return 0;
return wrtd_out_action_one_word(wrtd, WRTD_OUT_ACTION_DISABLE, output);
}
static struct wrnc_structure_tlv wrtd_trigger_tlv(uint32_t index,
......
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