This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
university:tools:pluto:controlling_the_transceiver_and_transferring_data [28 Apr 2017 15:50] – Michael Hennerich | university:tools:pluto:controlling_the_transceiver_and_transferring_data [18 Dec 2020 17:55] (current) – Fix broken link to IIO High Speed doc Rob Riggs | ||
---|---|---|---|
Line 13: | Line 13: | ||
* [[https:// | * [[https:// | ||
* [[http:// | * [[http:// | ||
- | * [[http://events.linuxfoundation.org/ | + | * [[https://events.static.linuxfound.org/ |
* [[http:// | * [[http:// | ||
* [[https:// | * [[https:// | ||
Line 19: | Line 19: | ||
===== Controlling the transceiver ===== | ===== Controlling the transceiver ===== | ||
+ | The code snippet below is a minimalistic example without error checking. | ||
+ | It shows how to control the AD936x transceiver via a remote connection. | ||
+ | |||
+ | - Create IIO IP Network context. Instead of '' | ||
+ | - Get the AD936x PHY device structure | ||
+ | - Set the TX LO frequency (see [[resources: | ||
+ | - Set RX baseband rate | ||
+ | |||
+ | \\ | ||
<code c> | <code c> | ||
+ | #include < | ||
+ | |||
int main (int argc, char **argv) | int main (int argc, char **argv) | ||
{ | { | ||
Line 25: | Line 36: | ||
struct iio_device *phy; | struct iio_device *phy; | ||
- | ctx = iio_create_context_from_uri(" | + | ctx = iio_create_context_from_uri(" |
phy = iio_context_find_device(ctx, | phy = iio_context_find_device(ctx, | ||
Line 32: | Line 43: | ||
iio_device_find_channel(phy, | iio_device_find_channel(phy, | ||
" | " | ||
- | 2400000000); | + | 2400000000); |
- | + | ||
iio_channel_attr_write_longlong( | iio_channel_attr_write_longlong( | ||
iio_device_find_channel(phy, | iio_device_find_channel(phy, | ||
" | " | ||
- | 50000000); | + | 5000000); /* RX baseband rate 5 MSPS */ |
receive(ctx); | receive(ctx); | ||
Line 44: | Line 55: | ||
return 0; | return 0; | ||
- | } | + | } |
</ | </ | ||
===== Receiving data ===== | ===== Receiving data ===== | ||
+ | |||
+ | - Get the RX capture device structure | ||
+ | - Get the IQ input channels | ||
+ | - Enable I and Q channel | ||
+ | - Create the RX buffer | ||
+ | - Fill the buffer | ||
+ | - Process samples | ||
+ | |||
+ | \\ | ||
<code c> | <code c> | ||
+ | int receive(struct iio_context *ctx) | ||
+ | { | ||
+ | struct iio_device *dev; | ||
+ | struct iio_channel *rx0_i, *rx0_q; | ||
+ | struct iio_buffer *rxbuf; | ||
+ | dev = iio_context_find_device(ctx, | ||
+ | |||
+ | rx0_i = iio_device_find_channel(dev, | ||
+ | rx0_q = iio_device_find_channel(dev, | ||
+ | |||
+ | iio_channel_enable(rx0_i); | ||
+ | iio_channel_enable(rx0_q); | ||
+ | |||
+ | rxbuf = iio_device_create_buffer(dev, | ||
+ | if (!rxbuf) { | ||
+ | perror(" | ||
+ | shutdown(); | ||
+ | } | ||
+ | |||
+ | while (true) { | ||
+ | void *p_dat, *p_end, *t_dat; | ||
+ | ptrdiff_t p_inc; | ||
+ | |||
+ | iio_buffer_refill(rxbuf); | ||
+ | |||
+ | p_inc = iio_buffer_step(rxbuf); | ||
+ | p_end = iio_buffer_end(rxbuf); | ||
+ | |||
+ | for (p_dat = iio_buffer_first(rxbuf, | ||
+ | const int16_t i = ((int16_t*)p_dat)[0]; | ||
+ | const int16_t q = ((int16_t*)p_dat)[1]; | ||
+ | |||
+ | /* Process here */ | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | iio_buffer_destroy(rxbuf); | ||
+ | |||
+ | } | ||
</ | </ | ||