Commit f551c3ce authored by Federico Vaga's avatar Federico Vaga

sw:lib: port to Mock Turtle 4.0 [UNTESTED]

This is part of a more complex work. Here, I just fixed all the GCC errors
and warning. The next step will be to actually test it.
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent d1f9bff6
......@@ -110,11 +110,11 @@
#define FD_MAX_QUEUE_PULSES 16
enum wrtd_in_actions {
WRTD_IN_ACTION_SW_TRIG = __RT_ACTION_RECV_STANDARD_NUMBER,
WRTD_IN_ACTION_SW_TRIG = 0,
WRTD_IN_ACTION_LOG,
};
enum wrtd_out_actions {
WRTD_OUT_ACTION_SW_TRIG = __RT_ACTION_RECV_STANDARD_NUMBER,
WRTD_OUT_ACTION_SW_TRIG = 0,
WRTD_OUT_ACTION_TRIG_IDX,
WRTD_OUT_ACTION_TRIG_FRE,
WRTD_OUT_ACTION_TRIG_ADD,
......
......@@ -104,7 +104,7 @@ void wrtd_exit()
*/
int wrtd_version_is_valid(struct wrtd_node *dev)
{
struct trtl_rt_version version;
struct trtl_fw_version version;
int err;
errno = 0;
......@@ -133,39 +133,23 @@ int wrtd_version_is_valid(struct wrtd_node *dev)
/**
* It opens and initialize the configuration for the given device
* @param[in] device_id device identifier
* @param[in] is_lun 1 if device_id is a LUN
* @return It returns an anonymous wrtd_node structure on success.
* On error, NULL is returned, and errno is set appropriately.
*/
static struct wrtd_node *wrtd_open(uint32_t device_id, unsigned int is_lun)
struct wrtd_node *wrtd_open(uint32_t device_id)
{
struct wrtd_desc *wrtd;
int err;
wrtd = malloc(sizeof(struct wrtd_desc));
if (!wrtd)
return NULL;
if (is_lun)
wrtd->trtl = trtl_open_by_lun(device_id);
else
wrtd->trtl = trtl_open_by_fmc(device_id);
wrtd->trtl = trtl_open_by_id(device_id);
if (!wrtd->trtl)
goto out;
wrtd->dev_id = device_id;
/* Logging interface is always in share mode */
err = trtl_hmq_share_set(wrtd->trtl, TRTL_HMQ_OUTCOMING,
WRTD_OUT_FD_LOGGING, 1);
if (err)
goto out;
err = trtl_hmq_share_set(wrtd->trtl, TRTL_HMQ_OUTCOMING,
WRTD_OUT_TDC_LOGGING, 1);
if (err)
goto out;
return (struct wrtd_node *)wrtd;
out:
......@@ -173,30 +157,6 @@ out:
return NULL;
}
/**
* Open a WRTD node device using FMC ID
* @param[in] device_id FMC device identificator
* @return It returns an anonymous wrtd_node structure on success.
* On error, NULL is returned, and errno is set appropriately.
*/
struct wrtd_node *wrtd_open_by_fmc(uint32_t device_id)
{
return wrtd_open(device_id, 0);
}
/**
* Open a WRTD node device using LUN
* @param[in] lun an integer argument to select the device or
* negative number to take the first one found.
* @return It returns an anonymous wrtd_node structure on success.
* On error, NULL is returned, and errno is set appropriately.
*/
struct wrtd_node *wrtd_open_by_lun(int lun)
{
return wrtd_open(lun, 1);
}
/**
* It closes a WRTD device opened with one of the following function:
......
This diff is collapsed.
......@@ -32,7 +32,7 @@
*/
int wrtd_validate_acknowledge(struct trtl_msg *msg)
{
if (msg->datalen != 2 || msg->data[0] != WRTD_REP_ACK_ID) {
if (msg->hdr.len != 2 || msg->data[0] != WRTD_REP_ACK_ID) {
errno = EWRTD_INVALID_ANSWER_ACK;
return -1;
}
......@@ -75,21 +75,10 @@ int wrtd_send_and_receive_sync(struct wrtd_desc *wrtd,
struct trtl_msg *msg,
enum wrtd_core core)
{
/* Send the message and get answer */
struct trtl_hmq *hmq;
unsigned int hmq_send = core ? WRTD_IN_FD_CONTROL : WRTD_IN_TDC_CONTROL;
unsigned int hmq_recv = core ? WRTD_OUT_FD_CONTROL :
WRTD_OUT_TDC_CONTROL;
int err;
hmq = trtl_hmq_open(wrtd->trtl, hmq_send, TRTL_HMQ_INCOMING);
if (!hmq)
return -1;
err = trtl_hmq_send_and_receive_sync(hmq, hmq_recv, msg,
WRTD_DEFAULT_TIMEOUT);
trtl_hmq_close(hmq);
err = trtl_msg_sync(wrtd->trtl, core, 0,
msg, msg, WRTD_DEFAULT_TIMEOUT);
return err < 0 ? err : 0; /* ignore timeout */
}
......
......@@ -104,61 +104,6 @@ enum wrtd_log_level wrtd_strlogging_to_level(char *log)
}
/**
* It opens the logging interface for a given divice. The default
* logging level will be applied to all device channels. You can change it
* later using wrtd_log_level_set()
* @param[in] dev device token
* @param[in] input channel number [-1, 4]. [-1] for all channels, [0,4] for a
* specific one.
* @param[in] core WRTD core to use
* @return a HMQ token on success, NULL on error and errno is set appropriately
*/
static struct trtl_hmq *wrtd_log_open(struct wrtd_node *dev,
int channel,
enum wrtd_core core)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct trtl_msg_filter filter = {
.operation = TRTL_MSG_FILTER_EQ,
.word_offset = 3, /* channel field */
.mask = 0xFFFF, /* entire field */
.value = channel, /* required channel */
};
struct trtl_hmq *hmq = NULL;
int err;
int n_chan = core ? FD_NUM_CHANNELS : TDC_NUM_CHANNELS;
unsigned int hmq_back_index = core ? WRTD_OUT_FD_LOGGING :
WRTD_OUT_TDC_LOGGING;
if (channel < -1 || channel >= n_chan) {
errno = EWRTD_INVALID_CHANNEL;
return NULL;
}
hmq = trtl_hmq_open(wrtd->trtl, hmq_back_index, 0);
if (!hmq)
return NULL;
if (channel > -1) {
if (core == WRTD_CORE_IN) {
/* On input side we have the header */
filter.word_offset = 6;
}
/* the user want to filter per channel */
err = trtl_hmq_filter_add(hmq, &filter);
if (err)
goto out_close;
}
return hmq;
out_close:
trtl_hmq_close(hmq);
return NULL;
}
/**
* It reads one or more log entry from a given hmq_log. The user of this
* function must check that the hmq_log used correspond to a logging interface
......@@ -169,59 +114,57 @@ out_close:
* @return number of read messages on success (check errno if it returns less
* messages than expected), -1 on error and errno is set appropriately
*/
int wrtd_log_read(struct trtl_hmq *hmq_log, struct wrtd_log_entry *log,
int wrtd_log_read(struct wrtd_node *dev,
struct wrtd_log_entry *log,
int count, int poll_timeout)
{
struct trtl_proto_header hdr;
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_log_entry *cur = log;
struct trtl_msg *msg;
struct pollfd p;
struct trtl_msg msg;
#define __WRTD_POLL_N 2
struct polltrtl p[__WRTD_POLL_N];
int remaining = count;
int n_read = 0, ret;
int n_read = 0, ret, i;
p.fd = hmq_log->fd;
p.events = POLLIN;
for (i = 0; i < __WRTD_POLL_N; ++i) {
p[i].trtl = wrtd->trtl;
p[i].idx_hmq = 0;
p[i].events = POLLIN;
}
p[0].idx_cpu = WRTD_CPU_TDC;
p[1].idx_cpu = WRTD_CPU_FD;
/* Clean up errno to be able to distinguish between error cases and
normal behaviour when the function return less messages
than expected */
errno = 0;
while (remaining) {
ret = poll(&p, 1, poll_timeout);
if (ret <= 0 || !(p.revents & POLLIN))
break;
msg = trtl_hmq_receive(hmq_log);
if (!msg)
while (remaining > 0) {
ret = trtl_msg_poll(p, 2, poll_timeout);
if (ret <= 0)
break;
trtl_message_unpack(msg, &hdr, cur);
if (hdr.msg_id != WRTD_IN_ACTION_LOG &&
hdr.msg_id != WRTD_OUT_ACTION_LOG) {
free(msg);
errno = EWRTD_INVALID_ANSWER_STATE;
break;
for (i = 0; i < __WRTD_POLL_N; ++i) {
if (!(p[i].revents & POLLIN))
continue;
ret = trtl_msg_async_recv(p[i].trtl,
p[i].idx_cpu,
p[i].idx_hmq,
&msg, 1);
if (ret <= 0)
break;
memcpy(cur, msg.data, sizeof(struct wrtd_log_entry));
wrtd_timestamp_endianess_fix(&cur->ts);
remaining--;
n_read++;
cur++;
}
wrtd_timestamp_endianess_fix(&cur->ts);
remaining--;
n_read++;
cur++;
free(msg);
}
#undef __WRTD_POLL_N
return (n_read > 0 || errno == 0 ? n_read : -1);
}
/**
* It closes the logging interface
* @param[in] hmq HMQ token to close
*/
void wrtd_log_close(struct trtl_hmq *hmq)
{
trtl_hmq_close(hmq);
}
/**
* @param[in] dev device token
......@@ -233,38 +176,31 @@ static int wrtd_log_level_set(struct wrtd_node *dev, unsigned int channel,
uint32_t log_level, enum wrtd_core core)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct trtl_structure_tlv tlv;
struct trtl_proto_header hdr;
struct trtl_tlv tlv;
struct wrtd_out_channel ochan;
struct wrtd_in_channel ichan;
int err;
hdr.flags = TRTL_PROTO_FLAG_SYNC;
if (core) {
if (channel >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
tlv.index = OUT_STRUCT_CHAN_0 + channel;
tlv.type = OUT_STRUCT_CHAN_0 + channel;
tlv.size = WRTD_OUT_CHANNEL_PUBLIC_SIZE;
tlv.structure = &ochan;
hdr.slot_io = (WRTD_IN_FD_CONTROL << 4) |
(WRTD_OUT_FD_CONTROL & 0xF);
/* TODO set promiscuous mode */
tlv.buf = &ochan;
} else {
if (channel >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
tlv.index = IN_STRUCT_CHAN_0 + channel;
tlv.type = IN_STRUCT_CHAN_0 + channel;
tlv.size = sizeof(struct wrtd_in_channel);
tlv.structure = &ichan;
hdr.slot_io = (WRTD_IN_TDC_CONTROL << 4) |
(WRTD_OUT_TDC_CONTROL & 0xF);
tlv.buf = &ichan;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
err = trtl_fw_buffer_get(wrtd->trtl, core, 0, &tlv, 1);
if (err)
return err;
......@@ -273,22 +209,7 @@ static int wrtd_log_level_set(struct wrtd_node *dev, unsigned int channel,
else
ichan.config.log_level = log_level;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It opens the logging interface for a given divice. The default
* logging level will be applied to all device channels. You can change it
* later using wrtd_out_log_level_set()
* @param[in] dev device token
* @param[in] output channel number [-1, 3]. [-1] for all channels, [0,3] for a
* specific one.
* @return a HMQ token on success, NULL on error and errno is set appropriately
*/
struct trtl_hmq *wrtd_out_log_open(struct wrtd_node *dev, int output)
{
return wrtd_log_open(dev, output, WRTD_CORE_OUT);
return trtl_fw_buffer_set(wrtd->trtl, core, 0, &tlv, 1);
}
......@@ -329,21 +250,6 @@ int wrtd_out_log_level_get(struct wrtd_node *dev, unsigned int input,
return 0;
}
/**
* It opens the logging interface for device a given divice. The default
* logging level will be applied to all device channels. You can change it
* later using wrtd_in_log_level_set()
* @param[in] dev device token
* @param[in] lvl default logging level
* @param[in] input channel number [-1, 4]. [-1] for all channels, [0,4] for a
* specific one.
* @return a HMQ token on success, NULL on error and errno is set appropriately
*/
struct trtl_hmq *wrtd_in_log_open(struct wrtd_node *dev, int input)
{
return wrtd_log_open(dev, input, WRTD_CORE_IN);
}
/**
* It sets the logging level for an input channel
......
This diff is collapsed.
......@@ -160,8 +160,7 @@ struct wrtd_output_state {
*/
extern int wrtd_init();
extern void wrtd_exit();
extern struct wrtd_node *wrtd_open_by_fmc(uint32_t device_id);
extern struct wrtd_node *wrtd_open_by_lun(int lun);
extern struct wrtd_node *wrtd_open(uint32_t device_id);
extern void wrtd_close(struct wrtd_node *dev);
extern struct trtl_dev *wrtd_get_trtl_dev(struct wrtd_node *dev);
extern int wrtd_load_application(struct wrtd_node *dev, char *rt_tdc,
......@@ -197,10 +196,9 @@ extern void wrtd_sec_pico_to_ts(uint64_t sec, uint64_t pico,
extern const char *wrtd_strlogging(enum wrtd_log_level lvl);
enum wrtd_log_level wrtd_strlogging_to_level(char *log);
extern void wrtd_strlogging_full(char *buf, uint32_t log_level);
extern int wrtd_log_read(struct trtl_hmq *hmq_log, struct wrtd_log_entry *log,
extern int wrtd_log_read(struct wrtd_node *dev,
struct wrtd_log_entry *log,
int count, int poll_timeout);
extern void wrtd_log_close(struct trtl_hmq *hmq);
extern struct trtl_hmq *wrtd_in_log_open(struct wrtd_node *dev, int input);
extern int wrtd_in_log_level_set(struct wrtd_node *dev, unsigned int input,
uint32_t log_level);
extern int wrtd_in_log_level_get(struct wrtd_node *dev, unsigned int input,
......@@ -209,7 +207,6 @@ extern int wrtd_out_log_level_set(struct wrtd_node *dev, unsigned int output,
uint32_t log_level);
extern int wrtd_out_log_level_get(struct wrtd_node *dev, unsigned int input,
uint32_t *log_level);
extern struct trtl_hmq *wrtd_out_log_open(struct wrtd_node *dev, int output);
/**@}*/
......@@ -251,7 +248,7 @@ extern int wrtd_in_has_trigger(struct wrtd_node *dev, unsigned int input,
extern int wrtd_in_ping(struct wrtd_node *dev);
extern int wrtd_in_base_time(struct wrtd_node *dev, struct wr_timestamp *ts);
extern int wrtd_in_version(struct wrtd_node *dev,
struct trtl_rt_version *version);
struct trtl_fw_version *version);
extern int wrtd_in_dead_time_get(struct wrtd_node *dev, unsigned int input,
uint64_t *dead_time_ps);
extern int wrtd_in_delay_get(struct wrtd_node *dev, unsigned int input,
......@@ -304,7 +301,7 @@ extern int wrtd_out_trig_enable(struct wrtd_node *dev,
extern int wrtd_out_ping(struct wrtd_node *dev);
extern int wrtd_out_base_time(struct wrtd_node *dev, struct wr_timestamp *ts);
extern int wrtd_out_version(struct wrtd_node *dev,
struct trtl_rt_version *version);
struct trtl_fw_version *version);
extern int wrtd_out_trigger_mode_set(struct wrtd_node *dev,
unsigned int output,
enum wrtd_trigger_mode mode);
......
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