Skip to content

Commit

Permalink
examples: adrv9009-iiostream: fix variable shadowing warnings
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nunojsa authored and pcercuei committed Jun 28, 2021
1 parent 2bf5645 commit 405addf
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions examples/adrv9009-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ static char* get_ch_name(const char* type, int id)
}

/* returns adrv9009 phy device */
static struct iio_device* get_adrv9009_phy(struct iio_context *ctx)
static struct iio_device* get_adrv9009_phy(void)
{
struct iio_device *dev = iio_context_find_device(ctx, "adrv9009-phy");
IIO_ENSURE(dev && "No adrv9009-phy found");
return dev;
}

/* finds adrv9009 streaming IIO devices */
static bool get_adrv9009_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev)
static bool get_adrv9009_stream_dev(enum iodev d, struct iio_device **dev)
{
switch (d) {
case TX: *dev = iio_context_find_device(ctx, "axi-adrv9009-tx-hpc"); return *dev != NULL;
Expand All @@ -147,7 +147,7 @@ static bool get_adrv9009_stream_dev(struct iio_context *ctx, enum iodev d, struc
}

/* finds adrv9009 streaming IIO channels */
static bool get_adrv9009_stream_ch(__notused struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, char modify, struct iio_channel **chn)
static bool get_adrv9009_stream_ch(enum iodev d, struct iio_device *dev, int chid, char modify, struct iio_channel **chn)
{
*chn = iio_device_find_channel(dev, modify ? get_ch_name_mod("voltage", chid, modify) : get_ch_name("voltage", chid), d == TX);
if (!*chn)
Expand All @@ -156,37 +156,37 @@ static bool get_adrv9009_stream_ch(__notused struct iio_context *ctx, enum iodev
}

/* finds adrv9009 phy IIO configuration channel with id chid */
static bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn)
static bool get_phy_chan(enum iodev d, int chid, struct iio_channel **chn)
{
switch (d) {
case RX: *chn = iio_device_find_channel(get_adrv9009_phy(ctx), get_ch_name("voltage", chid), false); return *chn != NULL;
case TX: *chn = iio_device_find_channel(get_adrv9009_phy(ctx), get_ch_name("voltage", chid), true); return *chn != NULL;
case RX: *chn = iio_device_find_channel(get_adrv9009_phy(), get_ch_name("voltage", chid), false); return *chn != NULL;
case TX: *chn = iio_device_find_channel(get_adrv9009_phy(), get_ch_name("voltage", chid), true); return *chn != NULL;
default: IIO_ENSURE(0); return false;
}
}

/* finds adrv9009 local oscillator IIO configuration channels */
static bool get_lo_chan(struct iio_context *ctx, struct iio_channel **chn)
static bool get_lo_chan(struct iio_channel **chn)
{
// LO chan is always output, i.e. true
*chn = iio_device_find_channel(get_adrv9009_phy(ctx), get_ch_name("altvoltage", 0), true); return *chn != NULL;
*chn = iio_device_find_channel(get_adrv9009_phy(), get_ch_name("altvoltage", 0), true); return *chn != NULL;
}

/* applies streaming configuration through IIO */
bool cfg_adrv9009_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, int chid)
bool cfg_adrv9009_streaming_ch(struct stream_cfg *cfg, int chid)
{
struct iio_channel *chn = NULL;

// Configure phy and lo channels
printf("* Acquiring ADRV9009 phy channel %d\n", chid);
if (!get_phy_chan(ctx, true, chid, &chn)) { return false; }
if (!get_phy_chan(true, chid, &chn)) { return false; }

rd_ch_lli(chn, "rf_bandwidth");
rd_ch_lli(chn, "sampling_frequency");

// Configure LO channel
printf("* Acquiring ADRV9009 TRX lo channel\n");
if (!get_lo_chan(ctx, &chn)) { return false; }
if (!get_lo_chan(&chn)) { return false; }
wr_ch_lli(chn, "frequency", cfg->lo_hz);
return true;
}
Expand Down Expand Up @@ -216,17 +216,17 @@ int main (__notused int argc, __notused char **argv)
IIO_ENSURE(iio_context_get_devices_count(ctx) > 0 && "No devices");

printf("* Acquiring ADRV9009 streaming devices\n");
IIO_ENSURE(get_adrv9009_stream_dev(ctx, TX, &tx) && "No tx dev found");
IIO_ENSURE(get_adrv9009_stream_dev(ctx, RX, &rx) && "No rx dev found");
IIO_ENSURE(get_adrv9009_stream_dev(TX, &tx) && "No tx dev found");
IIO_ENSURE(get_adrv9009_stream_dev(RX, &rx) && "No rx dev found");

printf("* Configuring ADRV9009 for streaming\n");
IIO_ENSURE(cfg_adrv9009_streaming_ch(ctx, &trxcfg, 0) && "TRX device not found");
IIO_ENSURE(cfg_adrv9009_streaming_ch(&trxcfg, 0) && "TRX device not found");

printf("* Initializing ADRV9009 IIO streaming channels\n");
IIO_ENSURE(get_adrv9009_stream_ch(ctx, RX, rx, 0, 'i', &rx0_i) && "RX chan i not found");
IIO_ENSURE(get_adrv9009_stream_ch(ctx, RX, rx, 0, 'q', &rx0_q) && "RX chan q not found");
IIO_ENSURE(get_adrv9009_stream_ch(ctx, TX, tx, 0, 0, &tx0_i) && "TX chan i not found");
IIO_ENSURE(get_adrv9009_stream_ch(ctx, TX, tx, 1, 0, &tx0_q) && "TX chan q not found");
IIO_ENSURE(get_adrv9009_stream_ch(RX, rx, 0, 'i', &rx0_i) && "RX chan i not found");
IIO_ENSURE(get_adrv9009_stream_ch(RX, rx, 0, 'q', &rx0_q) && "RX chan q not found");
IIO_ENSURE(get_adrv9009_stream_ch(TX, tx, 0, 0, &tx0_i) && "TX chan i not found");
IIO_ENSURE(get_adrv9009_stream_ch(TX, tx, 1, 0, &tx0_q) && "TX chan q not found");

printf("* Enabling IIO streaming channels\n");
iio_channel_enable(rx0_i);
Expand Down

0 comments on commit 405addf

Please sign in to comment.