# run_l_dfetest_lte20_lab1d
# this lab shows the generate test script radio framework.
# it requires file management, to update specific files, and scripts
# we load BBTx data with a specific gain, we adjust the digital gains using the dfe set 
# commands.  We then have frequency translation in the various sections
#    TxDDUC - channel NCO, frequency translation
#    sumchain channel -> stream selects which channels are in a Tx stream
#    CDFR Tx - stream NCO, used in digital combiner not in RFSDK controlled in TGTCFG
#    Tx - stream NCO, used for Tx stream IF translation
#    JESD Tx Transport - can modify Tx stream order to JESD
#    JESD Rx Transport - can modify Rx/Fb stream order to Rx and Fb
#    Rx RealtoComplex - if real input, translates by Fs/4, or 3Fs/4# not in RFSDK, controlled in TGTCFG
#    Rx switch - can translate JESD rx to Rx stream number not in RFSDK, controlled in TGTCFG
#    Rx - stream NCO, used for Rx stream iF translation *
#    Fb - stream select - selects one of two Fb stream inputs
#    Fb - RealtoComplex - if real input, translates by Fs/4, or 3Fs/4# not in RFSDK, controlled in TGTCFG
#    Fb - stream NCO, used for Fb stream iF translation *
#    RxDDUC Distributor - can select which Rx out stream or Fb stream for Rx DDUC channel
#    RxDDUC - channel NCO, frequency translation *
# the JESD loopback have xxxx and xxxx_Rxlb for small cell configurations, xxxx Tx1 -> Fb, xxxx_Rxlb Tx0/Tx1 -> Rx0/Rx1
# 
echo Start DFE NCO test on Lamarr EVM in JESD Loopback in LTE20

# jesd loopback doesn't care about RF, but needs a value
RFSDK_UPLINK_CN=2140.0
RFSDK_DOWNLINK_CN=2140.0

# erase previous test results
cd /usr/share/radio/tests/rf-verif
rm -f dsp_psd_dfe*.csv
rm -f dsp_dfe*.csv

cd /srv/www/data/
rm -f dsp_psd_dfe*.csv
rm -f dsp_dfe*.csv

cd /usr/share/radio/tests/rf-verif/
if [ -f report_result.dat ]
then 
 rm report_result.dat
fi

# start the test 
radio reset
echo selecting 2x2-2xLTE20 Tx0->Rx0, Tx1->Rx1 JESD loopback
radio select 2x2-2xLTE20-SC-JESD3b-SD-Rxlb-jesdlpbk 
radio init

echo Starting the DSP
playback program 
playback start
sleep 3

echo Turning the radio on in JESD loopback..
radio on $RFSDK_UPLINK_CN $RFSDK_DOWNLINK_CN

echo load single tone at center frequency 1Mhz on TX1 TX2
playback load 1 1 /usr/share/radio/patterns/onetoneIQ_30p72_1_m7_10ms.bin
playback load 1 2 /usr/share/radio/patterns/onetoneIQ_30p72_1_m7_10ms.bin
sleep 1

echo initial nco values for test these are overriden from .tgtcfg
echo Rx, Fb, RxDDUC values multiply by -1
radio set dfe.baseband.tx[0].nco 0.0
radio set dfe.baseband.tx[0].streamMask 1
radio set dfe.baseband.tx[1].nco 0.0
radio set dfe.baseband.tx[1].streamMask 2

radio set dfe.stream[0].txNco 0.0
radio set dfe.stream[1].txNco 0.0

radio set dfe.stream[0].rxNco 0.0
radio set dfe.stream[1].rxNco 0.0

radio set dfe.feedback[0].nco 0.0

radio set dfe.baseband.rx[0].nco 0.0
radio set dfe.baseband.rx[0].streamId 0
radio set dfe.baseband.rx[1].nco 0.0
radio set dfe.baseband.rx[1].streamId 1

read -p "use RFSDK webpage to look at the Tx, Rx stream, and BBRx for base frequency offsets from BBRx file" 

echo in the next test, we can check the difference for TxDDUC NCO Frequency shift

radio set dfe.baseband.tx[0].nco 3.0

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1" 

echo in the next test, we change the SumChain mapping, this should result in the carriers being swapped, this can be done in BBTx tgtcfg also
echo Tx channel -> stream can be mapped to multiple or NO Tx streams be careful stream mask is a bit field

radio set dfe.baseband.tx[0].streamMask 2
radio set dfe.baseband.tx[1].streamMask 1

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1" 

echo in the next test, we restore the TxDDUC0-0 NCO, and the sumchain mapping, and change the Tx1 NCO

radio set dfe.baseband.tx[0].nco 0.0
radio set dfe.baseband.tx[0].streamMask 1
radio set dfe.baseband.tx[1].streamMask 2
radio set dfe.stream[1].txNco -2.0

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1" 

echo in the next test, we change the Rx stream NCOs, remember the value is negated down conversion, check both BBRx 0,1 why is there a difference?

radio set dfe.stream[1].txNco 0.0
radio set dfe.stream[0].rxNco -2.0
radio set dfe.stream[1].rxNco 2.0

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1" 

echo in the next test, we can check the Fb NCO, remember the value is negated down conversion, check both BBRx 0, 1, was there a change expected?

radio set dfe.stream[0].rxNco 0.0
radio set dfe.stream[1].rxNco 0.0
radio set dfe.feedback[0].nco 2.0

echo in the next test, we can check the Rx distributor, check both stream BBRx outputs, check both BBRx 0,1

radio set dfe.stream[0].rxNco -1.0
radio set dfe.stream[1].rxNco -3.0
radio set dfe.baseband.rx[0].streamId 1
radio set dfe.baseband.rx[1].streamId 0

echo in the next test, we can check the RxDDUC NCO, remember the value is negated down conversion, check both BBRx 0, 1, was there a change expected?

radio set dfe.stream[0].rxNco 0.0
radio set dfe.stream[1].rxNco 0.0
radio set dfe.baseband.rx[0].streamId 0
radio set dfe.baseband.rx[1].streamId 1
radio set dfe.baseband.rx[0].nco 2.0
radio set dfe.baseband.rx[1].nco -2.0

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1"

playback stop
radio off
