Commit 07fe0a24 authored by Miguel Gómez Sexto's avatar Miguel Gómez Sexto

tdc: Added functions to set config parameters in the library.

Signed-off-by: Miguel Gómez Sexto's avatarMiguel Gómez <magomez@igalia.com>
parent f2a1998d
......@@ -33,8 +33,8 @@ DEFINE_ZATTR_STD(ZDEV, tdc_zattr_dev_std) = {
static struct zio_attribute tdc_zattr_dev[] = {
ZATTR_EXT_REG("version", S_IRUGO, TDC_ATTR_DEV_VERSION, TDC_VERSION),
ZATTR_EXT_REG("tstamp-thresh", _RW_, TDC_ATTR_DEV_TSTAMP_THRESH, 100),
ZATTR_EXT_REG("time-thresh", _RW_, TDC_ATTR_DEV_TIME_THRESH, 100),
ZATTR_EXT_REG("tstamp_thresh", _RW_, TDC_ATTR_DEV_TSTAMP_THRESH, 100),
ZATTR_EXT_REG("time_thresh", _RW_, TDC_ATTR_DEV_TIME_THRESH, 100),
ZATTR_EXT_REG("current_utc_time", S_IRUGO, TDC_ATTR_DEV_CURRENT_UTC, 0),
ZATTR_EXT_REG("set_utc_time", S_IWUGO, TDC_ATTR_DEV_SET_UTC, 0),
ZATTR_EXT_REG("input_enable", _RW_, TDC_ATTR_DEV_INPUT_ENABLED, 0x1F),
......
......@@ -13,8 +13,8 @@
static int tdc_nboards;
static struct tdc_board *tdc_boards;
static inline int fdelay_sysfs_get(struct tdc_board *b, char *name,
uint32_t *resp)
static inline int tdc_sysfs_get(struct tdc_board *b, char *name,
uint32_t *resp)
{
char path[128];
FILE *f;
......@@ -35,15 +35,15 @@ static inline int fdelay_sysfs_get(struct tdc_board *b, char *name,
return 0;
}
static inline int fdelay_sysfs_set(struct tdc_board *b, char *name,
uint32_t *value)
static inline int tdc_sysfs_set(struct tdc_board *b, char *name,
uint32_t value)
{
char path[128];
char s[16];
int fd, ret, len;
sprintf(path, "%s/%s", b->sysbase, name);
len = sprintf(s, "%i\n", *value);
len = sprintf(s, "%i\n", value);
fd = open(path, O_WRONLY);
if (fd < 0)
return -1;
......@@ -169,7 +169,7 @@ found:
return b;
}
extern int tdc_close(struct tdc_board *b)
int tdc_close(struct tdc_board *b)
{
int j;
......@@ -183,3 +183,94 @@ extern int tdc_close(struct tdc_board *b)
}
return 0;
}
int tdc_start_acquisition(struct tdc_board *b)
{
return tdc_sysfs_set(b, "activate_acquisition", 1);
}
int tdc_stop_acquisition(struct tdc_board *b)
{
return tdc_sysfs_set(b, "activate_acquisition", 0);
}
int tdc_set_host_utc_time(struct tdc_board *b)
{
return tdc_sysfs_set(b, "set_utc_time", 1);
}
int tdc_set_utc_time(struct tdc_board *b, uint32_t utc)
{
/* FIXME: we need a new ZIO attribute to put the user UTC */
return 0;
}
int tdc_get_utc_time(struct tdc_board *b, uint32_t *utc)
{
return tdc_sysfs_get(b, "current_utc_time", utc);
}
int tdc_set_dac_word(struct tdc_board *b, uint32_t dw)
{
return tdc_sysfs_set(b, "dac_word", dw);
}
int tdc_get_dac_word(struct tdc_board *b, uint32_t *dw)
{
return tdc_sysfs_get(b, "dac_word", dw);
}
int tdc_set_time_threshold(struct tdc_board *b, uint32_t thres)
{
return tdc_sysfs_set(b, "time_thresh", thres);
}
int tdc_get_time_threshold(struct tdc_board *b, uint32_t *thres)
{
return tdc_sysfs_get(b, "time_thresh", thres);
}
int tdc_set_timestamp_threshold(struct tdc_board *b, uint32_t thres)
{
return tdc_sysfs_set(b, "tstamp_thresh", thres);
}
int tdc_get_timestamp_threshold(struct tdc_board *b, uint32_t *thres)
{
return tdc_sysfs_get(b, "tstamp_thresh", thres);
}
int tdc_set_active_channels(struct tdc_board *b, uint32_t config)
{
int res = 0;
int i;
/* Hardware deactivation */
res = tdc_sysfs_set(b, "input_enable", config);
if (res) {
printf("Error setting chan config in hardware\n");
return res;
}
/* ZIO deactivation */
for (i = 0; i <= 4; i++) {
char file[20];
sprintf(file, "tdc-cset%i/enable", i);
if (config & (1 << i)) {
res = tdc_sysfs_set(b, file, 1);
} else {
res = tdc_sysfs_set(b, file, 0);
}
if (res) {
printf("Error setting ZIO chan config in cset %i\n", i);
return res;
}
}
return res;
}
int tdc_get_active_channels(struct tdc_board *b, uint32_t *config)
{
return tdc_sysfs_get(b, "input_enable", config);
}
......@@ -23,6 +23,25 @@ extern int tdc_init(void);
extern void tdc_exit(void);
extern struct tdc_board *tdc_open(int offset, int dev_id);
extern int tdc_close(struct tdc_board *);
extern int tdc_close(struct tdc_board *b);
extern int tdc_start_acquisition(struct tdc_board *b);
extern int tdc_stop_acquisition(struct tdc_board *b);
extern int tdc_set_host_utc_time(struct tdc_board *b);
extern int tdc_set_utc_time(struct tdc_board *b, uint32_t utc);
extern int tdc_get_utc_time(struct tdc_board *b, uint32_t *utc);
extern int tdc_set_dac_word(struct tdc_board *b, uint32_t dw);
extern int tdc_get_dac_word(struct tdc_board *b, uint32_t *dw);
extern int tdc_set_time_threshold(struct tdc_board *b, uint32_t thres);
extern int tdc_get_time_threshold(struct tdc_board *b, uint32_t *thres);
extern int tdc_set_timestamp_threshold(struct tdc_board *b, uint32_t thres);
extern int tdc_get_timestamp_threshold(struct tdc_board *b, uint32_t *thres);
extern int tdc_set_active_channels(struct tdc_board *b, uint32_t config);
extern int tdc_get_active_channels(struct tdc_board *b, uint32_t *config);
#endif
......@@ -8,6 +8,7 @@ int main(int argc, char **argv)
{
struct tdc_board *b;
int i;
uint32_t set, get;
i = tdc_init();
if (i < 0) {
......@@ -26,6 +27,42 @@ int main(int argc, char **argv)
b = tdc_open(0, -1);
/* set/get DAC word */
set = 123;
if (tdc_set_dac_word(b, set))
printf("Error setting DAC word");
if (tdc_get_dac_word(b, &get))
printf("Error getting DAC word");
if (set != get)
printf("DAC word set and get don't match");
/* set/get time threshold */
set = 123;
if (tdc_set_time_threshold(b, set))
printf("Error setting time thresh");
if (tdc_get_time_threshold(b, &get))
printf("Error getting time thresh");
if (set != get)
printf("Time thresh set and get don't match");
/* set/get timestamps threshold */
set = 123;
if (tdc_set_timestamp_threshold(b, set))
printf("Error setting timestamps thresh");
if (tdc_get_timestamp_threshold(b, &get))
printf("Error getting timestamps thresh");
if (set != get)
printf("Timestamps thresh set and get don't match");
/* set/get active channels */
set = 12;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels");
if (tdc_get_active_channels(b, &get))
printf("Error getting active channels");
if (set != get)
printf("Active channels set and get don't match");
tdc_close(b);
......
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