/*------------------------------------------------------------------------------ Copyright 2016-2019 Sony Semiconductor Solutions Corporation Last Updated : 2019/06/28 Modification ID : 4d12c6351929bcae29649d686be7d406fd4718c8 ------------------------------------------------------------------------------*/ /** @file sony_example_common.c @brief Common global variables and functions used in example files. */ /*------------------------------------------------------------------------------ Includes ------------------------------------------------------------------------------*/ #include #include #include "sony_example_common.h" #include "sat_device_ctrl/sony_demod_sat_device_ctrl.h" #if defined(SONY_EXAMPLE_LNBC_ALLEGRO_A8290) #include "allegro_a8290.h" #elif defined(SONY_EXAMPLE_LNBC_ST_LNBH23) #include "st_lnbh23.h" #elif defined(SONY_EXAMPLE_LNBC_INTERSIL_ISL9492) #include "intersil_isl9492.h" #endif /*------------------------------------------------------------------------------ Variables ------------------------------------------------------------------------------*/ const char *Common_Result[13] = {"OK", "ERROR_ARG", "ERROR_I2C", "ERROR_SW_STATE", "ERROR_HW_STATE", "ERROR_TIMEOUT", "ERROR_UNLOCK", "ERROR_RANGE", "ERROR_NOSUPPORT", "ERROR_CANCEL", "ERROR_OTHER", "ERROR_OVERFLOW", "OK_CONFIRM"}; const char *Common_System[15] = {"Unknown", "DVB-T", "DVB-T2", "DVB-C", "DVB-C2", "ATSC", "ATSC3", "ISDB-T", "ISDB-C", "J.83B", "DVB-S", "DVB-S2", "ISDB-S", "ISDB-S3", "Any"}; const char *Common_Bandwidth[11] = {"Unknown", "1.7MHz", "Invalid", "Invalid", "Invalid", "5MHz", "6MHz", "7MHz", "8MHz", "J.83B. 5.06/5.36Msps", "J.83B. 5.6Msps"}; /*------------------------------------------------------------------------------ Functions ------------------------------------------------------------------------------*/ sony_result_t sony_example_InitializeDriver (sony_example_driver_instance_t *pDriver, uint8_t enableLNBC) { sony_result_t result = SONY_RESULT_OK; sony_demod_create_param_t createParam; uint8_t enableTuner = 1; if (!pDriver) { return SONY_RESULT_ERROR_ARG; } createParam.xtalFreq = SONY_DEMOD_XTAL_24000KHz; /* 24MHz Xtal */ createParam.i2cAddressSLVT = 0xD8; /* I2C slave address is 0xD8 */ createParam.tunerI2cConfig = SONY_DEMOD_TUNER_I2C_CONFIG_REPEATER; /* I2C repeater is used */ createParam.atscCoreDisable = 0; /* ATSC 1.0 core enable */ #if defined(_WINDOWS) /* Initialize Windows USB-I2C driver */ result = drvi2c_feusb_Initialize (&pDriver->feusb); if (result != SONY_RESULT_OK) { printf ("drvi2c_feusb_Initialize failed. (%s)\n", Common_Result[result]); return result; } /* Prepare I2C struct instance for Windows USB-I2C */ result = drvi2c_feusb_CreateI2c (&pDriver->i2c, &pDriver->feusb); if (result != SONY_RESULT_OK) { printf ("drvi2c_feusb_CreateI2c failed. (%s)\n", Common_Result[result]); return result; } #else /* Add I2C initialization code for target environment */ #endif #if defined(SONY_EXAMPLE_TUNER_ASCOT3) /* Use Sony ASCOT3/3I (Terrestrial tuner) */ /* 16MHz Xtal, I2C slave address is 0xC0, IF/AGC 2 is used */ result = sony_tuner_ascot3_Create (&pDriver->tuner, SONY_ASCOT3_XTAL_16000KHz, 0xC0, &pDriver->i2c, SONY_ASCOT3_CONFIG_IFAGCSEL_ALL2, &pDriver->ascot3); if (result != SONY_RESULT_OK) { printf ("sony_tuner_ascot3_Create failed. (%s)\n", Common_Result[result]); return result; } #elif defined(SONY_EXAMPLE_TUNER_HELENE) /* Use Sony HELENE (Terrestrial/Satellite combined tuner) */ /* 16MHz Xtal, I2C slave address is 0xC0 */ result = sony_tuner_helene_Create (&pDriver->tuner, SONY_HELENE_XTAL_16000KHz, 0xC0, &pDriver->i2c, 0, &pDriver->helene); if (result != SONY_RESULT_OK) { printf ("sony_tuner_helene_Create failed. (%s)\n", Common_Result[result]); return result; } #elif defined(SONY_EXAMPLE_TUNER_HELENE2) /* Use Sony HELENE2 (Terrestrial/Satellite combined tuner) */ /* 24MHz Xtal, I2C slave address is 0xC0 */ result = sony_tuner_helene2_Create (&pDriver->tuner, SONY_HELENE2_XTAL_24000KHz, 0xC0, &pDriver->i2c, 0, &pDriver->helene2); if (result != SONY_RESULT_OK) { printf ("sony_tuner_helene2_Create failed. (%s)\n", Common_Result[result]); return result; } #elif defined(SONY_EXAMPLE_TUNER_CXD680X_SIP) /* For CXD6800, 6801, 6802 SiP setting example */ /* 24MHz Xtal, I2C slave address is 0xC0, IF/AGC 2 is used, REFOUT enable */ result = sony_tuner_ascot3_Create (&pDriver->tuner, SONY_ASCOT3_XTAL_24000KHz, 0xC0, &pDriver->i2c, SONY_ASCOT3_CONFIG_IFAGCSEL_ALL2 | SONY_ASCOT3_CONFIG_REFOUT_600mVpp, &pDriver->ascot3); if (result != SONY_RESULT_OK) { printf ("sony_tuner_ascot3_Create failed. (%s)\n", Common_Result[result]); return result; } pDriver->ascot3.xosc_cap_set = 0x28; /* For optimization */ #else /* Tuner is not controlled by this example code. */ enableTuner = 0; #endif if (enableLNBC) { #if defined(SONY_EXAMPLE_LNBC_ALLEGRO_A8290) /* Use Allegro A8290 LNB controller */ /* I2C slave address is 0x10 */ result = allegro_a8290_Create (&pDriver->lnbc, 0x10, &pDriver->i2c); if (result != SONY_RESULT_OK) { printf ("allegro_a8290_Create failed. (%s)\n", Common_Result[result]); return result; } #elif defined(SONY_EXAMPLE_LNBC_ST_LNBH23) /* Use ST LNBH23 LNB controller */ /* I2C slave address is 0x10 */ result = st_lnbh23_Create (&pDriver->lnbc, 0x10, &pDriver->i2c); if (result != SONY_RESULT_OK) { printf ("st_lnbh23_Create failed. (%s)\n", Common_Result[result]); return result; } #elif defined(SONY_EXAMPLE_LNBC_INTERSIL_ISL9492) /* Use Intersil ISL9492 LNB controller */ /* I2C slave address is 0x10 */ result = intersil_isl9492_Create (&pDriver->lnbc, 0x10, &pDriver->i2c); if (result != SONY_RESULT_OK) { printf ("intersil_isl9492_Create failed. (%s)\n", Common_Result[result]); return result; } #else /* LNBC is not controlled by this example code. */ enableLNBC = 0; #endif } /* Construct sony_integ_t and sony_demod_t instances */ result = sony_integ_Create (&pDriver->integ, &pDriver->demod, &createParam, &pDriver->i2c, (enableTuner ? &pDriver->tuner : NULL) #ifdef SONY_DEMOD_SUPPORT_SAT_DEVICE_CTRL , /* If the driver need not to control tuner, NULL can be used. */ (enableLNBC ? &pDriver->lnbc : NULL) #endif ); /* If the driver need not to control LNBC, NULL can be used. */ if (result != SONY_RESULT_OK) { printf ("sony_integ_Create failed. (%s)\n", Common_Result[result]); return result; } /* * Initialize devices. (demod, tuner, LNBC) * Following this call the driver will be in SONY_DEMOD_STATE_SLEEP state. * From here you can call any Sleep or Tune APIs. * Note : Initialize API should only be called once at the start of the driver creation. * Subsequent calls to any of the Tune API's do not require re-initialize. */ result = sony_integ_Initialize (&pDriver->integ); if (result != SONY_RESULT_OK) { printf ("sony_integ_Initialize failed. (%s)\n", Common_Result[result]); return result; } /* * In default, IF frequency is set for Sony silicon tuners. * If non-Sony tuner is used, the user should set the IF frequency like as follows. */ #if 0 { sony_demod_iffreq_config_t iffreqConfig; iffreqConfig.configDVBT_5 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.6); iffreqConfig.configDVBT_6 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.6); iffreqConfig.configDVBT_7 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.2); iffreqConfig.configDVBT_8 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.8); iffreqConfig.configDVBT2_1_7 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.5); iffreqConfig.configDVBT2_5 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.6); iffreqConfig.configDVBT2_6 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.6); iffreqConfig.configDVBT2_7 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.2); iffreqConfig.configDVBT2_8 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.8); iffreqConfig.configDVBC_6 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.7); iffreqConfig.configDVBC_7 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.9); iffreqConfig.configDVBC_8 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.9); iffreqConfig.configDVBC2_6 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.7); iffreqConfig.configDVBC2_8 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.9); iffreqConfig.configATSC = SONY_DEMOD_ATSC_MAKE_IFFREQ_CONFIG(3.7); iffreqConfig.configATSC3_6 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.6); iffreqConfig.configATSC3_7 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.2); iffreqConfig.configATSC3_8 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.8); iffreqConfig.configISDBT_6 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.55); iffreqConfig.configISDBT_7 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.15); iffreqConfig.configISDBT_8 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(4.75); iffreqConfig.configISDBC_6 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.7); iffreqConfig.configJ83B_5_06_5_36 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.7); iffreqConfig.configJ83B_5_60 = SONY_DEMOD_MAKE_IFFREQ_CONFIG(3.75); result = sony_demod_SetIFFreqConfig (&pDriver->demod, &iffreqConfig); if (result != SONY_RESULT_OK) { printf ("sony_demod_SetIFFreqConfig failed. (%s)\n", Common_Result[result]); return result; } } #endif /* * In default, The setting is optimized for Sony silicon tuners. * If non-Sony tuner is used, the user should call following to * disable Sony silicon tuner optimized setting. */ #if 0 result = sony_demod_SetConfig (&pDriver->demod, SONY_DEMOD_CONFIG_TUNER_OPTIMIZE, SONY_DEMOD_TUNER_OPTIMIZE_NONSONY); if (result != SONY_RESULT_OK) { printf ("sony_demod_SetConfig (SONY_DEMOD_CONFIG_TUNER_OPTIMIZE) failed. (%s)\n", Common_Result[result]); return result; } #endif /* * For Sony HELENE tuner, the satellite IFAGC setting should be changed. * If non-Sony tuner is used, the user should do this setting depend on the IFAGC sense of the tuner. */ #if defined(SONY_EXAMPLE_TUNER_HELENE) result = sony_demod_SetConfig (&pDriver->demod, SONY_DEMOD_CONFIG_SAT_IFAGCNEG, 1); if (result != SONY_RESULT_OK) { printf ("sony_demod_SetConfig (SONY_DEMOD_CONFIG_SAT_IFAGCNEG) failed. (%s)\n", Common_Result[result]); return result; } #endif /* * Configuration * If additional configuration is necessary, please use sony_demod_SetConfig here. * TS format, BER measurement period etc settings can be changed. * In detail, please check sony_demod.h, sony_demod_config_id_t definition. */ #if 0 /* TS clock inversion setting */ result = sony_demod_SetConfig (pTunerDemod, SONY_TUNERDEMOD_CONFIG_LATCH_ON_POSEDGE, 0); if (result != SONY_RESULT_OK) { printf ("Error : sony_demod_SetConfig failed. (result = %s)\n", Common_Result[result]); return -1; } #endif if (enableLNBC) { /* * Configure demodulator and LNB controller. * It's depend on LNB controller's specification. * (Tone generation is supported or not.) */ /* * Configure demod to output PWM. * The user can select envelope mode too. */ result = sony_demod_sat_device_ctrl_DSQOUTSetting (&pDriver->demod, SONY_DSQOUT_MODE_PWM, 22); if (result != SONY_RESULT_OK) { printf ("sony_demod_sat_device_ctrl_DSQOUTSetting failed. (%s)\n", Common_Result[result]); return result; } /* * Configure LNB controller not to generate tone by LNBC internally. * This setting should be synchronized to above demod setting. */ result = pDriver->lnbc.SetConfig(&pDriver->lnbc, SONY_LNBC_CONFIG_ID_TONE_INTERNAL, 0); if (result != SONY_RESULT_OK) { printf ("sony_demod_sat_device_ctrl_DSQOUTSetting failed. (%s)\n", Common_Result[result]); return result; } } return result; } sony_result_t sony_example_FinalizeDriver (sony_example_driver_instance_t *pDriver) { sony_result_t result = SONY_RESULT_OK; #if defined(_WINDOWS) /* Finalize Windows USB-I2C driver */ result = drvi2c_feusb_Finalize (&pDriver->feusb); if (result != SONY_RESULT_OK) { printf ("drvi2c_feusb_Finalize failed. (%s)\n", Common_Result[result]); return result; } #endif return result; }