| 1 | /***************************************************************************//** |
| 2 | * @file main.c |
| 3 | * @brief Implementation of Main Function. |
| 4 | * @author DBogdan ([email protected]) |
| 5 | ******************************************************************************** |
| 6 | * Copyright 2013(c) Analog Devices, Inc. |
| 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions are met: |
| 12 | * - Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * - Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * - The use of this software may or may not infringe the patent rights |
| 22 | * of one or more patent holders. This license does not release you |
| 23 | * from the requirement that you obtain separate licenses from these |
| 24 | * patent holders to use this software. |
| 25 | * - Use of the software either in source or binary form, must be run |
| 26 | * on or directly connected to an Analog Devices Inc. component. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | *******************************************************************************/ |
| 39 | |
| 40 | /******************************************************************************/ |
| 41 | /***************************** Include Files **********************************/ |
| 42 | /******************************************************************************/ |
| 43 | #include "config.h" |
| 44 | #include "ad9361_api.h" |
| 45 | #include "parameters.h" |
| 46 | #include "platform.h" |
| 47 | #ifdef CONSOLE_COMMANDS |
| 48 | #include "command.h" |
| 49 | #include "console.h" |
| 50 | #endif |
| 51 | #ifdef XILINX_PLATFORM |
| 52 | #include <xil_cache.h> |
| 53 | #endif |
| 54 | #if defined XILINX_PLATFORM || defined LINUX_PLATFORM |
| 55 | #include "adc_core.h" |
| 56 | #include "dac_core.h" |
| 57 | #endif |
| 58 | |
| 59 | /******************************************************************************/ |
| 60 | /************************ Variables Definitions *******************************/ |
| 61 | /******************************************************************************/ |
| 62 | #ifdef CONSOLE_COMMANDS |
| 63 | extern command cmd_list[]; |
| 64 | extern char cmd_no; |
| 65 | extern cmd_function cmd_functions[11]; |
| 66 | unsigned char cmd = 0; |
| 67 | double param[5] = {0, 0, 0, 0, 0}; |
| 68 | char param_no = 0; |
| 69 | int cmd_type = -1; |
| 70 | char invalid_cmd = 0; |
| 71 | char received_cmd[30] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 72 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 73 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 74 | #endif |
| 75 | |
| 76 | AD9361_InitParam default_init_param = { |
| 77 | /* Device selection */ |
| 78 | ID_AD9361, // dev_sel |
| 79 | /* Identification number */ |
| 80 | 0, //id_no |
| 81 | /* Reference Clock */ |
| 82 | 40000000UL, //reference_clk_rate |
| 83 | /* Base Configuration */ |
| 84 | 1, //two_rx_two_tx_mode_enable *** adi,2rx-2tx-mode-enable |
| 85 | 1, //one_rx_one_tx_mode_use_rx_num *** adi,1rx-1tx-mode-use-rx-num |
| 86 | 1, //one_rx_one_tx_mode_use_tx_num *** adi,1rx-1tx-mode-use-tx-num |
| 87 | 1, //frequency_division_duplex_mode_enable *** adi,frequency-division-duplex-mode-enable |
| 88 | 0, //frequency_division_duplex_independent_mode_enable *** adi,frequency-division-duplex-independent-mode-enable |
| 89 | 0, //tdd_use_dual_synth_mode_enable *** adi,tdd-use-dual-synth-mode-enable |
| 90 | 0, //tdd_skip_vco_cal_enable *** adi,tdd-skip-vco-cal-enable |
| 91 | 0, //tx_fastlock_delay_ns *** adi,tx-fastlock-delay-ns |
| 92 | 0, //rx_fastlock_delay_ns *** adi,rx-fastlock-delay-ns |
| 93 | 0, //rx_fastlock_pincontrol_enable *** adi,rx-fastlock-pincontrol-enable |
| 94 | 0, //tx_fastlock_pincontrol_enable *** adi,tx-fastlock-pincontrol-enable |
| 95 | 0, //external_rx_lo_enable *** adi,external-rx-lo-enable |
| 96 | 0, //external_tx_lo_enable *** adi,external-tx-lo-enable |
| 97 | 5, //dc_offset_tracking_update_event_mask *** adi,dc-offset-tracking-update-event-mask |
| 98 | 6, //dc_offset_attenuation_high_range *** adi,dc-offset-attenuation-high-range |
| 99 | 5, //dc_offset_attenuation_low_range *** adi,dc-offset-attenuation-low-range |
| 100 | 0x28, //dc_offset_count_high_range *** adi,dc-offset-count-high-range |
| 101 | 0x32, //dc_offset_count_low_range *** adi,dc-offset-count-low-range |
| 102 | 0, //split_gain_table_mode_enable *** adi,split-gain-table-mode-enable |
| 103 | MAX_SYNTH_FREF, //trx_synthesizer_target_fref_overwrite_hz *** adi,trx-synthesizer-target-fref-overwrite-hz |
| 104 | 0, // qec_tracking_slow_mode_enable *** adi,qec-tracking-slow-mode-enable |
| 105 | /* ENSM Control */ |
| 106 | 0, //ensm_enable_pin_pulse_mode_enable *** adi,ensm-enable-pin-pulse-mode-enable |
| 107 | 0, //ensm_enable_txnrx_control_enable *** adi,ensm-enable-txnrx-control-enable |
| 108 | /* LO Control */ |
| 109 | 2400000000UL, //rx_synthesizer_frequency_hz *** adi,rx-synthesizer-frequency-hz |
| 110 | 2400000000UL, //tx_synthesizer_frequency_hz *** adi,tx-synthesizer-frequency-hz |
| 111 | /* Rate & BW Control */ |
| 112 | {983040000, 245760000, 122880000, 61440000, 30720000, 30720000},//uint32_t rx_path_clock_frequencies[6] *** adi,rx-path-clock-frequencies |
| 113 | {983040000, 122880000, 122880000, 61440000, 30720000, 30720000},//uint32_t tx_path_clock_frequencies[6] *** adi,tx-path-clock-frequencies |
| 114 | 18000000,//rf_rx_bandwidth_hz *** adi,rf-rx-bandwidth-hz |
| 115 | 18000000,//rf_tx_bandwidth_hz *** adi,rf-tx-bandwidth-hz |
| 116 | /* RF Port Control */ |
| 117 | 0, //rx_rf_port_input_select *** adi,rx-rf-port-input-select |
| 118 | 0, //tx_rf_port_input_select *** adi,tx-rf-port-input-select |
| 119 | /* TX Attenuation Control */ |
| 120 | 10000, //tx_attenuation_mdB *** adi,tx-attenuation-mdB |
| 121 | 0, //update_tx_gain_in_alert_enable *** adi,update-tx-gain-in-alert-enable |
| 122 | /* Reference Clock Control */ |
| 123 | 0, //xo_disable_use_ext_refclk_enable *** adi,xo-disable-use-ext-refclk-enable |
| 124 | {8, 5920}, //dcxo_coarse_and_fine_tune[2] *** adi,dcxo-coarse-and-fine-tune |
| 125 | CLKOUT_DISABLE, //clk_output_mode_select *** adi,clk-output-mode-select |
| 126 | /* Gain Control */ |
| 127 | 2, //gc_rx1_mode *** adi,gc-rx1-mode |
| 128 | 2, //gc_rx2_mode *** adi,gc-rx2-mode |
| 129 | 58, //gc_adc_large_overload_thresh *** adi,gc-adc-large-overload-thresh |
| 130 | 4, //gc_adc_ovr_sample_size *** adi,gc-adc-ovr-sample-size |
| 131 | 47, //gc_adc_small_overload_thresh *** adi,gc-adc-small-overload-thresh |
| 132 | 8192, //gc_dec_pow_measurement_duration *** adi,gc-dec-pow-measurement-duration |
| 133 | 0, //gc_dig_gain_enable *** adi,gc-dig-gain-enable |
| 134 | 800, //gc_lmt_overload_high_thresh *** adi,gc-lmt-overload-high-thresh |
| 135 | 704, //gc_lmt_overload_low_thresh *** adi,gc-lmt-overload-low-thresh |
| 136 | 24, //gc_low_power_thresh *** adi,gc-low-power-thresh |
| 137 | 15, //gc_max_dig_gain *** adi,gc-max-dig-gain |
| 138 | /* Gain MGC Control */ |
| 139 | 2, //mgc_dec_gain_step *** adi,mgc-dec-gain-step |
| 140 | 2, //mgc_inc_gain_step *** adi,mgc-inc-gain-step |
| 141 | 0, //mgc_rx1_ctrl_inp_enable *** adi,mgc-rx1-ctrl-inp-enable |
| 142 | 0, //mgc_rx2_ctrl_inp_enable *** adi,mgc-rx2-ctrl-inp-enable |
| 143 | 0, //mgc_split_table_ctrl_inp_gain_mode *** adi,mgc-split-table-ctrl-inp-gain-mode |
| 144 | /* Gain AGC Control */ |
| 145 | 10, //agc_adc_large_overload_exceed_counter *** adi,agc-adc-large-overload-exceed-counter |
| 146 | 2, //agc_adc_large_overload_inc_steps *** adi,agc-adc-large-overload-inc-steps |
| 147 | 0, //agc_adc_lmt_small_overload_prevent_gain_inc_enable *** adi,agc-adc-lmt-small-overload-prevent-gain-inc-enable |
| 148 | 10, //agc_adc_small_overload_exceed_counter *** adi,agc-adc-small-overload-exceed-counter |
| 149 | 4, //agc_dig_gain_step_size *** adi,agc-dig-gain-step-size |
| 150 | 3, //agc_dig_saturation_exceed_counter *** adi,agc-dig-saturation-exceed-counter |
| 151 | 1000, // agc_gain_update_interval_us *** adi,agc-gain-update-interval-us |
| 152 | 0, //agc_immed_gain_change_if_large_adc_overload_enable *** adi,agc-immed-gain-change-if-large-adc-overload-enable |
| 153 | 0, //agc_immed_gain_change_if_large_lmt_overload_enable *** adi,agc-immed-gain-change-if-large-lmt-overload-enable |
| 154 | 10, //agc_inner_thresh_high *** adi,agc-inner-thresh-high |
| 155 | 1, //agc_inner_thresh_high_dec_steps *** adi,agc-inner-thresh-high-dec-steps |
| 156 | 12, //agc_inner_thresh_low *** adi,agc-inner-thresh-low |
| 157 | 1, //agc_inner_thresh_low_inc_steps *** adi,agc-inner-thresh-low-inc-steps |
| 158 | 10, //agc_lmt_overload_large_exceed_counter *** adi,agc-lmt-overload-large-exceed-counter |
| 159 | 2, //agc_lmt_overload_large_inc_steps *** adi,agc-lmt-overload-large-inc-steps |
| 160 | 10, //agc_lmt_overload_small_exceed_counter *** adi,agc-lmt-overload-small-exceed-counter |
| 161 | 5, //agc_outer_thresh_high *** adi,agc-outer-thresh-high |
| 162 | 2, //agc_outer_thresh_high_dec_steps *** adi,agc-outer-thresh-high-dec-steps |
| 163 | 18, //agc_outer_thresh_low *** adi,agc-outer-thresh-low |
| 164 | 2, //agc_outer_thresh_low_inc_steps *** adi,agc-outer-thresh-low-inc-steps |
| 165 | 1, //agc_attack_delay_extra_margin_us; *** adi,agc-attack-delay-extra-margin-us |
| 166 | 0, //agc_sync_for_gain_counter_enable *** adi,agc-sync-for-gain-counter-enable |
| 167 | /* Fast AGC */ |
| 168 | 64, //fagc_dec_pow_measuremnt_duration *** adi,fagc-dec-pow-measurement-duration |
| 169 | 260, //fagc_state_wait_time_ns *** adi,fagc-state-wait-time-ns |
| 170 | /* Fast AGC - Low Power */ |
| 171 | 0, //fagc_allow_agc_gain_increase *** adi,fagc-allow-agc-gain-increase-enable |
| 172 | 5, //fagc_lp_thresh_increment_time *** adi,fagc-lp-thresh-increment-time |
| 173 | 1, //fagc_lp_thresh_increment_steps *** adi,fagc-lp-thresh-increment-steps |
| 174 | /* Fast AGC - Lock Level */ |
| 175 | 10, //fagc_lock_level *** adi,fagc-lock-level |
| 176 | 1, //fagc_lock_level_lmt_gain_increase_en *** adi,fagc-lock-level-lmt-gain-increase-enable |
| 177 | 5, //fagc_lock_level_gain_increase_upper_limit *** adi,fagc-lock-level-gain-increase-upper-limit |
| 178 | /* Fast AGC - Peak Detectors and Final Settling */ |
| 179 | 1, //fagc_lpf_final_settling_steps *** adi,fagc-lpf-final-settling-steps |
| 180 | 1, //fagc_lmt_final_settling_steps *** adi,fagc-lmt-final-settling-steps |
| 181 | 3, //fagc_final_overrange_count *** adi,fagc-final-overrange-count |
| 182 | /* Fast AGC - Final Power Test */ |
| 183 | 0, //fagc_gain_increase_after_gain_lock_en *** adi,fagc-gain-increase-after-gain-lock-enable |
| 184 | /* Fast AGC - Unlocking the Gain */ |
| 185 | 0, //fagc_gain_index_type_after_exit_rx_mode *** adi,fagc-gain-index-type-after-exit-rx-mode |
| 186 | 1, //fagc_use_last_lock_level_for_set_gain_en *** adi,fagc-use-last-lock-level-for-set-gain-enable |
| 187 | 1, //fagc_rst_gla_stronger_sig_thresh_exceeded_en *** adi,fagc-rst-gla-stronger-sig-thresh-exceeded-enable |
| 188 | 5, //fagc_optimized_gain_offset *** adi,fagc-optimized-gain-offset |
| 189 | 10, //fagc_rst_gla_stronger_sig_thresh_above_ll *** adi,fagc-rst-gla-stronger-sig-thresh-above-ll |
| 190 | 1, //fagc_rst_gla_engergy_lost_sig_thresh_exceeded_en *** adi,fagc-rst-gla-engergy-lost-sig-thresh-exceeded-enable |
| 191 | 1, //fagc_rst_gla_engergy_lost_goto_optim_gain_en *** adi,fagc-rst-gla-engergy-lost-goto-optim-gain-enable |
| 192 | 10, //fagc_rst_gla_engergy_lost_sig_thresh_below_ll *** adi,fagc-rst-gla-engergy-lost-sig-thresh-below-ll |
| 193 | 8, //fagc_energy_lost_stronger_sig_gain_lock_exit_cnt *** adi,fagc-energy-lost-stronger-sig-gain-lock-exit-cnt |
| 194 | 1, //fagc_rst_gla_large_adc_overload_en *** adi,fagc-rst-gla-large-adc-overload-enable |
| 195 | 1, //fagc_rst_gla_large_lmt_overload_en *** adi,fagc-rst-gla-large-lmt-overload-enable |
| 196 | 0, //fagc_rst_gla_en_agc_pulled_high_en *** adi,fagc-rst-gla-en-agc-pulled-high-enable |
| 197 | 0, //fagc_rst_gla_if_en_agc_pulled_high_mode *** adi,fagc-rst-gla-if-en-agc-pulled-high-mode |
| 198 | 64, //fagc_power_measurement_duration_in_state5 *** adi,fagc-power-measurement-duration-in-state5 |
| 199 | /* RSSI Control */ |
| 200 | 1, //rssi_delay *** adi,rssi-delay |
| 201 | 1000, //rssi_duration *** adi,rssi-duration |
| 202 | 3, //rssi_restart_mode *** adi,rssi-restart-mode |
| 203 | 0, //rssi_unit_is_rx_samples_enable *** adi,rssi-unit-is-rx-samples-enable |
| 204 | 1, //rssi_wait *** adi,rssi-wait |
| 205 | /* Aux ADC Control */ |
| 206 | 256, //aux_adc_decimation *** adi,aux-adc-decimation |
| 207 | 40000000UL, //aux_adc_rate *** adi,aux-adc-rate |
| 208 | /* AuxDAC Control */ |
| 209 | 1, //aux_dac_manual_mode_enable *** adi,aux-dac-manual-mode-enable |
| 210 | 0, //aux_dac1_default_value_mV *** adi,aux-dac1-default-value-mV |
| 211 | 0, //aux_dac1_active_in_rx_enable *** adi,aux-dac1-active-in-rx-enable |
| 212 | 0, //aux_dac1_active_in_tx_enable *** adi,aux-dac1-active-in-tx-enable |
| 213 | 0, //aux_dac1_active_in_alert_enable *** adi,aux-dac1-active-in-alert-enable |
| 214 | 0, //aux_dac1_rx_delay_us *** adi,aux-dac1-rx-delay-us |
| 215 | 0, //aux_dac1_tx_delay_us *** adi,aux-dac1-tx-delay-us |
| 216 | 0, //aux_dac2_default_value_mV *** adi,aux-dac2-default-value-mV |
| 217 | 0, //aux_dac2_active_in_rx_enable *** adi,aux-dac2-active-in-rx-enable |
| 218 | 0, //aux_dac2_active_in_tx_enable *** adi,aux-dac2-active-in-tx-enable |
| 219 | 0, //aux_dac2_active_in_alert_enable *** adi,aux-dac2-active-in-alert-enable |
| 220 | 0, //aux_dac2_rx_delay_us *** adi,aux-dac2-rx-delay-us |
| 221 | 0, //aux_dac2_tx_delay_us *** adi,aux-dac2-tx-delay-us |
| 222 | /* Temperature Sensor Control */ |
| 223 | 256, //temp_sense_decimation *** adi,temp-sense-decimation |
| 224 | 1000, //temp_sense_measurement_interval_ms *** adi,temp-sense-measurement-interval-ms |
| 225 | 0xCE, //temp_sense_offset_signed *** adi,temp-sense-offset-signed |
| 226 | 1, //temp_sense_periodic_measurement_enable *** adi,temp-sense-periodic-measurement-enable |
| 227 | /* Control Out Setup */ |
| 228 | 0xFF, //ctrl_outs_enable_mask *** adi,ctrl-outs-enable-mask |
| 229 | 0, //ctrl_outs_index *** adi,ctrl-outs-index |
| 230 | /* External LNA Control */ |
| 231 | 0, //elna_settling_delay_ns *** adi,elna-settling-delay-ns |
| 232 | 0, //elna_gain_mdB *** adi,elna-gain-mdB |
| 233 | 0, //elna_bypass_loss_mdB *** adi,elna-bypass-loss-mdB |
| 234 | 0, //elna_rx1_gpo0_control_enable *** adi,elna-rx1-gpo0-control-enable |
| 235 | 0, //elna_rx2_gpo1_control_enable *** adi,elna-rx2-gpo1-control-enable |
| 236 | 0, //elna_gaintable_all_index_enable *** adi,elna-gaintable-all-index-enable |
| 237 | /* Digital Interface Control */ |
| 238 | 0, //digital_interface_tune_skip_mode *** adi,digital-interface-tune-skip-mode |
| 239 | 0, //digital_interface_tune_fir_disable *** adi,digital-interface-tune-fir-disable |
| 240 | 1, //pp_tx_swap_enable *** adi,pp-tx-swap-enable |
| 241 | 1, //pp_rx_swap_enable *** adi,pp-rx-swap-enable |
| 242 | 0, //tx_channel_swap_enable *** adi,tx-channel-swap-enable |
| 243 | 0, //rx_channel_swap_enable *** adi,rx-channel-swap-enable |
| 244 | 1, //rx_frame_pulse_mode_enable *** adi,rx-frame-pulse-mode-enable |
| 245 | 0, //two_t_two_r_timing_enable *** adi,2t2r-timing-enable |
| 246 | 0, //invert_data_bus_enable *** adi,invert-data-bus-enable |
| 247 | 0, //invert_data_clk_enable *** adi,invert-data-clk-enable |
| 248 | 0, //fdd_alt_word_order_enable *** adi,fdd-alt-word-order-enable |
| 249 | 0, //invert_rx_frame_enable *** adi,invert-rx-frame-enable |
| 250 | 0, //fdd_rx_rate_2tx_enable *** adi,fdd-rx-rate-2tx-enable |
| 251 | 0, //swap_ports_enable *** adi,swap-ports-enable |
| 252 | 0, //single_data_rate_enable *** adi,single-data-rate-enable |
| 253 | 1, //lvds_mode_enable *** adi,lvds-mode-enable |
| 254 | 0, //half_duplex_mode_enable *** adi,half-duplex-mode-enable |
| 255 | 0, //single_port_mode_enable *** adi,single-port-mode-enable |
| 256 | 0, //full_port_enable *** adi,full-port-enable |
| 257 | 0, //full_duplex_swap_bits_enable *** adi,full-duplex-swap-bits-enable |
| 258 | 0, //delay_rx_data *** adi,delay-rx-data |
| 259 | 0, //rx_data_clock_delay *** adi,rx-data-clock-delay |
| 260 | 4, //rx_data_delay *** adi,rx-data-delay |
| 261 | 7, //tx_fb_clock_delay *** adi,tx-fb-clock-delay |
| 262 | 0, //tx_data_delay *** adi,tx-data-delay |
| 263 | 150, //lvds_bias_mV *** adi,lvds-bias-mV |
| 264 | 1, //lvds_rx_onchip_termination_enable *** adi,lvds-rx-onchip-termination-enable |
| 265 | 0, //rx1rx2_phase_inversion_en *** adi,rx1-rx2-phase-inversion-enable |
| 266 | 0xFF, //lvds_invert1_control *** adi,lvds-invert1-control |
| 267 | 0x0F, //lvds_invert2_control *** adi,lvds-invert2-control |
| 268 | /* GPO Control */ |
| 269 | 0, //gpo0_inactive_state_high_enable *** adi,gpo0-inactive-state-high-enable |
| 270 | 0, //gpo1_inactive_state_high_enable *** adi,gpo1-inactive-state-high-enable |
| 271 | 0, //gpo2_inactive_state_high_enable *** adi,gpo2-inactive-state-high-enable |
| 272 | 0, //gpo3_inactive_state_high_enable *** adi,gpo3-inactive-state-high-enable |
| 273 | 0, //gpo0_slave_rx_enable *** adi,gpo0-slave-rx-enable |
| 274 | 0, //gpo0_slave_tx_enable *** adi,gpo0-slave-tx-enable |
| 275 | 0, //gpo1_slave_rx_enable *** adi,gpo1-slave-rx-enable |
| 276 | 0, //gpo1_slave_tx_enable *** adi,gpo1-slave-tx-enable |
| 277 | 0, //gpo2_slave_rx_enable *** adi,gpo2-slave-rx-enable |
| 278 | 0, //gpo2_slave_tx_enable *** adi,gpo2-slave-tx-enable |
| 279 | 0, //gpo3_slave_rx_enable *** adi,gpo3-slave-rx-enable |
| 280 | 0, //gpo3_slave_tx_enable *** adi,gpo3-slave-tx-enable |
| 281 | 0, //gpo0_rx_delay_us *** adi,gpo0-rx-delay-us |
| 282 | 0, //gpo0_tx_delay_us *** adi,gpo0-tx-delay-us |
| 283 | 0, //gpo1_rx_delay_us *** adi,gpo1-rx-delay-us |
| 284 | 0, //gpo1_tx_delay_us *** adi,gpo1-tx-delay-us |
| 285 | 0, //gpo2_rx_delay_us *** adi,gpo2-rx-delay-us |
| 286 | 0, //gpo2_tx_delay_us *** adi,gpo2-tx-delay-us |
| 287 | 0, //gpo3_rx_delay_us *** adi,gpo3-rx-delay-us |
| 288 | 0, //gpo3_tx_delay_us *** adi,gpo3-tx-delay-us |
| 289 | /* Tx Monitor Control */ |
| 290 | 37000, //low_high_gain_threshold_mdB *** adi,txmon-low-high-thresh |
| 291 | 0, //low_gain_dB *** adi,txmon-low-gain |
| 292 | 24, //high_gain_dB *** adi,txmon-high-gain |
| 293 | 0, //tx_mon_track_en *** adi,txmon-dc-tracking-enable |
| 294 | 0, //one_shot_mode_en *** adi,txmon-one-shot-mode-enable |
| 295 | 511, //tx_mon_delay *** adi,txmon-delay |
| 296 | 8192, //tx_mon_duration *** adi,txmon-duration |
| 297 | 2, //tx1_mon_front_end_gain *** adi,txmon-1-front-end-gain |
| 298 | 2, //tx2_mon_front_end_gain *** adi,txmon-2-front-end-gain |
| 299 | 48, //tx1_mon_lo_cm *** adi,txmon-1-lo-cm |
| 300 | 48, //tx2_mon_lo_cm *** adi,txmon-2-lo-cm |
| 301 | /* GPIO definitions */ |
| 302 | -1, //gpio_resetb *** reset-gpios |
| 303 | /* MCS Sync */ |
| 304 | -1, //gpio_sync *** sync-gpios |
| 305 | -1, //gpio_cal_sw1 *** cal-sw1-gpios |
| 306 | -1, //gpio_cal_sw2 *** cal-sw2-gpios |
| 307 | /* External LO clocks */ |
| 308 | NULL, //(*ad9361_rfpll_ext_recalc_rate)() |
| 309 | NULL, //(*ad9361_rfpll_ext_round_rate)() |
| 310 | NULL //(*ad9361_rfpll_ext_set_rate)() |
| 311 | }; |
| 312 | |
| 313 | AD9361_RXFIRConfig rx_fir_config = { // BPF PASSBAND 3/20 fs to 1/4 fs |
| 314 | 3, // rx |
| 315 | 0, // rx_gain |
| 316 | 1, // rx_dec |
| 317 | {-4, -6, -37, 35, 186, 86, -284, -315, |
| 318 | 107, 219, -4, 271, 558, -307, -1182, -356, |
| 319 | 658, 157, 207, 1648, 790, -2525, -2553, 748, |
| 320 | 865, -476, 3737, 6560, -3583, -14731, -5278, 14819, |
| 321 | 14819, -5278, -14731, -3583, 6560, 3737, -476, 865, |
| 322 | 748, -2553, -2525, 790, 1648, 207, 157, 658, |
| 323 | -356, -1182, -307, 558, 271, -4, 219, 107, |
| 324 | -315, -284, 86, 186, 35, -37, -6, -4, |
| 325 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 326 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 327 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 328 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 329 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 330 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 331 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 332 | 0, 0, 0, 0, 0, 0, 0, 0}, // rx_coef[128] |
| 333 | 64, // rx_coef_size |
| 334 | {0, 0, 0, 0, 0, 0}, //rx_path_clks[6] |
| 335 | 0 // rx_bandwidth |
| 336 | }; |
| 337 | |
| 338 | AD9361_TXFIRConfig tx_fir_config = { // BPF PASSBAND 3/20 fs to 1/4 fs |
| 339 | 3, // tx |
| 340 | -6, // tx_gain |
| 341 | 1, // tx_int |
| 342 | {-4, -6, -37, 35, 186, 86, -284, -315, |
| 343 | 107, 219, -4, 271, 558, -307, -1182, -356, |
| 344 | 658, 157, 207, 1648, 790, -2525, -2553, 748, |
| 345 | 865, -476, 3737, 6560, -3583, -14731, -5278, 14819, |
| 346 | 14819, -5278, -14731, -3583, 6560, 3737, -476, 865, |
| 347 | 748, -2553, -2525, 790, 1648, 207, 157, 658, |
| 348 | -356, -1182, -307, 558, 271, -4, 219, 107, |
| 349 | -315, -284, 86, 186, 35, -37, -6, -4, |
| 350 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 351 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 352 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 353 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 354 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 355 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 356 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 357 | 0, 0, 0, 0, 0, 0, 0, 0}, // tx_coef[128] |
| 358 | 64, // tx_coef_size |
| 359 | {0, 0, 0, 0, 0, 0}, // tx_path_clks[6] |
| 360 | 0 // tx_bandwidth |
| 361 | }; |
| 362 | struct ad9361_rf_phy *ad9361_phy; |
| 363 | #ifdef FMCOMMS5 |
| 364 | struct ad9361_rf_phy *ad9361_phy_b; |
| 365 | #endif |
| 366 | |
| 367 | /***************************************************************************//** |
| 368 | * @brief main |
| 369 | *******************************************************************************/ |
| 370 | int main(void) |
| 371 | { |
| 372 | #ifdef XILINX_PLATFORM |
| 373 | Xil_ICacheEnable(); |
| 374 | Xil_DCacheEnable(); |
| 375 | #endif |
| 376 | |
| 377 | #ifdef ALTERA_PLATFORM |
| 378 | if (altera_bridge_init()) { |
| 379 | printf("Altera Bridge Init Error!\n"); |
| 380 | return -1; |
| 381 | } |
| 382 | #endif |
| 383 | |
| 384 | // NOTE: The user has to choose the GPIO numbers according to desired |
| 385 | // carrier board. |
| 386 | default_init_param.gpio_resetb = GPIO_RESET_PIN; |
| 387 | #ifdef FMCOMMS5 |
| 388 | default_init_param.gpio_sync = GPIO_SYNC_PIN; |
| 389 | default_init_param.gpio_cal_sw1 = GPIO_CAL_SW1_PIN; |
| 390 | default_init_param.gpio_cal_sw2 = GPIO_CAL_SW2_PIN; |
| 391 | default_init_param.rx1rx2_phase_inversion_en = 1; |
| 392 | #else |
| 393 | default_init_param.gpio_sync = -1; |
| 394 | default_init_param.gpio_cal_sw1 = -1; |
| 395 | default_init_param.gpio_cal_sw2 = -1; |
| 396 | #endif |
| 397 | |
| 398 | #ifdef LINUX_PLATFORM |
| 399 | gpio_init(default_init_param.gpio_resetb); |
| 400 | #else |
| 401 | gpio_init(GPIO_DEVICE_ID); |
| 402 | #endif |
| 403 | gpio_direction(default_init_param.gpio_resetb, 1); |
| 404 | |
| 405 | spi_init(SPI_DEVICE_ID, 1, 0); |
| 406 | |
| 407 | if (AD9364_DEVICE) |
| 408 | default_init_param.dev_sel = ID_AD9364; |
| 409 | if (AD9363A_DEVICE) |
| 410 | default_init_param.dev_sel = ID_AD9363A; |
| 411 | |
| 412 | #if defined FMCOMMS5 || defined PICOZED_SDR || defined PICOZED_SDR_CMOS |
| 413 | default_init_param.xo_disable_use_ext_refclk_enable = 1; |
| 414 | #endif |
| 415 | |
| 416 | #ifdef PICOZED_SDR_CMOS |
| 417 | default_init_param.swap_ports_enable = 1; |
| 418 | default_init_param.lvds_mode_enable = 0; |
| 419 | default_init_param.lvds_rx_onchip_termination_enable = 0; |
| 420 | default_init_param.full_port_enable = 1; |
| 421 | default_init_param.digital_interface_tune_fir_disable = 1; |
| 422 | #endif |
| 423 | |
| 424 | ad9361_init(&ad9361_phy, &default_init_param); |
| 425 | |
| 426 | ad9361_set_tx_fir_config(ad9361_phy, tx_fir_config); |
| 427 | ad9361_set_rx_fir_config(ad9361_phy, rx_fir_config); |
| 428 | |
| 429 | #ifdef FMCOMMS5 |
| 430 | #ifdef LINUX_PLATFORM |
| 431 | gpio_init(default_init_param.gpio_sync); |
| 432 | #endif |
| 433 | gpio_direction(default_init_param.gpio_sync, 1); |
| 434 | default_init_param.id_no = 1; |
| 435 | default_init_param.gpio_resetb = GPIO_RESET_PIN_2; |
| 436 | #ifdef LINUX_PLATFORM |
| 437 | gpio_init(default_init_param.gpio_resetb); |
| 438 | #endif |
| 439 | default_init_param.gpio_sync = -1; |
| 440 | default_init_param.gpio_cal_sw1 = -1; |
| 441 | default_init_param.gpio_cal_sw2 = -1; |
| 442 | default_init_param.rx_synthesizer_frequency_hz = 2300000000UL; |
| 443 | default_init_param.tx_synthesizer_frequency_hz = 2300000000UL; |
| 444 | gpio_direction(default_init_param.gpio_resetb, 1); |
| 445 | ad9361_init(&ad9361_phy_b, &default_init_param); |
| 446 | |
| 447 | ad9361_set_tx_fir_config(ad9361_phy_b, tx_fir_config); |
| 448 | ad9361_set_rx_fir_config(ad9361_phy_b, rx_fir_config); |
| 449 | #endif |
| 450 | |
| 451 | #ifndef AXI_ADC_NOT_PRESENT |
| 452 | #if defined XILINX_PLATFORM || defined LINUX_PLATFORM |
| 453 | #ifdef DAC_DMA |
| 454 | #ifdef FMCOMMS5 |
| 455 | dac_init(ad9361_phy_b, DATA_SEL_DMA, 0); |
| 456 | #endif |
| 457 | dac_init(ad9361_phy, DATA_SEL_DMA, 1); |
| 458 | #else |
| 459 | #ifdef FMCOMMS5 |
| 460 | dac_init(ad9361_phy_b, DATA_SEL_DDS, 0); |
| 461 | #endif |
| 462 | dac_init(ad9361_phy, DATA_SEL_DDS, 1); |
| 463 | #endif |
| 464 | #endif |
| 465 | #endif |
| 466 | |
| 467 | #ifdef FMCOMMS5 |
| 468 | ad9361_do_mcs(ad9361_phy, ad9361_phy_b); |
| 469 | #endif |
| 470 | |
| 471 | #ifndef AXI_ADC_NOT_PRESENT |
| 472 | #if defined XILINX_PLATFORM && defined CAPTURE_SCRIPT |
| 473 | // NOTE: To prevent unwanted data loss, it's recommended to invalidate |
| 474 | // cache after each adc_capture() call, keeping in mind that the |
| 475 | // size of the capture and the start address must be alinged to the size |
| 476 | // of the cache line. |
| 477 | mdelay(1000); |
| 478 | adc_capture(16384, ADC_DDR_BASEADDR); |
| 479 | Xil_DCacheInvalidateRange(ADC_DDR_BASEADDR, 16384); |
| 480 | #endif |
| 481 | #endif |
| 482 | |
| 483 | #ifdef CONSOLE_COMMANDS |
| 484 | get_help(NULL, 0); |
| 485 | |
| 486 | while(1) |
| 487 | { |
| 488 | console_get_command(received_cmd); |
| 489 | invalid_cmd = 0; |
| 490 | for(cmd = 0; cmd < cmd_no; cmd++) |
| 491 | { |
| 492 | param_no = 0; |
| 493 | cmd_type = console_check_commands(received_cmd, cmd_list[cmd].name, |
| 494 | param, ¶m_no); |
| 495 | if(cmd_type == UNKNOWN_CMD) |
| 496 | { |
| 497 | invalid_cmd++; |
| 498 | } |
| 499 | else |
| 500 | { |
| 501 | cmd_list[cmd].function(param, param_no); |
| 502 | } |
| 503 | } |
| 504 | if(invalid_cmd == cmd_no) |
| 505 | { |
| 506 | console_print("Invalid command!\n"); |
| 507 | } |
| 508 | } |
| 509 | #endif |
| 510 | |
| 511 | printf("Done.\n"); |
| 512 | |
| 513 | #ifdef TDD_SWITCH_STATE_EXAMPLE |
| 514 | uint32_t ensm_mode; |
| 515 | if (!ad9361_phy->pdata->fdd) { |
| 516 | if (ad9361_phy->pdata->ensm_pin_ctrl) { |
| 517 | gpio_direction(GPIO_ENABLE_PIN, 1); |
| 518 | gpio_direction(GPIO_TXNRX_PIN, 1); |
| 519 | gpio_set_value(GPIO_ENABLE_PIN, 0); |
| 520 | gpio_set_value(GPIO_TXNRX_PIN, 0); |
| 521 | udelay(10); |
| 522 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 523 | printf("TXNRX control - Alert: %s\n", |
| 524 | ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error"); |
| 525 | mdelay(1000); |
| 526 | |
| 527 | if (ad9361_phy->pdata->ensm_pin_pulse_mode) { |
| 528 | while(1) { |
| 529 | gpio_set_value(GPIO_TXNRX_PIN, 0); |
| 530 | udelay(10); |
| 531 | gpio_set_value(GPIO_ENABLE_PIN, 1); |
| 532 | udelay(10); |
| 533 | gpio_set_value(GPIO_ENABLE_PIN, 0); |
| 534 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 535 | printf("TXNRX Pulse control - RX: %s\n", |
| 536 | ensm_mode == ENSM_MODE_RX ? "OK" : "Error"); |
| 537 | mdelay(1000); |
| 538 | |
| 539 | gpio_set_value(GPIO_ENABLE_PIN, 1); |
| 540 | udelay(10); |
| 541 | gpio_set_value(GPIO_ENABLE_PIN, 0); |
| 542 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 543 | printf("TXNRX Pulse control - Alert: %s\n", |
| 544 | ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error"); |
| 545 | mdelay(1000); |
| 546 | |
| 547 | gpio_set_value(GPIO_TXNRX_PIN, 1); |
| 548 | udelay(10); |
| 549 | gpio_set_value(GPIO_ENABLE_PIN, 1); |
| 550 | udelay(10); |
| 551 | gpio_set_value(GPIO_ENABLE_PIN, 0); |
| 552 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 553 | printf("TXNRX Pulse control - TX: %s\n", |
| 554 | ensm_mode == ENSM_MODE_TX ? "OK" : "Error"); |
| 555 | mdelay(1000); |
| 556 | |
| 557 | gpio_set_value(GPIO_ENABLE_PIN, 1); |
| 558 | udelay(10); |
| 559 | gpio_set_value(GPIO_ENABLE_PIN, 0); |
| 560 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 561 | printf("TXNRX Pulse control - Alert: %s\n", |
| 562 | ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error"); |
| 563 | mdelay(1000); |
| 564 | } |
| 565 | } else { |
| 566 | while(1) { |
| 567 | gpio_set_value(GPIO_TXNRX_PIN, 0); |
| 568 | udelay(10); |
| 569 | gpio_set_value(GPIO_ENABLE_PIN, 1); |
| 570 | udelay(10); |
| 571 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 572 | printf("TXNRX control - RX: %s\n", |
| 573 | ensm_mode == ENSM_MODE_RX ? "OK" : "Error"); |
| 574 | mdelay(1000); |
| 575 | |
| 576 | gpio_set_value(GPIO_ENABLE_PIN, 0); |
| 577 | udelay(10); |
| 578 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 579 | printf("TXNRX control - Alert: %s\n", |
| 580 | ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error"); |
| 581 | mdelay(1000); |
| 582 | |
| 583 | gpio_set_value(GPIO_TXNRX_PIN, 1); |
| 584 | udelay(10); |
| 585 | gpio_set_value(GPIO_ENABLE_PIN, 1); |
| 586 | udelay(10); |
| 587 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 588 | printf("TXNRX control - TX: %s\n", |
| 589 | ensm_mode == ENSM_MODE_TX ? "OK" : "Error"); |
| 590 | mdelay(1000); |
| 591 | |
| 592 | gpio_set_value(GPIO_ENABLE_PIN, 0); |
| 593 | udelay(10); |
| 594 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 595 | printf("TXNRX control - Alert: %s\n", |
| 596 | ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error"); |
| 597 | mdelay(1000); |
| 598 | } |
| 599 | } |
| 600 | } else { |
| 601 | while(1) { |
| 602 | ad9361_set_en_state_machine_mode(ad9361_phy, ENSM_MODE_RX); |
| 603 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 604 | printf("SPI control - RX: %s\n", |
| 605 | ensm_mode == ENSM_MODE_RX ? "OK" : "Error"); |
| 606 | mdelay(1000); |
| 607 | |
| 608 | ad9361_set_en_state_machine_mode(ad9361_phy, ENSM_MODE_ALERT); |
| 609 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 610 | printf("SPI control - Alert: %s\n", |
| 611 | ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error"); |
| 612 | mdelay(1000); |
| 613 | |
| 614 | ad9361_set_en_state_machine_mode(ad9361_phy, ENSM_MODE_TX); |
| 615 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 616 | printf("SPI control - TX: %s\n", |
| 617 | ensm_mode == ENSM_MODE_TX ? "OK" : "Error"); |
| 618 | mdelay(1000); |
| 619 | |
| 620 | ad9361_set_en_state_machine_mode(ad9361_phy, ENSM_MODE_ALERT); |
| 621 | ad9361_get_en_state_machine_mode(ad9361_phy, &ensm_mode); |
| 622 | printf("SPI control - Alert: %s\n", |
| 623 | ensm_mode == ENSM_MODE_ALERT ? "OK" : "Error"); |
| 624 | mdelay(1000); |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | #endif |
| 629 | |
| 630 | #ifdef XILINX_PLATFORM |
| 631 | Xil_DCacheDisable(); |
| 632 | Xil_ICacheDisable(); |
| 633 | #endif |
| 634 | |
| 635 | #ifdef ALTERA_PLATFORM |
| 636 | if (altera_bridge_uninit()) { |
| 637 | printf("Altera Bridge Uninit Error!\n"); |
| 638 | return -1; |
| 639 | } |
| 640 | #endif |
| 641 | |
| 642 | return 0; |
| 643 | } |