Commit 1312277e authored by Federico Vaga's avatar Federico Vaga

Merge branch 'feature/getsamples' into develop

parents fe930ae2 3185bd58
...@@ -330,6 +330,20 @@ static int adc_genfake_fill_buffer(struct adc_dev *dev, ...@@ -330,6 +330,20 @@ static int adc_genfake_fill_buffer(struct adc_dev *dev,
return 0; return 0;
} }
static int adc_genfake_buffer_get_sample(struct adc_buffer *buf,
unsigned int chan,
unsigned int acq_sample,
int32_t *value)
{
if (chan >= 1) {
errno = EINVAL;
return -1;
}
*value = ((int8_t *)buf->data)[acq_sample];
return 0;
}
static struct adc_operations fa_generic_fake_op = { static struct adc_operations fa_generic_fake_op = {
.open = adc_genfake_open, .open = adc_genfake_open,
...@@ -349,6 +363,7 @@ static struct adc_operations fa_generic_fake_op = { ...@@ -349,6 +363,7 @@ static struct adc_operations fa_generic_fake_op = {
.fill_buffer = adc_genfake_fill_buffer, .fill_buffer = adc_genfake_fill_buffer,
.tstamp_buffer = adc_genfake_tstamp_buffer, .tstamp_buffer = adc_genfake_tstamp_buffer,
.release_buffer = adc_genfake_release_buffer, .release_buffer = adc_genfake_release_buffer,
.buffer_get_sample = adc_genfake_buffer_get_sample,
}; };
#define ADC_GENERICFAKE_BRD_MASK (1LL << ADC_CONF_BRD_N_CHAN) #define ADC_GENERICFAKE_BRD_MASK (1LL << ADC_CONF_BRD_N_CHAN)
......
...@@ -45,6 +45,7 @@ struct adc_operations { ...@@ -45,6 +45,7 @@ struct adc_operations {
typeof(adc_release_buffer) *release_buffer; /**< @related adc_release_buffer */ typeof(adc_release_buffer) *release_buffer; /**< @related adc_release_buffer */
typeof(adc_trigger_fire) *trigger_fire; /**< @related adc_trigger_fire */ typeof(adc_trigger_fire) *trigger_fire; /**< @related adc_trigger_fire */
typeof(adc_buffer_get_sample) *buffer_get_sample; /**< @related adc_buffer_get_sample */
}; };
......
...@@ -396,6 +396,10 @@ extern struct adc_timestamp *adc_tstamp_buffer(struct adc_buffer *buf, ...@@ -396,6 +396,10 @@ extern struct adc_timestamp *adc_tstamp_buffer(struct adc_buffer *buf,
extern int adc_release_buffer(struct adc_dev *dev, extern int adc_release_buffer(struct adc_dev *dev,
struct adc_buffer *buf, struct adc_buffer *buf,
void (*free_fn)(void *)); void (*free_fn)(void *));
extern int adc_buffer_get_sample(struct adc_buffer *buf,
unsigned int chan,
unsigned int acq_sample,
int32_t *value);
/**@}*/ /**@}*/
/* libfmcadc version string */ /* libfmcadc version string */
......
...@@ -34,6 +34,20 @@ static struct adc_dev *adc_ziofake_open(const struct adc_board_type *b, ...@@ -34,6 +34,20 @@ static struct adc_dev *adc_ziofake_open(const struct adc_board_type *b,
return dev; return dev;
} }
static int adc_ziofake_buffer_get_sample(struct adc_buffer *buf,
unsigned int chan,
unsigned int acq_sample,
int32_t *value)
{
if (chan >= 1) {
errno = EINVAL;
return -1;
}
*value = ((int8_t *)buf->data)[acq_sample];
return 0;
}
#define ADC_ZIO_ACQ_MASK (1LL << ADC_CONF_ACQ_N_SHOTS) | \ #define ADC_ZIO_ACQ_MASK (1LL << ADC_CONF_ACQ_N_SHOTS) | \
(1LL << ADC_CONF_ACQ_POST_SAMP) | \ (1LL << ADC_CONF_ACQ_POST_SAMP) | \
...@@ -62,6 +76,7 @@ static struct adc_operations fa_zio_fake_op = { ...@@ -62,6 +76,7 @@ static struct adc_operations fa_zio_fake_op = {
.fill_buffer = adc_zio_fill_buffer, .fill_buffer = adc_zio_fill_buffer,
.tstamp_buffer = adc_zio_tstamp_buffer, .tstamp_buffer = adc_zio_tstamp_buffer,
.release_buffer = adc_zio_release_buffer, .release_buffer = adc_zio_release_buffer,
.buffer_get_sample = adc_ziofake_buffer_get_sample,
}; };
struct adc_board_type adc_ziofake = { struct adc_board_type adc_ziofake = {
......
...@@ -719,6 +719,22 @@ static int adc_100m14b4cha_trigger_fire(struct adc_dev *dev) ...@@ -719,6 +719,22 @@ static int adc_100m14b4cha_trigger_fire(struct adc_dev *dev)
NULL, &value); NULL, &value);
} }
static int adc_100m14b4cha_buffer_get_sample(struct adc_buffer *buf,
unsigned int chan,
unsigned int acq_sample,
int32_t *value)
{
if (chan >= FA100M14B4C_NCHAN) {
errno = EINVAL;
return -1;
}
*value = ((int16_t *)buf->data)[acq_sample * FA100M14B4C_NCHAN + chan];
return 0;
}
#define ADC_100M_4CH_14BIT_ACQ_MASK (1LL << ADC_CONF_ACQ_N_SHOTS) | \ #define ADC_100M_4CH_14BIT_ACQ_MASK (1LL << ADC_CONF_ACQ_N_SHOTS) | \
(1LL << ADC_CONF_ACQ_POST_SAMP) | \ (1LL << ADC_CONF_ACQ_POST_SAMP) | \
(1LL << ADC_CONF_ACQ_PRE_SAMP) | \ (1LL << ADC_CONF_ACQ_PRE_SAMP) | \
...@@ -763,6 +779,8 @@ static struct adc_operations fa_100ms_4ch_14bit_op = { ...@@ -763,6 +779,8 @@ static struct adc_operations fa_100ms_4ch_14bit_op = {
.tstamp_buffer = adc_zio_tstamp_buffer, .tstamp_buffer = adc_zio_tstamp_buffer,
.release_buffer = adc_zio_release_buffer, .release_buffer = adc_zio_release_buffer,
.trigger_fire = adc_100m14b4cha_trigger_fire, .trigger_fire = adc_100m14b4cha_trigger_fire,
.buffer_get_sample = adc_100m14b4cha_buffer_get_sample,
}; };
struct adc_board_type fmcadc_100ms_4ch_14bit = { struct adc_board_type fmcadc_100ms_4ch_14bit = {
......
...@@ -511,3 +511,35 @@ int adc_trigger_fire(struct adc_dev *dev) ...@@ -511,3 +511,35 @@ int adc_trigger_fire(struct adc_dev *dev)
} }
return b->adc_op->trigger_fire(dev); return b->adc_op->trigger_fire(dev);
} }
/**
* It gets a sample from the buffer
* @param[in] buf buffer to use
* @param[in] chan which channel
* @param[in] acq_sample acquisition sample
* @param[out] value
* @return 0 on success, -1 on error and errno is set appropriately
* ADC_ENOP if the operation is not supported by the board that
* acquired the buffer
*/
int adc_buffer_get_sample(struct adc_buffer *buf,
unsigned int chan,
unsigned int acq_sample,
int32_t *value)
{
struct adc_gid *g = (struct adc_gid *)buf->dev;
const struct adc_board_type *b = g->board;
if (!b->adc_op->buffer_get_sample) {
errno = ADC_ENOP;
return -1;
}
if (acq_sample >= buf->nsamples) {
errno = EINVAL;
return -1;
}
return b->adc_op->buffer_get_sample(buf, chan, acq_sample, value);
}
...@@ -674,7 +674,6 @@ static void fald_acq_print_data(struct adc_buffer *buf, ...@@ -674,7 +674,6 @@ static void fald_acq_print_data(struct adc_buffer *buf,
unsigned int n) unsigned int n)
{ {
int j, ch; int j, ch;
int16_t *data; /* FMC-ADC-100M sample size is 14bit, 16bit for ZIO */
uint32_t pre; uint32_t pre;
if (n == 0) if (n == 0)
...@@ -688,17 +687,18 @@ static void fald_acq_print_data(struct adc_buffer *buf, ...@@ -688,17 +687,18 @@ static void fald_acq_print_data(struct adc_buffer *buf,
adc_get_conf(acq_cfg, ADC_CONF_ACQ_PRE_SAMP, &pre); adc_get_conf(acq_cfg, ADC_CONF_ACQ_PRE_SAMP, &pre);
data = buf->data;
/* Print data */ /* Print data */
for (j = 0; j < nsamples; j++) { for (j = 0; j < nsamples; j++) {
if ( (n > 0 && j < n) || if ( (n > 0 && j < n) ||
(n < 0 && (nsamples - j) <= (-n)) ) { (n < 0 && (nsamples - j) <= (-n)) ) {
printf("%5i ", j - pre); printf("%5i ", j - pre);
for (ch = 0; ch < nchan; ch++) for (ch = 0; ch < nchan; ch++) {
printf("%7i", *(data++)); int32_t sample;
adc_buffer_get_sample(buf, ch, j, &sample);
printf("%7i", sample);
}
printf("\n"); printf("\n");
} else {
data += nchan;
} }
} }
} }
......
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