Commit 6ff1ace1 authored by Alessandro Rubini's avatar Alessandro Rubini

lib: added input config, functions and demo

parent ac179582
*.a
.depend
fdelay-list
fdelay-board-time
fdelay-term
......@@ -3,12 +3,14 @@
LIB = libfdelay.a
LOBJ := fdelay-init.o
LOBJ += fdelay-time.o
LOBJ += fdelay-tdc.o
CFLAGS = -Wall -ggdb -O2 -I.. -I$(ZIO)/include
LDFLAGS = -L. -lfdelay
DEMOSRC := fdelay-list.c
DEMOSRC += fdelay-board-time.c
DEMOSRC += fdelay-term.c
DEMOS := $(DEMOSRC:.c=)
......
/*
* TDC-related functions
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/zio.h>
#include <linux/zio-user.h>
#include <fine-delay.h>
#define FDELAY_INTERNAL
#include "fdelay.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
static int config_mask =
FD_TDCF_DISABLE_INPUT |
FD_TDCF_DISABLE_TSTAMP |
FD_TDCF_TERM_50;
int fdelay_set_config_tdc(struct fdelay_board *userb, int flags)
{
__define_board(b, userb);
uint32_t val;
if (flags & ~config_mask) {
errno = EINVAL;
return -1;
}
val = flags;
return fdelay_sysfs_set(b, "fd-input/flags", &val);
}
int fdelay_get_config_tdc(struct fdelay_board *userb)
{
__define_board(b, userb);
uint32_t val;
int ret;
ret = fdelay_sysfs_get(b, "fd-input/flags", &val);
if (ret) return ret;
return val;
}
/* Simple demo that acts on the termination of the first board */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fine-delay.h>
#include "fdelay.h"
int main(int argc, char **argv)
{
struct fdelay_board *b;
int i, hwval, newval;
if (argc > 2) {
fprintf(stderr, "%s: Use \"%s 1|0\n", argv[0], argv[0]);
exit(1);
}
newval = -1;
if (argc > 1) {
if (!strcmp(argv[1], "0"))
newval = 0;
else if (!strcmp(argv[1], "1"))
newval = 1;
else {
fprintf(stderr, "%s: arg \"%s\" is not 0 nor 1\n",
argv[0], argv[1]);
exit(1);
}
}
i = fdelay_init();
if (i < 0) {
fprintf(stderr, "%s: fdelay_init(): %s\n", argv[0],
strerror(errno));
exit(1);
}
if (i == 0) {
fprintf(stderr, "%s: no boards found\n", argv[0]);
exit(1);
}
if (i != 1) {
fprintf(stderr, "%s: found %i boards, using first one\n",
argv[0], i);
}
b = fdelay_open(0, -1);
if (!b) {
fprintf(stderr, "%s: fdelay_open(): %s\n", argv[0],
strerror(errno));
exit(1);
}
hwval = fdelay_get_config_tdc(b);
switch(newval) {
case 1:
hwval |= FD_TDCF_TERM_50;
break;
case 0:
hwval &= ~FD_TDCF_TERM_50;
break;
}
fdelay_set_config_tdc(b, hwval);
hwval = fdelay_get_config_tdc(b);
printf("%s: termination is %s\n", argv[0],
hwval & FD_TDCF_TERM_50 ? "on" : "off");
fdelay_close(b);
fdelay_exit();
return 0;
}
......@@ -38,6 +38,8 @@ extern int fdelay_set_time(struct fdelay_board *b, struct fdelay_time *t);
extern int fdelay_get_time(struct fdelay_board *b, struct fdelay_time *t);
extern int fdelay_set_host_time(struct fdelay_board *b);
extern int fdelay_set_config_tdc(struct fdelay_board *b, int flags);
extern int fdelay_get_config_tdc(struct fdelay_board *b);
#ifdef FDELAY_INTERNAL /* Libray users should ignore what follows */
......
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