Commit a6600f9d authored by Federico Vaga's avatar Federico Vaga

tools: add offset auto-clear support

It adds support for the offset auto-clear
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent afb0d6aa
......@@ -30,6 +30,7 @@ static int arg_plot = 0;
static int arg_x_display = 0;
static int arg_trgsw_delay = 0;
static int arg_trgsw = 0;
static int fixup = 0;
static char git_version[] = "version: " GIT_VERSION;
......@@ -52,6 +53,7 @@ static void fald_help()
printf(" <NOT IMPLEMENTED YET>\n");
printf(" --trg-sw <parameters> configure a software trigger\n");
printf(" <delay_seconds>\n");
printf(" --off-clr <mode>,<idx> run offset-clear on a given channel (mode: {a: automatic, m: manual})\n");
printf(" --channel| -c <parameters> configure an acquisition channel\n");
printf(" <channel>,<termination>,<range>,<offset>,<saturation>\n");
printf(" --timeout|-T <millisec> timeout for acquisition\n");
......@@ -75,6 +77,7 @@ enum fald_acq_options {
FALD_ACQ_OPT_TRG_THR,
FALD_ACQ_OPT_TRG_TIM,
FALD_ACQ_OPT_TRG_SW,
FALD_ACQ_OPT_OFF_CLR,
};
static struct option options[] = {
......@@ -86,6 +89,8 @@ static struct option options[] = {
{"trg-sw", required_argument, 0, FALD_ACQ_OPT_TRG_SW},
{"channel", required_argument, 0, 'c'},
{"timeout", required_argument, 0, 'T'},
{"off-clr", required_argument, 0, FALD_ACQ_OPT_OFF_CLR},
{"fixup", no_argument, &fixup, 1},
/* new options, to help stress-test */
......@@ -627,6 +632,58 @@ static int fald_trg_timer_configuration(struct adc_dev *adc, char *param)
return adc_apply_config(adc, 0 , &cfg);
}
/**
* It peforms the auto-clear offset according to the command line options
* @param[in] adc The ADC device token
* @param[in] argc number of arguments
* @param[in] argv arguments
* @return 0 on success, otherwise -1 and errno is appropriately set
*/
static int adc_acq_offset_auto_clear(struct adc_dev *adc,
int argc, char *argv[])
{
char offclr_mode;
unsigned int chan;
unsigned long flags;
int c, opt_index, ret;
optind = 1; /* set to 1 to make getopt_long happy */
/* Parse options */
while ((c = getopt_long(argc, argv, GETOPT_STRING, options, &opt_index))
>= 0 ) {
switch (c) {
case FALD_ACQ_OPT_OFF_CLR:
ret = sscanf(optarg, "%c,%d",
&offclr_mode, &chan);
if (ret <= 0) {
errno = EINVAL;
return -1;
}
flags = 0;
switch (offclr_mode) {
case 'm':
flags |= ADC_OFFSET_AC_F_MANUAL;
break;
case 'a':
flags |= ADC_OFFSET_AC_F_RESTORE;
break;
default:
fprintf(stderr,
"%s: invalid offset auto-clear mode '%c' (valid modes: {a: automatic, m: manual})",
_argv[0], offclr_mode);
return -1;
}
ret = adc_offset_auto_clear(adc, chan, flags);
if (ret < 0)
return ret;
break;
default:
break;
}
}
return 0;
}
/**
* It parses command line arguments and consequential it configures the device
......@@ -713,6 +770,10 @@ static int fald_acq_parse_args_and_configure(struct adc_dev *adc, int argc, char
}
}
err = adc_acq_offset_auto_clear(adc, argc, argv);
if (err)
return -1;
fald_acq_print_config(adc);
return 0;
......@@ -1080,7 +1141,9 @@ int main(int argc, char *argv[])
break;
}
err = adc_fill_buffer(adc, buf, 0, NULL);
err = adc_fill_buffer(adc, buf,
fixup ? ADC_F_FIXUP: 0,
NULL);
if (err) {
fprintf(stderr, "Failed to retrieve for data: (%d) %s\n",
errno, adc_strerror(errno));
......
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