Post Go back to editing

IIO: How to differentiate between input and output channels with the same name

Category: Software
Product Number: ad9375
Software Version: 2022_R2

Hello

I am using the IIO device driver for the AD9375. I am using version 2022_R2 of the meta-adi layer for Petalinux.

I have hopefully a simple question.

I am trying to select a specific IIO channel on the AD9375. It has two output channels named voltage0 and voltage1 and three input channels named voltage0, voltage1 and voltage2.

To select a channel I have been using iio_device_find_channel() which uses the name ("voltage0", "voltage1", etc). 

How do  I choose whether I want to find / select the input channel or the output channel? I assume there must be a function but I am unable to find it.

Thank you.

Gavin

  • Here is what iio_info prints out:


           iio:device2: ad9371-phy
                    23 channels found:
                            altvoltage0: RX_LO (output)
                            2 channel-specific attributes found:
                                    attr  0: frequency value: 2500000000
                                    attr  1: label value: RX_LO
                            voltage1:  (output)
                            34 channel-specific attributes found:
                                    attr  0: clgc_current_gain value: 0
                                    attr  1: clgc_desired_gain value: -200
                                    attr  2: clgc_orx_rms value: 0
                                    attr  3: clgc_status value: 0
                                    attr  4: clgc_track_count value: 0
                                    attr  5: clgc_tracking_en value: 0
                                    attr  6: clgc_tx_gain value: 0
                                    attr  7: clgc_tx_rms value: 0
                                    attr  8: dpd_actuator_en value: 1
                                    attr  9: dpd_external_path_delay value: 2488
                                    attr 10: dpd_model_error value: 1000
                                    attr 11: dpd_reset_en value: 0
                                    attr 12: dpd_status value: 0
                                    attr 13: dpd_track_count value: 0
                                    attr 14: dpd_tracking_en value: 0
                                    attr 15: hardwaregain value: -10.000000 dB
                                    attr 16: lo_leakage_tracking_en value: 0
                                    attr 17: quadrature_tracking_en value: 1
                                    attr 18: rf_bandwidth value: 75000000
                                    attr 19: sampling_frequency value: 250000000
                                    attr 20: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                                    attr 21: vswr_forward_gain value: 0
                                    attr 22: vswr_forward_gain_imag value: 0
                                    attr 23: vswr_forward_gain_real value: 0
                                    attr 24: vswr_forward_orx value: 0
                                    attr 25: vswr_forward_tx value: 0
                                    attr 26: vswr_reflected_gain value: 0
                                    attr 27: vswr_reflected_gain_imag value: 0
                                    attr 28: vswr_reflected_gain_real value: 0
                                    attr 29: vswr_reflected_orx value: 0
                                    attr 30: vswr_reflected_tx value: 0
                                    attr 31: vswr_status value: 0
                                    attr 32: vswr_track_count value: 0
                                    attr 33: vswr_tracking_en value: 0
                            voltage0:  (output)
                            34 channel-specific attributes found:
                                    attr  0: clgc_current_gain value: 0
                                    attr  1: clgc_desired_gain value: -200
                                    attr  2: clgc_orx_rms value: 0
                                    attr  3: clgc_status value: 0
                                    attr  4: clgc_track_count value: 0
                                    attr  5: clgc_tracking_en value: 0
                                    attr  6: clgc_tx_gain value: 0
                                    attr  7: clgc_tx_rms value: 0
                                    attr  8: dpd_actuator_en value: 1
                                    attr  9: dpd_external_path_delay value: 2297
                                    attr 10: dpd_model_error value: 1000
                                    attr 11: dpd_reset_en value: 0
                                    attr 12: dpd_status value: 0
                                    attr 13: dpd_track_count value: 0
                                    attr 14: dpd_tracking_en value: 0
                                    attr 15: hardwaregain value: -10.000000 dB
                                    attr 16: lo_leakage_tracking_en value: 0
                                    attr 17: quadrature_tracking_en value: 1
                                    attr 18: rf_bandwidth value: 75000000
                                    attr 19: sampling_frequency value: 250000000
                                    attr 20: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                                    attr 21: vswr_forward_gain value: 0
                                    attr 22: vswr_forward_gain_imag value: 0
                                    attr 23: vswr_forward_gain_real value: 0
                                    attr 24: vswr_forward_orx value: 0
                                    attr 25: vswr_forward_tx value: 0
                                    attr 26: vswr_reflected_gain value: 0
                                    attr 27: vswr_reflected_gain_imag value: 0
                                    attr 28: vswr_reflected_gain_real value: 0
                                    attr 29: vswr_reflected_orx value: 0
                                    attr 30: vswr_reflected_tx value: 0
                                    attr 31: vswr_status value: 0
                                    attr 32: vswr_track_count value: 0
                                    attr 33: vswr_tracking_en value: 0
                            voltage9:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            voltage8:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            voltage2:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            voltage2:  (input)
                            10 channel-specific attributes found:
                                    attr  0: gain_control_mode value: manual
                                    attr  1: gain_control_mode_available value: manual automatic hybrid
                                    attr  2: hardwaregain value: -190.000000 dB
                                    attr  3: quadrature_tracking_en value: 0
                                    attr  4: rf_bandwidth value: 200000000
                                    attr  5: rf_port_select value: INTERNALCALS
                                    attr  6: rf_port_select_available value: OFF INTERNALCALS OBS_SNIFFER SN_A SN_B SN_C ORX1_TX_LO ORX2_TX_LO ORX1_SN_LO ORX2_SN_LO
                                    attr  7: rssi value: 41.00 dB
                                    attr  8: sampling_frequency value: 250000000
                                    attr  9: temp_comp_gain value: 0.00 dB
                            altvoltage2: RX_SN_LO (output)
                            2 channel-specific attributes found:
                                    attr  0: frequency value: 2600000000
                                    attr  1: label value: RX_SN_LO
                            voltage5:  (input)
                            5 channel-specific attributes found:
                                    attr  0: gain_control_mode_available value: manual automatic hybrid
                                    attr  1: offset value: 45
                                    attr  2: raw value: 189
                                    attr  3: rf_port_select_available value: OFF INTERNALCALS OBS_SNIFFER SN_A SN_B SN_C ORX1_TX_LO ORX2_TX_LO ORX1_SN_LO ORX2_SN_LO
                                    attr  4: scale value: 0.775194
                            voltage6:  (input)
                            5 channel-specific attributes found:
                                    attr  0: gain_control_mode_available value: manual automatic hybrid
                                    attr  1: offset value: 45
                                    attr  2: raw value: 506
                                    attr  3: rf_port_select_available value: OFF INTERNALCALS OBS_SNIFFER SN_A SN_B SN_C ORX1_TX_LO ORX2_TX_LO ORX1_SN_LO ORX2_SN_LO
                                    attr  4: scale value: 0.775194
                            voltage3:  (input)
                            5 channel-specific attributes found:
                                    attr  0: gain_control_mode_available value: manual automatic hybrid
                                    attr  1: offset value: 45
                                    attr  2: raw value: 691
                                    attr  3: rf_port_select_available value: OFF INTERNALCALS OBS_SNIFFER SN_A SN_B SN_C ORX1_TX_LO ORX2_TX_LO ORX1_SN_LO ORX2_SN_LO
                                    attr  4: scale value: 0.775194
                            voltage6:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            voltage4:  (input)
                            5 channel-specific attributes found:
                                    attr  0: gain_control_mode_available value: manual automatic hybrid
                                    attr  1: offset value: 45
                                    attr  2: raw value: 37
                                    attr  3: rf_port_select_available value: OFF INTERNALCALS OBS_SNIFFER SN_A SN_B SN_C ORX1_TX_LO ORX2_TX_LO ORX1_SN_LO ORX2_SN_LO
                                    attr  4: scale value: 0.775194
                            voltage5:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            voltage1:  (input)
                            9 channel-specific attributes found:
                                    attr  0: gain_control_mode value: manual
                                    attr  1: gain_control_mode_available value: manual automatic hybrid
                                    attr  2: hardwaregain value: 30.000000 dB
                                    attr  3: quadrature_tracking_en value: 1
                                    attr  4: rf_bandwidth value: 100000000
                                    attr  5: rf_port_select_available value: OFF INTERNALCALS OBS_SNIFFER SN_A SN_B SN_C ORX1_TX_LO ORX2_TX_LO ORX1_SN_LO ORX2_SN_LO
                                    attr  6: rssi value: 44.750 dB
                                    attr  7: sampling_frequency value: 125000000
                                    attr  8: temp_comp_gain value: 0.00 dB
                            voltage3:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            voltage10:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            voltage4:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            voltage11:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            voltage7:  (output)
                            5 channel-specific attributes found:
                                    attr  0: offset value: 204
                                    attr  1: raw value: 0
                                    attr  2: sampling_frequency value: 250000000
                                    attr  3: scale value: 1.560671
                                    attr  4: scale_available value: 0.783951 0.798128 0.810932 0.822608 1.560671 1.590157 1.613612 1.637490
                            altvoltage1: TX_LO (output)
                            2 channel-specific attributes found:
                                    attr  0: frequency value: 2500000000
                                    attr  1: label value: TX_LO
                            voltage0:  (input)
                            9 channel-specific attributes found:
                                    attr  0: gain_control_mode value: manual
                                    attr  1: gain_control_mode_available value: manual automatic hybrid
                                    attr  2: hardwaregain value: 30.000000 dB
                                    attr  3: quadrature_tracking_en value: 1
                                    attr  4: rf_bandwidth value: 100000000
                                    attr  5: rf_port_select_available value: OFF INTERNALCALS OBS_SNIFFER SN_A SN_B SN_C ORX1_TX_LO ORX2_TX_LO ORX1_SN_LO ORX2_SN_LO
                                    attr  6: rssi value: 44.750 dB
                                    attr  7: sampling_frequency value: 125000000
                                    attr  8: temp_comp_gain value: 0.00 dB
                            temp:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 56
                                    attr  1: scale value: 1000.000000
                    16 device-specific attributes found:
                                    attr  0: calibrate value: 0
                                    attr  1: calibrate_clgc_en value: 0
                                    attr  2: calibrate_dpd_en value: 0
                                    attr  3: calibrate_loopback_rx_lo_delay_en value: 0
                                    attr  4: calibrate_loopback_rx_rx_qec_en value: 0
                                    attr  5: calibrate_rx_lo_delay_en value: 0
                                    attr  6: calibrate_rx_qec_en value: 0
                                    attr  7: calibrate_tx_lol_en value: 0
                                    attr  8: calibrate_tx_lol_ext_en value: 0
                                    attr  9: calibrate_tx_qec_en value: 0
                                    attr 10: calibrate_vswr_en value: 0
                                    attr 11: ensm_mode value: radio_on
                                    attr 12: ensm_mode_available value: radio_on radio_off
                                    attr 13: gain_table_config ERROR: Permission denied (13)
                                    attr 14: large_lo_step_calibration_en value: 0
                                    attr 15: profile_config value: TB

    I want to set the hardware gain of a specific channel (either TX channel or RX channel), but I can't find the right IIO function to specify which channel I want to access:


    voltage0 (output)

    or

    voltage0 (input).

    I hope I am making sense.

  • Sorry, my bad. There is a parameter in iio_device_find_channel which specifies whether it is an output or an input:

    /** @brief Try to find a channel structure by its name of ID
    * @param dev A pointer to an iio_device structure
    * @param name A NULL-terminated string corresponding to the name or the ID of
    * the channel to search for
    * @param output True if the searched channel is output, False otherwise
    * @return On success, a pointer to an iio_channel structure
    * @return If the name or ID does not correspond to any known channel of the
    * given device, NULL is returned */
    __api __check_ret __pure struct iio_channel * iio_device_find_channel(
    const struct iio_device *dev, const char *name, bool output);