Commit 84842d13 authored by Miguel Gómez Sexto's avatar Miguel Gómez Sexto

Added functions to activate and deactivate all channels

Signed-off-by: Miguel Gómez Sexto's avatarMiguel Gomez <magomez@igalia.com>
parent 5b68e79b
......@@ -134,7 +134,6 @@ static int tdc_zio_conf_set(struct device *dev,
tdc_set_utc_time(tdc, usr_val);
break;
case TDC_ATTR_DEV_INPUT_ENABLED:
usr_val |= TDC_INPUT_ENABLE_FLAG;
tdc_set_input_enable(tdc, usr_val);
break;
case TDC_ATTR_DEV_DAC_WORD:
......@@ -184,7 +183,7 @@ static int tdc_zio_info_get(struct device *dev,
case TDC_ATTR_DEV_SET_UTC:
break;
case TDC_ATTR_DEV_INPUT_ENABLED:
*usr_val = tdc_get_input_enable(tdc) & ~TDC_INPUT_ENABLE_FLAG;
*usr_val = tdc_get_input_enable(tdc);
break;
case TDC_ATTR_DEV_DAC_WORD:
*usr_val = tdc_get_dac_word(tdc);
......
......@@ -13,6 +13,7 @@
#include "libtdc.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define TDC_INPUT_ENABLE_FLAG (1 << 7)
static inline int __tdc_sysfs_get_lun(char *sysbase, uint32_t *resp)
{
......@@ -122,6 +123,7 @@ struct tdc_board *tdc_open(int lun)
b->lun = lun;
b->sysbase = strdup(glob_sys.gl_pathv[i]);
b->devbase = strdup(glob_dev.gl_pathv[i]);
b->chan_config = 0;
/* trim the "-0-0-ctrl" at the end */
b->devbase[strlen(b->devbase) - strlen("-0-0-ctrl")] = '\0';
/* extract dev_id */
......@@ -129,7 +131,6 @@ struct tdc_board *tdc_open(int lun)
for (j = 0; j < ARRAY_SIZE(b->ctrl); j++) {
b->ctrl[j] = -1;
b->data[j] = -1;
b->enabled[j] = 0;
}
break;
}
......@@ -230,10 +231,14 @@ int tdc_set_active_channels(struct tdc_board *b, uint32_t config)
int res = 0;
int i;
/* Clear other bits than the 5 smaller */
config = config & 0x1f;
b->chan_config = (b->chan_config & TDC_INPUT_ENABLE_FLAG) | config;
/* Hardware deactivation */
res = __tdc_sysfs_set(b, "input_enable", config);
res = __tdc_sysfs_set(b, "input_enable", b->chan_config);
if (res) {
printf("Error setting chan config in hardware\n");
fprintf(stderr, "Error setting chan config in hardware\n");
return res;
}
......@@ -243,10 +248,8 @@ int tdc_set_active_channels(struct tdc_board *b, uint32_t config)
sprintf(file, "tdc-cset%i/enable", i);
if (config & (1 << i)) {
res = __tdc_sysfs_set(b, file, 1);
b->enabled[i] = 1;
} else {
res = __tdc_sysfs_set(b, file, 0);
b->enabled[i] = 0;
}
if (res) {
printf("Error setting ZIO chan config in cset %i\n", i);
......@@ -259,7 +262,20 @@ int tdc_set_active_channels(struct tdc_board *b, uint32_t config)
int tdc_get_active_channels(struct tdc_board *b, uint32_t *config)
{
return __tdc_sysfs_get(b, "input_enable", config);
*config = b->chan_config & ~TDC_INPUT_ENABLE_FLAG;
return 0;
}
int tdc_activate_all_channels(struct tdc_board *b)
{
b->chan_config |= TDC_INPUT_ENABLE_FLAG;
return __tdc_sysfs_set(b, "input_enable", b->chan_config);
}
int tdc_deactivate_all_channels(struct tdc_board *b)
{
b->chan_config &= ~TDC_INPUT_ENABLE_FLAG;
return __tdc_sysfs_set(b, "input_enable", b->chan_config);
}
int tdc_get_circular_buffer_pointer(struct tdc_board *b, uint32_t *ptr)
......@@ -281,7 +297,14 @@ static int __tdc_valid_channel(struct tdc_board *b, int chan)
return 0;
}
if (!b->enabled[chan]) {
if (!(b->chan_config & TDC_INPUT_ENABLE_FLAG) ) {
fprintf(stderr, "%s: All channels disabled\n",
__func__, chan);
errno = EINVAL;
return 0;
}
if (!(b->chan_config & (1 << chan)) ) {
fprintf(stderr, "%s: Channel not enabled: %i\n",
__func__, chan);
errno = EINVAL;
......
......@@ -8,9 +8,9 @@ struct tdc_board {
int lun;
char *devbase;
char *sysbase;
uint32_t chan_config; /* Channel activation */
int ctrl[5]; /* The 5 control channels */
int data[5]; /* The 5 data channels */
int enabled[5]; /* channel activation */
};
struct tdc_time {
......@@ -50,6 +50,9 @@ 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);
extern int tdc_activate_all_channels(struct tdc_board *b);
extern int tdc_deactivate_all_channels(struct tdc_board *b);
extern int tdc_get_circular_buffer_ptr(struct tdc_board *b, uint32_t *ptr);
extern int tdc_clear_dacapo_flag(struct tdc_board *b);
......
......@@ -59,7 +59,8 @@ int main(int argc, char **argv)
else
printf("Timestamps threshold functions OK\n");
/* set/get active channels */
/* set/get active channels with general activation */
tdc_activate_all_channels(b);
set = CHAN0 | CHAN2 | CHAN4;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
......@@ -70,6 +71,44 @@ int main(int argc, char **argv)
else
printf("Channel activation functions OK\n");
/* set/get active channels with general deactivation */
tdc_deactivate_all_channels(b);
set = CHAN0 | CHAN2 | CHAN4;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
if (tdc_get_active_channels(b, &get))
printf("Error getting active channels\n");
if (set != get)
printf("Active channels set and get don't match\n");
else
printf("Channel activation functions OK\n");
/* set/get active channels with general activation change */
tdc_activate_all_channels(b);
set = CHAN0 | CHAN2 | CHAN4;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
tdc_deactivate_all_channels(b);
if (tdc_get_active_channels(b, &get))
printf("Error getting active channels\n");
if (set != get)
printf("Active channels set and get don't match\n");
else
printf("Channel activation functions OK\n");
/* set/get active channels with general activation change */
tdc_deactivate_all_channels(b);
set = CHAN0 | CHAN2 | CHAN4;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
tdc_activate_all_channels(b);
if (tdc_get_active_channels(b, &get))
printf("Error getting active channels\n");
if (set != get)
printf("Active channels set and get don't match\n");
else
printf("Channel activation functions OK\n");
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