/**
 * \file headless.c
 *
 * \brief Contains example code for user integration with their application
 *
 * All data structures required for operation have been initialized with values which reflect
 * these settings:
 *
 * Device Clock:
 * 122.88MHz
 *
 * Profiles:
 * Rx 100MHz, IQrate 122.88MSPS, Dec5
 * Tx 20/100MHz, IQrate 122.88MSPS, Dec5
 * ORX 100MHz, IQrate 122.88MSPS, Dec5
 * SRx 20MHz, IQrate 30.72MSPS, Dec5
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "miv_rv32_hal.h"
#include "sample_hw_platform.h"
#include "hw_reg_access.h"
#include "core_gpio.h"
#include "core_uart_apb.h"
#include "corespi_regs.h"
#include "core_spi.h"

#include "headless.h"
#include "t_mykonos.h"
#include "mykonos.h"
#include "mykonos_gpio.h"
#include "myAD9371.h"
#include "ad9528.h"
#include "Mykonos_M3.h"

#define CPRI_BASE_ADDR	0x70000000
#define CPRI_STATUS_REG (volatile uint32_t *)(CPRI_BASE_ADDR + 0x31C)

UART_instance_t g_uart;
uint32_t CPRI_check_status =0;
uint8_t  g_hello_msg[] = "\r\n RISCV - AD9371\r\n";

/******************************************************************************
 * GPIO instance data.
 *****************************************************************************/
gpio_instance_t g_gpio_out;

spi_instance_t g_core_spi;
spi_instance_t g_core_spi1;

extern ad9528Device_t clockAD9528;

int radio_config();
int AD9371_0_chip_calibration();
int AD9371_1_chip_calibration();
void CPRI_Config();

void delay(volatile int a)
{
	volatile unsigned int i =0,j = 0;
	for(i=0;i<a;i++)
	{

		   j = j+1;
	}

}
void radio_config_check_CPRI_status()
{
	volatile int test = 0;
	test = ((*CPRI_STATUS_REG)&0x1);

	while(1)
	{
		delay(100);
		test = ((*CPRI_STATUS_REG)&0x1);
		if(test == 1)
		{
			radio_config();
			return;
		}
	}
}
//int main()
//{int a,b;
//b= a+10;
//    while(1)
//    {
//
//    }
//}
/******************************************************************************
 * Global state counter.
 *****************************************************************************/
int main()
{
//	volatile uint32_t CPRI_STATUS_REG;


    //printf("\r**************************************************************\n\r");
   // printf("\r********************* RADIO CONFIG - AD9371 - JESD *********************\n\r");
   // printf("\r**************************************************************\n\n\r");
    UART_init(&g_uart,
                  COREUARTAPB0_BASE_ADDR,
                  BAUD_VALUE_115200,
                  (DATA_8_BITS | NO_PARITY));

        /**************************************************************************
         * Send the instructions message.
         *************************************************************************/
        UART_polled_tx_string(&g_uart, (const uint8_t *)"hello\n\r");


    GPIO_init(&g_gpio_out, COREGPIO_OUT_BASE_ADDR, GPIO_APB_32_BITS_BUS);

	/**************************************************************************
	* Configure the GPIOs.
	*************************************************************************/
//    GPIO_config( &g_gpio_out, GPIO_2, GPIO_OUTPUT_MODE );
//	GPIO_config( &g_gpio_out, GPIO_3, GPIO_OUTPUT_MODE );
//	GPIO_config( &g_gpio_out, GPIO_4, GPIO_OUTPUT_MODE );
//	GPIO_config( &g_gpio_out, GPIO_5, GPIO_OUTPUT_MODE );

	//
//	GPIO_config( &g_gpio_out, GPIO_6, GPIO_OUTPUT_MODE );
//	GPIO_config( &g_gpio_out, GPIO_7, GPIO_OUTPUT_MODE );
//	GPIO_config( &g_gpio_out, GPIO_8, GPIO_OUTPUT_MODE );
//	GPIO_config( &g_gpio_out, GPIO_9, GPIO_OUTPUT_MODE );

	// for JESD
//	GPIO_set_output( &g_gpio_out, GPIO_3,0 );
//	GPIO_set_output( &g_gpio_out, GPIO_2,0 );
	delay(100);

	//RX enable TX enable
//	GPIO_set_output( &g_gpio_out, GPIO_6,1 );
//	GPIO_set_output( &g_gpio_out, GPIO_7,1 );
//	GPIO_set_output( &g_gpio_out, GPIO_8,1 );
//	GPIO_set_output( &g_gpio_out, GPIO_9,1 );


	GPIO_config( &g_gpio_out, GPIO_10, GPIO_OUTPUT_MODE );
	GPIO_config( &g_gpio_out, GPIO_11, GPIO_OUTPUT_MODE );
	GPIO_config( &g_gpio_out, GPIO_12, GPIO_OUTPUT_MODE );
	GPIO_config( &g_gpio_out, GPIO_13, GPIO_OUTPUT_MODE );
	GPIO_config( &g_gpio_out, GPIO_14, GPIO_OUTPUT_MODE );

	//RX enable TX enable
	GPIO_set_output( &g_gpio_out, GPIO_11,1 );
	GPIO_set_output( &g_gpio_out, GPIO_12,1 );
	GPIO_set_output( &g_gpio_out, GPIO_13,1 );
	GPIO_set_output( &g_gpio_out, GPIO_14,1 );

	// initialize spi
	SPI_init( &g_core_spi, FLASH_CORE_SPI_BASE, 1 );
	SPI_configure_master_mode( &g_core_spi );

	// initialize spi1
	SPI_init( &g_core_spi1, FLASH_CORE_SPI1_BASE, 1 );
	SPI_configure_master_mode( &g_core_spi1 );


	CPRI_Config();
	delay(1000);
	radio_config_check_CPRI_status();
	//check for CPRI status
	while(1)
	{
		delay(1000);
		CPRI_check_status = *CPRI_STATUS_REG;

		if(CPRI_check_status == 0)
		{
			radio_config_check_CPRI_status();
		}

	}
 return 0;
}
int radio_config()
{
	const char* errorString;
	uint8_t mcsStatus = 0;
	uint8_t mcsStatus1 = 0;
	uint8_t pllLockStatus = 0;
	uint8_t pllLockStatus1 = 0;
	uint8_t errorFlag = 0;
	uint8_t errorCode = 0;
    uint32_t prbsErrorCount = 0;
	uint32_t initCalsCompleted = 0;
	uint16_t errorWord = 0,mismatch = 0;
	uint16_t statusWord = 0;
	uint8_t status = 0,test = 0;
	mykonosInitCalStatus_t initCalStatus = {0};

	uint8_t				arm_major;
	uint8_t				arm_minor;
	uint8_t				arm_release;

	uint8_t deframerStatus = 0;
	uint8_t obsFramerStatus = 0;
	uint8_t framerStatus = 0;

	uint32_t initCalMask = 0 |
      TX_BB_FILTER |
      ADC_TUNER |
      TIA_3DB_CORNER |
      DC_OFFSET |
      TX_ATTENUATION_DELAY |
      RX_GAIN_DELAY |
      FLASH_CAL |
      RX_LO_DELAY |
      RX_QEC_INIT;

	uint32_t trackingCalMask = 0 |
      TRACK_ORX1_QEC |
      TRACK_ORX2_QEC;

	mykonosErr_t mykError = MYKONOS_ERR_OK;
	mykonosGpioErr_t mykGpioErr = MYKONOS_ERR_GPIO_OK;


	/* Allocating memory for the errorString */
	errorString = (const char*) malloc(sizeof(char) * 200);
	uint8_t read_buffer;

	printf("intialize ad9528 clock chip \n\r");

    AD9528_resetDevice(&clockAD9528);
    AD9528_initialize(&clockAD9528);
    delay(5*1000);
    AD9528_enableClockOutputs(&clockAD9528,0x1ff);
    AD9528_readPllStatus(&clockAD9528,&test);

    delay(1500);
    GPIO_set_output( &g_gpio_out, GPIO_3,1 );
    GPIO_set_output( &g_gpio_out, GPIO_2,1 );

//For AD9371_0 chip config
    /*** < Action: Insert BBIC Initialization Code Here                     > ***/

	/*************************************************************************/
	/*****                Mykonos Initialization Sequence                *****/
	/*************************************************************************/

	/*** < Action: Toggle RESETB pin on Mykonos device                   > ***/
	if ((mykError = MYKONOS_resetDevice(&mykDevice)) != MYKONOS_ERR_OK)
    {
        /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	    printf("\r%s\n\r",errorString);
    }

	if ((mykError = MYKONOS_initialize(&mykDevice)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	    printf("\r%s\n\r",errorString);
	}

	GPIO_set_output( &g_gpio_out, GPIO_3,0 );
	delay(100);

	GPIO_set_output( &g_gpio_out, GPIO_3,1 );
	delay(100);

	/*************************************************************************/
	/*****                Mykonos CLKPLL Status Check                    *****/
	/*************************************************************************/

	if ((mykError = MYKONOS_checkPllsLockStatus(&mykDevice, &pllLockStatus)) != MYKONOS_ERR_OK)
    {
        /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	     printf("\r%s\n\r",errorString);
    }


//For AD9371_1 chip config
	/*** < Action: Toggle RESETB pin on Mykonos device                   > ***/
	if ((mykError = MYKONOS_resetDevice(&mykDevice1)) != MYKONOS_ERR_OK)
    {
        /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	    printf("\r%s\n\r",errorString);
    }

	if ((mykError = MYKONOS_initialize(&mykDevice1)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	    printf("\r%s\n\r",errorString);
	}

	// for JESD

	GPIO_set_output( &g_gpio_out, GPIO_2,0 );
	delay(100);

	GPIO_set_output( &g_gpio_out, GPIO_2,1 );
	delay(100);

	/*************************************************************************/
	/*****                Mykonos CLKPLL Status Check                    *****/
	/*************************************************************************/

	if ((mykError = MYKONOS_checkPllsLockStatus(&mykDevice1, &pllLockStatus1)) != MYKONOS_ERR_OK)
    {
        /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	     printf("\r%s\n\r",errorString);
    }


	/*************************************************************************/
	/*****                Mykonos Perform MultiChip Sync                 *****/
	/*************************************************************************/

//AD9371_0 chip
	if ((mykError = MYKONOS_enableMultichipSync(&mykDevice, 1, &mcsStatus)) != MYKONOS_ERR_OK)
    {
        /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	     printf("\r%s\n\r",errorString);
    }
//AD9371_1 chip
	if ((mykError = MYKONOS_enableMultichipSync(&mykDevice1, 1, &mcsStatus1)) != MYKONOS_ERR_OK)
    {
        /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	     printf("\r%s\n\r",errorString);
    }
	/*** < Action: minimum 3 SYSREF pulses from Clock Device has to be produced
	 * for MulticChip Sync > ***/
	AD9528_requestSysref(&clockAD9528,1);
	delay(1*1000);
	AD9528_requestSysref(&clockAD9528,1);
	delay(1*1000);
	AD9528_requestSysref(&clockAD9528,1);
	delay(1*1000);
	AD9528_requestSysref(&clockAD9528,1);
	delay(1*1000);
      
	/*************************************************************************/
	/*****                Mykonos Verify MultiChip Sync                 *****/
	/*************************************************************************/
// AD9371_0 chip
	if ((mykError = MYKONOS_enableMultichipSync(&mykDevice, 0, &mcsStatus)) != MYKONOS_ERR_OK)
    {
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	     printf("\r%s\n\r",errorString);
    }

	printf("\r AD9371_0 chip MCS status = 0x%x\n\r",mcsStatus);

	if ((mcsStatus & 0x0B) == 0x0B)
	{
		printf("\r AD9371_0 chip MCS successful\n\r");
		/*** < Info: MCS successful  > ***/
		/*** < Action: extra User code   > ***/
	}
	else
	{
		printf("\r AD9371_0 chip MCS failed\n\r");
		/*** < Info: MCS failed  > ***/
		/*** < Action: ensure MCS before proceeding  > ***/
	}


//  AD9371_1 chip
  	if ((mykError = MYKONOS_enableMultichipSync(&mykDevice1, 0, &mcsStatus1)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug failure > ***/
		errorString = getMykonosErrorMessage(mykError);
		printf("\r%s\n\r",errorString);
	}
    printf("\r AD9371_1 chip MCS status = 0x%x\n\r",mcsStatus1);

	if ((mcsStatus1 & 0x0B) == 0x0B)
	{
		printf("\r AD9371_1 chip MCS successful\n\r");
		/*** < Info: MCS successful  > ***/
	    /*** < Action: extra User code   > ***/
	}
	else
	{
		printf("\rAD9371_1 chip MCS failed\n\r");
	    /*** < Info: MCS failed  > ***/
		/*** < Action: ensure MCS before proceeding  > ***/
	}

	 if(!(mykError = AD9371_0_chip_calibration()));
	 {
		 printf("\r AD9371_0_chip Calibrations completed successfully\n\r");
	 }

	if(!(mykError = AD9371_1_chip_calibration()));
	{
		printf("\r AD9371_1_chip Calibrations completed successfully\n\r");
	}
	/*************************************************************************/
	/*****             SYSTEM JESD bring up procedure                    *****/
	/*************************************************************************/
	/*** < Action: Make sure SYSREF is stopped/disabled > ***/
        
	AD9528_requestSysref(&clockAD9528,0);
	delay(1*1000);
    
	/*** < Action: Make sure BBIC JESD is reset and ready to recieve CGS chars> ***/
        
    GPIO_set_output( &g_gpio_out, GPIO_3,0 );
    delay(100);


	GPIO_set_output( &g_gpio_out, GPIO_3,1 );
	delay(100);

	GPIO_set_output( &g_gpio_out, GPIO_2,0 );
	delay(100);
	GPIO_set_output( &g_gpio_out, GPIO_2,1 );
	delay(100);

// AD9371_0 chip
	if ((mykError = MYKONOS_enableSysrefToRxFramer(&mykDevice, 1)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
	    errorString = getMykonosErrorMessage(mykError);
	     printf("\r%s\n\r",errorString);
	}
	/*** < Info: Mykonos is waiting for sysref in order to start
	 * transmitting CGS from the RxFramer> ***/

	if ((mykError = MYKONOS_enableSysrefToObsRxFramer(&mykDevice, 1)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}
	/*** < Info: Mykonos is waiting for sysref in order to start
	 * transmitting CGS from the ObsRxFramer> ***/

	/*** < User: Make sure SYSREF is stopped/disabled > ***/
	if ((mykError = MYKONOS_enableSysrefToDeframer(&mykDevice, 0)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}

	if ((mykError = MYKONOS_resetDeframer(&mykDevice)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}

	/*** < User: make sure BBIC JESD framer is actively transmitting CGS> ***/
	if ((mykError = MYKONOS_enableSysrefToDeframer(&mykDevice, 1)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}

// AD9371_1 chip
	if ((mykError = MYKONOS_enableSysrefToRxFramer(&mykDevice1, 1)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug failure > ***/
		errorString = getMykonosErrorMessage(mykError);
		 printf("\r%s\n\r",errorString);
	}
	/*** < Info: Mykonos is waiting for sysref in order to start
	 * transmitting CGS from the RxFramer> ***/

	if ((mykError = MYKONOS_enableSysrefToObsRxFramer(&mykDevice1, 1)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug failure > ***/
		errorString = getMykonosErrorMessage(mykError);
		 printf("\r%s\n\r",errorString);
	}
	/*** < Info: Mykonos is waiting for sysref in order to start
	 * transmitting CGS from the ObsRxFramer> ***/

	/*** < User: Make sure SYSREF is stopped/disabled > ***/
	if ((mykError = MYKONOS_enableSysrefToDeframer(&mykDevice1, 0)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug failure > ***/
		errorString = getMykonosErrorMessage(mykError);
		 printf("\r%s\n\r",errorString);
	}

	if ((mykError = MYKONOS_resetDeframer(&mykDevice1)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug failure > ***/
		errorString = getMykonosErrorMessage(mykError);
		 printf("\r%s\n\r",errorString);
	}

	/*** < User: make sure BBIC JESD framer is actively transmitting CGS> ***/
	if ((mykError = MYKONOS_enableSysrefToDeframer(&mykDevice1, 1)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug failure > ***/
		errorString = getMykonosErrorMessage(mykError);
		 printf("\r%s\n\r",errorString);
	}

	/*************************************************************************/
	/*****            Enable SYSREF to Mykonos and BBIC                  *****/
	/*************************************************************************/
	/*** < Action: Sends SYSREF Here > ***/

	GPIO_set_output( &g_gpio_out, GPIO_3,0 );
	delay(100);
	GPIO_set_output( &g_gpio_out, GPIO_3,1 );
	delay(100);
	GPIO_set_output( &g_gpio_out, GPIO_2,0 );
	delay(100);
	GPIO_set_output( &g_gpio_out, GPIO_2,1 );
	delay(100);

	AD9528_requestSysref(&clockAD9528, 1);
	delay(1*1000);

    AD9528_requestSysref(&clockAD9528, 1);
	delay(1*1000);

	AD9528_requestSysref(&clockAD9528, 1);
	delay(1*1000);

	/*** < Info: Mykonos is actively transmitting CGS from the RxFramer> ***/

	/*** < Info: Mykonos is actively transmitting CGS from the ObsRxFramer> ***/

	/*** < Action: Insert User: BBIC JESD Sync Verification Code Here > ***/

// AD9371_0 chip
	/*************************************************************************/
	/*****               Check Mykonos Framer Status                     *****/
	/*************************************************************************/
	if ((mykError = MYKONOS_readRxFramerStatus(&mykDevice, &framerStatus)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}
        else 
          if(framerStatus != 0x3E)
          {
            printf("\r RXframerStatus = 0x%x\n\r",framerStatus);
          }
	if ((mykError = MYKONOS_readOrxFramerStatus(&mykDevice, &obsFramerStatus)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}
        else 
          if(obsFramerStatus != 0x3E)
          {
            printf("\r orxframerStatus = 0x%x\n\r",obsFramerStatus);
          }

	/*************************************************************************/
	/*****               Check Mykonos Deframer Status                   *****/
	/*************************************************************************/
	if ((mykError = MYKONOS_readDeframerStatus(&mykDevice, &deframerStatus)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}
        else
          if(deframerStatus != 0x68)
          {
            printf("\r deframerStatus = 0x%x\n\r",deframerStatus);
          }
	printf("\r RXframerStatus = 0x%x\n\r",framerStatus);
	printf("\r orxframerStatus = 0x%x\n\r",obsFramerStatus);
	printf("\r deframerStatus = 0x%x\n\r",deframerStatus);
	/*** < Action: When links have been verified, proceed > ***/
	printf("\rprbsErrorCount = %d\n\r",prbsErrorCount);

// AD9371_1 chip

     	/*************************************************************************/
     	/*****               Check Mykonos Framer Status                     *****/
     	/*************************************************************************/
     	if ((mykError = MYKONOS_readRxFramerStatus(&mykDevice1, &framerStatus)) != MYKONOS_ERR_OK)
     	{
     	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
             errorString = getMykonosErrorMessage(mykError);
              printf("\r%s\n\r",errorString);
     	}
             else
               if(framerStatus != 0x3E)
               {
                 printf("\r RXframerStatus = 0x%x\n\r",framerStatus);
               }
     	if ((mykError = MYKONOS_readOrxFramerStatus(&mykDevice1, &obsFramerStatus)) != MYKONOS_ERR_OK)
     	{
     	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
             errorString = getMykonosErrorMessage(mykError);
              printf("\r%s\n\r",errorString);
     	}
             else
               if(obsFramerStatus != 0x3E)
               {
                 printf("\r orxframerStatus = 0x%x\n\r",obsFramerStatus);
               }

     	/*************************************************************************/
     	/*****               Check Mykonos Deframer Status                   *****/
     	/*************************************************************************/
     	if ((mykError = MYKONOS_readDeframerStatus(&mykDevice1, &deframerStatus)) != MYKONOS_ERR_OK)
     	{
     	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
             errorString = getMykonosErrorMessage(mykError);
              printf("\r%s\n\r",errorString);
     	}
             else
               if(deframerStatus != 0x68)
               {
                 printf("\r deframerStatus = 0x%x\n\r",deframerStatus);
               }
	printf("\r RXframerStatus = 0x%x\n\r",framerStatus);
	printf("\r orxframerStatus = 0x%x\n\r",obsFramerStatus);
	printf("\r deframerStatus = 0x%x\n\r",deframerStatus);
	/*** < Action: When links have been verified, proceed > ***/
	printf("\rprbsErrorCount = %d\n\r",prbsErrorCount);


//AD9371_0 chip

	/*************************************************************************/
	/*****           Mykonos enable tracking calibrations                *****/
	/*************************************************************************/
	if ((mykError = MYKONOS_enableTrackingCals(&mykDevice, trackingCalMask)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug why enableTrackingCals failed > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}
	/*** < Info: Allow Rx1/2 QEC tracking and Tx1/2 QEC tracking to run when in the radioOn state
	     *  Tx calibrations will only run if radioOn and the obsRx path is set to OBS_INTERNAL_CALS > ***/

	/*** < Info: Function to turn radio on, Enables transmitters and receivers
	 * that were setup during MYKONOS_initialize() > ***/
	if ((mykError = MYKONOS_radioOn(&mykDevice)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}

	/*** < Info: Allow TxQEC to run when User: is not actively using ORx receive path > ***/
	if ((mykError = MYKONOS_setObsRxPathSource(&mykDevice, OBS_RXOFF)) != MYKONOS_ERR_OK)
    {
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
    }
	if ((mykError = MYKONOS_setObsRxPathSource(&mykDevice, OBS_INTERNALCALS)) != MYKONOS_ERR_OK)
	{
	    /*** < Info: errorString will contain log error string in order to debug failure > ***/
        errorString = getMykonosErrorMessage(mykError);
         printf("\r%s\n\r",errorString);
	}

	printf("End of AD9371_0 chip \n\r");
	MYKONOS_jesd204bIlasCheck(&mykDevice, &mismatch);
	printf("mismatch = 0x%x\n\r",mismatch);
	printf("\rprbsErrorCount = %d\n\r",prbsErrorCount);

// AD9371_1 chip


	/*************************************************************************/
	/*****           Mykonos enable tracking calibrations                *****/
	/*************************************************************************/
	if ((mykError = MYKONOS_enableTrackingCals(&mykDevice1, trackingCalMask)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug why enableTrackingCals failed > ***/
		errorString = getMykonosErrorMessage(mykError);
		 printf("\r%s\n\r",errorString);
	}

	/*** < Info: Allow Rx1/2 QEC tracking and Tx1/2 QEC tracking to run when in the radioOn state
		 *  Tx calibrations will only run if radioOn and the obsRx path is set to OBS_INTERNAL_CALS > ***/

	/*** < Info: Function to turn radio on, Enables transmitters and receivers
	 * that were setup during MYKONOS_initialize() > ***/
	if ((mykError = MYKONOS_radioOn(&mykDevice1)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug failure > ***/
		errorString = getMykonosErrorMessage(mykError);
		 printf("\r%s\n\r",errorString);
	}

	/*** < Info: Allow TxQEC to run when User: is not actively using ORx receive path > ***/
	if ((mykError = MYKONOS_setObsRxPathSource(&mykDevice1, OBS_RXOFF)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug failure > ***/
		errorString = getMykonosErrorMessage(mykError);
		 printf("\r%s\n\r",errorString);
	}
	if ((mykError = MYKONOS_setObsRxPathSource(&mykDevice1, OBS_INTERNALCALS)) != MYKONOS_ERR_OK)
	{
		/*** < Info: errorString will contain log error string in order to debug failure > ***/
		errorString = getMykonosErrorMessage(mykError);
		 printf("\r%s\n\r",errorString);
	}

	printf("End of AD9371_1 chip \n\r");
	MYKONOS_jesd204bIlasCheck(&mykDevice1, &mismatch);

	printf("mismatch = 0x%x\n\r",mismatch);

	printf("\rprbsErrorCount = %d\n\r",prbsErrorCount);

	return 0;
}
