Commit 2b72e5b9 authored by Federico Vaga's avatar Federico Vaga

lib: deprecate function for time configuration

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 18309d45
......@@ -785,7 +785,7 @@ int fmctdc_fread(struct fmctdc_board *userb, unsigned int channel,
* @param[in] t time-stamp
* @return 0 on success, otherwise -1 and errno is set
*/
int fmctdc_set_time(struct fmctdc_board *userb, struct fmctdc_time *t)
int fmctdc_time_set(struct fmctdc_board *userb, struct fmctdc_time *t)
{
__define_board(b, userb);
uint32_t attrs[ARRAY_SIZE(names)];
......@@ -810,7 +810,7 @@ int fmctdc_set_time(struct fmctdc_board *userb, struct fmctdc_time *t)
* @param[out] t time-stamp
* @return 0 on success, otherwise -1 and errno is set
*/
int fmctdc_get_time(struct fmctdc_board *userb, struct fmctdc_time *t)
int fmctdc_time_get(struct fmctdc_board *userb, struct fmctdc_time *t)
{
__define_board(b, userb);
uint32_t attrs[ARRAY_SIZE(names)];
......@@ -835,7 +835,7 @@ int fmctdc_get_time(struct fmctdc_board *userb, struct fmctdc_time *t)
* @param[in] userb TDC board instance token
* @return 0 on success, otherwise -1 and errno is set appropriately
*/
int fmctdc_set_host_time(struct fmctdc_board *userb)
int fmctdc_time_set_host(struct fmctdc_board *userb)
{
__define_board(b, userb);
......@@ -850,7 +850,7 @@ int fmctdc_set_host_time(struct fmctdc_board *userb)
* @return 0 on successful ON, -ENOLINK on successful OFF, otherwise other
* erro codes
*/
int fmctdc_wr_mode(struct fmctdc_board *userb, int on)
int fmctdc_wr_status_set(struct fmctdc_board *userb, int on)
{
__define_board(b, userb);
......@@ -861,21 +861,38 @@ int fmctdc_wr_mode(struct fmctdc_board *userb, int on)
return errno;
}
/**
* It check the current status of the WhiteRabbit timing system on a TDC device
* @param[in] userb TDC board instance token
* @return 0 if it properly works, -1 on error and errno is set appropriately.
* - ENOLINK if it is not synchronized and
* - ENODEV if it is not enabled
* @param[out] status the white-rabbit status
* @return 0 on success, -1 on error and errno is appropriately set
*/
extern int fmctdc_check_wr_mode(struct fmctdc_board *userb)
extern int fmctdc_wr_status_get(struct fmctdc_board *userb,
enum fmctdc_wr_status *status)
{
int err;
__define_board(b, userb);
if (__fmctdc_command(b, FT_CMD_WR_QUERY) == 0)
return 0;
return -1;
err = __fmctdc_command(b, FT_CMD_WR_QUERY);
if (err) {
switch (errno) {
case ENODEV:
*status = FMCTDC_WR_OFF;
break;
case ENOLINK:
*status = FMCTDC_WR_ON_NOLINK;
break;
case EAGAIN:
*status = FMCTDC_WR_ON_SYNCING;
break;
default:
return err;
}
}
*status = FMCTDC_WR_ON;
return 0;
}
......@@ -1210,3 +1227,43 @@ float fmctdc_read_temperature(struct fmctdc_board *userb)
fmctdc_temperature_get(userb, &t);
return t;
}
/**
* @copydoc fmctdc_time_set()
*/
int fmctdc_set_time(struct fmctdc_board *b, struct fmctdc_time *t)
__attribute__((alias("fmctdc_time_set")));
/**
* @copydoc fmctdc_time_get()
*/
int fmctdc_get_time(struct fmctdc_board *b, struct fmctdc_time *t)
__attribute__((alias("fmctdc_time_get")));
/**
* @copydoc fmctdc_time_set_host()
*/
int fmctdc_set_host_time(struct fmctdc_board *b)
__attribute__((alias("fmctdc_time_set_host")));
/**
* @copydoc fmctdc_wr_status_set()
*/
int fmctdc_wr_mode(struct fmctdc_board *userb, int on)
__attribute__((alias("fmctdc_wr_status_set")));
/**
* It check the current status of the WhiteRabbit timing system on a TDC device
* @param[in] userb TDC board instance token
* @return 0 if it properly works, -1 on error and errno is set appropriately.
* - ENOLINK if it is not synchronized and
* - ENODEV if it is not enabled
*/
int fmctdc_check_wr_mode(struct fmctdc_board *userb)
{
__define_board(b, userb);
if (__fmctdc_command(b, FT_CMD_WR_QUERY) == 0)
return 0;
return -1;
}
......@@ -67,6 +67,16 @@ enum fmctdc_ts_mode {
ONLY when debugging low level issues */
};
/**
* Enumeration of all possible White-Rabbit status
*/
enum fmctdc_wr_status {
FMCTDC_WR_OFF = 0,
FMCTDC_WR_ON_NOLINK,
FMCTDC_WR_ON_SYNCING,
FMCTDC_WR_ON,
};
/**
* Opaque data type used as token. Do not try to access.
*/
......@@ -122,6 +132,13 @@ extern int fmctdc_ts_mode_set(struct fmctdc_board *userb,
extern int fmctdc_ts_mode_get(struct fmctdc_board *userb,
unsigned int channel,
enum fmctdc_ts_mode *mode);
extern int fmctdc_time_set(struct fmctdc_board *b, struct fmctdc_time *t);
extern int fmctdc_time_get(struct fmctdc_board *b, struct fmctdc_time *t);
extern int fmctdc_time_set_host(struct fmctdc_board *userb);
extern int fmctdc_wr_status_set(struct fmctdc_board *userb, int on);
extern int fmctdc_wr_status_get(struct fmctdc_board *userb,
enum fmctdc_wr_status *status);
/* Acquire Time-Stamps */
extern int fmctdc_fread(struct fmctdc_board *b, unsigned int channel,
struct fmctdc_time *t, int n);
......@@ -168,11 +185,16 @@ extern int fmctdc_get_offset_user(struct fmctdc_board *userb,
extern int fmctdc_buffer_mode(struct fmctdc_board *userb,
unsigned int channel,
enum ft_transfer_mode *mode);
extern int fmctdc_set_time(struct fmctdc_board *b, struct fmctdc_time *t);
extern int fmctdc_get_time(struct fmctdc_board *b, struct fmctdc_time *t);
extern int fmctdc_set_host_time(struct fmctdc_board *b);
extern int fmctdc_wr_mode(struct fmctdc_board *b, int on);
extern int fmctdc_check_wr_mode(struct fmctdc_board *b);
extern int fmctdc_set_time(struct fmctdc_board *b, struct fmctdc_time *t)
__attribute__((deprecated));
extern int fmctdc_get_time(struct fmctdc_board *b, struct fmctdc_time *t)
__attribute__((deprecated));
extern int fmctdc_set_host_time(struct fmctdc_board *b)
__attribute__((deprecated));
extern int fmctdc_wr_mode(struct fmctdc_board *b, int on)
__attribute__((deprecated));
extern int fmctdc_check_wr_mode(struct fmctdc_board *b)
__attribute__((deprecated));
extern float fmctdc_read_temperature(struct fmctdc_board *b)
__attribute__((deprecated));
/* other */
......
......@@ -40,20 +40,31 @@ int main(int argc, char **argv)
cmd = argv[2];
if (!strcmp(cmd, "get")) {
if (fmctdc_get_time(brd, &ts) < 0) {
if (fmctdc_time_get(brd, &ts) < 0) {
perror("fmctdc_get_time()");
return -1;
}
int err = fmctdc_check_wr_mode(brd);
enum fmctdc_wr_status status;
int err = fmctdc_wr_status_get(brd, &status);
printf("WR Status: ");
switch(err)
if (err)
printf("error: %s\n", strerror(err));
switch(status)
{
case ENODEV: printf("disabled.\n"); break;
case ENOLINK: printf("link down.\n"); break;
case EAGAIN: printf("synchronization in progress.\n"); break;
case 0: printf("synchronized.\n"); break;
default: printf("error: %s\n", strerror(err)); break;
case FMCTDC_WR_OFF:
printf("disabled.\n");
break;
case FMCTDC_WR_ON_NOLINK:
printf("link down.\n");
break;
case FMCTDC_WR_ON_SYNCING:
printf("synchronization in progress.\n");
break;
case FMCTDC_WR_ON:
printf("synchronized.\n");
break;
}
printf("Current TAI time is %llu.%09d s\n", (unsigned long long) ts.seconds,
ts.coarse * 8);
......@@ -65,18 +76,18 @@ int main(int argc, char **argv)
ts.coarse = 0;
ts.seconds = atoi(argv[3]);
if (fmctdc_set_time(brd, &ts) < 0) {
if (fmctdc_time_set(brd, &ts) < 0) {
perror_hint("fmctdc_set_time()");
return -1;
}
} else if (!strcmp(cmd, "host")) {
if (fmctdc_set_host_time(brd) < 0) {
if (fmctdc_time_set_host(brd) < 0) {
perror_hint("fmctdc_set_host_time()");
return -1;
}
} else if (!strcmp(cmd, "wr")) {
int err = fmctdc_wr_mode(brd, 1);
int err = fmctdc_wr_status_set(brd, 1);
if(err == ENOTSUP)
{
......@@ -91,22 +102,26 @@ int main(int argc, char **argv)
setbuf(stdout, NULL);
printf("Locking the card to WR: ");
while ((err = fmctdc_check_wr_mode(brd)) != 0) {
if( err == ENOLINK ) {
fprintf(stderr, "\n%s: no White Rabbit link (check the cable and the switch).\n",
do {
enum fmctdc_wr_status status;
err = fmctdc_wr_status_get(brd, &status);
if (status == FMCTDC_WR_ON_NOLINK) {
fprintf(stderr,
"\n%s: no White Rabbit link (check the cable and the switch).\n",
argv[0]);
return -1;
}
printf(".");
sleep(1);
}
} while(err);
printf(" locked!\n");
} else if (!strcmp(cmd, "local"))
{
int err = fmctdc_wr_mode(brd, 0);
int err = fmctdc_wr_status_set(brd, 0);
if(err < 0) {
perror_hint("fmctdc_wr_mode()");
perror_hint("fmctdc_wr_status_set()");
return -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