Skip to content

Commit 7f9b88f

Browse files
nunojsapcercuei
authored andcommitted
examples: ad9361-iiostream: fix variable shadowing warnings
The IIO context is defined as a global variable so that it does not make sense to pass it around local functions. Moreover, this was triggering -Wshadow. Signed-off-by: Nuno Sá <[email protected]>
1 parent 405addf commit 7f9b88f

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

examples/ad9361-iiostream.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ static char* get_ch_name(const char* type, int id)
111111
}
112112

113113
/* returns ad9361 phy device */
114-
static struct iio_device* get_ad9361_phy(struct iio_context *ctx)
114+
static struct iio_device* get_ad9361_phy(void)
115115
{
116116
struct iio_device *dev = iio_context_find_device(ctx, "ad9361-phy");
117117
IIO_ENSURE(dev && "No ad9361-phy found");
118118
return dev;
119119
}
120120

121121
/* finds AD9361 streaming IIO devices */
122-
static bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev)
122+
static bool get_ad9361_stream_dev(enum iodev d, struct iio_device **dev)
123123
{
124124
switch (d) {
125125
case TX: *dev = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc"); return *dev != NULL;
@@ -129,7 +129,7 @@ static bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct
129129
}
130130

131131
/* finds AD9361 streaming IIO channels */
132-
static bool get_ad9361_stream_ch(__notused struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn)
132+
static bool get_ad9361_stream_ch(enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn)
133133
{
134134
*chn = iio_device_find_channel(dev, get_ch_name("voltage", chid), d == TX);
135135
if (!*chn)
@@ -138,51 +138,51 @@ static bool get_ad9361_stream_ch(__notused struct iio_context *ctx, enum iodev d
138138
}
139139

140140
/* finds AD9361 phy IIO configuration channel with id chid */
141-
static bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn)
141+
static bool get_phy_chan(enum iodev d, int chid, struct iio_channel **chn)
142142
{
143143
switch (d) {
144-
case RX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("voltage", chid), false); return *chn != NULL;
145-
case TX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("voltage", chid), true); return *chn != NULL;
144+
case RX: *chn = iio_device_find_channel(get_ad9361_phy(), get_ch_name("voltage", chid), false); return *chn != NULL;
145+
case TX: *chn = iio_device_find_channel(get_ad9361_phy(), get_ch_name("voltage", chid), true); return *chn != NULL;
146146
default: IIO_ENSURE(0); return false;
147147
}
148148
}
149149

150150
/* finds AD9361 local oscillator IIO configuration channels */
151-
static bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn)
151+
static bool get_lo_chan(enum iodev d, struct iio_channel **chn)
152152
{
153153
switch (d) {
154154
// LO chan is always output, i.e. true
155-
case RX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("altvoltage", 0), true); return *chn != NULL;
156-
case TX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("altvoltage", 1), true); return *chn != NULL;
155+
case RX: *chn = iio_device_find_channel(get_ad9361_phy(), get_ch_name("altvoltage", 0), true); return *chn != NULL;
156+
case TX: *chn = iio_device_find_channel(get_ad9361_phy(), get_ch_name("altvoltage", 1), true); return *chn != NULL;
157157
default: IIO_ENSURE(0); return false;
158158
}
159159
}
160160

161161
/* applies streaming configuration through IIO */
162-
bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, int chid)
162+
bool cfg_ad9361_streaming_ch(struct stream_cfg *cfg, enum iodev type, int chid)
163163
{
164164
struct iio_channel *chn = NULL;
165165

166166
// Configure phy and lo channels
167167
printf("* Acquiring AD9361 phy channel %d\n", chid);
168-
if (!get_phy_chan(ctx, type, chid, &chn)) { return false; }
168+
if (!get_phy_chan(type, chid, &chn)) { return false; }
169169
wr_ch_str(chn, "rf_port_select", cfg->rfport);
170170
wr_ch_lli(chn, "rf_bandwidth", cfg->bw_hz);
171171
wr_ch_lli(chn, "sampling_frequency", cfg->fs_hz);
172172

173173
// Configure LO channel
174174
printf("* Acquiring AD9361 %s lo channel\n", type == TX ? "TX" : "RX");
175-
if (!get_lo_chan(ctx, type, &chn)) { return false; }
175+
if (!get_lo_chan(type, &chn)) { return false; }
176176
wr_ch_lli(chn, "frequency", cfg->lo_hz);
177177
return true;
178178
}
179179

180180
/* simple configuration and streaming */
181-
/* usage:
181+
/* usage:
182182
* Default context, assuming local IIO devices, i.e., this script is run on ADALM-Pluto for example
183183
$./a.out
184184
* URI context, find out the uri by typing `iio_info -s` at the command line of the host PC
185-
$./a.out usb:x.x.x
185+
$./a.out usb:x.x.x
186186
*/
187187
int main (int argc, char **argv)
188188
{
@@ -223,18 +223,18 @@ int main (int argc, char **argv)
223223
IIO_ENSURE(iio_context_get_devices_count(ctx) > 0 && "No devices");
224224

225225
printf("* Acquiring AD9361 streaming devices\n");
226-
IIO_ENSURE(get_ad9361_stream_dev(ctx, TX, &tx) && "No tx dev found");
227-
IIO_ENSURE(get_ad9361_stream_dev(ctx, RX, &rx) && "No rx dev found");
226+
IIO_ENSURE(get_ad9361_stream_dev(TX, &tx) && "No tx dev found");
227+
IIO_ENSURE(get_ad9361_stream_dev(RX, &rx) && "No rx dev found");
228228

229229
printf("* Configuring AD9361 for streaming\n");
230-
IIO_ENSURE(cfg_ad9361_streaming_ch(ctx, &rxcfg, RX, 0) && "RX port 0 not found");
231-
IIO_ENSURE(cfg_ad9361_streaming_ch(ctx, &txcfg, TX, 0) && "TX port 0 not found");
230+
IIO_ENSURE(cfg_ad9361_streaming_ch(&rxcfg, RX, 0) && "RX port 0 not found");
231+
IIO_ENSURE(cfg_ad9361_streaming_ch(&txcfg, TX, 0) && "TX port 0 not found");
232232

233233
printf("* Initializing AD9361 IIO streaming channels\n");
234-
IIO_ENSURE(get_ad9361_stream_ch(ctx, RX, rx, 0, &rx0_i) && "RX chan i not found");
235-
IIO_ENSURE(get_ad9361_stream_ch(ctx, RX, rx, 1, &rx0_q) && "RX chan q not found");
236-
IIO_ENSURE(get_ad9361_stream_ch(ctx, TX, tx, 0, &tx0_i) && "TX chan i not found");
237-
IIO_ENSURE(get_ad9361_stream_ch(ctx, TX, tx, 1, &tx0_q) && "TX chan q not found");
234+
IIO_ENSURE(get_ad9361_stream_ch(RX, rx, 0, &rx0_i) && "RX chan i not found");
235+
IIO_ENSURE(get_ad9361_stream_ch(RX, rx, 1, &rx0_q) && "RX chan q not found");
236+
IIO_ENSURE(get_ad9361_stream_ch(TX, tx, 0, &tx0_i) && "TX chan i not found");
237+
IIO_ENSURE(get_ad9361_stream_ch(TX, tx, 1, &tx0_q) && "TX chan q not found");
238238

239239
printf("* Enabling IIO streaming channels\n");
240240
iio_channel_enable(rx0_i);
@@ -300,4 +300,4 @@ int main (int argc, char **argv)
300300
shutdown();
301301

302302
return 0;
303-
}
303+
}

0 commit comments

Comments
 (0)