Commit 9ffd708b authored by Federico Vaga's avatar Federico Vaga

wrtd: add version support

Now it is possibile to check the WRTD RT application version that
is running on the WRNC
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 d9f25cb9
......@@ -49,7 +49,7 @@
#define WRTD_CMD_TDC_CHAN_SET_LOG_LEVEL 0xe
#define WRTD_CMD_TDC_CHAN_RESET_COUNTERS 0xf
#define WRTD_CMD_TDC_BASE_TIME 0x10
#define WRTD_CMD_TDC_VERSION 0x11
#define WRTD_CMD_FD_TRIG_ENABLE 0x10
#define WRTD_CMD_FD_TRIG_REMOVE 0x11
......@@ -73,6 +73,7 @@
#define WRTD_CMD_FD_PING 0xa
#define WRTD_CMD_FD_BASE_TIME 0xb
#define WRTD_CMD_FD_CHAN_DEAD_TIME 0xc
#define WRTD_CMD_FD_VERSION 0xd
#define WRTD_REP_ACK_ID 0x100
......@@ -83,6 +84,7 @@
#define WRTD_REP_TIMESTAMP 0x105
#define WRTD_REP_LOG_MESSAGE 0x106
#define WRTD_REP_BASE_TIME_ID 0x107
#define WRTD_REP_VERSION 0x108
......
......@@ -685,3 +685,41 @@ int wrtd_in_base_time(struct wrtd_node *dev, struct wr_timestamp *ts)
return 0;
}
/**
* It gets the output version
* @param[in] dev device token
* @param[out] ts output device base time
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_version(struct wrtd_node *dev, uint32_t *gitsha1)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrnc_msg msg = wrnc_msg_init(6); /* FIXME cannot use 2 */
uint32_t id, seq = 0;
int err;
id = WRTD_CMD_TDC_VERSION;
wrnc_msg_header(&msg, &id, &seq);
/* Send the message and get answer */
err = wrtd_in_send_and_receive_sync(wrtd, &msg);
if (err) {
errno = EWRTD_INVALID_ANSWER_STATE;
return -1;
}
/* Deserialize and check the answer */
wrnc_msg_header(&msg, &id, &seq);
if(id != WRTD_REP_VERSION)
{
errno = EWRTD_INVALID_ANSWER_STATE;
return -1;
}
wrnc_msg_uint32(&msg, gitsha1);
return 0;
}
......@@ -900,3 +900,41 @@ int wrtd_out_base_time(struct wrtd_node *dev, struct wr_timestamp *ts)
return 0;
}
/**
* It gets the output version
* @param[in] dev device token
* @param[out] ts output device base time
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_version(struct wrtd_node *dev, uint32_t *gitsha1)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrnc_msg msg = wrnc_msg_init(6); /* FIXME cannot use 2 */
uint32_t id, seq = 0;
int err;
id = WRTD_CMD_FD_VERSION;
wrnc_msg_header(&msg, &id, &seq);
/* Send the message and get answer */
err = wrtd_out_send_and_receive_sync(wrtd, &msg);
if (err) {
errno = EWRTD_INVALID_ANSWER_STATE;
return -1;
}
/* Deserialize and check the answer */
wrnc_msg_header(&msg, &id, &seq);
if(id != WRTD_REP_VERSION)
{
errno = EWRTD_INVALID_ANSWER_STATE;
return -1;
}
wrnc_msg_uint32(&msg, gitsha1);
return 0;
}
......@@ -248,6 +248,7 @@ extern int wrtd_in_has_trigger(struct wrtd_node *dev, unsigned int input,
unsigned int *assigned);
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, uint32_t *gitsha1);
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,
......@@ -297,6 +298,7 @@ extern int wrtd_out_trig_enable(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle, int enable);
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, uint32_t *gitsha1);
extern int wrtd_out_trigger_mode_set(struct wrtd_node *dev,
unsigned int output,
enum wrtd_trigger_mode mode);
......
......@@ -30,6 +30,7 @@
#define OUT_ST_TEST_PENDING 2
#define OUT_ST_CONDITION_HIT 3
static const uint32_t version = GIT_VERSION;
/**
* Rule defining the behaviour of a trigger output upon reception of a
......@@ -1082,6 +1083,16 @@ static inline void ctl_base_time (uint32_t seq, struct wrnc_msg *ibuf)
hmq_msg_send (&buf);
}
static inline void ctl_version(uint32_t seq, struct wrnc_msg *ibuf)
{
struct wrnc_msg buf = ctl_claim_out_buf();
uint32_t id_ack = WRTD_REP_VERSION;
wrnc_msg_header(&buf, &id_ack, &seq);
wrnc_msg_uint32(&buf, &version);
hmq_msg_send(&buf);
}
static inline void ctl_chan_set_delay (uint32_t seq, struct wrnc_msg *ibuf)
{
int ch;
......@@ -1308,6 +1319,7 @@ static inline void do_control()
_CMD(WRTD_CMD_FD_BASE_TIME, ctl_base_time)
_CMD(WRTD_CMD_FD_PING, ctl_ping)
_CMD(WRTD_CMD_FD_CHAN_DEAD_TIME, ctl_chan_set_dead_time)
_CMD(WRTD_CMD_FD_VERSION, ctl_version)
default:
break;
}
......@@ -1424,6 +1436,7 @@ void init()
int main()
{
pp_printf("Running %s from commit 0x%x.\n", __FILE__, version);
init();
for(;;) {
......
......@@ -28,6 +28,8 @@
#define BASE_DP_TDC_REGS 0x2000
#define BASE_DP_TDC_DIRECT 0x8000
static const uint32_t version = GIT_VERSION;
/* Structure describing state of each TDC channel*/
struct tdc_channel_state {
/* Currently assigned trigger ID */
......@@ -332,6 +334,16 @@ static inline void ctl_base_time (uint32_t seq, struct wrnc_msg *ibuf)
hmq_msg_send (&buf);
}
static inline void ctl_version(uint32_t seq, struct wrnc_msg *ibuf)
{
struct wrnc_msg buf = ctl_claim_out_buf();
uint32_t id_ack = WRTD_REP_VERSION;
wrnc_msg_header(&buf, &id_ack, &seq);
wrnc_msg_uint32(&buf, &version);
hmq_msg_send(&buf);
}
static inline void ctl_chan_set_delay (uint32_t seq, struct wrnc_msg *ibuf)
{
int channel;
......@@ -556,6 +568,7 @@ static inline void do_control()
_CMD(WRTD_CMD_TDC_CHAN_RESET_COUNTERS, ctl_chan_reset_counters)
_CMD(WRTD_CMD_TDC_PING, ctl_ping)
_CMD(WRTD_CMD_TDC_BASE_TIME, ctl_base_time)
_CMD(WRTD_CMD_TDC_VERSION, ctl_version)
default:
break;
}
......@@ -692,6 +705,7 @@ void init()
main()
{
pp_printf("Running %s from commit 0x%x.\n", __FILE__, version);
init();
for(;;)
......
......@@ -21,18 +21,19 @@ void help()
fprintf(stderr, " -n <num> number of ping to perform\n");
fprintf(stderr, " -p <num> ping period in micro-seconds\n");
fprintf(stderr, " -t show device base time\n");
fprintf(stderr, " -v show device version\n");
}
int main(int argc, char *argv[])
{
struct wrtd_node *wrtd;
uint32_t dev_id = 0, n = 1;
uint32_t dev_id = 0, n = 1, vi, vo;
uint64_t period = 0;
struct wr_timestamp tsi, tso;
int err, time = 0;
int err, time = 0, version = 0;
char c;
while ((c = getopt (argc, argv, "hD:n:p:t")) != -1) {
while ((c = getopt (argc, argv, "hD:n:p:tv")) != -1) {
switch (c) {
case 'h':
case '?':
......@@ -51,6 +52,9 @@ int main(int argc, char *argv[])
case 't':
time = 1;
break;
case 'v':
version = 1;
break;
}
}
......@@ -81,31 +85,45 @@ int main(int argc, char *argv[])
wrtd_in_base_time(wrtd, &tsi);
wrtd_out_base_time(wrtd, &tso);
}
if (version) {
wrtd_in_version(wrtd, &vi);
wrtd_out_version(wrtd, &vo);
}
/* Check input */
err = wrtd_in_ping(wrtd);
if (err) {
fprintf(stderr, "Cannot ping input source: %s\n",
wrtd_strerror(errno));
} else {
fprintf(stdout, "input : it is running!\n");
if (time)
fprintf(stdout,
"\tbase time\ts:%"PRIu64" t:%d f:%d\n",
tsi.seconds, tsi.ticks, tsi.frac);
goto skip_input;
}
fprintf(stdout, "input : it is running!\n");
if (time)
fprintf(stdout,
"\tbase time\ts:%"PRIu64" t:%d f:%d\n",
tsi.seconds, tsi.ticks, tsi.frac);
if (version)
fprintf(stdout,
"\tversion\t\t%x\n", vi);
skip_input:
/* check output */
err = wrtd_out_ping(wrtd);
if (err) {
fprintf(stderr, "Cannot ping output source: %s\n",
wrtd_strerror(errno));
} else {
fprintf(stdout, "output : it is running!\n");
if (time)
fprintf(stdout,
"\tbase time\ts:%"PRIu64" t:%d f:%d\n",
tso.seconds, tso.ticks, tso.frac);
goto skip_output;
}
fprintf(stdout, "output : it is running!\n");
if (time)
fprintf(stdout,
"\tbase time\ts:%"PRIu64" t:%d f:%d\n",
tso.seconds, tso.ticks, tso.frac);
if (version)
fprintf(stdout,
"\tversion\t\t%x\n", vo);
skip_output:
fprintf(stdout, "\n");
usleep(period);
}
......
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