Commit 70e62b64 authored by Federico Vaga's avatar Federico Vaga

*: add support for timer trigger

The way this patch has been written is a bit inconsistent with other
parts, but this is the way to go: values should be clear for the user
and not to be interpreted according to the board type. So, for timer
trigger we talk about seconds and nanoseconds, instead of seconds and
coarse.

Another thing to be noted here is that the FMCADC100M has 64bit seconds
while the library supports only 32bit. I leave it like this before to
get something working as soon as possible.
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 90e7aa79
......@@ -147,6 +147,8 @@ enum adc_configuration_trigger_thr {
*/
enum adc_configuration_trigger_tim {
ADC_CONF_TRG_TIM_ENABLE, /**< It enable (1) or disable (0) the trigger */
ADC_CONF_TRG_TIM_SECONDS,
ADC_CONF_TRG_TIM_NANO_SECONDS,
__ADC_CONF_TRG_TIM_LAST_INDEX, /**< It represents the the last index
of this enum. It can be useful for
some sort of automation */
......
......@@ -66,7 +66,9 @@
(1LL << ADC_CONF_TRG_THR_DELAY) | \
(1LL << ADC_CONF_TRG_THR_THRESHOLD) | \
(1LL << ADC_CONF_TRG_THR_HYSTERESIS)
#define ADC_100M_4CH_14BIT_TRG_TIM_MASK 0x0
#define ADC_100M_4CH_14BIT_TRG_TIM_MASK (1LL << ADC_CONF_TRG_TIM_ENABLE) | \
(1LL << ADC_CONF_TRG_TIM_SECONDS) | \
(1LL << ADC_CONF_TRG_TIM_NANO_SECONDS)
static typeof(adc_get_param) *adc_param[] = {
......@@ -307,7 +309,7 @@ static int adc_100m14b4cha_config_brd(struct adc_dev *adc,
errno = ADC_ENOSET;
return -1;
} else {
*value = 0;
*value = 1;
return 0;
}
......@@ -609,8 +611,12 @@ static int adc_100m14b4cha_config_trg_thr(struct adc_dev *adc,
return 0;
}
static uint32_t __nanoseconds_to_ticks(uint32_t nanoseconds)
{
return nanoseconds / FA100M14B4C_UTC_CLOCK_NS;
}
#define ADC_100M14B4CHA_MAX_TIM_SRC (0)
#define ADC_100M14B4CHA_MAX_TIM_SRC (1)
/**
* It configures the options related to the time trigger
* @param[in] adc the ADC device token
......@@ -626,12 +632,35 @@ static int adc_100m14b4cha_config_trg_tim(struct adc_dev *adc,
uint32_t *value,
unsigned int direction)
{
char path[1024];
uint32_t tmp;
int err;
if (source > ADC_100M14B4CHA_MAX_TIM_SRC - 1) {
errno = ADC_EROUTE;
return -1;
}
switch (index) {
case ADC_CONF_TRG_TIM_ENABLE:
err = __config_trg_enable(adc, value, direction,
FA100M14B4C_TRG_SRC_TIM);
if (err)
return err;
break;
case ADC_CONF_TRG_TIM_SECONDS:
/* FIXME we need 64bit values to configure it completely */
tmp = 0;
sprintf(path, "cset0/trigger/trg-time-su");
err = adc_param[direction](adc, path, NULL, (int *)&tmp);
if (err)
return err;
sprintf(path, "cset0/trigger/trg-time-sl");
return adc_param[direction](adc, path, NULL, (int *)value);
case ADC_CONF_TRG_TIM_NANO_SECONDS:
tmp = __nanoseconds_to_ticks(*value);
sprintf(path, "cset0/trigger/trg-time-t");
return adc_param[direction](adc, path, NULL, (int *)&tmp);
default:
errno = ADC_ENOCAP;
return -1;
......
......@@ -46,7 +46,7 @@ static const char *help_msg_opt =
" --trg-thr <parameters> configure a threshold trigger\n"
" <idx>,<enable>,<polarity>,<threshold>,<hysteresis>,<delay>\n"
" --trg-tim <parameters> configure a timing trigger\n"
" <NOT IMPLEMENTED YET>\n"
" <idx>,<enable>,<seconds>,<nanoseconds>\n"
" --trg-sw <parameters> configure a software trigger\n"
" <delay_seconds>\n"
" --off-clr <ac-mode>,<idx> run offset-clear on a given channel\n"
......@@ -75,6 +75,8 @@ static const char *help_msg_opt_desc =
" enabled: 1, disabled: 0\n"
" <idx>\n"
" resource index [0, N]\n"
" <nanoseconds>\n"
" number of nanoseconds since the card base time.\n"
" <n-shots>\n"
" number of consecutive acquisitions\n"
" <offset>*\n"
......@@ -89,6 +91,8 @@ static const char *help_msg_opt_desc =
" voltage range to use\n"
" <saturation>*\n"
" saturation value for an input channel\n"
" <seconds>\n"
" number of seconds since the card base time.\n"
" <termination>\n"
" enabled: 1, disabled: 0\n"
" <threshold>*\n"
......@@ -365,13 +369,31 @@ static void fald_acq_print_config(struct adc_dev *adc)
fprintf(stdout, "Trigger (Time) Configuration\n");
memset(&cfg, 0, sizeof(struct adc_conf));
cfg.type = ADC_CONF_TYPE_TRG_EXT;
cfg.type = ADC_CONF_TYPE_TRG_TIM;
adc_set_conf_mask_all(&cfg, adc);
err = adc_retrieve_config(adc, &cfg);
err = adc_get_conf(&cfg_brd, ADC_CONF_BRD_N_TRG_THR, &n);
if (err)
fprintf(stderr,
"Cannot retrieve the time trigger configuration: (%d) %s\n",
n = 0;
for (i = 0; i < n; ++i) {
fprintf(stdout, "\tTimer trigger %d\n", i + 1);
cfg.route_to = i;
err = adc_retrieve_config(adc, &cfg);
if (err) {
fprintf(stderr,
"Cannot retrieve the timer trigger configuration: (%d) %s\n",
errno, adc_strerror(errno));
} else {
err = adc_get_conf(&cfg, ADC_CONF_TRG_TIM_ENABLE, &value);
if (!err)
fprintf(stdout, "\t\tEnable: %d\n", value);
err = adc_get_conf(&cfg, ADC_CONF_TRG_TIM_SECONDS, &value);
if (!err)
fprintf(stdout, "\t\tSeconds: %d\n", value);
err = adc_get_conf(&cfg, ADC_CONF_TRG_TIM_NANO_SECONDS, &value);
if (!err)
fprintf(stdout, "\t\tNanoseconds: %d\n", value);
}
}
}
......@@ -664,10 +686,31 @@ static int fald_trg_threshold_configuration(struct adc_dev *adc, char *param)
static int fald_trg_timer_configuration(struct adc_dev *adc, char *param)
{
struct adc_conf cfg;
uint32_t n, enable, seconds, nanoseconds = 0;
int ret;
ret = sscanf(param, "%"SCNu32",%"SCNu32",%"SCNu32",%"SCNu32,
&n, &enable, &seconds, &nanoseconds);
if (ret <= 2) {
errno = EINVAL;
return -1;
}
memset(&cfg, 0, sizeof(struct adc_conf));
cfg.type = ADC_CONF_TYPE_TRG_TIM;
cfg.route_to = 0;
cfg.route_to = n;
switch (ret) {
case 4:
case 3:
adc_set_conf(&cfg, ADC_CONF_TRG_TIM_NANO_SECONDS, nanoseconds);
adc_set_conf(&cfg, ADC_CONF_TRG_TIM_SECONDS, seconds);
adc_set_conf(&cfg, ADC_CONF_TRG_TIM_ENABLE, enable);
break;
default:
errno = -EINVAL;
return -1;
}
return adc_apply_config(adc, 0 , &cfg);
}
......
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