Skip to content

Commit f2e7c76

Browse files
dNechitacristina-suteu
authored andcommitted
treewide: Use the channels mask that is stored for each io device
Signed-off-by: Dan Nechita <[email protected]>
1 parent 1877133 commit f2e7c76

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

Diff for: osc.c

+35-38
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,25 @@ bool dma_valid_selection(const char *device, unsigned mask, unsigned channel_cou
163163
return ret;
164164
}
165165

166-
unsigned global_enabled_channels_mask(struct iio_device *dev, struct iio_channels_mask *ch_mask)
166+
unsigned global_enabled_channels_mask(struct iio_device *dev)
167167
{
168168
unsigned mask = 0;
169169
int scan_i = 0;
170170
unsigned int i = 0;
171+
struct extra_dev_info *dev_info;
172+
173+
dev_info = iio_device_get_data(dev);
174+
if (!dev_info || !dev_info->channels_mask) {
175+
fprintf(stderr, "error! Cannot retrieve channels mask of device: %s\n",
176+
iio_device_get_id(dev));
177+
return 0;
178+
}
171179

172180
for (; i < iio_device_get_channels_count(dev); i++) {
173181
struct iio_channel *chn = iio_device_get_channel(dev, i);
174182

175183
if (iio_channel_is_scan_element(chn)) {
176-
if (iio_channel_is_enabled(chn, ch_mask))
184+
if (iio_channel_is_enabled(chn, dev_info->channels_mask))
177185
mask |= 1 << scan_i;
178186
scan_i++;
179187
}
@@ -255,25 +263,25 @@ static void destroy_all_plots(void)
255263
g_list_foreach(plot_list, gfunc_destroy_plot, NULL);
256264
}
257265

258-
static void disable_all_channels(struct iio_device *dev, struct iio_channels_mask *ch_mask)
266+
static void disable_all_channels(struct iio_device *dev)
259267
{
260268
unsigned int i, nb_channels = iio_device_get_channels_count(dev);
269+
struct extra_dev_info *info = iio_device_get_data(dev);
270+
261271
for (i = 0; i < nb_channels; i++)
262-
iio_channel_disable(iio_device_get_channel(dev, i), ch_mask);
272+
iio_channel_disable(iio_device_get_channel(dev, i), info->channels_mask);
263273
}
264274

265275
static void close_active_buffers(void)
266276
{
267277
unsigned int i;
268-
const struct iio_channels_mask *mask = NULL;
269278

270279
for (i = 0; i < num_devices; i++) {
271280
struct iio_device *dev = iio_context_get_device(ctx, i);
272281
struct extra_dev_info *info = iio_device_get_data(dev);
273282

274283
if (info->buffer) {
275-
mask = iio_buffer_get_channels_mask(info->buffer);
276-
disable_all_channels(dev,(struct iio_channels_mask *) mask);
284+
disable_all_channels(dev);
277285
iio_buffer_destroy(info->buffer);
278286
info->buffer = NULL;
279287
}
@@ -557,28 +565,26 @@ gdouble plugin_get_plot_fft_avg(OscPlot *plot, const char *device)
557565

558566
int plugin_data_capture_size(const char *device)
559567
{
560-
struct extra_dev_info *info;
561568
struct iio_device *dev;
562-
const struct iio_channels_mask *mask;
569+
struct extra_dev_info *info;
563570

564571
if (!device)
565572
return 0;
566573

567574
dev = iio_context_find_device(ctx, device);
568575
if (!dev)
569576
return 0;
570-
571577
info = iio_device_get_data(dev);
572-
mask = iio_buffer_get_channels_mask(info->buffer);
573-
return info->sample_count * iio_device_get_sample_size(dev, mask);
578+
579+
return info->sample_count * iio_device_get_sample_size(dev, info->channels_mask);
574580
}
575581

576582
int plugin_data_capture_num_active_channels(const char *device)
577583
{
578584
int nb_active = 0;
579585
unsigned int i, nb_channels;
580586
struct iio_device *dev;
581-
const struct iio_channels_mask *mask;
587+
struct extra_dev_info *info;
582588

583589
if (!device)
584590
return 0;
@@ -587,11 +593,11 @@ int plugin_data_capture_num_active_channels(const char *device)
587593
if (!dev)
588594
return 0;
589595

596+
info = iio_device_get_data(dev);
590597
nb_channels = iio_device_get_channels_count(dev);
591-
mask = iio_create_channels_mask(nb_channels);
592598
for (i = 0; i < nb_channels; i++) {
593599
struct iio_channel *chn = iio_device_get_channel(dev, i);
594-
if (iio_channel_is_enabled(chn, mask))
600+
if (iio_channel_is_enabled(chn, info->channels_mask))
595601
nb_active++;
596602
}
597603

@@ -601,7 +607,7 @@ int plugin_data_capture_num_active_channels(const char *device)
601607
int plugin_data_capture_bytes_per_sample(const char *device)
602608
{
603609
struct iio_device *dev;
604-
const struct iio_channels_mask *mask;
610+
struct extra_dev_info *dev_info;
605611
int nb_channels;
606612

607613
if (!device)
@@ -612,9 +618,9 @@ int plugin_data_capture_bytes_per_sample(const char *device)
612618
if (!dev)
613619
return 0;
614620
nb_channels = iio_device_get_channels_count(dev);
615-
mask = iio_create_channels_mask(nb_channels);
621+
dev_info = iio_device_get_data(dev);
616622

617-
return iio_device_get_sample_size(dev, mask);
623+
return iio_device_get_sample_size(dev, dev_info->channels_mask);
618624
}
619625

620626
int plugin_data_capture_of_plot(OscPlot *plot, const char *device, gfloat ***cooked_data,
@@ -1240,11 +1246,10 @@ static off_t get_trigger_offset(const struct iio_channel *chn,
12401246
struct extra_info *info = iio_channel_get_data(chn);
12411247
size_t i;
12421248
const struct iio_device *dev = iio_channel_get_device(chn);
1249+
struct extra_dev_info *dev_info = iio_device_get_data(dev);
12431250
int nb_channels = iio_device_get_channels_count(dev);
1244-
const struct iio_channels_mask *mask = iio_create_channels_mask(nb_channels);
12451251

1246-
1247-
if (iio_channel_is_enabled(chn, mask)) {
1252+
if (iio_channel_is_enabled(chn, dev_info->channels_mask)) {
12481253
for (i = info->offset / 2; i >= 1; i--) {
12491254
if (!falling_edge && info->data_ref[i - 1] < trigger_value &&
12501255
info->data_ref[i] >= trigger_value)
@@ -1288,14 +1293,7 @@ static gboolean capture_process(void *data)
12881293
struct iio_device *dev = iio_context_get_device(ctx, i);
12891294
struct extra_dev_info *dev_info = iio_device_get_data(dev);
12901295
unsigned int nb_channels = iio_device_get_channels_count(dev);
1291-
const struct iio_channels_mask *mask = NULL;
1292-
if(dev_info->buffer == NULL)
1293-
mask = iio_create_channels_mask(nb_channels);
1294-
else
1295-
mask = iio_buffer_get_channels_mask(dev_info->buffer);
1296-
1297-
1298-
unsigned int i, sample_size = iio_device_get_sample_size(dev, mask);
1296+
unsigned int i, sample_size = iio_device_get_sample_size(dev, dev_info->channels_mask);
12991297
ssize_t sample_count = dev_info->sample_count;
13001298
struct iio_channel *chn;
13011299
off_t offset = 0;
@@ -1310,7 +1308,7 @@ static gboolean capture_process(void *data)
13101308

13111309
if (dev_info->buffer == NULL || device_is_oneshot(dev)) {
13121310
dev_info->buffer_size = sample_count;
1313-
dev_info->buffer = iio_device_create_buffer(dev, 0, mask);
1311+
dev_info->buffer = iio_device_create_buffer(dev, 0, dev_info->channels_mask);
13141312
if (!dev_info->buffer) {
13151313
fprintf(stderr, "Error: Unable to create buffer: %s\n", strerror(errno));
13161314
goto capture_stop_check;
@@ -1342,7 +1340,7 @@ static gboolean capture_process(void *data)
13421340
ret /= sample_size;
13431341
if (ret >= sample_count) {
13441342

1345-
iio_block_foreach_sample(block, mask, demux_sample, NULL);
1343+
iio_block_foreach_sample(block, dev_info->channels_mask, demux_sample, NULL);
13461344
if (ret >= sample_count * 2) {
13471345
printf("Decreasing block size\n");
13481346
iio_stream_destroy(dev_info->stream);
@@ -1366,7 +1364,7 @@ static gboolean capture_process(void *data)
13661364

13671365
if (dev_info->channel_trigger_enabled) {
13681366
chn = iio_device_get_channel(dev, dev_info->channel_trigger);
1369-
if (!iio_channel_is_enabled(chn, mask))
1367+
if (!iio_channel_is_enabled(chn, dev_info->channels_mask))
13701368
dev_info->channel_trigger_enabled = false;
13711369
}
13721370

@@ -1385,7 +1383,7 @@ static gboolean capture_process(void *data)
13851383
offset -= quatter_of_capture_interval * sizeof(gfloat);
13861384
for (i = 0; i < nb_channels; i++) {
13871385
chn = iio_device_get_channel(dev, i);
1388-
if (iio_channel_is_enabled(chn, mask))
1386+
if (iio_channel_is_enabled(chn, dev_info->channels_mask))
13891387
apply_trigger_offset(chn, offset);
13901388
}
13911389
}
@@ -1500,7 +1498,6 @@ static int capture_setup(void)
15001498
struct extra_dev_info *dev_info = iio_device_get_data(dev);
15011499
unsigned int nb_channels = iio_device_get_channels_count(dev);
15021500
unsigned int sample_size, sample_count = max_sample_count_from_plots(dev_info);
1503-
const struct iio_channels_mask *mask = iio_create_channels_mask(nb_channels);
15041501

15051502

15061503
/* We capture a double amount o data. Then we look for a trigger
@@ -1514,13 +1511,13 @@ static int capture_setup(void)
15141511
struct iio_channel *ch = iio_device_get_channel(dev, j);
15151512
struct extra_info *info = iio_channel_get_data(ch);
15161513
if (info->shadow_of_enabled > 0)
1517-
iio_channel_enable(ch, (struct iio_channels_mask *)mask);
1514+
iio_channel_enable(ch, dev_info->channels_mask);
15181515
else
1519-
iio_channel_disable(ch, (struct iio_channels_mask *)mask);
1516+
iio_channel_disable(ch, dev_info->channels_mask);
15201517
}
15211518

15221519

1523-
sample_size = iio_device_get_sample_size(dev, mask);
1520+
sample_size = iio_device_get_sample_size(dev, dev_info->channels_mask);
15241521
if (sample_size == 0 || sample_count == 0)
15251522
continue;
15261523

@@ -1538,7 +1535,7 @@ static int capture_setup(void)
15381535
dev_info->buffer = NULL;
15391536
dev_info->sample_count = sample_count;
15401537
dev_info->buffer_size = sample_count;
1541-
dev_info->buffer = iio_device_create_buffer(dev, 0, mask);
1538+
dev_info->buffer = iio_device_create_buffer(dev, 0, dev_info->channels_mask);
15421539
dev_info->stream = iio_buffer_create_stream(dev_info->buffer, 4, dev_info->sample_count);
15431540
if (!dev_info->buffer) {
15441541
fprintf(stderr, "Error: Unable to create buffer: %s\n", strerror(errno));

Diff for: osc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void trigger_settings_for_device(GtkBuilder *builder, const char *device);
112112
void application_quit (void);
113113

114114
bool dma_valid_selection(const char *device, unsigned mask, unsigned channel_count);
115-
unsigned global_enabled_channels_mask(struct iio_device *dev, struct iio_channels_mask *ch_mask);
115+
unsigned global_enabled_channels_mask(struct iio_device *dev);
116116
void add_ch_setup_check_fct(char *device_name, void *fp);
117117
void *find_setup_check_fct_by_devname(const char *dev_name);
118118
bool is_input_device(const struct iio_device *dev);

Diff for: oscplot.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,6 @@ static gboolean check_valid_setup_of_device(OscPlot *plot, const char *name)
21132113
struct iio_device *dev;
21142114
unsigned int nb_channels = num_of_channels_of_device(treeview, name);
21152115
unsigned enabled_channels_mask;
2116-
const struct iio_channels_mask *mask = NULL;
21172116

21182117
GtkTreeModel *model;
21192118
GtkTreeIter iter;
@@ -2133,9 +2132,6 @@ static gboolean check_valid_setup_of_device(OscPlot *plot, const char *name)
21332132
if (!dev)
21342133
return TRUE;
21352134
num_enabled = enabled_channels_of_device(treeview, name, &enabled_channels_mask);
2136-
mask = iio_create_channels_mask(iio_device_get_channels_count(dev));
2137-
2138-
21392135

21402136
/* Basic validation rules */
21412137
if (plot_type == FFT_PLOT) {
@@ -2156,7 +2152,7 @@ static gboolean check_valid_setup_of_device(OscPlot *plot, const char *name)
21562152
"Time Domain needs at least one channel");
21572153
return false;
21582154
} else if (dev && !dma_valid_selection(name, enabled_channels_mask |
2159-
global_enabled_channels_mask(dev, (struct iio_channels_mask *) mask), nb_channels)) {
2155+
global_enabled_channels_mask(dev), nb_channels)) {
21602156
gtk_widget_set_tooltip_text(priv->capture_button,
21612157
"Channel selection not supported");
21622158
return false;

0 commit comments

Comments
 (0)